diff --git a/backend/src/main/java/ch/puzzle/okr/controller/CompletedController.java b/backend/src/main/java/ch/puzzle/okr/controller/CompletedController.java index 0996623793..4b8e10e5dc 100644 --- a/backend/src/main/java/ch/puzzle/okr/controller/CompletedController.java +++ b/backend/src/main/java/ch/puzzle/okr/controller/CompletedController.java @@ -1,5 +1,7 @@ package ch.puzzle.okr.controller; +import ch.puzzle.okr.dto.CompletedDto; +import ch.puzzle.okr.mapper.CompletedMapper; import ch.puzzle.okr.models.Completed; import ch.puzzle.okr.service.authorization.CompletedAuthorizationService; import io.swagger.v3.oas.annotations.Operation; @@ -16,9 +18,12 @@ public class CompletedController { private final CompletedAuthorizationService completedAuthorizationService; + private final CompletedMapper completedMapper; - public CompletedController(CompletedAuthorizationService completedAuthorizationService) { + public CompletedController(CompletedAuthorizationService completedAuthorizationService, + CompletedMapper completedMapper) { this.completedAuthorizationService = completedAuthorizationService; + this.completedMapper = completedMapper; } @Operation(summary = "Create Completed", description = "Create a new Completed Reference.") @@ -28,9 +33,10 @@ public CompletedController(CompletedAuthorizationService completedAuthorizationS @ApiResponse(responseCode = "401", description = "Not authorized to create Completed Reference", content = @Content), @ApiResponse(responseCode = "404", description = "Could not create Completed Reference", content = @Content) }) @PostMapping - public ResponseEntity createCompleted(@RequestBody Completed completed) { + public ResponseEntity createCompleted(@RequestBody CompletedDto completedDto) { + Completed completed = completedMapper.toCompleted(completedDto); Completed createdCompleted = completedAuthorizationService.createCompleted(completed); - return ResponseEntity.status(HttpStatus.CREATED).body(createdCompleted); + return ResponseEntity.status(HttpStatus.CREATED).body(completedMapper.toDto(createdCompleted)); } @Operation(summary = "Delete Completed by Objective Id", description = "Delete Completed Reference by Objective Id") diff --git a/backend/src/main/java/ch/puzzle/okr/dto/CompletedDto.java b/backend/src/main/java/ch/puzzle/okr/dto/CompletedDto.java new file mode 100644 index 0000000000..8be0cebefc --- /dev/null +++ b/backend/src/main/java/ch/puzzle/okr/dto/CompletedDto.java @@ -0,0 +1,6 @@ +package ch.puzzle.okr.dto; + +import ch.puzzle.okr.models.Objective; + +public record CompletedDto(Long id, Objective objective, String comment) { +} diff --git a/backend/src/main/java/ch/puzzle/okr/mapper/CompletedMapper.java b/backend/src/main/java/ch/puzzle/okr/mapper/CompletedMapper.java new file mode 100644 index 0000000000..9003754951 --- /dev/null +++ b/backend/src/main/java/ch/puzzle/okr/mapper/CompletedMapper.java @@ -0,0 +1,18 @@ +package ch.puzzle.okr.mapper; + +import ch.puzzle.okr.dto.CompletedDto; +import ch.puzzle.okr.models.Completed; +import org.springframework.stereotype.Component; + +@Component +public class CompletedMapper { + + public CompletedDto toDto(Completed completed) { + return new CompletedDto(completed.getId(), completed.getObjective(), completed.getComment()); + } + + public Completed toCompleted(CompletedDto completedDto) { + return Completed.Builder.builder().withId(completedDto.id()).withObjective(completedDto.objective()) + .withComment(completedDto.comment()).build(); + } +} diff --git a/backend/src/main/java/ch/puzzle/okr/repository/OverviewRepository.java b/backend/src/main/java/ch/puzzle/okr/repository/OverviewRepository.java deleted file mode 100644 index e69de29bb2..0000000000 diff --git a/backend/src/test/java/ch/puzzle/okr/TestHelper.java b/backend/src/test/java/ch/puzzle/okr/TestHelper.java index db161e9c6c..2df53552c9 100644 --- a/backend/src/test/java/ch/puzzle/okr/TestHelper.java +++ b/backend/src/test/java/ch/puzzle/okr/TestHelper.java @@ -15,13 +15,18 @@ public class TestHelper { private TestHelper() { } + private static final String FIRSTNAME = "Bob"; + private static final String LASTNAME = "Kaufmann"; + private static final String USERNAME = "bkaufmann"; + private static final String EMAIL = "kaufmann@puzzle.ch"; + public static User defaultUser(Long id) { - return User.Builder.builder().withId(id).withFirstname("Bob").withLastname("Kaufmann").withUsername("bkaufmann") - .withEmail("kaufmann@puzzle.ch").build(); + return User.Builder.builder().withId(id).withFirstname(FIRSTNAME).withLastname(LASTNAME).withUsername(USERNAME) + .withEmail(EMAIL).build(); } public static AuthorizationUser defaultAuthorizationUser() { - return mockAuthorizationUser(1L, "bkaufmann", "Bob", "Kaufmann", "kaufmann@puzzle.ch", List.of(5L), 5L, + return mockAuthorizationUser(1L, USERNAME, FIRSTNAME, LASTNAME, EMAIL, List.of(5L), 5L, List.of(READ_ALL_PUBLISHED, READ_ALL_DRAFT, WRITE_ALL)); } @@ -38,7 +43,7 @@ public static AuthorizationUser mockAuthorizationUser(Long id, String username, } public static Jwt defaultJwtToken() { - return mockJwtToken("bkaufmann", "Bob", "Kaufmann", "kaufmann@puzzle.ch", List.of("org_gl")); + return mockJwtToken(USERNAME, FIRSTNAME, LASTNAME, EMAIL, List.of("org_gl")); } public static Jwt mockJwtToken(String username, String firstname, String lastname, String email) { diff --git a/backend/src/test/java/ch/puzzle/okr/controller/CompletedControllerIT.java b/backend/src/test/java/ch/puzzle/okr/controller/CompletedControllerIT.java index b7c9bc4d9b..55cb28d206 100644 --- a/backend/src/test/java/ch/puzzle/okr/controller/CompletedControllerIT.java +++ b/backend/src/test/java/ch/puzzle/okr/controller/CompletedControllerIT.java @@ -1,9 +1,12 @@ package ch.puzzle.okr.controller; +import ch.puzzle.okr.dto.CompletedDto; +import ch.puzzle.okr.mapper.CompletedMapper; import ch.puzzle.okr.models.Completed; import ch.puzzle.okr.models.Objective; import ch.puzzle.okr.service.authorization.CompletedAuthorizationService; import org.hamcrest.core.Is; +import org.junit.jupiter.api.BeforeEach; import org.junit.jupiter.api.Test; import org.junit.jupiter.api.extension.ExtendWith; import org.mockito.BDDMockito; @@ -40,22 +43,34 @@ class CompletedControllerIT { """; @MockBean CompletedAuthorizationService completedAuthorizationService; + @MockBean + private CompletedMapper completedMapper; + private static final String WELL_DONE = "Wir haben es gut geschafft"; + Completed successfulCompleted = Completed.Builder.builder().withId(1L) .withObjective(Objective.Builder.builder().withId(3L).withTitle("Gute Lernende").build()) - .withComment("Wir haben es gut geschafft").build(); + .withComment(WELL_DONE).build(); + CompletedDto completedDto = new CompletedDto(22L, + Objective.Builder.builder().withId(3L).withTitle("Gute Lernende").build(), WELL_DONE); String baseUrl = "/api/v2/completed"; @Autowired private MockMvc mvc; + @BeforeEach + void setUp() { + BDDMockito.given(completedMapper.toDto(any())).willReturn(completedDto); + BDDMockito.given(completedMapper.toCompleted(any())).willReturn(successfulCompleted); + } + @Test void createSuccessfulCompleted() throws Exception { BDDMockito.given(this.completedAuthorizationService.createCompleted(any())).willReturn(successfulCompleted); mvc.perform(post(baseUrl).content(SUCCESSFUL_CREATE_BODY).contentType(MediaType.APPLICATION_JSON) .with(SecurityMockMvcRequestPostProcessors.csrf())) - .andExpect(MockMvcResultMatchers.status().is2xxSuccessful()).andExpect(jsonPath(JSON_PATH_ID, Is.is(1))) - .andExpect(jsonPath("$.objective.id", Is.is(3))) - .andExpect(jsonPath("$.comment", Is.is("Wir haben es gut geschafft"))); + .andExpect(MockMvcResultMatchers.status().is2xxSuccessful()) + .andExpect(jsonPath(JSON_PATH_ID, Is.is(22))).andExpect(jsonPath("$.objective.id", Is.is(3))) + .andExpect(jsonPath("$.comment", Is.is(WELL_DONE))); } @Test diff --git a/backend/src/test/java/ch/puzzle/okr/controller/ObjectiveControllerIT.java b/backend/src/test/java/ch/puzzle/okr/controller/ObjectiveControllerIT.java index 9d4918a54e..48ce9d1585 100644 --- a/backend/src/test/java/ch/puzzle/okr/controller/ObjectiveControllerIT.java +++ b/backend/src/test/java/ch/puzzle/okr/controller/ObjectiveControllerIT.java @@ -38,8 +38,6 @@ @ExtendWith(MockitoExtension.class) @WebMvcTest(ObjectiveController.class) class ObjectiveControllerIT { - - private static final AuthorizationUser authorizationUser = defaultAuthorizationUser(); private static final String OBJECTIVE_TITLE_1 = "Objective 1"; private static final String OBJECTIVE_TITLE_2 = "Objective 2"; private static final String DESCRIPTION = "This is our description"; diff --git a/backend/src/test/java/ch/puzzle/okr/converter/JwtOrganisationConverterTest.java b/backend/src/test/java/ch/puzzle/okr/converter/JwtOrganisationConverterTest.java index 247fd6c370..a379beb147 100644 --- a/backend/src/test/java/ch/puzzle/okr/converter/JwtOrganisationConverterTest.java +++ b/backend/src/test/java/ch/puzzle/okr/converter/JwtOrganisationConverterTest.java @@ -22,14 +22,14 @@ public void setup() { } @Test - void convert_shouldReturnOrganisations_whenValidJwt() { + void convertShouldReturnOrganisationsWhenValidJwt() { List organisations = converter.convert(jwt); assertThat(List.of("org_gl")).hasSameElementsAs(organisations); } @Test - void convert_shouldReturnEmptyList_whenNoClaimRealmSection() { + void convertShouldReturnEmptyListWhenNoClaimRealmSection() { setClaimRealm("foo"); List organisations = converter.convert(jwt); @@ -38,7 +38,7 @@ void convert_shouldReturnEmptyList_whenNoClaimRealmSection() { } @Test - void convert_shouldReturnEmptyList_whenNoClaimOrganisationsSection() { + void convertShouldReturnEmptyListWhenNoClaimOrganisationsSection() { setClaimOrganisations("bar"); List organisations = converter.convert(jwt); @@ -47,7 +47,7 @@ void convert_shouldReturnEmptyList_whenNoClaimOrganisationsSection() { } @Test - void convert_shouldReturnEmptyList_whenNoRoleNameMatch() { + void convertShouldReturnEmptyListWhenNoRoleNameMatch() { setOrganisationNamePrefix("foo_"); List organisations = converter.convert(jwt); diff --git a/backend/src/test/java/ch/puzzle/okr/converter/JwtUserConverterTest.java b/backend/src/test/java/ch/puzzle/okr/converter/JwtUserConverterTest.java index 1e2d2752ac..1b684ca6a0 100644 --- a/backend/src/test/java/ch/puzzle/okr/converter/JwtUserConverterTest.java +++ b/backend/src/test/java/ch/puzzle/okr/converter/JwtUserConverterTest.java @@ -25,7 +25,7 @@ public void setup() { } @Test - void convert_shouldReturnUser_whenValidJwt() { + void convertShouldReturnUserWhenValidJwt() { User user = converter.convert(jwt); assertEquals(User.Builder.builder().withUsername("bkaufmann").withFirstname("Bob").withLastname("Kaufmann") @@ -33,7 +33,7 @@ void convert_shouldReturnUser_whenValidJwt() { } @Test - void convert_shouldThrowException_whenClaimNameDoesNotMatch() { + void convertShouldThrowExceptionWhenClaimNameDoesNotMatch() { setUsername("foo_name"); ResponseStatusException exception = assertThrows(ResponseStatusException.class, () -> converter.convert(jwt)); diff --git a/backend/src/test/java/ch/puzzle/okr/service/business/KeyResultBusinessServiceIT.java b/backend/src/test/java/ch/puzzle/okr/service/business/KeyResultBusinessServiceIT.java index 35828d2842..1a1132ef21 100644 --- a/backend/src/test/java/ch/puzzle/okr/service/business/KeyResultBusinessServiceIT.java +++ b/backend/src/test/java/ch/puzzle/okr/service/business/KeyResultBusinessServiceIT.java @@ -103,7 +103,7 @@ void tearDown() { } @Test - void updateEntity_shouldUpdateKeyResultWithSameTypeMetric() { + void updateEntityShouldUpdateKeyResultWithSameTypeMetric() { createdKeyResult = keyResultBusinessService.createEntity(createKeyResultMetric(null), authorizationUser); createdKeyResult.setTitle(KEY_RESULT_UPDATED); @@ -114,7 +114,7 @@ void updateEntity_shouldUpdateKeyResultWithSameTypeMetric() { } @Test - void updateEntity_shouldUpdateKeyResultWithSameTypeOrdinal() { + void updateEntityShouldUpdateKeyResultWithSameTypeOrdinal() { createdKeyResult = keyResultBusinessService.createEntity(createKeyResultOrdinal(null), authorizationUser); createdKeyResult.setTitle(KEY_RESULT_UPDATED); diff --git a/backend/src/test/java/ch/puzzle/okr/service/business/KeyResultBusinessServiceTest.java b/backend/src/test/java/ch/puzzle/okr/service/business/KeyResultBusinessServiceTest.java index f0b4876109..5465d7da52 100644 --- a/backend/src/test/java/ch/puzzle/okr/service/business/KeyResultBusinessServiceTest.java +++ b/backend/src/test/java/ch/puzzle/okr/service/business/KeyResultBusinessServiceTest.java @@ -327,7 +327,7 @@ void shouldDeleteKeyResultAndAssociatedCheckInsAndActions() { } @Test - void shouldReturnImUsedProperly_False1() { + void shouldReturnImUsedProperlyFalse1() { when(checkInBusinessService.getCheckInsByKeyResultId(any())).thenReturn(Collections.emptyList()); boolean returnValue = this.keyResultBusinessService.isImUsed(1L, this.metricKeyResult); @@ -336,7 +336,7 @@ void shouldReturnImUsedProperly_False1() { } @Test - void shouldReturnImUsedProperly_False2() { + void shouldReturnImUsedProperlyFalse2() { when(checkInBusinessService.getCheckInsByKeyResultId(any())).thenReturn(Collections.emptyList()); boolean returnValue = this.keyResultBusinessService.isImUsed(1L, this.ordinalKeyResult); @@ -345,7 +345,7 @@ void shouldReturnImUsedProperly_False2() { } @Test - void shouldReturnImUsedProperly_False3() { + void shouldReturnImUsedProperlyFalse3() { when(keyResultPersistenceService.findById(any())).thenReturn(this.metricKeyResult); when(checkInBusinessService.getCheckInsByKeyResultId(any())).thenReturn(checkIns); @@ -355,7 +355,7 @@ void shouldReturnImUsedProperly_False3() { } @Test - void shouldReturnImUsedProperly_True1() { + void shouldReturnImUsedProperlyTrue1() { when(keyResultPersistenceService.findById(any())).thenReturn(this.metricKeyResult); when(checkInBusinessService.getCheckInsByKeyResultId(any())).thenReturn(checkIns); diff --git a/backend/src/test/java/ch/puzzle/okr/service/persistence/AlignmentSelectionPersistenceServiceIT.java b/backend/src/test/java/ch/puzzle/okr/service/persistence/AlignmentSelectionPersistenceServiceIT.java index 567c94faaf..d01a662f88 100644 --- a/backend/src/test/java/ch/puzzle/okr/service/persistence/AlignmentSelectionPersistenceServiceIT.java +++ b/backend/src/test/java/ch/puzzle/okr/service/persistence/AlignmentSelectionPersistenceServiceIT.java @@ -13,7 +13,7 @@ import static org.junit.jupiter.api.Assertions.assertTrue; @SpringIntegrationTest -public class AlignmentSelectionPersistenceServiceIT { +class AlignmentSelectionPersistenceServiceIT { @Autowired private AlignmentSelectionPersistenceService alignmentSelectionPersistenceService; diff --git a/backend/src/test/java/ch/puzzle/okr/service/persistence/AuthorizationCriteriaIT.java b/backend/src/test/java/ch/puzzle/okr/service/persistence/AuthorizationCriteriaIT.java index ab90c4501b..04d590b9ce 100644 --- a/backend/src/test/java/ch/puzzle/okr/service/persistence/AuthorizationCriteriaIT.java +++ b/backend/src/test/java/ch/puzzle/okr/service/persistence/AuthorizationCriteriaIT.java @@ -15,8 +15,7 @@ @SpringIntegrationTest class AuthorizationCriteriaIT { - private final String reason = "not authorized to read objective"; - private final AuthorizationUser authorizationUser = defaultAuthorizationUser(); + private static final String REASON = "not authorized to read objective"; @Autowired ObjectivePersistenceService objectivePersistenceService; @@ -27,7 +26,7 @@ class AuthorizationCriteriaIT { void appendObjectiveShouldReturnObjectiveWhenFirstLevelRole() { Long objectiveId = 5L; AuthorizationUser authorizationUser = defaultAuthorizationUser(); - Objective objective = objectivePersistenceService.findObjectiveById(objectiveId, authorizationUser, reason); + Objective objective = objectivePersistenceService.findObjectiveById(objectiveId, authorizationUser, REASON); assertEquals(objectiveId, objective.getId()); } @@ -37,7 +36,7 @@ void appendObjectiveShouldReturnObjectiveWhenSecondLevelRole() { Long objectiveId = 6L; AuthorizationUser authorizationUser = mockAuthorizationUser(defaultUser(null), List.of(), 5L, List.of(READ_ALL_PUBLISHED, READ_TEAMS_DRAFT)); - Objective objective = objectivePersistenceService.findObjectiveById(objectiveId, authorizationUser, reason); + Objective objective = objectivePersistenceService.findObjectiveById(objectiveId, authorizationUser, REASON); assertEquals(objectiveId, objective.getId()); } @@ -47,7 +46,7 @@ void appendObjectiveShouldReturnObjectiveWhenMemberRole() { Long objectiveId = 6L; AuthorizationUser authorizationUser = mockAuthorizationUser(defaultUser(null), List.of(), 5L, List.of(READ_ALL_PUBLISHED, READ_TEAM_DRAFT)); - Objective objective = objectivePersistenceService.findObjectiveById(objectiveId, authorizationUser, reason); + Objective objective = objectivePersistenceService.findObjectiveById(objectiveId, authorizationUser, REASON); assertEquals(objectiveId, objective.getId()); } diff --git a/backend/src/test/java/ch/puzzle/okr/service/persistence/CheckInPersistenceServiceIT.java b/backend/src/test/java/ch/puzzle/okr/service/persistence/CheckInPersistenceServiceIT.java index 4605ab2f92..8ec5261b3e 100644 --- a/backend/src/test/java/ch/puzzle/okr/service/persistence/CheckInPersistenceServiceIT.java +++ b/backend/src/test/java/ch/puzzle/okr/service/persistence/CheckInPersistenceServiceIT.java @@ -28,6 +28,8 @@ private static CheckIn createCheckIn(Long id) { return createCheckIn(id, 1); } + private static final String UPDATED_CHECKIN = "Updated CheckIn"; + private static CheckIn createCheckIn(Long id, int version) { return CheckInMetric.Builder.builder().withValue(30D).withId(id).withVersion(version) .withCreatedBy(User.Builder.builder().withId(1L).withFirstname("Frank").build()) @@ -71,20 +73,20 @@ void saveCheckInShouldSaveNewCheckIn() { void updateKeyResultShouldUpdateKeyResult() { createdCheckIn = checkInPersistenceService.save(createCheckIn(null)); CheckIn updateCheckIn = createCheckIn(createdCheckIn.getId(), createdCheckIn.getVersion()); - updateCheckIn.setChangeInfo("Updated CheckIn"); + updateCheckIn.setChangeInfo(UPDATED_CHECKIN); CheckIn updatedCheckIn = checkInPersistenceService.save(updateCheckIn); assertEquals(createdCheckIn.getId(), updatedCheckIn.getId()); assertEquals(createdCheckIn.getVersion() + 1, updatedCheckIn.getVersion()); - assertEquals("Updated CheckIn", updatedCheckIn.getChangeInfo()); + assertEquals(UPDATED_CHECKIN, updatedCheckIn.getChangeInfo()); } @Test void updateKeyResultShouldThrowExceptionWhenAlreadyUpdated() { createdCheckIn = checkInPersistenceService.save(createCheckIn(null)); CheckIn updateCheckIn = createCheckIn(createdCheckIn.getId(), 0); - updateCheckIn.setChangeInfo("Updated CheckIn"); + updateCheckIn.setChangeInfo(UPDATED_CHECKIN); ResponseStatusException exception = assertThrows(ResponseStatusException.class, () -> checkInPersistenceService.save(updateCheckIn)); diff --git a/backend/src/test/java/ch/puzzle/okr/service/persistence/KeyResultPersistenceServiceIT.java b/backend/src/test/java/ch/puzzle/okr/service/persistence/KeyResultPersistenceServiceIT.java index ac167b5a27..6576cfe8d6 100644 --- a/backend/src/test/java/ch/puzzle/okr/service/persistence/KeyResultPersistenceServiceIT.java +++ b/backend/src/test/java/ch/puzzle/okr/service/persistence/KeyResultPersistenceServiceIT.java @@ -47,6 +47,7 @@ private static KeyResult createKeyResultOrdinal(Long id, int version) { } private static final String KEY_RESULT_UPDATED = "Updated Key Result"; + private static final String THIS_IS_DESCRIPTION = "This is a new description"; @AfterEach void tearDown() { @@ -120,7 +121,7 @@ void recreateEntityShouldUpdateKeyResultNoTypeChange() { // Should delete the old KeyResult ResponseStatusException exception = assertThrows(ResponseStatusException.class, this::execute); assertEquals(HttpStatus.NOT_FOUND, exception.getStatus()); - assertEquals("KeyResult with id " + createdKeyResult.getId() + " not found", exception.getReason()); + assertEquals("KeyResult with id " + keyResultId + " not found", exception.getReason()); // delete re-created key result in tearDown() createdKeyResult = recreatedKeyResult; @@ -148,9 +149,9 @@ void recreateEntityShouldUpdateKeyResultWithTypeChange() { Long keyResultId = createdKeyResult.getId(); // Should delete the old KeyResult ResponseStatusException exception = assertThrows(ResponseStatusException.class, - () -> keyResultPersistenceService.findById(createdKeyResult.getId())); + () -> keyResultPersistenceService.findById(keyResultId)); assertEquals(HttpStatus.NOT_FOUND, exception.getStatus()); - assertEquals("KeyResult with id " + createdKeyResult.getId() + " not found", exception.getReason()); + assertEquals("KeyResult with id " + keyResultId + " not found", exception.getReason()); // delete re-created key result in tearDown() createdKeyResult = recreatedKeyResult; @@ -162,14 +163,14 @@ void updateEntityShouldUpdateKeyResult() { createdKeyResult = keyResultPersistenceService.save(keyResult); KeyResult updateKeyResult = createKeyResultOrdinal(createdKeyResult.getId(), createdKeyResult.getVersion()); updateKeyResult.setTitle(KEY_RESULT_UPDATED); - updateKeyResult.setDescription("This is a new description"); + updateKeyResult.setDescription(THIS_IS_DESCRIPTION); KeyResult updatedKeyResult = keyResultPersistenceService.updateEntity(updateKeyResult); assertEquals(createdKeyResult.getId(), updatedKeyResult.getId()); assertEquals(createdKeyResult.getVersion() + 1, updatedKeyResult.getVersion()); assertEquals(KEY_RESULT_UPDATED, updatedKeyResult.getTitle()); - assertEquals("This is a new description", updatedKeyResult.getDescription()); + assertEquals(THIS_IS_DESCRIPTION, updatedKeyResult.getDescription()); assertEquals(createdKeyResult.getOwner().getId(), updatedKeyResult.getOwner().getId()); assertEquals(createdKeyResult.getObjective().getId(), updatedKeyResult.getObjective().getId()); assertEquals(createdKeyResult.getModifiedOn(), updatedKeyResult.getModifiedOn()); @@ -181,7 +182,7 @@ void updateEntityShouldThrowExceptionWhenAlreadyUpdated() { createdKeyResult = keyResultPersistenceService.save(keyResult); KeyResult updateKeyResult = createKeyResultOrdinal(createdKeyResult.getId(), 0); updateKeyResult.setTitle(KEY_RESULT_UPDATED); - updateKeyResult.setDescription("This is a new description"); + updateKeyResult.setDescription(THIS_IS_DESCRIPTION); ResponseStatusException exception = assertThrows(ResponseStatusException.class, () -> keyResultPersistenceService.updateEntity(updateKeyResult)); diff --git a/backend/src/test/java/ch/puzzle/okr/service/persistence/ObjectivePersistenceServiceIT.java b/backend/src/test/java/ch/puzzle/okr/service/persistence/ObjectivePersistenceServiceIT.java index f19ae04b0b..dc41736934 100644 --- a/backend/src/test/java/ch/puzzle/okr/service/persistence/ObjectivePersistenceServiceIT.java +++ b/backend/src/test/java/ch/puzzle/okr/service/persistence/ObjectivePersistenceServiceIT.java @@ -16,8 +16,10 @@ import static org.springframework.http.HttpStatus.*; @SpringIntegrationTest -public class ObjectivePersistenceServiceIT { - private final String reason = "not authorized to read objective"; +class ObjectivePersistenceServiceIT { + private static final String REASON = "not authorized to read objective"; + private static final String MISSING_IDENTIFIER = "Missing identifier for Objective"; + private static final String HIGHER_CUSTOMER_HAPPINESS = "Wir wollen die Kundenzufriedenheit steigern"; private final AuthorizationUser authorizationUser = defaultAuthorizationUser(); private Objective createdObjective; @@ -64,80 +66,80 @@ void findAllShouldReturnListOfObjectives() { @Test void findObjectiveByIdShouldReturnObjectiveProperly() { - Objective objective = objectivePersistenceService.findObjectiveById(3L, authorizationUser, reason); + Objective objective = objectivePersistenceService.findObjectiveById(3L, authorizationUser, REASON); assertEquals(3L, objective.getId()); - assertEquals("Wir wollen die Kundenzufriedenheit steigern", objective.getTitle()); + assertEquals(HIGHER_CUSTOMER_HAPPINESS, objective.getTitle()); } @Test void findObjectiveByIdShouldThrowExceptionWhenObjectiveNotFound() { ResponseStatusException exception = assertThrows(ResponseStatusException.class, - () -> objectivePersistenceService.findObjectiveById(321L, authorizationUser, reason)); + () -> objectivePersistenceService.findObjectiveById(321L, authorizationUser, REASON)); assertEquals(UNAUTHORIZED, exception.getStatus()); - assertEquals("not authorized to read objective", exception.getReason()); + assertEquals(REASON, exception.getReason()); } @Test void findObjectiveByIdShouldThrowExceptionWhenObjectiveIdIsNull() { ResponseStatusException exception = assertThrows(ResponseStatusException.class, - () -> objectivePersistenceService.findObjectiveById(null, authorizationUser, reason)); + () -> objectivePersistenceService.findObjectiveById(null, authorizationUser, REASON)); assertEquals(BAD_REQUEST, exception.getStatus()); - assertEquals("Missing identifier for Objective", exception.getReason()); + assertEquals(MISSING_IDENTIFIER, exception.getReason()); } @Test void findObjectiveByKeyResultIdShouldReturnObjectiveProperly() { - Objective objective = objectivePersistenceService.findObjectiveByKeyResultId(5L, authorizationUser, reason); + Objective objective = objectivePersistenceService.findObjectiveByKeyResultId(5L, authorizationUser, REASON); assertEquals(3L, objective.getId()); - assertEquals("Wir wollen die Kundenzufriedenheit steigern", objective.getTitle()); + assertEquals(HIGHER_CUSTOMER_HAPPINESS, objective.getTitle()); } @Test void findObjectiveByKeyResultIdShouldThrowExceptionWhenObjectiveNotFound() { ResponseStatusException exception = assertThrows(ResponseStatusException.class, - () -> objectivePersistenceService.findObjectiveByKeyResultId(321L, authorizationUser, reason)); + () -> objectivePersistenceService.findObjectiveByKeyResultId(321L, authorizationUser, REASON)); assertEquals(UNAUTHORIZED, exception.getStatus()); - assertEquals("not authorized to read objective", exception.getReason()); + assertEquals(REASON, exception.getReason()); } @Test void findObjectiveByKeyResultIdShouldThrowExceptionWhenObjectiveIdIsNull() { ResponseStatusException exception = assertThrows(ResponseStatusException.class, - () -> objectivePersistenceService.findObjectiveByKeyResultId(null, authorizationUser, reason)); + () -> objectivePersistenceService.findObjectiveByKeyResultId(null, authorizationUser, REASON)); assertEquals(BAD_REQUEST, exception.getStatus()); - assertEquals("Missing identifier for Objective", exception.getReason()); + assertEquals(MISSING_IDENTIFIER, exception.getReason()); } @Test void findObjectiveByCheckInIdShouldReturnObjectiveProperly() { - Objective objective = objectivePersistenceService.findObjectiveByCheckInId(7L, authorizationUser, reason); + Objective objective = objectivePersistenceService.findObjectiveByCheckInId(7L, authorizationUser, REASON); assertEquals(3L, objective.getId()); - assertEquals("Wir wollen die Kundenzufriedenheit steigern", objective.getTitle()); + assertEquals(HIGHER_CUSTOMER_HAPPINESS, objective.getTitle()); } @Test void findObjectiveByCheckInIdShouldThrowExceptionWhenObjectiveNotFound() { ResponseStatusException exception = assertThrows(ResponseStatusException.class, - () -> objectivePersistenceService.findObjectiveByCheckInId(321L, authorizationUser, reason)); + () -> objectivePersistenceService.findObjectiveByCheckInId(321L, authorizationUser, REASON)); assertEquals(UNAUTHORIZED, exception.getStatus()); - assertEquals("not authorized to read objective", exception.getReason()); + assertEquals(REASON, exception.getReason()); } @Test void findObjectiveByCheckInIdShouldThrowExceptionWhenObjectiveIdIsNull() { ResponseStatusException exception = assertThrows(ResponseStatusException.class, - () -> objectivePersistenceService.findObjectiveByCheckInId(null, authorizationUser, reason)); + () -> objectivePersistenceService.findObjectiveByCheckInId(null, authorizationUser, REASON)); assertEquals(BAD_REQUEST, exception.getStatus()); - assertEquals("Missing identifier for Objective", exception.getReason()); + assertEquals(MISSING_IDENTIFIER, exception.getReason()); } @Test @@ -184,7 +186,7 @@ void deleteObjectiveShouldThrowExceptionWhenKeyResultNotFound() { Long objectiveId = createdObjective.getId(); ResponseStatusException exception = assertThrows(ResponseStatusException.class, - () -> objectivePersistenceService.findById(createdObjective.getId())); + () -> objectivePersistenceService.findById(objectiveId)); assertEquals(NOT_FOUND, exception.getStatus()); assertEquals(String.format("Objective with id %d not found", createdObjective.getId()), exception.getReason()); } @@ -208,7 +210,7 @@ void countByTeamAndQuarterShouldThrowErrorIfQuarterDoesNotExist() { Quarter quarterId2 = quarterPersistenceService.findById(2L); ResponseStatusException exceptionTeam = assertThrows(ResponseStatusException.class, () -> objectivePersistenceService.countByTeamAndQuarter(teamPersistenceService.findById(500L), - quarterPersistenceService.findById(2L))); + quarterId2)); assertEquals(NOT_FOUND, exceptionTeam.getStatus()); assertEquals(String.format("Team with id %d not found", 500), exceptionTeam.getReason()); diff --git a/backend/src/test/java/ch/puzzle/okr/service/persistence/OrganisationPersistenceIT.java b/backend/src/test/java/ch/puzzle/okr/service/persistence/OrganisationPersistenceIT.java index aef951ee2d..604a5c3724 100644 --- a/backend/src/test/java/ch/puzzle/okr/service/persistence/OrganisationPersistenceIT.java +++ b/backend/src/test/java/ch/puzzle/okr/service/persistence/OrganisationPersistenceIT.java @@ -16,7 +16,7 @@ import static org.mockito.Mockito.verify; @SpringIntegrationTest -public class OrganisationPersistenceIT { +class OrganisationPersistenceIT { @Autowired private OrganisationPersistenceService organisationPersistenceService; diff --git a/frontend/src/app/keyresult/keyresult.component.ts b/frontend/src/app/keyresult/keyresult.component.ts index c42ed21821..c2a9c8ec79 100644 --- a/frontend/src/app/keyresult/keyresult.component.ts +++ b/frontend/src/app/keyresult/keyresult.component.ts @@ -1,7 +1,5 @@ import { ChangeDetectionStrategy, Component, Input } from '@angular/core'; import { KeyresultMin } from '../shared/types/model/KeyresultMin'; -import { MatDialog } from '@angular/material/dialog'; -import { CheckInHistoryDialogComponent } from '../shared/dialog/check-in-history-dialog/check-in-history-dialog.component'; import { Router } from '@angular/router'; import { DATE_FORMAT } from '../shared/constantLibary';