|
|
|
|
@ -33,6 +33,13 @@ class MarketOpportunitySelectionStepThreeServiceImplTest {
|
|
|
|
|
MarketOpportunitySelectionStepThreeServiceImpl service = new MarketOpportunitySelectionStepThreeServiceImpl(); StudentTrainingAnswerService answers = mock(StudentTrainingAnswerService.class); ReflectionTestUtils.setField(service, "studentTrainingAnswerService", answers); when(answers.get(anyString(), any(), any(JwtUser.class))).thenReturn(null);
|
|
|
|
|
assertThrows(ServiceException.class, () -> service.validate(completedRequest(), student()));
|
|
|
|
|
}
|
|
|
|
|
@Test
|
|
|
|
|
void validateRejectsUnknownOrDuplicateProductCategories() {
|
|
|
|
|
MarketOpportunitySelectionStepThreeValidationRequest unknownCategory = completedRequest(); unknownCategory.getScores().get(2).setId("unknown-category");
|
|
|
|
|
assertThrows(ServiceException.class, () -> serviceWithStepTwo().validate(unknownCategory, student()));
|
|
|
|
|
MarketOpportunitySelectionStepThreeValidationRequest duplicateCategory = completedRequest(); duplicateCategory.getScores().get(2).setId("smart-fitness-mirror");
|
|
|
|
|
assertThrows(ServiceException.class, () -> serviceWithStepTwo().validate(duplicateCategory, student()));
|
|
|
|
|
}
|
|
|
|
|
private MarketOpportunitySelectionStepThreeServiceImpl serviceWithStepTwo() { MarketOpportunitySelectionStepThreeServiceImpl service = new MarketOpportunitySelectionStepThreeServiceImpl(); StudentTrainingAnswerService answers = mock(StudentTrainingAnswerService.class); StudentTrainingAnswer answer = new StudentTrainingAnswer(); answer.setStep2Answer("{\"primaryWeights\":{\"市场规模\":25,\"市场潜力\":25,\"竞争强度\":25,\"运营难度\":25},\"dimensionWeights\":{\"search-count\":50,\"transaction-amount\":50,\"transaction-growth\":50,\"category-transaction-growth\":50,\"demand-supply-ratio\":34,\"online-products\":33,\"online-merchants\":33,\"organic-traffic-ratio\":50,\"return-rate\":50}}"); when(answers.get(anyString(), any(), any(JwtUser.class))).thenReturn(answer); ReflectionTestUtils.setField(service, "studentTrainingAnswerService", answers); return service; }
|
|
|
|
|
private MarketOpportunitySelectionStepThreeValidationRequest completedRequest() { MarketOpportunitySelectionStepThreeValidationRequest request = new MarketOpportunitySelectionStepThreeValidationRequest(); ArrayList<MarketOpportunitySelectionStepThreeValidationRequest.Score> scores = new ArrayList<>(); Arrays.asList("smart-fitness-mirror", "smart-bathroom-mirror", "smart-beauty-mirror").forEach(id -> { MarketOpportunitySelectionStepThreeValidationRequest.Score score = new MarketOpportunitySelectionStepThreeValidationRequest.Score(); score.setId(id); score.setScore(new BigDecimal("86.50")); scores.add(score); }); request.setScores(scores); return request; }
|
|
|
|
|
private JwtUser student() { JwtUser user = new JwtUser(); user.setUserId("stu-1"); user.setRoleId(4); return user; }
|
|
|
|
|
|