Skip to content

Commit

Permalink
fix backend review items
Browse files Browse the repository at this point in the history
  • Loading branch information
pizzi-cato committed Oct 3, 2024
1 parent f2eac53 commit 13090e5
Show file tree
Hide file tree
Showing 4 changed files with 78 additions and 26 deletions.
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
package ch.puzzle.okr.controller;

import ch.puzzle.okr.ForwardFilter;
import ch.puzzle.okr.dto.ClientConfigDto;
import ch.puzzle.okr.service.clientconfig.ClientConfigService;
import jakarta.servlet.http.HttpServletRequest;
import org.springframework.http.HttpStatus;
import org.springframework.http.ResponseEntity;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;

@Controller
public class ClientConfigController {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,17 +33,21 @@ VALUES (1, 1, '[email protected]', 'Paco', 'Eggimann', FALSE),
(51, 1, '[email protected]', 'Robin', 'Papierer', FALSE),
(61, 1, '[email protected]', 'Jaya', 'Norris', TRUE);

CREATE ALIAS INIT_QUARTER_DATA FOR 'ch.puzzle.okr.util.quarter.generate.h2.QuarterFunction.initQuarterData';
CREATE ALIAS CURRENT_QUARTER_LABEL FOR 'ch.puzzle.okr.util.quarter.generate.h2.QuarterFunction.currentQuarterLabel';
CREATE ALIAS CURRENT_QUARTER_START_DATE FOR 'ch.puzzle.okr.util.quarter.generate.h2.QuarterFunction.currentQuarterStartDate';
CREATE ALIAS CURRENT_QUARTER_END_DATE FOR 'ch.puzzle.okr.util.quarter.generate.h2.QuarterFunction.currentQuarterEndDate';
CREATE ALIAS NEXT_QUARTER_LABEL FOR 'ch.puzzle.okr.util.quarter.generate.h2.QuarterFunction.nextQuarterLabel';
CREATE ALIAS NEXT_QUARTER_START_DATE FOR 'ch.puzzle.okr.util.quarter.generate.h2.QuarterFunction.nextQuarterStartDate';
CREATE ALIAS NEXT_QUARTER_END_DATE FOR 'ch.puzzle.okr.util.quarter.generate.h2.QuarterFunction.nextQuarterEndDate';

call INIT_QUARTER_DATA();

insert into quarter (id, label, start_date, end_date)
values (1, 'GJ 22/23-Q4', '2023-04-01', '2023-06-30'),
(2, 'GJ 23/24-Q1', '2023-07-01', '2023-09-30'),
(3, 'GJ 22/23-Q3', '2023-01-01', '2023-03-31'),
(4, 'GJ 22/23-Q2', '2022-10-01', '2022-12-31'),
(5, 'GJ 22/23-Q1', '2022-07-01', '2022-09-30'),
(6, 'GJ 21/22-Q4', '2022-04-01', '2022-06-30'),
(7, 'GJ 23/24-Q2', '2023-10-01', '2023-12-31'),
(8, 'GJ 23/24-Q3', '2024-01-01', '2024-03-31'),
(9, 'GJ 24/25-Q2', '2024-10-01', '2024-12-31'),
(199, 'Backlog', null, null);
values (2, CURRENT_QUARTER_LABEL(), CURRENT_QUARTER_START_DATE(), CURRENT_QUARTER_END_DATE()),
(3, NEXT_QUARTER_LABEL(), NEXT_QUARTER_START_DATE(), NEXT_QUARTER_END_DATE()),
(99, 'GJ ForTests', '2000-07-01', '2000-09-30'),
(999, 'Backlog', null, null);

insert into team (id, version, name)
values (4, 1, '/BBT'),
Expand Down
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
package ch.puzzle.okr.service.persistence;

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.models.authorization.AuthorizationUser;
import ch.puzzle.okr.multitenancy.TenantContext;
import ch.puzzle.okr.test.SpringIntegrationTest;
import ch.puzzle.okr.test.TestHelper;
import org.junit.jupiter.api.AfterEach;
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Test;
Expand All @@ -29,6 +29,7 @@ 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;

Expand All @@ -47,9 +48,9 @@ private static Objective createObjective(Long id, int version) {
return Objective.Builder.builder().withId(id).withVersion(version).withTitle("title")
.withCreatedBy(User.Builder.builder().withId(1L).build())
.withTeam(Team.Builder.builder().withId(5L).build())
.withQuarter(Quarter.Builder.builder().withId(1L).build()).withDescription("This is our description")
.withState(State.DRAFT).withCreatedOn(LocalDateTime.MAX).withModifiedOn(LocalDateTime.MAX)
.withModifiedBy(User.Builder.builder().withId(1L).build()).build();
.withQuarter(Quarter.Builder.builder().withId(GJ_FOR_TESTS_QUARTER_ID).build())
.withDescription("This is our description").withState(State.DRAFT).withCreatedOn(LocalDateTime.MAX)
.withModifiedOn(LocalDateTime.MAX).withModifiedBy(User.Builder.builder().withId(1L).build()).build();
}

@BeforeEach
Expand Down
Original file line number Diff line number Diff line change
@@ -1,13 +1,15 @@
package ch.puzzle.okr.service.persistence;

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.multitenancy.TenantContext;
import ch.puzzle.okr.test.SpringIntegrationTest;
import ch.puzzle.okr.test.TestHelper;
import ch.puzzle.okr.util.quarter.check.QuarterRangeChecker;
import org.junit.jupiter.api.AfterEach;
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.DisplayName;
import org.junit.jupiter.api.Test;
import org.springframework.beans.factory.annotation.Autowired;

Expand Down Expand Up @@ -37,12 +39,12 @@ void tearDown() {

@Test
void shouldReturnSingleQuarterWhenFindingByValidId() {
Quarter returnedQuarter = quarterPersistenceService.findById(1L);
Quarter returnedQuarter = quarterPersistenceService.findById(99L);

assertEquals(1L, returnedQuarter.getId());
assertEquals("GJ 22/23-Q4", returnedQuarter.getLabel());
assertEquals(LocalDate.of(2023, 4, 1), returnedQuarter.getStartDate());
assertEquals(LocalDate.of(2023, 6, 30), returnedQuarter.getEndDate());
assertEquals(99L, returnedQuarter.getId());
assertEquals("GJ ForTests", returnedQuarter.getLabel());
assertEquals(LocalDate.of(2000, 7, 1), returnedQuarter.getStartDate());
assertEquals(LocalDate.of(2000, 9, 30), returnedQuarter.getEndDate());
}

@Test
Expand All @@ -69,13 +71,26 @@ void shouldThrowExceptionWhenFindingQuarterWithIdNull() {
assertTrue(TestHelper.getAllErrorKeys(expectedErrors).contains(exception.getReason()));
}

@DisplayName("getMostCurrentQuarters() should return current quarter and future quarter and GJForTests quarter")
@Test
void shouldReturnCurrentQuarterFutureQuarterAnd4PastQuarters() {
void getMostCurrentQuartersShouldReturnCurrentQuarterAndFutureQuarterAndGJForTestsQuarter() {
List<Quarter> quarterListFromFunction = quarterPersistenceService.getMostCurrentQuarters();

assertEquals(6, quarterListFromFunction.size());
assertTrue(
quarterListFromFunction.get(0).getStartDate().isAfter(quarterListFromFunction.get(5).getStartDate()));
assertEquals(3, quarterListFromFunction.size());
assertGJForTestsQuarterIsFoundOnce(quarterListFromFunction);
assertCurrentQuarterIsFoundOnce(quarterListFromFunction);
}

private void assertGJForTestsQuarterIsFoundOnce(List<Quarter> quarters) {
long foundGJForTestsQuartersCount = quarters.stream()
.filter(quarter -> quarter.getLabel().equals("GJ ForTests")).count();
assertEquals(1, foundGJForTestsQuartersCount);
}

private void assertCurrentQuarterIsFoundOnce(List<Quarter> quarters) {
long foundCurrentQuartersCount = quarters.stream()
.filter(quarter -> QuarterRangeChecker.nowIsInQuarter(LocalDate.now(), quarter)).count();
assertEquals(1, foundCurrentQuartersCount);
}

@Test
Expand All @@ -92,4 +107,36 @@ void shouldReturnCurrentQuarter() {
assertNotNull(quarter.getLabel());
}

@DisplayName("findByLabel() should return single Quarter when label is valid")
@Test
void findByLabelShouldReturnSingleQuarterWhenLabelIsValid() {
// arrange + act
Quarter returnedQuarter = quarterPersistenceService.findByLabel("GJ ForTests");

// assert
assertEquals(99L, returnedQuarter.getId());
assertEquals("GJ ForTests", returnedQuarter.getLabel());
assertEquals(LocalDate.of(2000, 7, 1), returnedQuarter.getStartDate());
assertEquals(LocalDate.of(2000, 9, 30), returnedQuarter.getEndDate());
}

@DisplayName("findByLabel() should return null when label is not valid")
@Test
void findByLabelShouldReturnNullWhenLabelIsNotValid() {
// arrange + act
Quarter returnedQuarter = quarterPersistenceService.findByLabel("a_not_valid_label");

// assert
assertNull(returnedQuarter);
}

@DisplayName("findByLabel() should return null when label is null")
@Test
void findByLabelShouldReturnNullWhenLabelIsNull() {
// arrange + act
Quarter returnedQuarter = quarterPersistenceService.findByLabel(null);

// assert
assertNull(returnedQuarter);
}
}

0 comments on commit 13090e5

Please sign in to comment.