Skip to content

Commit

Permalink
try to fix tests
Browse files Browse the repository at this point in the history
  • Loading branch information
kcinay055679 committed Feb 15, 2025
1 parent 97c50e7 commit a89befb
Show file tree
Hide file tree
Showing 5 changed files with 44 additions and 36 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@

import ch.puzzle.okr.models.keyresult.KeyResult;
import ch.puzzle.okr.repository.KeyResultRepository;
import ch.puzzle.okr.service.persistence.customCrud.HardDelete;
import ch.puzzle.okr.service.persistence.customCrud.SoftDelete;
import jakarta.transaction.Transactional;
import java.util.List;
Expand All @@ -28,7 +29,8 @@ public List<KeyResult> getKeyResultsByObjective(Long objectiveId) {
@Transactional
public KeyResult recreateEntity(Long id, KeyResult keyResult) {
// delete entity in order to prevent duplicates in case of changed keyResultType
deleteById(id);
deleteById(id);
// deleteById(id, new HardDelete<>());

// reset id of key result, so it gets saved as a new entity
keyResult.resetId();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -183,39 +183,41 @@ create index if not exists idx_completed_objective

DROP VIEW IF EXISTS OVERVIEW;
CREATE VIEW OVERVIEW AS
SELECT tq.team_id AS "team_id",
tq.team_version AS "team_version",
tq.name AS "team_name",
tq.quater_id AS "quarter_id",
tq.label AS "quarter_label",
coalesce(o.id, -1) AS "objective_id",
o.title AS "objective_title",
o.state AS "objective_state",
o.created_on AS "objective_created_on",
coalesce(kr.id, -1) AS "key_result_id",
kr.title AS "key_result_title",
kr.key_result_type AS "key_result_type",
U.unit_name as "unit",
kr.baseline,
kr.stretch_goal,
kr.commit_zone,
kr.target_zone,
kr.stretch_zone,
coalesce(c.id, -1) AS "check_in_id",
c.value_metric AS "check_in_value",
c.zone AS "check_in_zone",
c.confidence,
c.created_on AS "check_in_created_on"
FROM (select t.id as team_id, t.version as team_version, t.name, q.id as quater_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
SELECT TQ.TEAM_ID AS "TEAM_ID",
TQ.TEAM_VERSION AS "TEAM_VERSION",
TQ.NAME AS "TEAM_NAME",
TQ.QUARTER_ID AS "QUARTER_ID",
TQ.LABEL AS "QUARTER_LABEL",
COALESCE(O.ID, -1) AS "OBJECTIVE_ID",
O.TITLE AS "OBJECTIVE_TITLE",
O.STATE AS "OBJECTIVE_STATE",
O.CREATED_ON AS "OBJECTIVE_CREATED_ON",
COALESCE(KR.ID, -1) AS "KEY_RESULT_ID",
KR.TITLE AS "KEY_RESULT_TITLE",
KR.KEY_RESULT_TYPE AS "KEY_RESULT_TYPE",
U.unit_name as "UNIT",
KR.BASELINE,
KR.STRETCH_GOAL,
KR.COMMIT_ZONE,
KR.TARGET_ZONE,
KR.STRETCH_ZONE,
COALESCE(C.ID, -1) AS "CHECK_IN_ID",
C.VALUE_METRIC AS "CHECK_IN_VALUE",
C.ZONE AS "CHECK_IN_ZONE",
C.CONFIDENCE,
C.CREATED_ON AS "CHECK_IN_CREATED_ON"
FROM (SELECT T.ID AS TEAM_ID, T.VERSION AS TEAM_VERSION, T.NAME, Q.ID AS QUARTER_ID, Q.LABEL
FROM TEAM T,
QUARTER Q where T.is_deleted is not true) TQ
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 unit U ON U.ID = KR.unit_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
WHERE CC.KEY_RESULT_ID = C.KEY_RESULT_ID AND CC.is_deleted = false)
WHERE KR.is_deleted = false;
WHERE CC.KEY_RESULT_ID = C.KEY_RESULT_ID and CC.is_deleted is not true )

WHERE KR.is_deleted is not true
;


create table if not exists alignment
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,8 +32,8 @@
LEFT JOIN unit U ON U.ID = KR.unit_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
WHERE CC.KEY_RESULT_ID = C.KEY_RESULT_ID AND CC.is_deleted = false)
WHERE KR.is_deleted = false;
WHERE CC.KEY_RESULT_ID = C.KEY_RESULT_ID AND CC.is_deleted is not true)
WHERE KR.is_deleted is not true;
-- AND u.is_deleted = false
-- AND c.is_deleted = false;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -63,15 +63,15 @@ void getFilteredOverviewShouldReturnOverviewsWhenTeamIdsSet() {
List<Overview> overviews = overviewPersistenceService
.getFilteredOverview(2L, List.of(5L, 6L, 8L), "", authorizationUser);

assertThat(expectedOverviewIds.subList(5, 18)).hasSameElementsAs(getOverviewIds(overviews));
assertThat(getOverviewIds(overviews)).hasSameElementsAs(expectedOverviewIds.subList(5, 18));
}

