diff --git a/service/src/main/java/skills/skillLoading/SubjectDataLoader.groovy b/service/src/main/java/skills/skillLoading/SubjectDataLoader.groovy index 832777be23..988804ea3b 100644 --- a/service/src/main/java/skills/skillLoading/SubjectDataLoader.groovy +++ b/service/src/main/java/skills/skillLoading/SubjectDataLoader.groovy @@ -184,8 +184,11 @@ class SubjectDataLoader { def expiredSkills = expiredUserAchievementRepo.findMostRecentExpirationForAllSkills(projectId, userId, skillIds) if (expiredSkills) { skillsAndPoints.each { it -> - def expirationInfo = expiredSkills.find{ skill -> skill.skillId == it.skillDef.skillId } - it.expiredOn = expirationInfo?.expiredOn + def expirations = expiredSkills.findAll{skill -> skill.skillId == it.skillDef.skillId} + if(expirations) { + expirations?.sort { skill -> skill.expiredOn } + it.expiredOn = expirations.first()?.expiredOn + } } } } diff --git a/service/src/test/java/skills/intTests/skillExpiration/PostAchievementSkillExpirationSpecs.groovy b/service/src/test/java/skills/intTests/skillExpiration/PostAchievementSkillExpirationSpecs.groovy index e7f4c27908..50d7bb091c 100644 --- a/service/src/test/java/skills/intTests/skillExpiration/PostAchievementSkillExpirationSpecs.groovy +++ b/service/src/test/java/skills/intTests/skillExpiration/PostAchievementSkillExpirationSpecs.groovy @@ -1971,6 +1971,83 @@ class PostAchievementSkillExpirationSpecs extends DefaultIntSpec { def subjectInfo = skillsService.getSkillSummary(userId, proj.projectId, subj.subjectId) then: - subjectInfo.skills.lastExpiredDate != null + subjectInfo.skills.lastExpirationDate != null + } + + def "achieve skill after expiration and get subject summary"() { + def proj = SkillsFactory.createProject() + def subj = SkillsFactory.createSubject() + def skills = SkillsFactory.createSkills(10, ) + + skillsService.createProject(proj) + skillsService.createSubject(subj) + skillsService.createSkills(skills) + + Map badge = [projectId: proj.projectId, badgeId: 'badge1', name: 'Test Badge 1'] + skillsService.addBadge(badge) + skillsService.assignSkillToBadge(projectId: proj.projectId, badgeId: badge.badgeId, skillId: skills[0].skillId) + badge.enabled = 'true' + skillsService.updateBadge(badge, badge.badgeId) + + String userId = "user1" + + setup: + skills.forEach { it -> + skillsService.addSkill([projectId: proj.projectId, skillId: it.skillId], userId, new Date() - 21) + skillsService.addSkill([projectId: proj.projectId, skillId: it.skillId], userId, new Date() - 20) + } + + when: + expireSkills(proj.projectId, skills) + def subjectInfo = skillsService.getSkillSummary(userId, proj.projectId, subj.subjectId) + skillsService.addSkill([projectId: proj.projectId, skillId: skills[0].skillId], userId, new Date() - 8) + skillsService.addSkill([projectId: proj.projectId, skillId: skills[0].skillId], userId, new Date() - 9) + def laterSubjectInfo = skillsService.getSkillSummary(userId, proj.projectId, subj.subjectId) + + then: + subjectInfo.skills.lastExpirationDate != null + laterSubjectInfo.skills[0].lastExpirationDate == null + } + + def "with multiple expirations, latest expiration is returned in subject summary"() { + def proj = SkillsFactory.createProject() + def subj = SkillsFactory.createSubject() + def skills = SkillsFactory.createSkills(10, ) + + skillsService.createProject(proj) + skillsService.createSubject(subj) + skillsService.createSkills(skills) + + Map badge = [projectId: proj.projectId, badgeId: 'badge1', name: 'Test Badge 1'] + skillsService.addBadge(badge) + skillsService.assignSkillToBadge(projectId: proj.projectId, badgeId: badge.badgeId, skillId: skills[0].skillId) + badge.enabled = 'true' + skillsService.updateBadge(badge, badge.badgeId) + + String userId = "user1" + + setup: + skills.forEach { it -> + skillsService.addSkill([projectId: proj.projectId, skillId: it.skillId], userId, new Date() - 31) + skillsService.addSkill([projectId: proj.projectId, skillId: it.skillId], userId, new Date() - 30) + } + + when: + expireSkills(proj.projectId, skills) + def subjectInfo = skillsService.getSkillSummary(userId, proj.projectId, subj.subjectId) + skillsService.addSkill([projectId: proj.projectId, skillId: skills[0].skillId], userId, new Date() - 20) + skillsService.addSkill([projectId: proj.projectId, skillId: skills[0].skillId], userId, new Date() - 19) + expireSkills(proj.projectId, skills) + def secondSubjectInfo = skillsService.getSkillSummary(userId, proj.projectId, subj.subjectId) + skillsService.addSkill([projectId: proj.projectId, skillId: skills[0].skillId], userId, new Date() - 9) + skillsService.addSkill([projectId: proj.projectId, skillId: skills[0].skillId], userId, new Date() - 8) + expireSkills(proj.projectId, skills) + def laterSubjectInfo = skillsService.getSkillSummary(userId, proj.projectId, subj.subjectId) + + then: + laterSubjectInfo.skills[0].lastExpirationDate != null + subjectInfo.skills[0].lastExpirationDate != laterSubjectInfo.skills[0].lastExpirationDate != null + secondSubjectInfo.skills[0].lastExpirationDate != laterSubjectInfo.skills[0].lastExpirationDate != null + subjectInfo.skills[0].lastExpirationDate != secondSubjectInfo.skills[0].lastExpirationDate != null } }