From e8057730146a8aff6a048161dab93f12fdb7a87c Mon Sep 17 00:00:00 2001 From: Lias Kleisa Date: Wed, 1 Nov 2023 14:48:12 +0100 Subject: [PATCH] Fix current backend tests --- .../V1_0_0__current-db-schema-for-testing.sql | 6 ++-- .../ch/puzzle/okr/KeyResultTestHelpers.java | 17 +++++++---- .../business/KeyResultBusinessServiceIT.java | 28 +++++++++++++++++++ .../KeyResultBusinessServiceTest.java | 4 --- .../OverviewPersistenceServiceIT.java | 10 ++++--- 5 files changed, 48 insertions(+), 17 deletions(-) diff --git a/backend/src/main/resources/db/h2-db/database-h2-schema/V1_0_0__current-db-schema-for-testing.sql b/backend/src/main/resources/db/h2-db/database-h2-schema/V1_0_0__current-db-schema-for-testing.sql index c1e44f1027..1af942e41f 100644 --- a/backend/src/main/resources/db/h2-db/database-h2-schema/V1_0_0__current-db-schema-for-testing.sql +++ b/backend/src/main/resources/db/h2-db/database-h2-schema/V1_0_0__current-db-schema-for-testing.sql @@ -137,7 +137,7 @@ DROP VIEW IF EXISTS OVERVIEW; CREATE VIEW OVERVIEW AS SELECT TQ.TEAM_ID AS "TEAM_ID", TQ.NAME AS "TEAM_NAME", - TQ.QUATER_ID AS "QUARTER_ID", + TQ.QUARTER_ID AS "QUARTER_ID", TQ.LABEL AS "QUARTER_LABEL", COALESCE(O.ID, -1) AS "OBJECTIVE_ID", O.TITLE AS "OBJECTIVE_TITLE", @@ -157,10 +157,10 @@ SELECT TQ.TEAM_ID AS "TEAM_ID", C.ZONE AS "CHECK_IN_ZONE", C.CONFIDENCE, C.CREATED_ON AS "CHECK_IN_CREATED_ON" -FROM (SELECT T.ID AS TEAM_ID, T.NAME, Q.ID AS QUATER_ID, Q.LABEL +FROM (SELECT T.ID AS TEAM_ID, T.NAME, Q.ID AS QUARTER_ID, Q.LABEL FROM TEAM T, QUARTER Q) TQ - LEFT JOIN OBJECTIVE O ON TQ.TEAM_ID = O.TEAM_ID AND TQ.QUATER_ID = O.QUARTER_ID + LEFT JOIN OBJECTIVE O ON TQ.TEAM_ID = O.TEAM_ID AND TQ.QUARTER_ID = O.QUARTER_ID LEFT JOIN KEY_RESULT KR ON O.ID = KR.OBJECTIVE_ID LEFT JOIN CHECK_IN C ON KR.ID = C.KEY_RESULT_ID AND C.MODIFIED_ON = (SELECT MAX(CC.MODIFIED_ON) FROM CHECK_IN CC diff --git a/backend/src/test/java/ch/puzzle/okr/KeyResultTestHelpers.java b/backend/src/test/java/ch/puzzle/okr/KeyResultTestHelpers.java index 535b83b56c..1533032cfe 100644 --- a/backend/src/test/java/ch/puzzle/okr/KeyResultTestHelpers.java +++ b/backend/src/test/java/ch/puzzle/okr/KeyResultTestHelpers.java @@ -15,6 +15,7 @@ import java.time.LocalDate; import java.time.LocalDateTime; +import java.util.List; import static ch.puzzle.okr.Constants.KEY_RESULT_TYPE_METRIC; import static ch.puzzle.okr.Constants.KEY_RESULT_TYPE_ORDINAL; @@ -99,10 +100,10 @@ public class KeyResultTestHelpers { public static final KeyResultMetricDto keyResultMetricDto = new KeyResultMetricDto(5L, KEY_RESULT_TYPE_METRIC, TITLE, DESCRIPTION, 1.0, 5.0, KEY_RESULT_UNIT, keyResultUserDto, keyResultObjectiveDto, - keyResultLastCheckInDto, LocalDateTime.MIN, LocalDateTime.MAX, true, null); + keyResultLastCheckInDto, LocalDateTime.MIN, LocalDateTime.MAX, true, List.of()); public static final KeyResultOrdinalDto keyResultOrdinalDto = new KeyResultOrdinalDto(5L, KEY_RESULT_TYPE_ORDINAL, TITLE, DESCRIPTION, COMMIT_ZONE, TARGET_ZONE, STRETCH_ZONE, keyResultUserDto, keyResultObjectiveDto, - keyResultLastCheckInOrdinalDto, LocalDateTime.MIN, LocalDateTime.MAX, true, null); + keyResultLastCheckInOrdinalDto, LocalDateTime.MIN, LocalDateTime.MAX, true, List.of()); public static final Objective objective = Objective.Builder.builder().withId(5L).withTitle("Objective 1").build(); public static final KeyResult ordinalKeyResult = KeyResultOrdinal.Builder.builder().withId(3L) .withTitle("Keyresult 2").withOwner(user).withObjective(objective).build(); @@ -120,7 +121,8 @@ public class KeyResultTestHelpers { "modifiedOn":null, "baseline":2.0, "stretchGoal":5.0, - "unit":"FTE" + "unit":"FTE", + "actionList":[] } """; @@ -137,7 +139,8 @@ public class KeyResultTestHelpers { "modifiedOn":null, "commitZone":"Eine Pflanze", "targetZone":"Ein Baum", - "stretchZone":"Ein Wald" + "stretchZone":"Ein Wald", + "actionList":[] } """; @@ -181,7 +184,8 @@ public class KeyResultTestHelpers { "modifiedOn":null, "baseline":2.0, "stretchGoal":5.0, - "unit":"PERCENT" + "unit":"PERCENT", + "actionList":[] } """; @@ -212,7 +216,8 @@ public class KeyResultTestHelpers { "createdByFirstname":"", "createdByLastname":"", "createdOn":null, - "modifiedOn":null + "modifiedOn":null, + "actionList":[] } """; 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 bdac4880b3..288f398b31 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 @@ -1,5 +1,6 @@ package ch.puzzle.okr.service.business; +import ch.puzzle.okr.models.Action; import ch.puzzle.okr.models.Objective; import ch.puzzle.okr.models.Unit; import ch.puzzle.okr.models.User; @@ -11,18 +12,28 @@ import ch.puzzle.okr.models.keyresult.KeyResult; import ch.puzzle.okr.models.keyresult.KeyResultMetric; import ch.puzzle.okr.models.keyresult.KeyResultOrdinal; +import ch.puzzle.okr.service.authorization.ActionAuthorizationService; +import ch.puzzle.okr.service.authorization.AuthorizationService; import ch.puzzle.okr.test.SpringIntegrationTest; import org.junit.jupiter.api.AfterEach; +import org.junit.jupiter.api.BeforeEach; import org.junit.jupiter.api.Test; +import org.mockito.Mock; import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.boot.test.mock.mockito.MockBean; import org.springframework.web.server.ResponseStatusException; import java.time.LocalDateTime; +import java.util.ArrayList; +import java.util.List; 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.KeyResultTestHelpers.ordinalKeyResult; import static ch.puzzle.okr.TestHelper.defaultAuthorizationUser; import static org.junit.jupiter.api.Assertions.assertEquals; +import static org.mockito.ArgumentMatchers.any; +import static org.mockito.Mockito.when; @SpringIntegrationTest class KeyResultBusinessServiceIT { @@ -37,6 +48,12 @@ class KeyResultBusinessServiceIT { @Autowired private CheckInBusinessService checkInBusinessService; + @Mock + private ActionAuthorizationService actionAuthorizationService; + + @MockBean + private AuthorizationService authorizationService; + private static KeyResult createKeyResultMetric(Long id) { return KeyResultMetric.Builder.builder().withBaseline(3.0).withStretchGoal(5.0).withUnit(Unit.FTE).withId(id) .withTitle("Title").withCreatedBy(User.Builder.builder().withId(1L).build()) @@ -63,6 +80,17 @@ private static CheckIn createCheckInOrdinal(KeyResult keyResult) { .build(); } + @BeforeEach + void setUp() { + Action action1 = Action.Builder.builder().withId(11L).withIsChecked(false).withAction("Neuer Drucker") + .withPriority(0).withKeyResult(ordinalKeyResult).build(); + Action action2 = Action.Builder.builder().withId(22L).withIsChecked(false).withAction("Neues Papier") + .withPriority(1).withKeyResult(ordinalKeyResult).build(); + List actionList = List.of(action1, action2); + when(authorizationService.getAuthorizationUser()).thenReturn(authorizationUser); + when(actionAuthorizationService.getEntitiesByKeyResultId(any())).thenReturn(actionList); + } + @AfterEach void tearDown() { try { 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 a0186c7fb3..5865e97713 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 @@ -11,7 +11,6 @@ import ch.puzzle.okr.models.keyresult.KeyResultMetric; import ch.puzzle.okr.models.keyresult.KeyResultOrdinal; import ch.puzzle.okr.service.authorization.ActionAuthorizationService; -import ch.puzzle.okr.service.persistence.ActionPersistenceService; import ch.puzzle.okr.service.persistence.KeyResultPersistenceService; import ch.puzzle.okr.service.validation.KeyResultValidationService; @@ -21,7 +20,6 @@ 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.http.HttpStatus; import org.springframework.web.server.ResponseStatusException; @@ -45,8 +43,6 @@ class KeyResultBusinessServiceTest { @InjectMocks KeyResultValidationService validator = Mockito.mock(KeyResultValidationService.class); @Mock - ActionPersistenceService actionPersistenceService = Mockito.mock(ActionPersistenceService.class); - @Mock ActionAuthorizationService actionAuthorizationService = Mockito.mock(ActionAuthorizationService.class); @InjectMocks private KeyResultBusinessService keyResultBusinessService; diff --git a/backend/src/test/java/ch/puzzle/okr/service/persistence/OverviewPersistenceServiceIT.java b/backend/src/test/java/ch/puzzle/okr/service/persistence/OverviewPersistenceServiceIT.java index 4072e52b46..c234369575 100644 --- a/backend/src/test/java/ch/puzzle/okr/service/persistence/OverviewPersistenceServiceIT.java +++ b/backend/src/test/java/ch/puzzle/okr/service/persistence/OverviewPersistenceServiceIT.java @@ -25,7 +25,7 @@ void getFilteredOverviewShouldReturnOverviews() { List overviews = overviewPersistenceService.getFilteredOverview(2L, List.of(5L, 6L, 8L), "", authorizationUser); - assertEquals(12, overviews.size()); + assertEquals(13, overviews.size()); assertIterableEquals(getOverviewIdsForFilteredOverviewShouldReturnOverviews(), getOverviewIds(overviews)); } @@ -34,7 +34,7 @@ void getFilteredOverviewShouldReturnOverviewsWhenObjectiveQuery() { List overviews = overviewPersistenceService.getFilteredOverview(2L, List.of(5L, 6L, 8L), "kundenzufriedenheit", authorizationUser); - assertEquals(3, overviews.size()); + assertEquals(4, overviews.size()); assertIterableEquals(getOverviewIdsForFilteredOverviewShouldReturnOverviewsWhenObjectiveQuery(), getOverviewIds(overviews)); } @@ -47,10 +47,12 @@ private static List getOverviewIdsForFilteredOverviewShouldReturnOve return List.of(OverviewId.of(5L, 3L, 3L, 9L), OverviewId.of(5L, 3L, 4L, 8L), OverviewId.of(5L, 3L, 5L, 7L), OverviewId.of(5L, 4L, 6L, 5L), OverviewId.of(5L, 4L, 7L, 4L), OverviewId.of(5L, 4L, 8L, 2L), OverviewId.of(6L, 8L, 18L, 20L), OverviewId.of(6L, 8L, 19L, 19L), OverviewId.of(6L, 9L, 15L, 18L), - OverviewId.of(6L, 9L, 16L, 17L), OverviewId.of(6L, 9L, 17L, 16L), OverviewId.of(6L, 10L, -1L, -1L)); + OverviewId.of(6L, 9L, 16L, 17L), OverviewId.of(6L, 9L, 17L, 16L), OverviewId.of(6L, 10L, -1L, -1L), + OverviewId.of(8L, -1L, -1L, -1L)); } private static List getOverviewIdsForFilteredOverviewShouldReturnOverviewsWhenObjectiveQuery() { - return List.of(OverviewId.of(5L, 3L, 3L, 9L), OverviewId.of(5L, 3L, 4L, 8L), OverviewId.of(5L, 3L, 5L, 7L)); + return List.of(OverviewId.of(5L, 3L, 3L, 9L), OverviewId.of(5L, 3L, 4L, 8L), OverviewId.of(5L, 3L, 5L, 7L), + OverviewId.of(8L, -1L, -1L, -1L)); } } \ No newline at end of file