diff --git a/server/src/main/java/com/objectcomputing/checkins/services/pulseresponse/PulseResponse.java b/server/src/main/java/com/objectcomputing/checkins/services/pulseresponse/PulseResponse.java index d0ae99d3f1..5c47607036 100644 --- a/server/src/main/java/com/objectcomputing/checkins/services/pulseresponse/PulseResponse.java +++ b/server/src/main/java/com/objectcomputing/checkins/services/pulseresponse/PulseResponse.java @@ -2,6 +2,7 @@ import com.objectcomputing.checkins.converter.LocalDateConverter; import io.micronaut.core.annotation.Introspected; +import io.micronaut.core.annotation.Nullable; import io.micronaut.data.annotation.AutoPopulated; import io.micronaut.data.annotation.TypeDef; import io.micronaut.data.annotation.sql.ColumnTransformer; @@ -23,7 +24,6 @@ @Entity @Getter @Setter -@NoArgsConstructor @Introspected @Table(name = "pulse_response") public class PulseResponse { @@ -35,18 +35,22 @@ public class PulseResponse { @Schema(description = "the id of the pulse_response") private UUID id; + @Column(name="internal_score") + @NotNull + @Schema(description = "integer for internalScore", required = true) + private Integer internalScore; + + @Column(name="external_score") + @Nullable + @Schema(description = "integer for externalScore", required = true) + private Integer externalScore; + @Column(name="submissiondate") @NotNull @Schema(description = "date for submissionDate") @TypeDef(type = DataType.DATE, converter = LocalDateConverter.class) private LocalDate submissionDate; - @Column(name="updateddate") - @NotNull - @Schema(description = "date for updatedDate") - @TypeDef(type = DataType.DATE, converter = LocalDateConverter.class) - private LocalDate updatedDate; - @Column(name="teammemberid") @TypeDef(type=DataType.STRING) @NotNull @@ -58,7 +62,7 @@ public class PulseResponse { read = "pgp_sym_decrypt(internalFeelings::bytea,'${aes.key}')", write = "pgp_sym_encrypt(?,'${aes.key}') " ) - @NotNull + @Nullable @Schema(description = "description of internalfeelings") private String internalFeelings; @@ -67,21 +71,81 @@ public class PulseResponse { read = "pgp_sym_decrypt(externalFeelings::bytea,'${aes.key}')", write = "pgp_sym_encrypt(?,'${aes.key}') " ) - @NotNull + @Nullable @Schema(description = "description of externalfeelings") private String externalFeelings; - public PulseResponse(UUID id,LocalDate submissionDate,LocalDate updatedDate, UUID teamMemberId, String internalFeelings, String externalFeelings) { + protected PulseResponse() { + } + + public PulseResponse(UUID id, Integer internalScore, Integer externalScore, LocalDate submissionDate, UUID teamMemberId, String internalFeelings, String externalFeelings) { this.id = id; + this.internalScore = internalScore; + this.externalScore = externalScore; this.submissionDate = submissionDate; - this.updatedDate = updatedDate; this.teamMemberId = teamMemberId; this.internalFeelings = internalFeelings; this.externalFeelings = externalFeelings; } - public PulseResponse(LocalDate submissionDate,LocalDate updatedDate, UUID teamMemberId, String internalFeelings, String externalFeelings) { - this(null,submissionDate, updatedDate, teamMemberId, internalFeelings, externalFeelings); + public PulseResponse(Integer internalScore, Integer externalScore, LocalDate submissionDate, UUID teamMemberId, String internalFeelings, String externalFeelings) { + this(null,internalScore, externalScore, submissionDate, teamMemberId, internalFeelings, externalFeelings); + } + + public UUID getId() { + return this.id; + } + + public void setId(UUID id) { + this.id = id; + } + + public Integer getInternalScore() { + return internalScore; + } + + public void setInternalScore(Integer internalScore) { + this.internalScore = internalScore; + } + + public Integer getExternalScore() { + return externalScore; + } + + public void setExternalScore(Integer externalScore) { + this.externalScore = externalScore; + } + + public LocalDate getSubmissionDate() { + return submissionDate; + } + + public void setSubmissionDate(LocalDate submissionDate) { + this.submissionDate = submissionDate; + } + + public UUID getTeamMemberId() { + return this.teamMemberId; + } + + public void setTeamMemberId(UUID teamMemberId) { + this.teamMemberId = teamMemberId; + } + + public String getInternalFeelings() { + return internalFeelings; + } + + public void setInternalFeelings(String internalFeelings) { + this.internalFeelings = internalFeelings; + } + + public String getExternalFeelings() { + return externalFeelings; + } + + public void setExternalFeelings(String externalFeelings) { + this.externalFeelings = externalFeelings; } @Override @@ -90,6 +154,8 @@ public boolean equals(Object o) { if (o == null || getClass() != o.getClass()) return false; PulseResponse that = (PulseResponse) o; return Objects.equals(id, that.id) && + Objects.equals(internalScore, that.internalScore) && + Objects.equals(externalScore, that.externalScore) && Objects.equals(submissionDate, that.submissionDate) && Objects.equals(teamMemberId, that.teamMemberId) && Objects.equals(internalFeelings, that.internalFeelings) && @@ -100,8 +166,9 @@ public boolean equals(Object o) { public String toString() { return "PulseResponse{" + "id=" + id + + ", internalScore" + internalScore + + ", externalScore" + externalScore + ", submissionDate=" + submissionDate + - ", updatedDate=" + updatedDate + ", teamMemberId=" + teamMemberId + ", internalFeelings=" + internalFeelings + ", externalFeelings=" + externalFeelings + @@ -109,7 +176,7 @@ public String toString() { } @Override public int hashCode() { - return Objects.hash(id, submissionDate, updatedDate, teamMemberId, internalFeelings, externalFeelings); + return Objects.hash(id, internalScore, externalScore, submissionDate, teamMemberId, internalFeelings, externalFeelings); } } diff --git a/server/src/main/java/com/objectcomputing/checkins/services/pulseresponse/PulseResponseController.java b/server/src/main/java/com/objectcomputing/checkins/services/pulseresponse/PulseResponseController.java index ac4350d846..d7a5f6fc76 100644 --- a/server/src/main/java/com/objectcomputing/checkins/services/pulseresponse/PulseResponseController.java +++ b/server/src/main/java/com/objectcomputing/checkins/services/pulseresponse/PulseResponseController.java @@ -61,12 +61,10 @@ public Mono>> findPulseResponses(@Nullable @Form @Post() public Mono> createPulseResponse(@Body @Valid PulseResponseCreateDTO pulseResponse, HttpRequest request) { - return Mono.fromCallable(() -> pulseResponseServices.save(new PulseResponse(pulseResponse.getSubmissionDate(), - pulseResponse.getUpdatedDate(), pulseResponse.getTeamMemberId(), pulseResponse.getInternalFeelings(), - pulseResponse.getExternalFeelings()))) + return Mono.fromCallable(() -> pulseResponseServices.save(new PulseResponse(pulseResponse.getInternalScore(), pulseResponse.getExternalScore(), pulseResponse.getSubmissionDate(), pulseResponse.getTeamMemberId(), pulseResponse.getInternalFeelings(), pulseResponse.getExternalFeelings()))) .map(pulseresponse -> HttpResponse.created(pulseresponse) - .headers(headers -> headers.location(URI.create(String.format("%s/%s", request.getPath(), - pulseresponse.getId()))))); + .headers(headers -> headers.location(URI.create(String.format("%s/%s", request.getPath(), pulseresponse.getId())))) + ); } /** diff --git a/server/src/main/java/com/objectcomputing/checkins/services/pulseresponse/PulseResponseCreateDTO.java b/server/src/main/java/com/objectcomputing/checkins/services/pulseresponse/PulseResponseCreateDTO.java index 30e7198173..aecb35e607 100644 --- a/server/src/main/java/com/objectcomputing/checkins/services/pulseresponse/PulseResponseCreateDTO.java +++ b/server/src/main/java/com/objectcomputing/checkins/services/pulseresponse/PulseResponseCreateDTO.java @@ -1,6 +1,7 @@ package com.objectcomputing.checkins.services.pulseresponse; import io.micronaut.core.annotation.Introspected; +import io.micronaut.core.annotation.Nullable; import io.swagger.v3.oas.annotations.media.Schema; import jakarta.validation.constraints.NotNull; import lombok.Getter; @@ -15,23 +16,74 @@ public class PulseResponseCreateDTO { @NotNull - @Schema(description = "date for submissionDate") - private LocalDate submissionDate; + @Schema(required = true, description = "integer value of internal score") + private Integer internalScore; + + @Nullable + @Schema(description = "integer value of external score") + private Integer externalScore; @NotNull - @Schema(description = "date for updatedDate") - private LocalDate updatedDate; + @Schema(description = "date for submissionDate") + private LocalDate submissionDate; @NotNull @Schema(description = "id of the associated member") private UUID teamMemberId; - @NotNull + @Nullable @Schema(description = "description of internal feelings") private String internalFeelings; - @NotNull + @Nullable @Schema(description = "description of external feelings") private String externalFeelings; + public Integer getInternalScore() { + return internalScore; + } + + public void setInternalScore(Integer internalScore) { + this.internalScore = internalScore; + } + + public Integer getExternalScore() { + return externalScore; + } + + public void setExternalScore(Integer externalScore) { + this.externalScore = externalScore; + } + + public LocalDate getSubmissionDate() { + return submissionDate; + } + + public void setSubmissionDate(LocalDate submissionDate) { + this.submissionDate = submissionDate; + } + + public UUID getTeamMemberId() { + return teamMemberId; + } + + public void setTeamMemberId(UUID teamMemberId) { + this.teamMemberId = teamMemberId; + } + + public String getInternalFeelings() { + return internalFeelings; + } + + public void setInternalFeelings(String internalFeelings) { + this.internalFeelings = internalFeelings; + } + + public String getExternalFeelings() { + return externalFeelings; + } + + public void setExternalFeelings(String externalFeelings) { + this.externalFeelings = externalFeelings; + } } diff --git a/server/src/main/java/com/objectcomputing/checkins/services/pulseresponse/PulseResponseServicesImpl.java b/server/src/main/java/com/objectcomputing/checkins/services/pulseresponse/PulseResponseServicesImpl.java index 4209bf56b7..92ee6f223f 100644 --- a/server/src/main/java/com/objectcomputing/checkins/services/pulseresponse/PulseResponseServicesImpl.java +++ b/server/src/main/java/com/objectcomputing/checkins/services/pulseresponse/PulseResponseServicesImpl.java @@ -28,15 +28,12 @@ public PulseResponse save(PulseResponse pulseResponse) { if(pulseResponse!=null){ final UUID memberId = pulseResponse.getTeamMemberId(); LocalDate pulseSubDate = pulseResponse.getSubmissionDate(); - LocalDate pulseUpDate = pulseResponse.getUpdatedDate(); if(pulseResponse.getId()!=null){ throw new BadArgException(String.format("Found unexpected id for pulseresponse %s", pulseResponse.getId())); } else if(!memberRepo.findById(memberId).isPresent()){ throw new BadArgException(String.format("Member %s doesn't exists", memberId)); } else if(pulseSubDate.isBefore(LocalDate.EPOCH) || pulseSubDate.isAfter(LocalDate.MAX)) { throw new BadArgException(String.format("Invalid date for pulseresponse submission date %s",memberId)); - } else if(pulseUpDate.isBefore(LocalDate.EPOCH) || pulseUpDate.isAfter(LocalDate.MAX)) { - throw new BadArgException(String.format("Invalid date for pulseresponse updated date %s",memberId)); } pulseResponseRet = pulseResponseRepo.save(pulseResponse); } @@ -56,7 +53,6 @@ public PulseResponse update(PulseResponse pulseResponse) { final UUID id = pulseResponse.getId(); final UUID memberId = pulseResponse.getTeamMemberId(); LocalDate pulseSubDate = pulseResponse.getSubmissionDate(); - LocalDate pulseUpDate = pulseResponse.getUpdatedDate(); if(id==null||!pulseResponseRepo.findById(id).isPresent()){ throw new BadArgException(String.format("Unable to find pulseresponse record with id %s", pulseResponse.getId())); }else if(!memberRepo.findById(memberId).isPresent()){ @@ -65,8 +61,6 @@ public PulseResponse update(PulseResponse pulseResponse) { throw new BadArgException(String.format("Invalid pulseresponse %s", pulseResponse)); } else if(pulseSubDate.isBefore(LocalDate.EPOCH) || pulseSubDate.isAfter(LocalDate.MAX)) { throw new BadArgException(String.format("Invalid date for pulseresponse submission date %s",memberId)); - } else if(pulseUpDate.isBefore(LocalDate.EPOCH) || pulseUpDate.isAfter(LocalDate.MAX)) { - throw new BadArgException(String.format("Invalid date for pulseresponse %s",memberId)); } pulseResponseRet = pulseResponseRepo.update(pulseResponse); diff --git a/server/src/main/resources/db/common/V102__alter_pulse_responses_table.sql b/server/src/main/resources/db/common/V102__alter_pulse_responses_table.sql new file mode 100644 index 0000000000..fbff23646c --- /dev/null +++ b/server/src/main/resources/db/common/V102__alter_pulse_responses_table.sql @@ -0,0 +1,4 @@ +ALTER TABLE pulse_response DROP COLUMN updatedDate; + +ALTER TABLE pulse_response ADD COLUMN internal_score Integer; +ALTER TABLE pulse_response ADD COLUMN external_score Integer; \ No newline at end of file diff --git a/server/src/test/java/com/objectcomputing/checkins/services/fixture/PulseResponseFixture.java b/server/src/test/java/com/objectcomputing/checkins/services/fixture/PulseResponseFixture.java index 0e52b19cf3..f3e2d667c1 100644 --- a/server/src/test/java/com/objectcomputing/checkins/services/fixture/PulseResponseFixture.java +++ b/server/src/test/java/com/objectcomputing/checkins/services/fixture/PulseResponseFixture.java @@ -7,7 +7,7 @@ public interface PulseResponseFixture extends RepositoryFixture { default PulseResponse createADefaultPulseResponse(MemberProfile memberprofile) { - return getPulseResponseRepository().save(new PulseResponse(LocalDate.now(), LocalDate.now(), + return getPulseResponseRepository().save(new PulseResponse(0, 0, LocalDate.now(), memberprofile.getId(), "internalfeelings", "externalfeelings")); } } diff --git a/server/src/test/java/com/objectcomputing/checkins/services/pulseresponse/PulseResponseControllerTest.java b/server/src/test/java/com/objectcomputing/checkins/services/pulseresponse/PulseResponseControllerTest.java index 949947610a..58a6173143 100644 --- a/server/src/test/java/com/objectcomputing/checkins/services/pulseresponse/PulseResponseControllerTest.java +++ b/server/src/test/java/com/objectcomputing/checkins/services/pulseresponse/PulseResponseControllerTest.java @@ -15,29 +15,33 @@ import io.micronaut.http.client.annotation.Client; import io.micronaut.http.client.exceptions.HttpClientResponseException; import jakarta.inject.Inject; +import org.junit.jupiter.api.Assertions; import org.junit.jupiter.api.Test; import java.time.LocalDate; import java.util.*; import java.util.stream.Collectors; +import java.util.stream.Stream; import static com.objectcomputing.checkins.services.role.RoleType.Constants.MEMBER_ROLE; -import static org.junit.Assert.assertNotNull; -import static org.junit.jupiter.api.Assertions.*; +import static org.junit.jupiter.api.Assertions.assertEquals; +import static org.junit.jupiter.api.Assertions.assertThrows; +import static org.junit.jupiter.api.Assertions.assertNotEquals; public class PulseResponseControllerTest extends TestContainersSuite implements MemberProfileFixture, RoleFixture, PulseResponseFixture { @Inject @Client("/services/pulse-responses") - private HttpClient client; + protected HttpClient client; @Test public void testCreateAPulseResponse(){ MemberProfile memberProfile = createADefaultMemberProfile(); PulseResponseCreateDTO pulseResponseCreateDTO = new PulseResponseCreateDTO(); + pulseResponseCreateDTO.setInternalScore(1); + pulseResponseCreateDTO.setExternalScore(2); pulseResponseCreateDTO.setSubmissionDate(LocalDate.now()); - pulseResponseCreateDTO.setUpdatedDate(LocalDate.now()); pulseResponseCreateDTO.setTeamMemberId(memberProfile.getId()); pulseResponseCreateDTO.setInternalFeelings("internalfeelings"); pulseResponseCreateDTO.setExternalFeelings("externalfeelings"); @@ -47,7 +51,7 @@ public void testCreateAPulseResponse(){ PulseResponse pulseResponseResponse = response.body(); - assertNotNull(pulseResponseResponse); + Assertions.assertNotNull(pulseResponseResponse); assertEquals(HttpStatus.CREATED, response.getStatus()); assertEquals(pulseResponseCreateDTO.getTeamMemberId(),pulseResponseResponse.getTeamMemberId()); assertEquals(String.format("%s/%s", request.getPath(), pulseResponseResponse.getId()), response.getHeaders().get("location")); @@ -64,10 +68,8 @@ void testCreateAnInvalidPulseResponse() { JsonNode body = responseException.getResponse().getBody(JsonNode.class).orElse(null); JsonNode errors = Objects.requireNonNull(body).get("_embedded").get("errors"); JsonNode href = Objects.requireNonNull(body).get("_links").get("self").get("href"); - List errorList = List.of(errors.get(0).get("message").asText(), errors.get(1).get("message").asText(), - errors.get(2).get("message").asText(), errors.get(3).get("message").asText(), errors.get(4).get("message").asText()) - .stream().sorted().collect(Collectors.toList()); - assertEquals(5,errorList.size()); + List errorList = Stream.of(errors.get(0).get("message").asText(), errors.get(1).get("message").asText(), errors.get(2).get("message").asText()).sorted().collect(Collectors.toList()); + assertEquals(3,errorList.size()); assertEquals(request.getPath(),href.asText()); assertEquals(HttpStatus.BAD_REQUEST, responseException.getStatus()); } @@ -75,8 +77,9 @@ void testCreateAnInvalidPulseResponse() { @Test void testCreatePulseResponseForNonExistingMember(){ PulseResponseCreateDTO pulseResponseCreateDTO = new PulseResponseCreateDTO(); + pulseResponseCreateDTO.setInternalScore(1); + pulseResponseCreateDTO.setExternalScore(2); pulseResponseCreateDTO.setSubmissionDate(LocalDate.now()); - pulseResponseCreateDTO.setUpdatedDate(LocalDate.now()); pulseResponseCreateDTO.setTeamMemberId(UUID.randomUUID()); pulseResponseCreateDTO.setInternalFeelings("internalfeelings"); pulseResponseCreateDTO.setExternalFeelings("externalfeelings"); @@ -112,8 +115,9 @@ void testCreateANullPulseResponse() { void testCreateAPulseResponseForInvalidDate() { MemberProfile memberProfile = createADefaultMemberProfile(); PulseResponseCreateDTO pulseResponseCreateDTO = new PulseResponseCreateDTO(); + pulseResponseCreateDTO.setInternalScore(1); + pulseResponseCreateDTO.setExternalScore(2); pulseResponseCreateDTO.setSubmissionDate(LocalDate.of(1965,11,12)); - pulseResponseCreateDTO.setUpdatedDate(LocalDate.of(1965,11,12)); pulseResponseCreateDTO.setTeamMemberId(memberProfile.getId()); pulseResponseCreateDTO.setInternalFeelings("internalfeelings"); pulseResponseCreateDTO.setExternalFeelings("externalfeelings"); @@ -134,10 +138,7 @@ void testCreateAPulseResponseForInvalidDate() { public void testGetFindByTeamMemberId() { MemberProfile memberProfile = createADefaultMemberProfile(); - - PulseResponse pulseResponse = createADefaultPulseResponse(memberProfile); - final HttpRequest request = HttpRequest.GET(String.format("/?teamMemberId=%s", pulseResponse.getTeamMemberId())).basicAuth(MEMBER_ROLE,MEMBER_ROLE); final HttpResponse> response = client.toBlocking().exchange(request, Argument.setOf(PulseResponse.class)); assertEquals(Set.of(pulseResponse), response.body()); @@ -149,12 +150,11 @@ public void testGetFindByTeamMemberId() { @Test public void testGetFindBySubmissionDateBetweenReturnsEmptyBody() { - LocalDate testDateFrom = LocalDate.of(2019, 01, 01); - LocalDate testDateTo = LocalDate.of(2019, 02, 01); - MemberProfile memberProfile = createADefaultMemberProfile(); + createADefaultPulseResponse(memberProfile); - PulseResponse pulseResponse = createADefaultPulseResponse(memberProfile); + LocalDate testDateFrom = LocalDate.of(2019, 1, 1); + LocalDate testDateTo = LocalDate.of(2019, 2, 1); final HttpRequest request = HttpRequest.GET(String.format("/?dateFrom=%tF&dateTo=%tF", testDateFrom, testDateTo)).basicAuth(MEMBER_ROLE,MEMBER_ROLE); final HttpResponse> response = client.toBlocking().exchange(request, Argument.setOf(PulseResponse.class)); @@ -165,12 +165,11 @@ public void testGetFindBySubmissionDateBetweenReturnsEmptyBody() { // Find By findBySubmissionDateBetween @Test public void testGetFindByfindBySubmissionDateBetween() { - MemberProfile memberProfile = createADefaultMemberProfile(); - PulseResponse pulseResponse = createADefaultPulseResponse(memberProfile); + createADefaultPulseResponse(memberProfile); - LocalDate testDateFrom = LocalDate.of(2019, 01, 01); + LocalDate testDateFrom = LocalDate.of(2019, 1, 1); LocalDate testDateTo = Util.MAX.toLocalDate(); final HttpRequest request = HttpRequest.GET(String.format("/?dateFrom=%tF&dateTo=%tF", testDateFrom, testDateTo)).basicAuth(MEMBER_ROLE,MEMBER_ROLE); @@ -292,14 +291,14 @@ void testUpdateNotMemberPulseResponseWithoutId(){ String error = Objects.requireNonNull(body).get("message").asText(); String href = Objects.requireNonNull(body).get("_links").get("self").get("href").asText(); - assertEquals(String.format("Unable to find pulseresponse record with id null", pulseResponse.getId()), error); + assertEquals("Unable to find pulseresponse record with id null", error); assertEquals(request.getPath(), href); } @Test void testUpdateUnAuthorized() { - PulseResponse pulseResponse = new PulseResponse(LocalDate.now(),LocalDate.now(),UUID.randomUUID(),"internalfeeling","externalfeeling"); + PulseResponse pulseResponse = new PulseResponse(1, 2, LocalDate.now(),UUID.randomUUID(),"internalfeeling","externalfeeling"); final HttpRequest request = HttpRequest.PUT("", pulseResponse); HttpClientResponseException responseException = assertThrows(HttpClientResponseException.class, () -> @@ -330,6 +329,8 @@ void testUpdateInvalidDatePulseResponse(){ MemberProfile memberProfile = createADefaultMemberProfile(); PulseResponse pulseResponse = createADefaultPulseResponse(memberProfile); + pulseResponse.setInternalScore(1); + pulseResponse.setExternalScore(2); pulseResponse.setSubmissionDate(LocalDate.of(1965,12,11)); final HttpRequest request = HttpRequest.PUT("", pulseResponse) diff --git a/server/src/test/java/com/objectcomputing/checkins/services/pulseresponse/PulseReponseCreateDTOTest.java b/server/src/test/java/com/objectcomputing/checkins/services/pulseresponse/PulseResponseCreateDTOTest.java similarity index 80% rename from server/src/test/java/com/objectcomputing/checkins/services/pulseresponse/PulseReponseCreateDTOTest.java rename to server/src/test/java/com/objectcomputing/checkins/services/pulseresponse/PulseResponseCreateDTOTest.java index a9c2078d7c..9799a18754 100644 --- a/server/src/test/java/com/objectcomputing/checkins/services/pulseresponse/PulseReponseCreateDTOTest.java +++ b/server/src/test/java/com/objectcomputing/checkins/services/pulseresponse/PulseResponseCreateDTOTest.java @@ -13,16 +13,17 @@ import static org.junit.jupiter.api.Assertions.*; @MicronautTest -public class PulseReponseCreateDTOTest { +public class PulseResponseCreateDTOTest { @Inject - private Validator validator; + protected Validator validator; @Test void testDTOInstantiation() { PulseResponseCreateDTO dto = new PulseResponseCreateDTO(); + assertNull(dto.getInternalScore()); + assertNull(dto.getExternalScore()); assertNull(dto.getSubmissionDate()); - assertNull(dto.getUpdatedDate()); assertNull(dto.getTeamMemberId()); assertNull(dto.getInternalFeelings()); assertNull(dto.getExternalFeelings()); @@ -33,7 +34,7 @@ void testConstraintViolation() { PulseResponseCreateDTO dto = new PulseResponseCreateDTO(); Set> violations = validator.validate(dto); - assertEquals(violations.size(), 5); + assertEquals(violations.size(), 3); for (ConstraintViolation violation : violations) { assertEquals(violation.getMessage(), "must not be null"); } @@ -45,11 +46,14 @@ void testPopulatedDTO() { UUID teamMemberId = UUID.randomUUID(); - dto.setSubmissionDate(LocalDate.of(2019, 1, 01)); - assertEquals(dto.getSubmissionDate(), LocalDate.of(2019, 1, 01)); + dto.setInternalScore(1); + assertEquals(1, dto.getInternalScore()); - dto.setUpdatedDate(LocalDate.of(2019, 1, 01)); - assertEquals(dto.getUpdatedDate(), LocalDate.of(2019, 1, 01)); + dto.setExternalScore(2); + assertEquals(2, dto.getExternalScore()); + + dto.setSubmissionDate(LocalDate.of(2019, 1, 1)); + assertEquals(dto.getSubmissionDate(), LocalDate.of(2019, 1, 1)); dto.setTeamMemberId(teamMemberId); assertEquals(dto.getTeamMemberId(), teamMemberId); diff --git a/server/src/test/java/com/objectcomputing/checkins/services/pulseresponse/PulseResponseServiceImplTest.java b/server/src/test/java/com/objectcomputing/checkins/services/pulseresponse/PulseResponseServiceImplTest.java index fc1334f4de..d945973ae3 100644 --- a/server/src/test/java/com/objectcomputing/checkins/services/pulseresponse/PulseResponseServiceImplTest.java +++ b/server/src/test/java/com/objectcomputing/checkins/services/pulseresponse/PulseResponseServiceImplTest.java @@ -38,7 +38,7 @@ public class PulseResponseServiceImplTest { @BeforeAll void initMocks() { - MockitoAnnotations.initMocks(this); + MockitoAnnotations.openMocks(this); } @BeforeEach @@ -50,7 +50,7 @@ void resetMocks() { @Test void testRead() { - PulseResponse cd = new PulseResponse(UUID.randomUUID(),LocalDate.of(2019, 1, 01),LocalDate.of(2019, 1, 01),UUID.randomUUID(),"examplePRId" , "examplePRId2"); + PulseResponse cd = new PulseResponse(UUID.randomUUID(),1, 2, LocalDate.of(2019, 1, 1),UUID.randomUUID(),"examplePRId" , "examplePRId2"); when(pulseResponseRepository.findById(cd.getId())).thenReturn(Optional.of(cd)); @@ -67,7 +67,7 @@ void testReadNullId() { @Test void testSave() { - PulseResponse cd = new PulseResponse(LocalDate.of(2019, 1, 01),LocalDate.of(2019, 1, 01), UUID.randomUUID(), "PRId", "PRId2"); + PulseResponse cd = new PulseResponse(1, 2, LocalDate.of(2019, 1, 1),UUID.randomUUID(), "PRId", "PRId2"); MemberProfile memberprofile = new MemberProfile(); when(memberprofileRepository.findById(eq(cd.getTeamMemberId()))).thenReturn(Optional.of(memberprofile)); @@ -81,7 +81,7 @@ void testSave() { @Test void testSaveWithId() { - PulseResponse cd = new PulseResponse(UUID.randomUUID(),LocalDate.of(2019, 1, 01),LocalDate.of(2019, 1, 01), UUID.randomUUID(), "PRId", "PRId2"); + PulseResponse cd = new PulseResponse(UUID.randomUUID(),1, 2, LocalDate.of(2019, 1, 1), UUID.randomUUID(), "PRId", "PRId2"); BadArgException exception = assertThrows(BadArgException.class, () -> services.save(cd)); assertEquals(String.format("Found unexpected id for pulseresponse %s", cd.getId()), exception.getMessage()); @@ -92,7 +92,7 @@ void testSaveWithId() { @Test void testSavePulseResponseNullTeamMemberId() { - PulseResponse cd = new PulseResponse(LocalDate.of(2019, 1, 01),LocalDate.of(2019, 1, 01), null, "PRId", "PRId2"); + PulseResponse cd = new PulseResponse(1, 2, LocalDate.of(2019, 1, 1),null, "PRId", "PRId2"); BadArgException exception = assertThrows(BadArgException.class, () -> services.save(cd)); assertEquals("Member null doesn't exists", exception.getMessage()); @@ -103,7 +103,7 @@ void testSavePulseResponseNullTeamMemberId() { @Test void testSavePulseResponseNullPRId() { - PulseResponse cd = new PulseResponse(LocalDate.of(2019, 1, 01),LocalDate.of(2019, 1, 01), UUID.randomUUID(), null, null); + PulseResponse cd = new PulseResponse(1, 2, LocalDate.of(2019, 1, 1), UUID.randomUUID(), null, null); BadArgException exception = assertThrows(BadArgException.class, () -> services.save(cd)); assertEquals(String.format("Member %s doesn't exists", cd.getTeamMemberId()), exception.getMessage()); @@ -121,7 +121,7 @@ void testSaveNullPulseResponse() { @Test void testSavePulseResponseNonExistingMemberProfile() { - PulseResponse cd = new PulseResponse(LocalDate.of(2019, 1, 01),LocalDate.of(2019, 1, 01), UUID.randomUUID(), "PRId", "PRId2"); + PulseResponse cd = new PulseResponse(1, 2, LocalDate.of(2019, 1, 1),UUID.randomUUID(), "PRId", "PRId2"); when(memberprofileRepository.findById(eq(cd.getTeamMemberId()))).thenReturn(Optional.empty()); @@ -134,7 +134,7 @@ void testSavePulseResponseNonExistingMemberProfile() { @Test void testUpdate() { - PulseResponse cd = new PulseResponse(UUID.randomUUID(),LocalDate.of(2019, 1, 01),LocalDate.of(2019, 1, 01), UUID.randomUUID(), "PRId", "PRId2"); + PulseResponse cd = new PulseResponse(UUID.randomUUID(),1, 2, LocalDate.of(2019, 1, 1), UUID.randomUUID(), "PRId", "PRId2"); MemberProfile memberprofile = new MemberProfile(); when(memberprofileRepository.findById(eq(cd.getTeamMemberId()))).thenReturn(Optional.of(memberprofile)); @@ -150,7 +150,7 @@ void testUpdate() { @Test void testUpdateWithoutId() { - PulseResponse cd = new PulseResponse(LocalDate.of(2019, 1, 01),LocalDate.of(2019, 1, 01), UUID.randomUUID(), "PRId", "PRId2"); + PulseResponse cd = new PulseResponse(1, 2, LocalDate.of(2019, 1, 1),UUID.randomUUID(), "PRId", "PRId2"); BadArgException exception = assertThrows(BadArgException.class, () -> services.update(cd)); assertEquals(String.format("Unable to find pulseresponse record with id %s", cd.getId()), exception.getMessage()); @@ -162,7 +162,7 @@ void testUpdateWithoutId() { @Test void testUpdatePulseResponseNullTeamMemberId() { - PulseResponse cd = new PulseResponse(LocalDate.of(2019, 1, 01),LocalDate.of(2019, 1, 01), null, "PRId", "PRId2"); + PulseResponse cd = new PulseResponse(1, 2, LocalDate.of(2019, 1, 1), null, "PRId", "PRId2"); BadArgException exception = assertThrows(BadArgException.class, () -> services.update(cd)); assertEquals("Unable to find pulseresponse record with id null", exception.getMessage()); @@ -174,7 +174,7 @@ void testUpdatePulseResponseNullTeamMemberId() { @Test void testUpdatePulseResponseNullPRId() { - PulseResponse cd = new PulseResponse(LocalDate.of(2019, 1, 01),LocalDate.of(2019, 1, 01), UUID.randomUUID(), null, null); + PulseResponse cd = new PulseResponse(1, 2, LocalDate.of(2019, 1, 1), UUID.randomUUID(), null, null); BadArgException exception = assertThrows(BadArgException.class, () -> services.update(cd)); assertEquals("Unable to find pulseresponse record with id null", exception.getMessage()); @@ -186,7 +186,7 @@ void testUpdatePulseResponseNullPRId() { @Test void testUpdatePulseResponseDoesNotExist() { - PulseResponse cd = new PulseResponse(UUID.randomUUID(),LocalDate.of(2019, 1, 01),LocalDate.of(2019, 1, 01), UUID.randomUUID(), "PRId", "PRId2"); + PulseResponse cd = new PulseResponse(UUID.randomUUID(), 1, 2, LocalDate.of(2019, 1, 1), UUID.randomUUID(), "PRId", "PRId2"); when(pulseResponseRepository.findById(eq(cd.getTeamMemberId()))).thenReturn(Optional.empty()); BadArgException exception = assertThrows(BadArgException.class, () -> services.update(cd)); @@ -199,7 +199,7 @@ void testUpdatePulseResponseDoesNotExist() { @Test void testUpdateMemberProfileDoesNotExist() { - PulseResponse cd = new PulseResponse(UUID.randomUUID(),LocalDate.of(2019, 1, 01),LocalDate.of(2019, 1, 01), UUID.randomUUID(), "PRId", "PRId2"); + PulseResponse cd = new PulseResponse(UUID.randomUUID(),1, 2, LocalDate.of(2019, 1, 1), UUID.randomUUID(), "PRId", "PRId2"); when(pulseResponseRepository.findById(eq(cd.getId()))).thenReturn(Optional.of(cd)); when(memberprofileRepository.findById(eq(cd.getTeamMemberId()))).thenReturn(Optional.empty()); diff --git a/server/src/test/java/com/objectcomputing/checkins/services/pulseresponse/PulseResponseTest.java b/server/src/test/java/com/objectcomputing/checkins/services/pulseresponse/PulseResponseTest.java index 903ae0f2b7..25904bb31e 100644 --- a/server/src/test/java/com/objectcomputing/checkins/services/pulseresponse/PulseResponseTest.java +++ b/server/src/test/java/com/objectcomputing/checkins/services/pulseresponse/PulseResponseTest.java @@ -18,16 +18,15 @@ public class PulseResponseTest { @Inject - private Validator validator; + protected Validator validator; @Test void testPulseResponseInstantiation() { - LocalDate submissionDate= LocalDate.of(2019, 1, 01); - LocalDate updatedDate= LocalDate.of(2019, 1, 01); + LocalDate submissionDate = LocalDate.of(2019, 1, 1); final UUID teamMemberId = UUID.randomUUID(); - final String internalFeelings = "exampleId"; - final String externalFeelings = "exampleId2"; - PulseResponse pulseResponse = new PulseResponse(submissionDate,updatedDate, teamMemberId, internalFeelings, externalFeelings); + final String internalFeelings = "exampleId"; + final String externalFeelings = "exampleId2"; + PulseResponse pulseResponse = new PulseResponse(1, 2, submissionDate,teamMemberId, internalFeelings, externalFeelings); assertEquals(teamMemberId, pulseResponse.getTeamMemberId()); assertEquals(internalFeelings , pulseResponse.getInternalFeelings ()); assertEquals(externalFeelings , pulseResponse.getExternalFeelings ()); @@ -35,18 +34,19 @@ void testPulseResponseInstantiation() { @Test void testConstraintViolation() { - LocalDate submissionDate= LocalDate.of(2019, 1, 01); - LocalDate updatedDate= LocalDate.of(2019, 1, 01); + LocalDate submissionDate = LocalDate.of(2019, 1, 1); final UUID teamMemberId = UUID.randomUUID(); - final String internalFeelings = "exampleId"; - final String externalFeelings = "exampleId2"; - PulseResponse pulseResponse = new PulseResponse(submissionDate,updatedDate, teamMemberId, internalFeelings,externalFeelings); + final String internalFeelings = "exampleId"; + final String externalFeelings = "exampleId2"; + final Integer internalScore = 1; + final Integer externalScore = 2; + PulseResponse pulseResponse = new PulseResponse(internalScore, externalScore, submissionDate, teamMemberId, internalFeelings, externalFeelings); - pulseResponse.setInternalFeelings (null); - pulseResponse.setExternalFeelings (null); + pulseResponse.setInternalScore(null); + pulseResponse.setExternalFeelings(null); Set> violations = validator.validate(pulseResponse); - assertEquals(2, violations.size()); + assertEquals(1, violations.size()); for (ConstraintViolation violation : violations) { assertEquals(violation.getMessage(), "must not be null"); } @@ -55,14 +55,15 @@ void testConstraintViolation() { @Test void testEquals() { final UUID id = UUID.randomUUID(); - LocalDate submissionDate= LocalDate.of(2019, 1, 01); - LocalDate updatedDate= LocalDate.of(2019, 1, 01); + final Integer internalScore = 1; + final Integer externalScore = 2; + LocalDate submissionDate= LocalDate.of(2019, 1, 1); final UUID teamMemberId = UUID.randomUUID(); - final String internalFeelings = "exampleId"; - final String externalFeelings = "exampleId2"; + final String internalFeelings = "exampleId"; + final String externalFeelings = "exampleId2"; - PulseResponse pulseResponse1 = new PulseResponse(id,submissionDate,updatedDate, teamMemberId, internalFeelings, externalFeelings ); - PulseResponse pulseResponse2 = new PulseResponse(id,submissionDate,updatedDate, teamMemberId, internalFeelings, externalFeelings ); + PulseResponse pulseResponse1 = new PulseResponse(id,internalScore,externalScore,submissionDate,teamMemberId, internalFeelings, externalFeelings ); + PulseResponse pulseResponse2 = new PulseResponse(id,internalScore,externalScore,submissionDate,teamMemberId, internalFeelings, externalFeelings ); assertEquals(pulseResponse1, pulseResponse2); pulseResponse2.setId(null); @@ -71,20 +72,31 @@ void testEquals() { pulseResponse2.setId(pulseResponse1.getId()); assertEquals(pulseResponse1, pulseResponse2); + pulseResponse2.setInternalScore(pulseResponse1.getInternalScore()); + assertEquals(pulseResponse1, pulseResponse2); + + pulseResponse2.setExternalScore(pulseResponse1.getExternalScore()); + assertEquals(pulseResponse1, pulseResponse2); + pulseResponse2.setInternalFeelings ("exampleId2"); pulseResponse2.setExternalFeelings ("exampleId3"); assertNotEquals(pulseResponse1, pulseResponse2); + + pulseResponse2.setInternalScore(3); + pulseResponse2.setExternalScore(4); + assertNotEquals(pulseResponse1, pulseResponse2); } @Test void testToString() { final UUID id = UUID.randomUUID(); - LocalDate submissionDate= LocalDate.of(2019, 1, 01); - LocalDate updatedDate= LocalDate.of(2019, 1, 01); + LocalDate submissionDate = LocalDate.of(2019, 1, 1); final UUID teamMemberId = UUID.randomUUID(); - final String internalFeelings = "exampleId"; - final String externalFeelings = "exampleId2"; - PulseResponse pulseResponse = new PulseResponse(id,submissionDate,updatedDate, teamMemberId, internalFeelings, externalFeelings ); + final Integer internalScore = 1; + final Integer externalScore = 2; + final String internalFeelings = "exampleId"; + final String externalFeelings = "exampleId2"; + PulseResponse pulseResponse = new PulseResponse(id,internalScore,externalScore,submissionDate, teamMemberId, internalFeelings, externalFeelings ); String toString = pulseResponse.toString(); assertTrue(toString.contains(teamMemberId.toString())); diff --git a/web-ui/package.json b/web-ui/package.json index 9025a87e55..ccb58953fa 100644 --- a/web-ui/package.json +++ b/web-ui/package.json @@ -81,8 +81,9 @@ "@storybook/preset-create-react-app": "^8.0.4", "@storybook/react": "^8.0.4", "@storybook/react-webpack5": "^8.0.4", - "@testing-library/jest-dom": "^6.4.2", + "@testing-library/jest-dom": "^6.4.5", "@testing-library/react": "^14.2.2", + "@testing-library/react-hooks": "^8.0.1", "@testing-library/user-event": "^14.5.2", "@vitejs/plugin-react-swc": "^3.6.0", "@vitest/coverage-v8": "^1.4.0", diff --git a/web-ui/src/components/admin/permissions/__snapshots__/MobileTable.test.jsx.snap b/web-ui/src/components/admin/permissions/__snapshots__/MobileTable.test.jsx.snap index 6d3126a20e..bde9e448b0 100644 --- a/web-ui/src/components/admin/permissions/__snapshots__/MobileTable.test.jsx.snap +++ b/web-ui/src/components/admin/permissions/__snapshots__/MobileTable.test.jsx.snap @@ -20,7 +20,7 @@ exports[`MobileTable > renders correctly 1`] = ` scope="col" >
renders correctly 1`] = `
{ - const component = renderer.create( + const component = render( { setScore={() => {}} /> ); - expect(component.toJSON()).toMatchSnapshot(); + expect(component).toMatchSnapshot(); }); it('calls setComment', () => { @@ -25,7 +24,7 @@ it('calls setComment', () => { setScore={() => {}} /> ); - const input = screen.getByTestId('comment-input').querySelector('input'); + const input = screen.getByTestId('comment-input').querySelector('textarea'); const text = 'new comment'; fireEvent.change(input, { target: { value: text } }); expect(setComment).toHaveBeenCalledWith(text); @@ -39,4 +38,4 @@ it('calls setScore', () => { const button = screen.getByTestId('score-button-4'); fireEvent.click(button); expect(setScore).toHaveBeenCalledWith(4); -}); +}); \ No newline at end of file diff --git a/web-ui/src/components/pulse/__snapshots__/Pulse.test.jsx.snap b/web-ui/src/components/pulse/__snapshots__/Pulse.test.jsx.snap index 23101d7d35..4e25559042 100644 --- a/web-ui/src/components/pulse/__snapshots__/Pulse.test.jsx.snap +++ b/web-ui/src/components/pulse/__snapshots__/Pulse.test.jsx.snap @@ -1,308 +1,514 @@ // Vitest Snapshot v1, https://vitest.dev/guide/snapshot.html exports[`renders correctly 1`] = ` -
-
-
- - - - - -
-
- +
+ + + + + +
+
+ +
+ + +