Skip to content

Commit

Permalink
fix back log ID and use constants for quarters
Browse files Browse the repository at this point in the history
  • Loading branch information
pizzi-cato committed Oct 3, 2024
1 parent 13090e5 commit a853885
Show file tree
Hide file tree
Showing 18 changed files with 107 additions and 82 deletions.
3 changes: 2 additions & 1 deletion backend/src/main/java/ch/puzzle/okr/Constants.java
Original file line number Diff line number Diff line change
Expand Up @@ -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";
}
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand All @@ -42,7 +44,7 @@ public Quarter getQuarterById(Long quarterId) {

public List<Quarter> getQuarters() {
List<Quarter> mostCurrentQuarterList = quarterPersistenceService.getMostCurrentQuarters();
Quarter backlog = quarterPersistenceService.findByLabel("Backlog");
Quarter backlog = quarterPersistenceService.findByLabel(BACK_LOG_QUARTER_LABEL);
mostCurrentQuarterList.add(0, backlog);
return mostCurrentQuarterList;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,8 @@

import java.util.List;

import static ch.puzzle.okr.Constants.BACK_LOG_QUARTER_LABEL;

@Service
public class QuarterValidationService
extends ValidationBase<Quarter, Long, QuarterRepository, QuarterPersistenceService> {
Expand All @@ -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()));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ call INIT_QUARTER_DATA();
insert into quarter (id, label, start_date, end_date)
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'),
(998, 'GJ ForTests', '2000-07-01', '2000-09-30'),
(999, 'Backlog', null, null);

insert into team (id, version, name)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand All @@ -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<Quarter> quaterList = Arrays.asList(quarter1, quarter2, backlogQuarter);

@Autowired
Expand All @@ -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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand All @@ -25,7 +26,7 @@ void toDtoShouldReturnEmptyListWhenNoObjectiveFound() {
void toDtoShouldReturnOneElementWhenObjectiveFound() {
List<AlignmentSelection> 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<AlignmentObjectiveDto> alignmentObjectiveDtos = alignmentSelectionMapper.toDto(alignmentSelections);

assertEquals(1, alignmentObjectiveDtos.size());
Expand All @@ -37,7 +38,7 @@ void toDtoShouldReturnOneElementWhenObjectiveWithKeyResultFound() {
List<AlignmentSelection> 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<AlignmentObjectiveDto> alignmentObjectiveDtos = alignmentSelectionMapper.toDto(alignmentSelections);

Expand All @@ -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<AlignmentObjectiveDto> alignmentObjectiveDtos = alignmentSelectionMapper.toDto(alignmentSelections);

Expand All @@ -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<AlignmentObjectiveDto> alignmentObjectiveDtos = alignmentSelectionMapper.toDto(alignmentSelections);

Expand Down
26 changes: 13 additions & 13 deletions backend/src/test/java/ch/puzzle/okr/mapper/OverviewMapperTest.java
Original file line number Diff line number Diff line change
@@ -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;
Expand All @@ -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;
Expand All @@ -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;
Expand All @@ -38,9 +39,8 @@ void toDtoShouldReturnEmptyListWhenNoTeamFound() {

@Test
void toDtoShouldReturnEmptyListWhenTeamFound() {
List<Overview> overviews = List
.of(Overview.Builder.builder().withOverviewId(OverviewId.Builder.builder().withTeamId(2L).build())
.withTeamName("Puzzle ITC").build());
List<Overview> overviews = List.of(Overview.Builder.builder()
.withOverviewId(OverviewId.Builder.builder().withTeamId(2L).build()).withTeamName(TEAM_PUZZLE).build());
List<OverviewDto> overviewDtos = overviewMapper.toDto(overviews);

assertEquals(1, overviewDtos.size());
Expand All @@ -51,7 +51,7 @@ void toDtoShouldReturnEmptyListWhenTeamFound() {
void toDtoShouldReturnOneElementWhenObjectiveFound() {
List<Overview> 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<OverviewDto> overviewDtos = overviewMapper.toDto(overviews);

assertEquals(1, overviewDtos.size());
Expand All @@ -64,7 +64,7 @@ void toDtoShouldReturnOneElementWhenObjectiveWithKeyResultFound() {
List<Overview> 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<OverviewDto> overviewDtos = overviewMapper.toDto(overviews);

Expand All @@ -78,7 +78,7 @@ void toDtoShouldReturnOneElementWhenObjectiveWithKeyResultAndCheckInsFound() {
List<Overview> 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<OverviewDto> overviewDtos = overviewMapper.toDto(overviews);

Expand All @@ -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<OverviewDto> overviewDtos = overviewMapper.toDto(overviews);

Expand All @@ -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<OverviewDto> overviewDtos = overviewMapper.toDto(overviews);
Expand Down Expand Up @@ -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)
Expand All @@ -177,7 +177,7 @@ void toDtoShouldThrowExceptionWhenKeyResultTypeNotSupported() {
List<Overview> 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,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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.*;

Expand All @@ -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<AlignmentSelection> alignmentSelections = alignmentSelectionBusinessService
.getAlignmentSelectionByQuarterIdAndTeamIdNot(2L, 4L);
List<AlignmentSelection> alignmentSelections = alignmentSelectionBusinessService.getAlignmentSelectionByQuarterIdAndTeamIdNot(
2L,
4L);

assertEquals(1, alignmentSelections.size());
verify(alignmentSelectionPersistenceService, times(1)).getAlignmentSelectionByQuarterIdAndTeamIdNot(2L, 4L);
Expand Down
Loading

0 comments on commit a853885

Please sign in to comment.