Skip to content

Commit

Permalink
Fix current backend tests
Browse files Browse the repository at this point in the history
  • Loading branch information
lkleisa committed Nov 1, 2023
1 parent 2eec4b9 commit e805773
Show file tree
Hide file tree
Showing 5 changed files with 48 additions and 17 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand All @@ -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
Expand Down
17 changes: 11 additions & 6 deletions backend/src/test/java/ch/puzzle/okr/KeyResultTestHelpers.java
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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();
Expand All @@ -120,7 +121,8 @@ public class KeyResultTestHelpers {
"modifiedOn":null,
"baseline":2.0,
"stretchGoal":5.0,
"unit":"FTE"
"unit":"FTE",
"actionList":[]
}
""";

Expand All @@ -137,7 +139,8 @@ public class KeyResultTestHelpers {
"modifiedOn":null,
"commitZone":"Eine Pflanze",
"targetZone":"Ein Baum",
"stretchZone":"Ein Wald"
"stretchZone":"Ein Wald",
"actionList":[]
}
""";

Expand Down Expand Up @@ -181,7 +184,8 @@ public class KeyResultTestHelpers {
"modifiedOn":null,
"baseline":2.0,
"stretchGoal":5.0,
"unit":"PERCENT"
"unit":"PERCENT",
"actionList":[]
}
""";

Expand Down Expand Up @@ -212,7 +216,8 @@ public class KeyResultTestHelpers {
"createdByFirstname":"",
"createdByLastname":"",
"createdOn":null,
"modifiedOn":null
"modifiedOn":null,
"actionList":[]
}
""";

Expand Down
Original file line number Diff line number Diff line change
@@ -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;
Expand All @@ -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 {
Expand All @@ -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())
Expand All @@ -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<Action> actionList = List.of(action1, action2);
when(authorizationService.getAuthorizationUser()).thenReturn(authorizationUser);
when(actionAuthorizationService.getEntitiesByKeyResultId(any())).thenReturn(actionList);
}

@AfterEach
void tearDown() {
try {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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;
Expand All @@ -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;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ void getFilteredOverviewShouldReturnOverviews() {
List<Overview> overviews = overviewPersistenceService.getFilteredOverview(2L, List.of(5L, 6L, 8L), "",
authorizationUser);

assertEquals(12, overviews.size());
assertEquals(13, overviews.size());
assertIterableEquals(getOverviewIdsForFilteredOverviewShouldReturnOverviews(), getOverviewIds(overviews));
}

Expand All @@ -34,7 +34,7 @@ void getFilteredOverviewShouldReturnOverviewsWhenObjectiveQuery() {
List<Overview> overviews = overviewPersistenceService.getFilteredOverview(2L, List.of(5L, 6L, 8L),
"kundenzufriedenheit", authorizationUser);

assertEquals(3, overviews.size());
assertEquals(4, overviews.size());
assertIterableEquals(getOverviewIdsForFilteredOverviewShouldReturnOverviewsWhenObjectiveQuery(),
getOverviewIds(overviews));
}
Expand All @@ -47,10 +47,12 @@ private static List<OverviewId> 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<OverviewId> 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));
}
}

0 comments on commit e805773

Please sign in to comment.