From e786609c5ebe15f1e236298fa9ac91e3d3dbda17 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Christoph=20G=C3=A4chter?= Date: Thu, 3 Oct 2024 11:30:44 +0200 Subject: [PATCH] fix back log ID and use constants for quarters --- .../main/java/ch/puzzle/okr/Constants.java | 3 ++- .../business/QuarterBusinessService.java | 4 ++- .../ObjectiveValidationService.java | 2 +- .../validation/QuarterValidationService.java | 4 ++- .../okr/controller/QuarterControllerIT.java | 9 ++++--- .../mapper/AlignmentSelectionMapperTest.java | 15 ++++++----- .../puzzle/okr/mapper/OverviewMapperTest.java | 26 +++++++++---------- ...AlignmentSelectionBusinessServiceTest.java | 13 ++++++---- .../business/QuarterBusinessServiceTest.java | 22 +++++++++++----- .../ObjectivePersistenceServiceIT.java | 2 +- .../QuarterPersistenceServiceIT.java | 16 +++++++----- .../ObjectiveValidationServiceTest.java | 17 ++++++------ .../QuarterValidationServiceTest.java | 5 ++-- .../ch/puzzle/okr/test/TestConstants.java | 8 +++--- frontend/cypress/e2e/objective-backlog.cy.ts | 14 +++++----- .../quarter-filter.component.spec.ts | 2 +- .../objective-form.component.spec.ts | 12 ++++----- 17 files changed, 100 insertions(+), 74 deletions(-) diff --git a/backend/src/main/java/ch/puzzle/okr/Constants.java b/backend/src/main/java/ch/puzzle/okr/Constants.java index 469deecb2b..dcc7bb8a03 100644 --- a/backend/src/main/java/ch/puzzle/okr/Constants.java +++ b/backend/src/main/java/ch/puzzle/okr/Constants.java @@ -13,9 +13,10 @@ private Constants() { public static final String ACTION = "Action"; public static final String ALIGNMENT = "Alignment"; public static final String COMPLETED = "Completed"; - public static final String ORGANISATION = "Organisation"; public static final String QUARTER = "Quarter"; public static final String TEAM = "Team"; public static final String USER = "User"; public static final String USER_TEAM = "UserTeam"; + + public static final String BACK_LOG_QUARTER_LABEL = "Backlog"; } diff --git a/backend/src/main/java/ch/puzzle/okr/service/business/QuarterBusinessService.java b/backend/src/main/java/ch/puzzle/okr/service/business/QuarterBusinessService.java index 1fbb86f4fd..5f6c35053b 100644 --- a/backend/src/main/java/ch/puzzle/okr/service/business/QuarterBusinessService.java +++ b/backend/src/main/java/ch/puzzle/okr/service/business/QuarterBusinessService.java @@ -16,6 +16,8 @@ import java.util.List; import java.util.Map; +import static ch.puzzle.okr.Constants.BACK_LOG_QUARTER_LABEL; + @Service public class QuarterBusinessService { private static final Logger logger = LoggerFactory.getLogger(QuarterBusinessService.class); @@ -42,7 +44,7 @@ public Quarter getQuarterById(Long quarterId) { public List getQuarters() { List mostCurrentQuarterList = quarterPersistenceService.getMostCurrentQuarters(); - Quarter backlog = quarterPersistenceService.findByLabel("Backlog"); + Quarter backlog = quarterPersistenceService.findByLabel(BACK_LOG_QUARTER_LABEL); mostCurrentQuarterList.add(0, backlog); return mostCurrentQuarterList; } diff --git a/backend/src/main/java/ch/puzzle/okr/service/validation/ObjectiveValidationService.java b/backend/src/main/java/ch/puzzle/okr/service/validation/ObjectiveValidationService.java index a8fa5f59de..72f518c738 100644 --- a/backend/src/main/java/ch/puzzle/okr/service/validation/ObjectiveValidationService.java +++ b/backend/src/main/java/ch/puzzle/okr/service/validation/ObjectiveValidationService.java @@ -76,7 +76,7 @@ private void throwExceptionWhenNotDraftInBacklogQuarter(Objective model) { } private boolean isInvalidBacklogObjective(Objective model) { - return model.getQuarter().getLabel().equals("Backlog") // + return model.getQuarter().getLabel().equals(BACK_LOG_QUARTER_LABEL) // && model.getQuarter().getStartDate() == null // && model.getQuarter().getEndDate() == null // && (model.getState() != State.DRAFT); diff --git a/backend/src/main/java/ch/puzzle/okr/service/validation/QuarterValidationService.java b/backend/src/main/java/ch/puzzle/okr/service/validation/QuarterValidationService.java index e129abac70..baa9df7252 100644 --- a/backend/src/main/java/ch/puzzle/okr/service/validation/QuarterValidationService.java +++ b/backend/src/main/java/ch/puzzle/okr/service/validation/QuarterValidationService.java @@ -10,6 +10,8 @@ import java.util.List; +import static ch.puzzle.okr.Constants.BACK_LOG_QUARTER_LABEL; + @Service public class QuarterValidationService extends ValidationBase { @@ -29,7 +31,7 @@ public void validateOnUpdate(Long id, Quarter model) { } public static void throwExceptionWhenStartEndDateQuarterIsNull(Quarter model) { - if (!model.getLabel().equals("Backlog")) { + if (!model.getLabel().equals(BACK_LOG_QUARTER_LABEL)) { if (model.getStartDate() == null) { throw new OkrResponseStatusException(HttpStatus.BAD_REQUEST, ErrorKey.ATTRIBUTE_NULL, List.of("StartDate", model.getLabel())); diff --git a/backend/src/test/java/ch/puzzle/okr/controller/QuarterControllerIT.java b/backend/src/test/java/ch/puzzle/okr/controller/QuarterControllerIT.java index 76f9f27da6..cfd844139f 100644 --- a/backend/src/test/java/ch/puzzle/okr/controller/QuarterControllerIT.java +++ b/backend/src/test/java/ch/puzzle/okr/controller/QuarterControllerIT.java @@ -21,6 +21,8 @@ import java.util.Collections; import java.util.List; +import static ch.puzzle.okr.Constants.BACK_LOG_QUARTER_LABEL; +import static ch.puzzle.okr.test.TestConstants.BACK_LOG_QUARTER_ID; import static org.springframework.test.web.servlet.request.MockMvcRequestBuilders.get; import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.jsonPath; @@ -33,8 +35,8 @@ class QuarterControllerIT { .withStartDate(LocalDate.of(2022, 9, 1)).withEndDate(LocalDate.of(2022, 12, 31)).build(); static Quarter quarter2 = Quarter.Builder.builder().withId(2L).withLabel("GJ 22/23-Q3") .withStartDate(LocalDate.of(2023, 1, 1)).withEndDate(LocalDate.of(2023, 3, 31)).build(); - static Quarter backlogQuarter = Quarter.Builder.builder().withId(199L).withLabel("Backlog").withStartDate(null) - .withEndDate(null).build(); + static Quarter backlogQuarter = Quarter.Builder.builder().withId(BACK_LOG_QUARTER_ID) + .withLabel(BACK_LOG_QUARTER_LABEL).withStartDate(null).withEndDate(null).build(); static List quaterList = Arrays.asList(quarter1, quarter2, backlogQuarter); @Autowired @@ -54,7 +56,8 @@ void shouldGetAllQuarters() throws Exception { .andExpect(jsonPath("$[1].id", Is.is(2))).andExpect(jsonPath("$[1].label", Is.is("GJ 22/23-Q3"))) .andExpect(jsonPath("$[1].startDate", Is.is(LocalDate.of(2023, 1, 1).toString()))) .andExpect(jsonPath("$[1].endDate", Is.is(LocalDate.of(2023, 3, 31).toString()))) - .andExpect(jsonPath("$[2].id", Is.is(199))).andExpect(jsonPath("$[2].label", Is.is("Backlog"))); + .andExpect(jsonPath("$[2].id", Is.is((int) BACK_LOG_QUARTER_ID))) + .andExpect(jsonPath("$[2].label", Is.is(BACK_LOG_QUARTER_LABEL))); } @Test diff --git a/backend/src/test/java/ch/puzzle/okr/mapper/AlignmentSelectionMapperTest.java b/backend/src/test/java/ch/puzzle/okr/mapper/AlignmentSelectionMapperTest.java index 26b799ff15..84c1db2ff8 100644 --- a/backend/src/test/java/ch/puzzle/okr/mapper/AlignmentSelectionMapperTest.java +++ b/backend/src/test/java/ch/puzzle/okr/mapper/AlignmentSelectionMapperTest.java @@ -7,6 +7,7 @@ import java.util.List; +import static ch.puzzle.okr.test.TestConstants.TEAM_PUZZLE; import static org.junit.jupiter.api.Assertions.assertEquals; import static org.junit.jupiter.api.Assertions.assertTrue; @@ -25,7 +26,7 @@ void toDtoShouldReturnEmptyListWhenNoObjectiveFound() { void toDtoShouldReturnOneElementWhenObjectiveFound() { List alignmentSelections = List.of(AlignmentSelection.Builder.builder() .withAlignmentSelectionId(AlignmentSelectionId.Builder.builder().withObjectiveId(1L).build()) - .withTeamId(2L).withTeamName("Puzzle ITC").withObjectiveTitle("Objective 1").build()); + .withTeamId(2L).withTeamName(TEAM_PUZZLE).withObjectiveTitle("Objective 1").build()); List alignmentObjectiveDtos = alignmentSelectionMapper.toDto(alignmentSelections); assertEquals(1, alignmentObjectiveDtos.size()); @@ -37,7 +38,7 @@ void toDtoShouldReturnOneElementWhenObjectiveWithKeyResultFound() { List alignmentSelections = List.of(AlignmentSelection.Builder.builder() .withAlignmentSelectionId( AlignmentSelectionId.Builder.builder().withObjectiveId(1L).withKeyResultId(3L).build()) - .withTeamId(2L).withTeamName("Puzzle ITC").withObjectiveTitle("Objective 1") + .withTeamId(2L).withTeamName(TEAM_PUZZLE).withObjectiveTitle("Objective 1") .withKeyResultTitle("Key Result 3").build()); List alignmentObjectiveDtos = alignmentSelectionMapper.toDto(alignmentSelections); @@ -51,12 +52,12 @@ void toDtoShouldReturnOneElementWhenObjectiveWithTwoKeyResultsFound() { AlignmentSelection.Builder.builder() .withAlignmentSelectionId( AlignmentSelectionId.Builder.builder().withObjectiveId(1L).withKeyResultId(3L).build()) - .withTeamId(2L).withTeamName("Puzzle ITC").withObjectiveTitle("Objective 1") + .withTeamId(2L).withTeamName(TEAM_PUZZLE).withObjectiveTitle("Objective 1") .withKeyResultTitle("Key Result 3").build(), AlignmentSelection.Builder.builder() .withAlignmentSelectionId( AlignmentSelectionId.Builder.builder().withObjectiveId(1L).withKeyResultId(5L).build()) - .withTeamId(2L).withTeamName("Puzzle ITC").withObjectiveTitle("Objective 1") + .withTeamId(2L).withTeamName(TEAM_PUZZLE).withObjectiveTitle("Objective 1") .withKeyResultTitle("Key Result 5").build()); List alignmentObjectiveDtos = alignmentSelectionMapper.toDto(alignmentSelections); @@ -70,17 +71,17 @@ void toDtoShouldReturnOneElementWhenTwoObjectivesWithKeyResultsFound() { AlignmentSelection.Builder.builder() .withAlignmentSelectionId( AlignmentSelectionId.Builder.builder().withObjectiveId(1L).withKeyResultId(3L).build()) - .withTeamId(2L).withTeamName("Puzzle ITC").withObjectiveTitle("Objective 1") + .withTeamId(2L).withTeamName(TEAM_PUZZLE).withObjectiveTitle("Objective 1") .withKeyResultTitle("Key Result 3").build(), AlignmentSelection.Builder.builder() .withAlignmentSelectionId( AlignmentSelectionId.Builder.builder().withObjectiveId(5L).withKeyResultId(6L).build()) - .withTeamId(2L).withTeamName("Puzzle ITC").withObjectiveTitle("Objective 5") + .withTeamId(2L).withTeamName(TEAM_PUZZLE).withObjectiveTitle("Objective 5") .withKeyResultTitle("Key Result 6").build(), AlignmentSelection.Builder.builder() .withAlignmentSelectionId( AlignmentSelectionId.Builder.builder().withObjectiveId(1L).withKeyResultId(9L).build()) - .withTeamId(2L).withTeamName("Puzzle ITC").withObjectiveTitle("Objective 1") + .withTeamId(2L).withTeamName(TEAM_PUZZLE).withObjectiveTitle("Objective 1") .withKeyResultTitle("Key Result 9").build()); List alignmentObjectiveDtos = alignmentSelectionMapper.toDto(alignmentSelections); diff --git a/backend/src/test/java/ch/puzzle/okr/mapper/OverviewMapperTest.java b/backend/src/test/java/ch/puzzle/okr/mapper/OverviewMapperTest.java index 0e41ed0dfc..374057e987 100644 --- a/backend/src/test/java/ch/puzzle/okr/mapper/OverviewMapperTest.java +++ b/backend/src/test/java/ch/puzzle/okr/mapper/OverviewMapperTest.java @@ -1,6 +1,5 @@ package ch.puzzle.okr.mapper; -import ch.puzzle.okr.test.TestHelper; import ch.puzzle.okr.dto.ErrorDto; import ch.puzzle.okr.dto.overview.OverviewDto; import ch.puzzle.okr.dto.overview.OverviewKeyResultDto; @@ -9,6 +8,7 @@ import ch.puzzle.okr.exception.OkrResponseStatusException; import ch.puzzle.okr.models.overview.Overview; import ch.puzzle.okr.models.overview.OverviewId; +import ch.puzzle.okr.test.TestHelper; import org.junit.jupiter.api.Test; import org.junit.jupiter.api.extension.ExtendWith; import org.mockito.InjectMocks; @@ -18,6 +18,7 @@ import static ch.puzzle.okr.Constants.KEY_RESULT_TYPE_METRIC; import static ch.puzzle.okr.Constants.KEY_RESULT_TYPE_ORDINAL; +import static ch.puzzle.okr.test.TestConstants.TEAM_PUZZLE; import static org.assertj.core.api.Assertions.assertThat; import static org.junit.jupiter.api.Assertions.*; import static org.springframework.http.HttpStatus.BAD_REQUEST; @@ -38,9 +39,8 @@ void toDtoShouldReturnEmptyListWhenNoTeamFound() { @Test void toDtoShouldReturnEmptyListWhenTeamFound() { - List overviews = List - .of(Overview.Builder.builder().withOverviewId(OverviewId.Builder.builder().withTeamId(2L).build()) - .withTeamName("Puzzle ITC").build()); + List overviews = List.of(Overview.Builder.builder() + .withOverviewId(OverviewId.Builder.builder().withTeamId(2L).build()).withTeamName(TEAM_PUZZLE).build()); List overviewDtos = overviewMapper.toDto(overviews); assertEquals(1, overviewDtos.size()); @@ -51,7 +51,7 @@ void toDtoShouldReturnEmptyListWhenTeamFound() { void toDtoShouldReturnOneElementWhenObjectiveFound() { List overviews = List.of(Overview.Builder.builder() .withOverviewId(OverviewId.Builder.builder().withObjectiveId(1L).withTeamId(2L).build()) - .withTeamName("Puzzle ITC").withObjectiveTitle("Objective 1").build()); + .withTeamName(TEAM_PUZZLE).withObjectiveTitle("Objective 1").build()); List overviewDtos = overviewMapper.toDto(overviews); assertEquals(1, overviewDtos.size()); @@ -64,7 +64,7 @@ void toDtoShouldReturnOneElementWhenObjectiveWithKeyResultFound() { List overviews = List.of(Overview.Builder.builder() .withOverviewId( OverviewId.Builder.builder().withObjectiveId(1L).withTeamId(2L).withKeyResultId(3L).build()) - .withTeamName("Puzzle ITC").withObjectiveTitle("Objective 1").withKeyResultTitle("Key Result 1") + .withTeamName(TEAM_PUZZLE).withObjectiveTitle("Objective 1").withKeyResultTitle("Key Result 1") .withKeyResultType(KEY_RESULT_TYPE_METRIC).build()); List overviewDtos = overviewMapper.toDto(overviews); @@ -78,7 +78,7 @@ void toDtoShouldReturnOneElementWhenObjectiveWithKeyResultAndCheckInsFound() { List overviews = List.of(Overview.Builder.builder() .withOverviewId(OverviewId.Builder.builder().withObjectiveId(1L).withTeamId(2L).withKeyResultId(3L) .withCheckInId(4L).build()) - .withTeamName("Puzzle ITC").withObjectiveTitle("Objective 1").withKeyResultTitle("Key Result 1") + .withTeamName(TEAM_PUZZLE).withObjectiveTitle("Objective 1").withKeyResultTitle("Key Result 1") .withKeyResultType(KEY_RESULT_TYPE_METRIC).withCheckInValue(27.5).withConfidence(5).build()); List overviewDtos = overviewMapper.toDto(overviews); @@ -93,12 +93,12 @@ void toDtoShouldReturnOneElementWhenObjectiveWithTwoKeyResultAndCheckInFound() { Overview.Builder.builder() .withOverviewId(OverviewId.Builder.builder().withObjectiveId(1L).withTeamId(2L) .withKeyResultId(3L).withCheckInId(4L).build()) - .withTeamName("Puzzle ITC").withObjectiveTitle("Objective 1").withKeyResultTitle("Key Result 1") + .withTeamName(TEAM_PUZZLE).withObjectiveTitle("Objective 1").withKeyResultTitle("Key Result 1") .withKeyResultType(KEY_RESULT_TYPE_ORDINAL).withCheckInZone("COMMIT").build(), Overview.Builder.builder() .withOverviewId(OverviewId.Builder.builder().withObjectiveId(1L).withTeamId(2L) .withKeyResultId(5L).build()) - .withTeamName("Puzzle ITC").withObjectiveTitle("Objective 1").withKeyResultTitle("Key Result 5") + .withTeamName(TEAM_PUZZLE).withObjectiveTitle("Objective 1").withKeyResultTitle("Key Result 5") .withKeyResultType(KEY_RESULT_TYPE_METRIC).build()); List overviewDtos = overviewMapper.toDto(overviews); @@ -113,13 +113,13 @@ void toDtoShouldReturnOneElementWhenTwoObjectivesWithKeyResultAndCheckInFound() Overview.Builder.builder() .withOverviewId(OverviewId.Builder.builder().withObjectiveId(1L).withTeamId(2L) .withKeyResultId(3L).withCheckInId(4L).build()) - .withTeamName("Puzzle ITC").withObjectiveTitle("Objective 1").withKeyResultTitle("Key Result 1") + .withTeamName(TEAM_PUZZLE).withObjectiveTitle("Objective 1").withKeyResultTitle("Key Result 1") .withKeyResultType(KEY_RESULT_TYPE_METRIC).withBaseline(20.0).withStretchGoal(37.0) .withUnit("TCHF").withCheckInValue(27.5).build(), Overview.Builder.builder() .withOverviewId(OverviewId.Builder.builder().withObjectiveId(5L).withTeamId(2L) .withKeyResultId(6L).withCheckInId(7L).build()) - .withTeamName("Puzzle ITC").withObjectiveTitle("Objective 5").withKeyResultTitle("Key Result 6") + .withTeamName(TEAM_PUZZLE).withObjectiveTitle("Objective 5").withKeyResultTitle("Key Result 6") .withKeyResultType(KEY_RESULT_TYPE_ORDINAL).withCommitZone("commit").withTargetZone("target") .withStretchZone("stretch").withCheckInZone("checkIn").build()); List overviewDtos = overviewMapper.toDto(overviews); @@ -151,7 +151,7 @@ void toDtoShouldReturnOneElementWhenTwoTeamsWithObjectivesAndKeyResultsFound() { Overview.Builder.builder() .withOverviewId(OverviewId.Builder.builder().withObjectiveId(1L).withTeamId(2L) .withKeyResultId(3L).withCheckInId(4L).build()) - .withTeamName("Puzzle ITC").withObjectiveTitle("Objective 1").withKeyResultTitle("Key Result 1") + .withTeamName(TEAM_PUZZLE).withObjectiveTitle("Objective 1").withKeyResultTitle("Key Result 1") .withKeyResultType(KEY_RESULT_TYPE_ORDINAL).withCheckInZone("TARGET").build(), Overview.Builder.builder() .withOverviewId(OverviewId.Builder.builder().withObjectiveId(5L).withTeamId(4L) @@ -177,7 +177,7 @@ void toDtoShouldThrowExceptionWhenKeyResultTypeNotSupported() { List overviews = List.of(Overview.Builder.builder() .withOverviewId(OverviewId.Builder.builder().withObjectiveId(1L).withTeamId(2L).withKeyResultId(3L) .withCheckInId(4L).build()) - .withTeamName("Puzzle ITC").withObjectiveTitle("Objective 1").withKeyResultTitle("Key Result 1") + .withTeamName(TEAM_PUZZLE).withObjectiveTitle("Objective 1").withKeyResultTitle("Key Result 1") .withKeyResultType("unknown").withCheckInZone("TARGET").build()); OkrResponseStatusException exception = assertThrows(OkrResponseStatusException.class, diff --git a/backend/src/test/java/ch/puzzle/okr/service/business/AlignmentSelectionBusinessServiceTest.java b/backend/src/test/java/ch/puzzle/okr/service/business/AlignmentSelectionBusinessServiceTest.java index 961b1e12cb..91257a4974 100644 --- a/backend/src/test/java/ch/puzzle/okr/service/business/AlignmentSelectionBusinessServiceTest.java +++ b/backend/src/test/java/ch/puzzle/okr/service/business/AlignmentSelectionBusinessServiceTest.java @@ -11,6 +11,7 @@ import java.util.List; +import static ch.puzzle.okr.test.TestConstants.TEAM_PUZZLE; import static org.junit.jupiter.api.Assertions.assertEquals; import static org.mockito.Mockito.*; @@ -24,17 +25,19 @@ class AlignmentSelectionBusinessServiceTest { private static AlignmentSelection createAlignmentSelection() { return AlignmentSelection.Builder.builder().withAlignmentSelectionId(AlignmentSelectionId.of(9L, 15L)) - .withTeamId(5L).withTeamName("Puzzle ITC").withObjectiveTitle("Objective 9").withQuarterId(2L) + .withTeamId(5L).withTeamName(TEAM_PUZZLE).withObjectiveTitle("Objective 9").withQuarterId(2L) .withQuarterLabel("GJ 23/24-Q1").withKeyResultTitle("Key Result 15").build(); } @Test void getAlignmentSelectionByQuarterIdAndTeamIdNotShouldReturnListOfAlignmentSelections() { - when(alignmentSelectionPersistenceService.getAlignmentSelectionByQuarterIdAndTeamIdNot(2L, 4L)) - .thenReturn(List.of(createAlignmentSelection())); + when(alignmentSelectionPersistenceService.getAlignmentSelectionByQuarterIdAndTeamIdNot(2L, + 4L)).thenReturn(List.of( + createAlignmentSelection())); - List alignmentSelections = alignmentSelectionBusinessService - .getAlignmentSelectionByQuarterIdAndTeamIdNot(2L, 4L); + List alignmentSelections = alignmentSelectionBusinessService.getAlignmentSelectionByQuarterIdAndTeamIdNot( + 2L, + 4L); assertEquals(1, alignmentSelections.size()); verify(alignmentSelectionPersistenceService, times(1)).getAlignmentSelectionByQuarterIdAndTeamIdNot(2L, 4L); diff --git a/backend/src/test/java/ch/puzzle/okr/service/business/QuarterBusinessServiceTest.java b/backend/src/test/java/ch/puzzle/okr/service/business/QuarterBusinessServiceTest.java index c931679c21..479620ad3d 100644 --- a/backend/src/test/java/ch/puzzle/okr/service/business/QuarterBusinessServiceTest.java +++ b/backend/src/test/java/ch/puzzle/okr/service/business/QuarterBusinessServiceTest.java @@ -9,16 +9,25 @@ import org.junit.jupiter.params.provider.Arguments; import org.junit.jupiter.params.provider.MethodSource; import org.junit.jupiter.params.provider.ValueSource; -import org.mockito.*; +import org.mockito.InjectMocks; +import org.mockito.Mock; +import org.mockito.Mockito; +import org.mockito.Spy; import org.mockito.junit.jupiter.MockitoExtension; import org.springframework.test.util.ReflectionTestUtils; import java.time.LocalDate; import java.time.YearMonth; -import java.util.*; +import java.util.ArrayList; +import java.util.Arrays; +import java.util.List; +import java.util.Map; import java.util.stream.Stream; -import static org.junit.jupiter.api.Assertions.*; +import static ch.puzzle.okr.Constants.BACK_LOG_QUARTER_LABEL; +import static ch.puzzle.okr.test.TestConstants.BACK_LOG_QUARTER_ID; +import static org.junit.jupiter.api.Assertions.assertEquals; +import static org.junit.jupiter.api.Assertions.assertNull; import static org.mockito.Mockito.*; @ExtendWith(MockitoExtension.class) @@ -71,13 +80,14 @@ void shouldGetBacklogQuarter() { .withStartDate(LocalDate.of(2022, 8, 1)).withEndDate(LocalDate.of(2022, 11, 30)).build(); List quarterList = new ArrayList<>(Arrays.asList(realQuarter1, realQuarter2)); - Quarter backlogQuarter = Quarter.Builder.builder().withId(199L).withLabel("Backlog").build(); + Quarter backlogQuarter = Quarter.Builder.builder().withId(BACK_LOG_QUARTER_ID).withLabel(BACK_LOG_QUARTER_LABEL) + .build(); when(quarterPersistenceService.getMostCurrentQuarters()).thenReturn(quarterList); - when(quarterPersistenceService.findByLabel("Backlog")).thenReturn(backlogQuarter); + when(quarterPersistenceService.findByLabel(BACK_LOG_QUARTER_LABEL)).thenReturn(backlogQuarter); quarterList = quarterBusinessService.getQuarters(); assertEquals(3, quarterList.size()); - assertEquals("Backlog", quarterList.get(0).getLabel()); + assertEquals(BACK_LOG_QUARTER_LABEL, quarterList.get(0).getLabel()); assertNull(quarterList.get(0).getStartDate()); assertNull(quarterList.get(0).getEndDate()); } 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 f6fed4a394..ccc6c3a8a0 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,6 +16,7 @@ import java.time.LocalDateTime; import java.util.List; +import static ch.puzzle.okr.test.TestConstants.GJ_FOR_TESTS_QUARTER_ID; import static ch.puzzle.okr.test.TestHelper.defaultAuthorizationUser; import static org.assertj.core.api.Assertions.assertThat; import static org.junit.jupiter.api.Assertions.*; @@ -29,7 +30,6 @@ class ObjectivePersistenceServiceIT { private static final String MODEL_WITH_ID_NOT_FOUND = "MODEL_WITH_ID_NOT_FOUND"; private static final String OBJECTIVE = "Objective"; private static final String ATTRIBUTE_NULL = "ATTRIBUTE_NULL"; - private static final long GJ_FOR_TESTS_QUARTER_ID = 99L; private final AuthorizationUser authorizationUser = defaultAuthorizationUser(); private Objective createdObjective; diff --git a/backend/src/test/java/ch/puzzle/okr/service/persistence/QuarterPersistenceServiceIT.java b/backend/src/test/java/ch/puzzle/okr/service/persistence/QuarterPersistenceServiceIT.java index 589ea9e4c3..23a1ce5faf 100644 --- a/backend/src/test/java/ch/puzzle/okr/service/persistence/QuarterPersistenceServiceIT.java +++ b/backend/src/test/java/ch/puzzle/okr/service/persistence/QuarterPersistenceServiceIT.java @@ -16,6 +16,8 @@ import java.time.LocalDate; import java.util.List; +import static ch.puzzle.okr.test.TestConstants.GJ_FOR_TESTS_QUARTER_ID; +import static ch.puzzle.okr.test.TestConstants.GJ_FOR_TEST_QUARTER_LABEL; import static org.assertj.core.api.Assertions.assertThat; import static org.junit.jupiter.api.Assertions.*; import static org.springframework.http.HttpStatus.BAD_REQUEST; @@ -39,10 +41,10 @@ void tearDown() { @Test void shouldReturnSingleQuarterWhenFindingByValidId() { - Quarter returnedQuarter = quarterPersistenceService.findById(99L); + Quarter returnedQuarter = quarterPersistenceService.findById(GJ_FOR_TESTS_QUARTER_ID); - assertEquals(99L, returnedQuarter.getId()); - assertEquals("GJ ForTests", returnedQuarter.getLabel()); + assertEquals(GJ_FOR_TESTS_QUARTER_ID, returnedQuarter.getId()); + assertEquals(GJ_FOR_TEST_QUARTER_LABEL, returnedQuarter.getLabel()); assertEquals(LocalDate.of(2000, 7, 1), returnedQuarter.getStartDate()); assertEquals(LocalDate.of(2000, 9, 30), returnedQuarter.getEndDate()); } @@ -83,7 +85,7 @@ void getMostCurrentQuartersShouldReturnCurrentQuarterAndFutureQuarterAndGJForTes private void assertGJForTestsQuarterIsFoundOnce(List quarters) { long foundGJForTestsQuartersCount = quarters.stream() - .filter(quarter -> quarter.getLabel().equals("GJ ForTests")).count(); + .filter(quarter -> quarter.getLabel().equals(GJ_FOR_TEST_QUARTER_LABEL)).count(); assertEquals(1, foundGJForTestsQuartersCount); } @@ -111,11 +113,11 @@ void shouldReturnCurrentQuarter() { @Test void findByLabelShouldReturnSingleQuarterWhenLabelIsValid() { // arrange + act - Quarter returnedQuarter = quarterPersistenceService.findByLabel("GJ ForTests"); + Quarter returnedQuarter = quarterPersistenceService.findByLabel(GJ_FOR_TEST_QUARTER_LABEL); // assert - assertEquals(99L, returnedQuarter.getId()); - assertEquals("GJ ForTests", returnedQuarter.getLabel()); + assertEquals(GJ_FOR_TESTS_QUARTER_ID, returnedQuarter.getId()); + assertEquals(GJ_FOR_TEST_QUARTER_LABEL, returnedQuarter.getLabel()); assertEquals(LocalDate.of(2000, 7, 1), returnedQuarter.getStartDate()); assertEquals(LocalDate.of(2000, 9, 30), returnedQuarter.getEndDate()); } diff --git a/backend/src/test/java/ch/puzzle/okr/service/validation/ObjectiveValidationServiceTest.java b/backend/src/test/java/ch/puzzle/okr/service/validation/ObjectiveValidationServiceTest.java index 5d07c6f15d..cc52bad997 100644 --- a/backend/src/test/java/ch/puzzle/okr/service/validation/ObjectiveValidationServiceTest.java +++ b/backend/src/test/java/ch/puzzle/okr/service/validation/ObjectiveValidationServiceTest.java @@ -1,10 +1,10 @@ package ch.puzzle.okr.service.validation; -import ch.puzzle.okr.test.TestHelper; import ch.puzzle.okr.dto.ErrorDto; import ch.puzzle.okr.exception.OkrResponseStatusException; import ch.puzzle.okr.models.*; import ch.puzzle.okr.service.persistence.ObjectivePersistenceService; +import ch.puzzle.okr.test.TestHelper; import org.apache.commons.lang3.StringUtils; import org.junit.jupiter.api.BeforeEach; import org.junit.jupiter.api.Test; @@ -13,7 +13,6 @@ import org.junit.jupiter.params.provider.Arguments; import org.junit.jupiter.params.provider.EnumSource; import org.junit.jupiter.params.provider.MethodSource; -import org.junit.jupiter.params.provider.ValueSource; import org.mockito.InjectMocks; import org.mockito.Mockito; import org.mockito.Spy; @@ -26,6 +25,8 @@ import java.util.List; import java.util.stream.Stream; +import static ch.puzzle.okr.Constants.BACK_LOG_QUARTER_LABEL; +import static ch.puzzle.okr.test.TestConstants.BACK_LOG_QUARTER_ID; import static org.assertj.core.api.Assertions.assertThat; import static org.junit.jupiter.api.Assertions.*; import static org.junit.jupiter.params.provider.Arguments.arguments; @@ -384,8 +385,8 @@ void validateOnUpdateShouldThrowExceptionWheTeamHasChanged() { @ParameterizedTest @EnumSource(value = State.class, names = { "DRAFT" }, mode = EnumSource.Mode.EXCLUDE) void validateOnCreateShouldThrowExceptionWhenQuarterIsBacklogAndStateIsNotDraft(State state) { - Quarter backlogQuarter = Quarter.Builder.builder().withId(199L).withLabel("Backlog").withStartDate(null) - .withEndDate(null).build(); + Quarter backlogQuarter = Quarter.Builder.builder().withId(BACK_LOG_QUARTER_ID).withLabel(BACK_LOG_QUARTER_LABEL) + .withStartDate(null).withEndDate(null).build(); Objective invalidObjective = Objective.Builder.builder().withTitle("Invalid Objective").withCreatedBy(user) .withCreatedOn(LocalDateTime.MAX).withState(state).withTeam(team).withQuarter(backlogQuarter).build(); @@ -403,8 +404,8 @@ void validateOnCreateShouldThrowExceptionWhenQuarterIsBacklogAndStateIsNotDraft( @ParameterizedTest @EnumSource(value = State.class, names = { "DRAFT" }, mode = EnumSource.Mode.EXCLUDE) void validateOnUpdateShouldThrowExceptionWhenQuarterIsBacklogAndStateIsNotDraft(State state) { - Quarter backlogQuarter = Quarter.Builder.builder().withId(199L).withLabel("Backlog").withStartDate(null) - .withEndDate(null).build(); + Quarter backlogQuarter = Quarter.Builder.builder().withId(BACK_LOG_QUARTER_ID).withLabel(BACK_LOG_QUARTER_LABEL) + .withStartDate(null).withEndDate(null).build(); Objective invalidObjective = Objective.Builder.builder().withId(1L).withTitle("Invalid Objective") .withCreatedBy(user).withCreatedOn(LocalDateTime.MAX).withState(state).withTeam(team) @@ -422,8 +423,8 @@ void validateOnUpdateShouldThrowExceptionWhenQuarterIsBacklogAndStateIsNotDraft( @Test void validateOnUpdateShouldPassWhenQuarterIsBacklogAndStateIsDraft() { - Quarter backlogQuarter = Quarter.Builder.builder().withId(199L).withLabel("Backlog").withStartDate(null) - .withEndDate(null).build(); + Quarter backlogQuarter = Quarter.Builder.builder().withId(BACK_LOG_QUARTER_ID).withLabel(BACK_LOG_QUARTER_LABEL) + .withStartDate(null).withEndDate(null).build(); Objective validObjective = Objective.Builder.builder().withId(1L).withTitle("Invalid Objective") .withCreatedBy(user).withCreatedOn(LocalDateTime.MAX).withState(State.DRAFT).withTeam(team) diff --git a/backend/src/test/java/ch/puzzle/okr/service/validation/QuarterValidationServiceTest.java b/backend/src/test/java/ch/puzzle/okr/service/validation/QuarterValidationServiceTest.java index cefe3e4567..d47a98e53c 100644 --- a/backend/src/test/java/ch/puzzle/okr/service/validation/QuarterValidationServiceTest.java +++ b/backend/src/test/java/ch/puzzle/okr/service/validation/QuarterValidationServiceTest.java @@ -1,10 +1,10 @@ package ch.puzzle.okr.service.validation; -import ch.puzzle.okr.test.TestHelper; import ch.puzzle.okr.dto.ErrorDto; import ch.puzzle.okr.exception.OkrResponseStatusException; import ch.puzzle.okr.models.Quarter; import ch.puzzle.okr.service.persistence.QuarterPersistenceService; +import ch.puzzle.okr.test.TestHelper; import org.junit.jupiter.api.DisplayName; import org.junit.jupiter.api.Test; import org.junit.jupiter.api.extension.ExtendWith; @@ -17,6 +17,7 @@ import java.time.LocalDate; import java.util.List; +import static ch.puzzle.okr.Constants.BACK_LOG_QUARTER_LABEL; import static org.assertj.core.api.Assertions.assertThat; import static org.junit.jupiter.api.Assertions.*; import static org.mockito.Mockito.*; @@ -36,7 +37,7 @@ class QuarterValidationServiceTest { void throwExceptionWhenStartEndDateQuarterIsNullShouldDoNothingWhenQuarterLabelIsBacklog() { // arrange Quarter quarter = mock(Quarter.class); - when(quarter.getLabel()).thenReturn("Backlog"); + when(quarter.getLabel()).thenReturn(BACK_LOG_QUARTER_LABEL); // act QuarterValidationService.throwExceptionWhenStartEndDateQuarterIsNull(quarter); diff --git a/backend/src/test/java/ch/puzzle/okr/test/TestConstants.java b/backend/src/test/java/ch/puzzle/okr/test/TestConstants.java index b7453ac0b5..5dede20076 100644 --- a/backend/src/test/java/ch/puzzle/okr/test/TestConstants.java +++ b/backend/src/test/java/ch/puzzle/okr/test/TestConstants.java @@ -4,9 +4,9 @@ public class TestConstants { private TestConstants() { } - public static final String ORGANISATION_FIRST_LEVEL = "org_gl"; - public static final String ORGANISATION_SECOND_LEVEL = "org_bl"; - public static final String ORGANISATION_TEAM = "org_mobility"; - public static final String TEAM_PUZZLE = "Puzzle ITC"; + public static final String GJ_FOR_TEST_QUARTER_LABEL = "GJ ForTests"; + + public static final long GJ_FOR_TESTS_QUARTER_ID = 99L; + public static final long BACK_LOG_QUARTER_ID = 999L; } diff --git a/frontend/cypress/e2e/objective-backlog.cy.ts b/frontend/cypress/e2e/objective-backlog.cy.ts index bf7aefb375..aff1c3f7e5 100644 --- a/frontend/cypress/e2e/objective-backlog.cy.ts +++ b/frontend/cypress/e2e/objective-backlog.cy.ts @@ -18,7 +18,7 @@ describe('OKR Objective Backlog e2e tests', () => { cy.get('Objective in quarter backlog').should('not.exist'); - cy.visit('/?quarter=199'); + cy.visit('/?quarter=999'); cy.contains('Objective in quarter backlog'); }); @@ -41,7 +41,7 @@ describe('OKR Objective Backlog e2e tests', () => { cy.get('This goes now to backlog').should('not.exist'); - cy.visit('/?quarter=199'); + cy.visit('/?quarter=999'); cy.contains('This goes now to backlog'); }); @@ -65,7 +65,7 @@ describe('OKR Objective Backlog e2e tests', () => { }); it(`Can release Objective to another quarter from backlog`, () => { - cy.visit('/?quarter=199'); + cy.visit('/?quarter=999'); cy.getByTestId('add-objective').first().click(); cy.getByTestId('title').first().clear().type('We can not release this'); cy.getByTestId('safe').should('not.exist'); @@ -103,7 +103,7 @@ describe('OKR Objective Backlog e2e tests', () => { }); it(`Can edit Objective title in backlog`, () => { - cy.visit('/?quarter=199'); + cy.visit('/?quarter=999'); cy.getByTestId('add-objective').first().click(); cy.fillOutObjective('This is possible for edit', 'safe-draft', undefined, '', false); @@ -125,7 +125,7 @@ describe('OKR Objective Backlog e2e tests', () => { }); it(`Can edit Objective in backlog and change quarter`, () => { - cy.visit('/?quarter=199'); + cy.visit('/?quarter=999'); cy.getByTestId('add-objective').first().click(); cy.fillOutObjective('This goes to other quarter later', 'safe-draft', undefined, '', false); @@ -147,7 +147,7 @@ describe('OKR Objective Backlog e2e tests', () => { }); it(`Can duplicate from backlog`, () => { - cy.visit('/?quarter=199'); + cy.visit('/?quarter=999'); cy.getByTestId('add-objective').first().click(); cy.fillOutObjective('Ready for duplicate', 'safe-draft', undefined, '', false); @@ -200,7 +200,7 @@ describe('OKR Objective Backlog e2e tests', () => { cy.get('select#quarter').select('Backlog'); cy.getByTestId('safe').first().click(); - cy.visit('/?quarter=199'); + cy.visit('/?quarter=999'); cy.contains('Possible to duplicate into backlog'); }); }); diff --git a/frontend/src/app/components/quarter-filter/quarter-filter.component.spec.ts b/frontend/src/app/components/quarter-filter/quarter-filter.component.spec.ts index 114d4716b3..e2507f74ce 100644 --- a/frontend/src/app/components/quarter-filter/quarter-filter.component.spec.ts +++ b/frontend/src/app/components/quarter-filter/quarter-filter.component.spec.ts @@ -21,7 +21,7 @@ const overviewService = { }; const quarters = [ - { id: 199, label: 'Backlog', startDate: null, endDate: null }, + { id: 999, label: 'Backlog', startDate: null, endDate: null }, { ...quarter, id: 2 }, { ...quarter, id: 5 }, { ...quarter, id: 7 }, diff --git a/frontend/src/app/shared/dialog/objective-dialog/objective-form.component.spec.ts b/frontend/src/app/shared/dialog/objective-dialog/objective-form.component.spec.ts index b98b302ef2..47ca3ba9ff 100644 --- a/frontend/src/app/shared/dialog/objective-dialog/objective-form.component.spec.ts +++ b/frontend/src/app/shared/dialog/objective-dialog/objective-form.component.spec.ts @@ -40,7 +40,7 @@ const quarterService = { return of([ { id: 1, startDate: quarter.startDate, endDate: quarter.endDate, label: quarter.label }, { id: 2, startDate: quarter.startDate, endDate: quarter.endDate, label: quarter.label }, - { id: 199, startDate: null, endDate: null, label: 'Backlog' }, + { id: 999, startDate: null, endDate: null, label: 'Backlog' }, ]); }, }; @@ -68,7 +68,7 @@ let matDataMock: { objective: { objectiveId: number | undefined; teamId: number const mockActivatedRoute = { snapshot: { queryParams: { - quarter: '199', + quarter: '999', }, }, }; @@ -293,8 +293,8 @@ describe('ObjectiveDialogComponent', () => { it('should return if option is allowed for quarter select', async () => { let quarter: Quarter = { - id: 199, - label: 'GJ 22/23-Q3', + id: 999, + label: 'Backlog', startDate: null, endDate: null, }; @@ -386,7 +386,7 @@ describe('ObjectiveDialogComponent', () => { isBacklogQuarterSpy.mockReturnValue(false); const routerHarness = await RouterTestingHarness.create(); - await routerHarness.navigateByUrl('/?quarter=199'); + await routerHarness.navigateByUrl('/?quarter=999'); objectiveService.getFullObjective.mockReturnValue(of(objective)); fixture.detectChanges(); component.ngOnInit(); @@ -395,7 +395,7 @@ describe('ObjectiveDialogComponent', () => { expect(rawFormValue.title).toBe(objective.title); expect(rawFormValue.description).toBe(objective.description); expect(rawFormValue.team).toBe(objective.teamId); - expect(rawFormValue.quarter).not.toBe(199); + expect(rawFormValue.quarter).not.toBe(999); expect(rawFormValue.quarter).toBe(2); }); });