From 351d451379d6f0cfb075df4567882ac2c86a8989 Mon Sep 17 00:00:00 2001 From: Chad Elliott Date: Mon, 30 Sep 2024 08:20:36 -0500 Subject: [PATCH] #2609 - Updated certification tests to reflect the database change to move the description into the certification and the name change for certification image URL. --- .../CertificationControllerTest.java | 54 ++++---- .../EarnedCertificationControllerTest.java | 123 ++++++------------ .../fixture/CertificationFixture.java | 19 ++- 3 files changed, 84 insertions(+), 112 deletions(-) diff --git a/server/src/test/java/com/objectcomputing/checkins/services/certification/CertificationControllerTest.java b/server/src/test/java/com/objectcomputing/checkins/services/certification/CertificationControllerTest.java index 383813567..15199dbc2 100644 --- a/server/src/test/java/com/objectcomputing/checkins/services/certification/CertificationControllerTest.java +++ b/server/src/test/java/com/objectcomputing/checkins/services/certification/CertificationControllerTest.java @@ -48,11 +48,12 @@ void testStartsEmpty() { @Test void canCreateCertification() { createDefaultCertification(); - CertificationDTO newCertification = new CertificationDTO("New Certification", "https://badge.url"); + CertificationDTO newCertification = new CertificationDTO("New Certification", "Description", "https://badge.url"); Certification createdCertification = create(newCertification); assertNotNull(createdCertification.getId()); assertEquals(newCertification.getName(), createdCertification.getName()); + assertEquals(newCertification.getDescription(), createdCertification.getDescription()); assertEquals(newCertification.getBadgeUrl(), createdCertification.getBadgeUrl()); List retrieve = certificationClient.toBlocking().retrieve(HttpRequest.GET("/").basicAuth(ADMIN_ROLE, ADMIN_ROLE), Argument.listOf(Certification.class)); @@ -61,8 +62,8 @@ void canCreateCertification() { @Test void inactiveCerificatesAreHidden() { - createCertification("Certificate"); - createCertification("Another Certificate", "https://badge.url", false); + createCertification("Certificate", "Description"); + createCertification("Another Certificate", "Description", "https://badge.url", false); List list = certificationClient.toBlocking().retrieve(HttpRequest.GET("/").basicAuth(ADMIN_ROLE, ADMIN_ROLE), Argument.listOf(Certification.class)); assertEquals(List.of("Certificate"), list.stream().map(Certification::getName).toList()); @@ -75,11 +76,12 @@ void inactiveCerificatesAreHidden() { void canCreateCertificationWithoutThePermission() { MemberProfile tim = createASecondDefaultMemberProfile(); createDefaultCertification(); - CertificationDTO newCertification = new CertificationDTO("New Certification", "https://badge.url"); + CertificationDTO newCertification = new CertificationDTO("New Certification", "Description", "https://badge.url"); Certification createdCertification = create(newCertification, tim.getWorkEmail(), MEMBER_ROLE); assertNotNull(createdCertification.getId()); assertEquals(newCertification.getName(), createdCertification.getName()); + assertEquals(newCertification.getDescription(), createdCertification.getDescription()); assertEquals(newCertification.getBadgeUrl(), createdCertification.getBadgeUrl()); List retrieve = certificationClient.toBlocking().retrieve(HttpRequest.GET("/").basicAuth(ADMIN_ROLE, ADMIN_ROLE), Argument.listOf(Certification.class)); @@ -88,26 +90,28 @@ void canCreateCertificationWithoutThePermission() { @Test void listIsOrdered() { - createCertification("Donkey husbandry"); - createCertification("Aardvark upkeep"); - createCertification("Zebu and you", "https://badge.url"); + createCertification("Donkey husbandry", "Description 1"); + createCertification("Aardvark upkeep", "Description 2"); + createCertification("Zebu and you", "Description 3", "https://badge.url"); List list = list(); assertEquals(3, list.size()); assertEquals(List.of("Aardvark upkeep", "Donkey husbandry", "Zebu and you"), list.stream().map(Certification::getName).toList()); + assertEquals(List.of("Description 2", "Description 1", "Description 3"), list.stream().map(Certification::getDescription).toList()); } @Test void canUpdate() { - Certification certification = createCertification("To update"); + Certification certification = createCertification("To update", "To describe"); - CertificationDTO update = new CertificationDTO("Updated", "https://badge.url"); + CertificationDTO update = new CertificationDTO("Updated", "Description", "https://badge.url"); Certification updated = update(certification.getId(), update); assertEquals(certification.getId(), updated.getId()); assertEquals(update.getName(), updated.getName()); + assertEquals(update.getDescription(), updated.getDescription()); assertEquals(update.getBadgeUrl(), updated.getBadgeUrl()); List list = list(); @@ -117,9 +121,9 @@ void canUpdate() { @Test void cannotUpdateWithoutThePermission() { MemberProfile tim = createASecondDefaultMemberProfile(); - Certification certification = createCertification("To update"); + Certification certification = createCertification("To update", "Description"); - CertificationDTO update = new CertificationDTO("Updated", "https://badge.url"); + CertificationDTO update = new CertificationDTO("Updated", "Description", "https://badge.url"); HttpClientResponseException e = assertThrows(HttpClientResponseException.class, () -> update(certification.getId(), update, tim.getWorkEmail(), MEMBER_ROLE)); assertEquals(HttpStatus.FORBIDDEN, e.getStatus()); @@ -128,7 +132,7 @@ void cannotUpdateWithoutThePermission() { @Test void certificationNameRequired() { HttpClientResponseException exception = assertThrows(HttpClientResponseException.class, () -> create(""" - {"badgeUrl":"badge"}""")); + {"description":"description","badgeUrl":"badge"}""")); assertEquals(HttpStatus.BAD_REQUEST, exception.getResponse().status()); assertTrue(exception.getResponse().getBody(String.class).get().contains("certification.name: must not be null"), "Validation message is as expected"); @@ -136,18 +140,18 @@ void certificationNameRequired() { @Test void certificationNameUniquenessTest() { - Certification original = createCertification("Default"); + Certification original = createCertification("Default", "Description"); // Cannot create a certification with the same name String postBody = """ - {"name":"%s"}""".formatted(original.getName()); + {"name":"%s","description":"description"}""".formatted(original.getName()); HttpClientResponseException exception = assertThrows(HttpClientResponseException.class, () -> create(postBody)); assertEquals(HttpStatus.BAD_REQUEST, exception.getResponse().status()); assertEquals("Certification with name Default already exists", exception.getMessage()); // Cannot update a certification to have the same name as another - Certification other = createCertification("Other"); + Certification other = createCertification("Other", "Description"); UUID otherId = other.getId(); HttpClientResponseException exception2 = assertThrows(HttpClientResponseException.class, () -> update(otherId, postBody)); @@ -156,53 +160,59 @@ void certificationNameUniquenessTest() { // But we can successfully rename the certification update(other.getId(), """ - {"name":"Updated"}"""); + {"name":"Updated","description":"d"}"""); // and we can update to keep the same name update(other.getId(), """ - {"name":"Updated","badgeUrl":"woo"}"""); + {"name":"Updated","description":"desc","badgeUrl":"woo"}"""); // Check the list of exceptions are as we expect List list = list(); assertEquals(2, list.size()); assertEquals(List.of("Default", "Updated"), list.stream().map(Certification::getName).toList()); + assertEquals(List.of("Description", "desc"), list.stream().map(Certification::getDescription).toList()); assertEquals(Arrays.asList(null, "woo"), list.stream().map(Certification::getBadgeUrl).toList()); } @Test void certificationsDefaultToEnabled() { Certification nameAndUrlActive = create(""" - {"name":"a","badgeUrl":"badge"}"""); + {"name":"a","description":"da","badgeUrl":"badge"}"""); assertEquals("a", nameAndUrlActive.getName()); + assertEquals("da", nameAndUrlActive.getDescription()); assertEquals("badge", nameAndUrlActive.getBadgeUrl()); assertTrue(nameAndUrlActive.isActive()); Certification nameNoUrlActive = create(""" - {"name":"b"}"""); + {"name":"b","description":"db"}"""); assertEquals("b", nameNoUrlActive.getName()); + assertEquals("db", nameNoUrlActive.getDescription()); assertNull(nameNoUrlActive.getBadgeUrl()); assertTrue(nameNoUrlActive.isActive()); Certification nameNoUrlInactive = create(""" - {"name":"c","active":"false"}"""); + {"name":"c","description":"dc","active":"false"}"""); assertEquals("c", nameNoUrlInactive.getName()); + assertEquals("dc", nameNoUrlInactive.getDescription()); assertNull(nameNoUrlInactive.getBadgeUrl()); assertFalse(nameNoUrlInactive.isActive()); Certification nameNoUrlInactiveBool = create(""" - {"name":"d","active":false}"""); + {"name":"d","description":"dd","active":false}"""); assertEquals("d", nameNoUrlInactiveBool.getName()); + assertEquals("dd", nameNoUrlInactiveBool.getDescription()); assertNull(nameNoUrlInactiveBool.getBadgeUrl()); assertFalse(nameNoUrlInactiveBool.isActive()); Certification nameUrlSetActive = create(""" - {"name":"e","badgeUrl":"badge2","active":true}"""); + {"name":"e","description":"de","badgeUrl":"badge2","active":true}"""); assertEquals("e", nameUrlSetActive.getName()); + assertEquals("de", nameUrlSetActive.getDescription()); assertEquals("badge2", nameUrlSetActive.getBadgeUrl()); assertTrue(nameUrlSetActive.isActive()); } diff --git a/server/src/test/java/com/objectcomputing/checkins/services/certification/EarnedCertificationControllerTest.java b/server/src/test/java/com/objectcomputing/checkins/services/certification/EarnedCertificationControllerTest.java index 9acf9840e..0cbd8b3f8 100644 --- a/server/src/test/java/com/objectcomputing/checkins/services/certification/EarnedCertificationControllerTest.java +++ b/server/src/test/java/com/objectcomputing/checkins/services/certification/EarnedCertificationControllerTest.java @@ -56,16 +56,15 @@ void canCreateEarnedCertificationForSelf() { MemberProfile member = createADefaultMemberProfile(); Certification certification = createDefaultCertification(); LocalDate earnedDate = LocalDate.now(); - EarnedCertificationDTO newEarnedCertification = new EarnedCertificationDTO(member.getId(), certification.getId(), "Description", earnedDate); + EarnedCertificationDTO newEarnedCertification = new EarnedCertificationDTO(member.getId(), certification.getId(), earnedDate); EarnedCertification created = create(newEarnedCertification, member.getWorkEmail(), MEMBER_ROLE); assertNotNull(created.getId()); assertEquals(member.getId(), created.getMemberId()); assertEquals(certification.getId(), created.getCertificationId()); - assertEquals("Description", created.getDescription()); assertEquals(earnedDate, created.getEarnedDate()); assertNull(created.getExpirationDate()); - assertNull(created.getCertificateImageUrl()); + assertNull(created.getValidationUrl()); } @Test @@ -73,16 +72,15 @@ void canCreateEarnedCertificationForOtherIfRoleApplied() { MemberProfile member = createADefaultMemberProfile(); Certification certification = createDefaultCertification(); LocalDate earnedDate = LocalDate.now(); - EarnedCertificationDTO newEarnedCertification = new EarnedCertificationDTO(member.getId(), certification.getId(), "Description", earnedDate); + EarnedCertificationDTO newEarnedCertification = new EarnedCertificationDTO(member.getId(), certification.getId(), earnedDate); EarnedCertification created = create(newEarnedCertification, ADMIN_ROLE, ADMIN_ROLE); assertNotNull(created.getId()); assertEquals(member.getId(), created.getMemberId()); assertEquals(certification.getId(), created.getCertificationId()); - assertEquals("Description", created.getDescription()); assertEquals(earnedDate, created.getEarnedDate()); assertNull(created.getExpirationDate()); - assertNull(created.getCertificateImageUrl()); + assertNull(created.getValidationUrl()); } @Test @@ -91,7 +89,7 @@ void cannotCreateEarnedCertificationForOther() { MemberProfile tim = memberWithoutBoss("Tim"); Certification certification = createDefaultCertification(); LocalDate earnedDate = LocalDate.now(); - EarnedCertificationDTO newEarnedCertification = new EarnedCertificationDTO(member.getId(), certification.getId(), "Description", earnedDate); + EarnedCertificationDTO newEarnedCertification = new EarnedCertificationDTO(member.getId(), certification.getId(), earnedDate); HttpClientResponseException thrown = assertThrows(HttpClientResponseException.class, () -> create(newEarnedCertification, tim.getWorkEmail(), MEMBER_ROLE)); assertEquals(HttpStatus.BAD_REQUEST, thrown.getStatus()); @@ -103,12 +101,11 @@ void canUpdateEarnedCertification() { MemberProfile member = createADefaultMemberProfile(); Certification certification = createDefaultCertification(); LocalDate earnedDate = LocalDate.now(); - EarnedCertification earnedCertification = createEarnedCertification(member, certification, "Description", earnedDate); + EarnedCertification earnedCertification = createEarnedCertification(member, certification, earnedDate); EarnedCertificationDTO update = new EarnedCertificationDTO( member.getId(), certification.getId(), - "Updated description", earnedDate.minusDays(1), earnedDate.plusYears(2), "https://certificate.url" @@ -118,10 +115,9 @@ void canUpdateEarnedCertification() { assertEquals(earnedCertification.getId(), updated.getId()); assertEquals(member.getId(), updated.getMemberId()); assertEquals(certification.getId(), updated.getCertificationId()); - assertEquals("Updated description", updated.getDescription()); assertEquals(earnedDate.minusDays(1), updated.getEarnedDate()); assertEquals(earnedDate.plusYears(2), updated.getExpirationDate()); - assertEquals("https://certificate.url", updated.getCertificateImageUrl()); + assertEquals("https://certificate.url", updated.getValidationUrl()); } @Test @@ -129,12 +125,11 @@ void canUpdateEarnedCertificationForOthersIfHavePermission() { MemberProfile member = createADefaultMemberProfile(); Certification certification = createDefaultCertification(); LocalDate earnedDate = LocalDate.now(); - EarnedCertification earnedCertification = createEarnedCertification(member, certification, "Description", earnedDate); + EarnedCertification earnedCertification = createEarnedCertification(member, certification, earnedDate); EarnedCertificationDTO update = new EarnedCertificationDTO( member.getId(), certification.getId(), - "Updated description", earnedDate.minusDays(1), earnedDate.plusYears(2), "https://certificate.url" @@ -144,10 +139,9 @@ void canUpdateEarnedCertificationForOthersIfHavePermission() { assertEquals(earnedCertification.getId(), updated.getId()); assertEquals(member.getId(), updated.getMemberId()); assertEquals(certification.getId(), updated.getCertificationId()); - assertEquals("Updated description", updated.getDescription()); assertEquals(earnedDate.minusDays(1), updated.getEarnedDate()); assertEquals(earnedDate.plusYears(2), updated.getExpirationDate()); - assertEquals("https://certificate.url", updated.getCertificateImageUrl()); + assertEquals("https://certificate.url", updated.getValidationUrl()); } @Test @@ -156,12 +150,11 @@ void cannotUpdateEarnedCertificationForOthers() { MemberProfile tim = memberWithoutBoss("Tim"); Certification certification = createDefaultCertification(); LocalDate earnedDate = LocalDate.now(); - EarnedCertification earnedCertification = createEarnedCertification(member, certification, "Description", earnedDate); + EarnedCertification earnedCertification = createEarnedCertification(member, certification, earnedDate); EarnedCertificationDTO update = new EarnedCertificationDTO( member.getId(), certification.getId(), - "Updated description", earnedDate.minusDays(1), earnedDate.plusYears(2), "https://certificate.url" @@ -177,13 +170,12 @@ void cannotUpdateEarnedCertificationToSomeoneElse() { MemberProfile sarah = memberWithoutBoss("Sarah"); Certification certification = createDefaultCertification(); - EarnedCertification sarahsCertification = createEarnedCertification(sarah, certification, "Description", LocalDate.now()); + EarnedCertification sarahsCertification = createEarnedCertification(sarah, certification, LocalDate.now()); // Try to change the owner to me EarnedCertificationDTO update = new EarnedCertificationDTO( tim.getId(), sarahsCertification.getCertificationId(), - sarahsCertification.getDescription(), sarahsCertification.getEarnedDate() ); HttpClientResponseException exception = assertThrows(HttpClientResponseException.class, () -> @@ -201,13 +193,12 @@ void cannotUpdateSomeoneElsesEarnedCertificateToMe() { MemberProfile sarah = memberWithoutBoss("Sarah"); Certification certification = createDefaultCertification(); - EarnedCertification sarahsCertification = createEarnedCertification(sarah, certification, "Description", LocalDate.now()); + EarnedCertification sarahsCertification = createEarnedCertification(sarah, certification, LocalDate.now()); // Try to change the owner to me EarnedCertificationDTO update = new EarnedCertificationDTO( tim.getId(), sarahsCertification.getCertificationId(), - sarahsCertification.getDescription(), sarahsCertification.getEarnedDate() ); HttpClientResponseException exception = assertThrows(HttpClientResponseException.class, () -> @@ -224,7 +215,7 @@ void canDeleteEarnedCertificationWithRole() { MemberProfile member = createADefaultMemberProfile(); Certification certification = createDefaultCertification(); LocalDate earnedDate = LocalDate.now(); - EarnedCertification earnedCertification = createEarnedCertification(member, certification, "Description", earnedDate); + EarnedCertification earnedCertification = createEarnedCertification(member, certification, earnedDate); HttpResponse exchange = earnedCertificationClient.toBlocking().exchange(HttpRequest.DELETE("/%s".formatted(earnedCertification.getId())).basicAuth(ADMIN_ROLE, ADMIN_ROLE)); assertEquals(HttpStatus.OK, exchange.getStatus()); @@ -238,7 +229,7 @@ void canDeleteOwnEarnedCertification() { MemberProfile member = createADefaultMemberProfile(); Certification certification = createDefaultCertification(); LocalDate earnedDate = LocalDate.now(); - EarnedCertification earnedCertification = createEarnedCertification(member, certification, "Description", earnedDate); + EarnedCertification earnedCertification = createEarnedCertification(member, certification, earnedDate); HttpResponse exchange = earnedCertificationClient.toBlocking().exchange(HttpRequest.DELETE("/%s".formatted(earnedCertification.getId())).basicAuth(member.getWorkEmail(), MEMBER_ROLE)); assertEquals(HttpStatus.OK, exchange.getStatus()); @@ -253,7 +244,7 @@ void cannotDeleteOthersEarnedCertification() { MemberProfile tim = memberWithoutBoss("Tim"); Certification certification = createDefaultCertification(); LocalDate earnedDate = LocalDate.now(); - EarnedCertification earnedCertification = createEarnedCertification(member, certification, "Description", earnedDate); + EarnedCertification earnedCertification = createEarnedCertification(member, certification, earnedDate); HttpClientResponseException exception = assertThrows(HttpClientResponseException.class, () -> earnedCertificationClient.toBlocking().exchange(HttpRequest.DELETE("/%s".formatted(earnedCertification.getId())).basicAuth(tim.getWorkEmail(), MEMBER_ROLE))); @@ -275,7 +266,7 @@ void checkValidation() { MemberProfile member = createADefaultMemberProfile(); Certification certification = createDefaultCertification(); LocalDate earnedDate = LocalDate.now(); - EarnedCertificationDTO newEarnedCertification = new EarnedCertificationDTO(member.getId(), certification.getId(), "Description", earnedDate); + EarnedCertificationDTO newEarnedCertification = new EarnedCertificationDTO(member.getId(), certification.getId(), earnedDate); // No member ID newEarnedCertification.setMemberId(null); @@ -292,23 +283,7 @@ void checkValidation() { body = exception.getResponse().getBody(String.class).get(); assertTrue(body.contains("certification.certificationId: must not be null"), body + " should contain 'certification.certificationId: must not be null'"); - // Null description - newEarnedCertification.setCertificationId(certification.getId()); - newEarnedCertification.setDescription(null); - exception = assertThrows(HttpClientResponseException.class, () -> create(newEarnedCertification, member.getWorkEmail(), MEMBER_ROLE)); - assertEquals(HttpStatus.BAD_REQUEST, exception.getStatus()); - body = exception.getResponse().getBody(String.class).get(); - assertTrue(body.contains("certification.description: must not be blank"), body + " should contain 'certification.description: must not be null'"); - - // Empty description - newEarnedCertification.setDescription(""); - exception = assertThrows(HttpClientResponseException.class, () -> create(newEarnedCertification, member.getWorkEmail(), MEMBER_ROLE)); - assertEquals(HttpStatus.BAD_REQUEST, exception.getStatus()); - body = exception.getResponse().getBody(String.class).get(); - assertTrue(body.contains("certification.description: must not be blank"), body + " should contain 'certification.description: must not be null'"); - // No earned date - newEarnedCertification.setDescription("Description"); newEarnedCertification.setEarnedDate(null); exception = assertThrows(HttpClientResponseException.class, () -> create(newEarnedCertification, member.getWorkEmail(), MEMBER_ROLE)); assertEquals(HttpStatus.BAD_REQUEST, exception.getStatus()); @@ -318,23 +293,22 @@ void checkValidation() { void canFindAllEarnedCertifications() { MemberProfile tim = memberWithoutBoss("Tim"); MemberProfile sarah = memberWithoutBoss("Sarah"); - Certification source = createCertification("Source"); - Certification target = createCertification("Target"); - createEarnedCertification(tim, source, "Tim's source certification", LocalDate.now().minusDays(1)); - createEarnedCertification(tim, target, "Tim's target certification", LocalDate.now().minusDays(10)); - createEarnedCertification(sarah, target, "Sarah's target certification", LocalDate.now()); + Certification source = createCertification("Source", "Source certification"); + Certification target = createCertification("Target", "Target certification"); + createEarnedCertification(tim, source, LocalDate.now().minusDays(1)); + createEarnedCertification(tim, target, LocalDate.now().minusDays(10)); + createEarnedCertification(sarah, target, LocalDate.now()); List list = earnedCertificationClient.toBlocking().retrieve(HttpRequest.GET("/").basicAuth(MEMBER_ROLE, MEMBER_ROLE), Argument.listOf(EarnedCertification.class)); assertEquals(3, list.size()); - assertEquals(List.of("Sarah's target certification", "Tim's source certification", "Tim's target certification"), list.stream().map(EarnedCertification::getDescription).toList()); } @Test void sensibleOutputForInvalidMemberId() { Certification certification = createDefaultCertification(); UUID memberId = UUID.randomUUID(); - EarnedCertificationDTO newEarnedCertification = new EarnedCertificationDTO(memberId, certification.getId(), "Description", LocalDate.now()); + EarnedCertificationDTO newEarnedCertification = new EarnedCertificationDTO(memberId, certification.getId(), LocalDate.now()); HttpClientResponseException exception = assertThrows(HttpClientResponseException.class, () -> create(newEarnedCertification, ADMIN_ROLE, ADMIN_ROLE)); assertEquals(HttpStatus.BAD_REQUEST, exception.getStatus()); @@ -345,7 +319,7 @@ void sensibleOutputForInvalidMemberId() { void sensibleOutputForInvalidCertificateId() { MemberProfile member = createADefaultMemberProfile(); UUID certificationId = UUID.randomUUID(); - EarnedCertificationDTO newEarnedCertification = new EarnedCertificationDTO(member.getId(), certificationId, "Description", LocalDate.now()); + EarnedCertificationDTO newEarnedCertification = new EarnedCertificationDTO(member.getId(), certificationId, LocalDate.now()); HttpClientResponseException exception = assertThrows(HttpClientResponseException.class, () -> create(newEarnedCertification, member.getWorkEmail(), MEMBER_ROLE)); assertEquals(HttpStatus.BAD_REQUEST, exception.getStatus()); @@ -356,77 +330,70 @@ void sensibleOutputForInvalidCertificateId() { void canFindEarnedCertificationsByCertification() { MemberProfile tim = memberWithoutBoss("Tim"); MemberProfile sarah = memberWithoutBoss("Sarah"); - Certification source = createCertification("Source"); - Certification target = createCertification("Target"); - createEarnedCertification(tim, source, "Tim's source certification", LocalDate.now().minusDays(1)); - createEarnedCertification(tim, target, "Tim's target certification", LocalDate.now().minusDays(10)); - createEarnedCertification(sarah, target, "Sarah's target certification", LocalDate.now()); + Certification source = createCertification("Source", "Source certification"); + Certification target = createCertification("Target", "Target certification"); + createEarnedCertification(tim, source, LocalDate.now().minusDays(1)); + createEarnedCertification(tim, target, LocalDate.now().minusDays(10)); + createEarnedCertification(sarah, target, LocalDate.now()); List sourceCertifications = earnedCertificationClient.toBlocking().retrieve(HttpRequest.GET("/?certificationId=%s".formatted(source.getId())).basicAuth(MEMBER_ROLE, MEMBER_ROLE), Argument.listOf(EarnedCertification.class)); assertEquals(1, sourceCertifications.size()); - assertEquals("Tim's source certification", sourceCertifications.getFirst().getDescription()); List targetCertifications = earnedCertificationClient.toBlocking().retrieve(HttpRequest.GET("/?certificationId=%s".formatted(target.getId())).basicAuth(MEMBER_ROLE, MEMBER_ROLE), Argument.listOf(EarnedCertification.class)); assertEquals(2, targetCertifications.size()); - assertEquals(List.of("Sarah's target certification", "Tim's target certification"), targetCertifications.stream().map(EarnedCertification::getDescription).toList()); } @Test void canFindEarnedCertificationsByMember() { MemberProfile tim = memberWithoutBoss("Tim"); MemberProfile sarah = memberWithoutBoss("Sarah"); - Certification source = createCertification("Source"); - Certification target = createCertification("Target"); - createEarnedCertification(tim, source, "Tim's source certification", LocalDate.now().minusDays(1)); - createEarnedCertification(tim, target, "Tim's target certification", LocalDate.now().minusDays(10)); - createEarnedCertification(sarah, target, "Sarah's target certification", LocalDate.now()); + Certification source = createCertification("Source", "Source certification"); + Certification target = createCertification("Target", "Target certification"); + createEarnedCertification(tim, source, LocalDate.now().minusDays(1)); + createEarnedCertification(tim, target, LocalDate.now().minusDays(10)); + createEarnedCertification(sarah, target, LocalDate.now()); List timCertifications = earnedCertificationClient.toBlocking().retrieve(HttpRequest.GET("/?memberId=%s".formatted(tim.getId())).basicAuth(MEMBER_ROLE, MEMBER_ROLE), Argument.listOf(EarnedCertification.class)); assertEquals(2, timCertifications.size()); - assertEquals(List.of("Tim's source certification", "Tim's target certification"), timCertifications.stream().map(EarnedCertification::getDescription).toList()); List sarahCertifications = earnedCertificationClient.toBlocking().retrieve(HttpRequest.GET("/?memberId=%s".formatted(sarah.getId())).basicAuth(MEMBER_ROLE, MEMBER_ROLE), Argument.listOf(EarnedCertification.class)); assertEquals(1, sarahCertifications.size()); - assertEquals("Sarah's target certification", sarahCertifications.getFirst().getDescription()); } @Test void canFindEarnedCertificationsByMemberAndCertification() { MemberProfile tim = memberWithoutBoss("Tim"); MemberProfile sarah = memberWithoutBoss("Sarah"); - Certification source = createCertification("Source"); - Certification target = createCertification("Target"); - createEarnedCertification(tim, source, "Tim's source certification", LocalDate.now().minusDays(1)); - createEarnedCertification(tim, target, "Tim's target certification", LocalDate.now().minusDays(10)); - createEarnedCertification(sarah, target, "Sarah's target certification", LocalDate.now()); + Certification source = createCertification("Source", "Source certification"); + Certification target = createCertification("Target", "Target certification"); + createEarnedCertification(tim, source, LocalDate.now().minusDays(1)); + createEarnedCertification(tim, target, LocalDate.now().minusDays(10)); + createEarnedCertification(sarah, target, LocalDate.now()); List timSource = earnedCertificationClient.toBlocking().retrieve(HttpRequest.GET("/?memberId=%s&certificationId=%s".formatted(tim.getId(), source.getId())).basicAuth(MEMBER_ROLE, MEMBER_ROLE), Argument.listOf(EarnedCertification.class)); assertEquals(1, timSource.size()); - assertEquals("Tim's source certification", timSource.getFirst().getDescription()); List timTarget = earnedCertificationClient.toBlocking().retrieve(HttpRequest.GET("/?memberId=%s&certificationId=%s".formatted(tim.getId(), target.getId())).basicAuth(MEMBER_ROLE, MEMBER_ROLE), Argument.listOf(EarnedCertification.class)); assertEquals(1, timTarget.size()); - assertEquals("Tim's target certification", timTarget.getFirst().getDescription()); } @Test void canMerge() { MemberProfile tim = memberWithoutBoss("Tim"); MemberProfile sarah = memberWithoutBoss("Sarah"); - Certification source = createCertification("Source"); - Certification target = createCertification("Target"); - createEarnedCertification(tim, source, "Tim's source certification", LocalDate.now().minusDays(1)); - createEarnedCertification(tim, target, "Tim's target certification", LocalDate.now().minusDays(10)); - createEarnedCertification(sarah, target, "Sarah's target certification", LocalDate.now()); + Certification source = createCertification("Source", "Source certification"); + Certification target = createCertification("Target", "Target certification"); + createEarnedCertification(tim, source, LocalDate.now().minusDays(1)); + createEarnedCertification(tim, target, LocalDate.now().minusDays(10)); + createEarnedCertification(sarah, target, LocalDate.now()); // Tim has one certification assigned from the source certification List list = earnedCertificationClient.toBlocking().retrieve(HttpRequest.GET("/?memberId=%s".formatted(tim.getId())).basicAuth(tim.getWorkEmail(), MEMBER_ROLE), Argument.listOf(EarnedCertification.class)); assertEquals(2, list.size()); assertEquals(source.getId(), list.getFirst().getCertificationId()); assertEquals(target.getId(), list.getLast().getCertificationId()); - assertEquals(List.of("Tim's source certification", "Tim's target certification"), list.stream().map(EarnedCertification::getDescription).toList()); CertificationMergeDTO mergeDTO = new CertificationMergeDTO(source.getId(), target.getId()); @@ -443,7 +410,6 @@ void canMerge() { assertEquals(2, list.size()); assertEquals(target.getId(), list.getFirst().getCertificationId()); assertEquals(target.getId(), list.getLast().getCertificationId()); - assertEquals(List.of("Tim's source certification", "Tim's target certification"), list.stream().map(EarnedCertification::getDescription).toList()); // And when we list all of them, we should see that the source certification is gone List certificationList = certificationClient.toBlocking().retrieve(HttpRequest.GET("/").basicAuth(tim.getWorkEmail(), MEMBER_ROLE), Argument.listOf(Certification.class)); @@ -454,9 +420,6 @@ void canMerge() { List earnedCertifications = earnedCertificationClient.toBlocking().retrieve(HttpRequest.GET("/").basicAuth(tim.getWorkEmail(), MEMBER_ROLE), Argument.listOf(EarnedCertification.class)); assertEquals(3, earnedCertifications.size()); assertAll(earnedCertifications.stream().map(c -> () -> assertEquals(target.getId(), c.getCertificationId()))); - - // And they are sorted by earned date descending - assertEquals(List.of("Sarah's target certification", "Tim's source certification", "Tim's target certification"), earnedCertifications.stream().map(EarnedCertification::getDescription).toList()); } @Test diff --git a/server/src/test/java/com/objectcomputing/checkins/services/fixture/CertificationFixture.java b/server/src/test/java/com/objectcomputing/checkins/services/fixture/CertificationFixture.java index 3d8e8705a..75182a955 100644 --- a/server/src/test/java/com/objectcomputing/checkins/services/fixture/CertificationFixture.java +++ b/server/src/test/java/com/objectcomputing/checkins/services/fixture/CertificationFixture.java @@ -9,30 +9,29 @@ public interface CertificationFixture extends RepositoryFixture { default Certification createDefaultCertification() { - return createCertification("Default", "Default Badge URL"); + return createCertification("Default", "Description", "Default Badge URL"); } - default Certification createCertification(String name) { - return createCertification(name, null); + default Certification createCertification(String name, String description) { + return createCertification(name, description, null); } - default Certification createCertification(String name, String badgeUrl) { - return createCertification(name, badgeUrl, true); + default Certification createCertification(String name, String description, String badgeUrl) { + return createCertification(name, description, badgeUrl, true); } - default Certification createCertification(String name, String badgeUrl, boolean active) { - return getCertificationRepository().save(new Certification(name, badgeUrl, active)); + default Certification createCertification(String name, String description, String badgeUrl, boolean active) { + return getCertificationRepository().save(new Certification(name, description, badgeUrl, active)); } default EarnedCertification createEarnedCertification(MemberProfile member, Certification certification) { - return createEarnedCertification(member, certification, "Default Earned certification", LocalDate.now()); + return createEarnedCertification(member, certification, LocalDate.now()); } - default EarnedCertification createEarnedCertification(MemberProfile member, Certification certification, String description, LocalDate earnedDate) { + default EarnedCertification createEarnedCertification(MemberProfile member, Certification certification, LocalDate earnedDate) { return getEarnedCertificationRepository().save(new EarnedCertification( member.getId(), certification.getId(), - description, earnedDate, null, null