@DisplayName("Should return correct overview on getFilteredOverview() when team ids are not set")
@Test
void getFilteredOverviewShouldReturnOverviewsWhenTeamIdsEmpty() {
List<Overview> overviews = overviewPersistenceService.getFilteredOverview(2L, List.of(), "", authorizationUser);

assertThat(expectedOverviewIds.subList(0, 18)).hasSameElementsAs(getOverviewIds(overviews));
assertThat(getOverviewIds(overviews)).hasSameElementsAs(expectedOverviewIds.subList(0, 18));
}

@DisplayName("Should return correct overview on getFilteredOverview() when query is set")
Expand All @@ -80,7 +80,7 @@ void getFilteredOverviewShouldReturnOverviewsWhenObjectiveQuery() {
List<Overview> overviews = overviewPersistenceService
.getFilteredOverview(2L, List.of(5L, 6L, 8L), "kundenzufriedenheit", authorizationUser);

assertThat(expectedOverviewIds.subList(5, 8)).hasSameElementsAs(getOverviewIds(overviews));
assertThat(getOverviewIds(overviews)).hasSameElementsAs(expectedOverviewIds.subList(5, 8));
}

@DisplayName("Should return correct overview on getFilteredOverview() when quarter has no objectives")
Expand All @@ -89,7 +89,7 @@ void getFilteredOverviewShouldReturnOverviewsWhenQuarterWithoutObjectives() {
List<Overview> overviews = overviewPersistenceService
.getFilteredOverview(3L, List.of(5L, 6L, 8L), null, authorizationUser);

assertThat(expectedOverviewIds.subList(17, 20)).hasSameElementsAs(getOverviewIds(overviews));
assertThat(getOverviewIds(overviews)).hasSameElementsAs(expectedOverviewIds.subList(17, 20));
}

@DisplayName("Should return empty overview on getFilteredOverview() when query is set and no objectives are present")
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
package ch.puzzle.okr.test;

import java.lang.annotation.*;

import org.springframework.boot.test.autoconfigure.jdbc.AutoConfigureTestDatabase;
import org.springframework.boot.test.context.SpringBootTest;
import org.springframework.test.annotation.DirtiesContext;
import org.springframework.test.context.ActiveProfiles;
Expand All @@ -11,6 +13,8 @@
@Documented
@Inherited
@SpringBootTest
@AutoConfigureTestDatabase(replace = AutoConfigureTestDatabase.Replace.ANY)

@DirtiesContext(classMode = DirtiesContext.ClassMode.BEFORE_CLASS)
@ContextConfiguration(initializers = TestContextInitializer.class)
@ActiveProfiles(value = "integration-test")
Expand Down

0 comments on commit a89befb

Please sign in to comment.