Browse Source

test: harden learning path ordering regression

backup/master-local-20261012
pwklppg 1 month ago
parent
commit
f296df453c
  1. 55
      mydreamjob-server/src/test/java/com/mydreamjob/skill/SkillLearningPathServiceTest.java

55
mydreamjob-server/src/test/java/com/mydreamjob/skill/SkillLearningPathServiceTest.java

@ -48,6 +48,8 @@ class SkillLearningPathServiceTest {
private static final Long INDUSTRY_ID = 1L; private static final Long INDUSTRY_ID = 1L;
private static final Long OCCUPATION_ID = 1L; private static final Long OCCUPATION_ID = 1L;
private static final Long CATEGORY_ID = 101L; private static final Long CATEGORY_ID = 101L;
private static final Long EDUCATION_INDUSTRY_ID = 3L;
private static final Long INSTRUCTIONAL_DESIGNER_OCCUPATION_ID = 9L;
@Autowired @Autowired
private SkillLearningPathService learningPathService; private SkillLearningPathService learningPathService;
@ -83,6 +85,41 @@ class SkillLearningPathServiceTest {
}); });
} }
@Test
void v36LearningPathPreservesMatchOrderAcrossHeatGroupsWhenNameOrderDiffers() {
SkillMatchResponse matchResponse = matchService.match(
USER_ID, EDUCATION_INDUSTRY_ID, INSTRUCTIONAL_DESIGNER_OCCUPATION_ID, null);
SkillLearningPathResponse response = learningPathService.generate(
USER_ID, EDUCATION_INDUSTRY_ID, INSTRUCTIONAL_DESIGNER_OCCUPATION_ID, null);
List<SkillCloudItem> missingSkills = matchResponse.missingSkills();
List<String> missingNames = missingSkills.stream()
.map(SkillCloudItem::nameZh)
.toList();
List<Long> missingIds = missingSkills.stream()
.map(SkillCloudItem::skillId)
.toList();
List<BigDecimal> distinctHeats = missingSkills.stream()
.map(SkillCloudItem::heat)
.distinct()
.toList();
assertThat(missingSkills).hasSize(10);
assertThat(distinctHeats.size()).isGreaterThan(1);
assertThat(missingNames).isNotEqualTo(missingNames.stream().sorted().toList());
assertThat(missingIds).isNotEqualTo(missingIds.stream().sorted().toList());
assertThat(response.total()).isEqualTo(missingSkills.size());
assertThat(response.items())
.extracting(SkillLearningPathItem::skillId)
.containsExactlyElementsOf(missingIds);
assertThat(response.items())
.extracting(SkillLearningPathItem::skillName)
.containsExactlyElementsOf(missingNames);
assertThat(response.items())
.extracting(SkillLearningPathItem::priority)
.containsExactly(1, 2, 3, 4, 5, 6, 7, 8, 9, 10);
}
@Nested @Nested
class TemplateAndOrderingTests { class TemplateAndOrderingTests {
@ -96,10 +133,16 @@ class SkillLearningPathServiceTest {
SkillCloudItem matched = skill(11L, "Matched", "Matched", CATEGORY_ID, SkillCloudItem matched = skill(11L, "Matched", "Matched", CATEGORY_ID,
"编程语言", new BigDecimal("9.00")); "编程语言", new BigDecimal("9.00"));
List<SkillCloudItem> missing = List.of( List<SkillCloudItem> missing = List.of(
skill(31L, "First", "First", 101L, "编程语言", new BigDecimal("1.00")), skill(30L, "Skill Z", "Skill Z", 101L, "编程语言", new BigDecimal("1.00")),
skill(32L, "Second", "Second", 102L, "框架", new BigDecimal("10.00")), skill(10L, "Skill A", "Skill A", 102L, "框架", new BigDecimal("10.00")),
skill(33L, "Third", "Third", 103L, "工具", new BigDecimal("5.00")) skill(20L, "Skill M", "Skill M", 103L, "工具", new BigDecimal("5.00"))
); );
List<String> missingNames = missing.stream()
.map(SkillCloudItem::nameZh)
.toList();
List<Long> missingIds = missing.stream()
.map(SkillCloudItem::skillId)
.toList();
when(matchService.match(USER_ID, INDUSTRY_ID, OCCUPATION_ID, null)) when(matchService.match(USER_ID, INDUSTRY_ID, OCCUPATION_ID, null))
.thenReturn(matchResponse(List.of(matched), missing)); .thenReturn(matchResponse(List.of(matched), missing));
stubCategory(101L, "PROGRAMMING_LANGUAGE"); stubCategory(101L, "PROGRAMMING_LANGUAGE");
@ -109,15 +152,17 @@ class SkillLearningPathServiceTest {
SkillLearningPathResponse response = service.generate(USER_ID, INDUSTRY_ID, OCCUPATION_ID, null); SkillLearningPathResponse response = service.generate(USER_ID, INDUSTRY_ID, OCCUPATION_ID, null);
assertThat(response.total()).isEqualTo(3); assertThat(response.total()).isEqualTo(3);
assertThat(missingNames).isNotEqualTo(missingNames.stream().sorted().toList());
assertThat(missingIds).isNotEqualTo(missingIds.stream().sorted().toList());
assertThat(response.items()) assertThat(response.items())
.extracting(SkillLearningPathItem::skillId) .extracting(SkillLearningPathItem::skillId)
.containsExactly(31L, 32L, 33L); .containsExactly(30L, 10L, 20L);
assertThat(response.items()) assertThat(response.items())
.extracting(SkillLearningPathItem::priority) .extracting(SkillLearningPathItem::priority)
.containsExactly(1, 2, 3); .containsExactly(1, 2, 3);
assertThat(response.items()) assertThat(response.items())
.extracting(SkillLearningPathItem::skillName) .extracting(SkillLearningPathItem::skillName)
.containsExactly("First", "Second", "Third"); .containsExactly("Skill Z", "Skill A", "Skill M");
assertThat(response.items()) assertThat(response.items())
.noneMatch(item -> item.skillId().equals(matched.skillId())); .noneMatch(item -> item.skillId().equals(matched.skillId()));
verify(matchService).match(USER_ID, INDUSTRY_ID, OCCUPATION_ID, null); verify(matchService).match(USER_ID, INDUSTRY_ID, OCCUPATION_ID, null);

Loading…
Cancel
Save