Skip to content

Commit

Permalink
make shouldDupllicateActionList check if every attribute was copied e…
Browse files Browse the repository at this point in the history
…xcept id
  • Loading branch information
nevio18324 committed Jan 14, 2025
1 parent 9e34b16 commit dc85487
Show file tree
Hide file tree
Showing 2 changed files with 35 additions and 22 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -186,6 +186,7 @@ public List<Action> duplicateActionList(KeyResult oldKeyResult, KeyResult newKey
.isChecked(e.isChecked())
.withAction(e.getActionPoint())
.withPriority(e.getPriority())
.withVersion(e.getVersion())
.build())
.toList();
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,23 +1,12 @@
package ch.puzzle.okr.service.business;

import static ch.puzzle.okr.models.State.DRAFT;
import static ch.puzzle.okr.test.TestHelper.defaultAuthorizationUser;
import static org.assertj.core.api.Assertions.assertThat;
import static org.junit.jupiter.api.Assertions.*;
import static org.mockito.ArgumentMatchers.any;
import static org.mockito.Mockito.*;
import static org.springframework.http.HttpStatus.NOT_FOUND;

import ch.puzzle.okr.models.*;
import ch.puzzle.okr.models.authorization.AuthorizationUser;
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.persistence.ObjectivePersistenceService;
import ch.puzzle.okr.service.validation.ObjectiveValidationService;
import java.time.LocalDateTime;
import java.util.ArrayList;
import java.util.List;
import org.junit.jupiter.api.DisplayName;
import org.junit.jupiter.api.Test;
import org.junit.jupiter.api.extension.ExtendWith;
Expand All @@ -30,6 +19,18 @@
import org.mockito.junit.jupiter.MockitoExtension;
import org.springframework.web.server.ResponseStatusException;

import java.time.LocalDateTime;
import java.util.ArrayList;
import java.util.List;

import static ch.puzzle.okr.models.State.DRAFT;
import static ch.puzzle.okr.test.TestHelper.defaultAuthorizationUser;
import static org.assertj.core.api.Assertions.assertThat;
import static org.junit.jupiter.api.Assertions.*;
import static org.mockito.ArgumentMatchers.any;
import static org.mockito.Mockito.*;
import static org.springframework.http.HttpStatus.NOT_FOUND;

@ExtendWith(MockitoExtension.class)
class ObjectiveBusinessServiceTest {
private static final AuthorizationUser authorizationUser = defaultAuthorizationUser();
Expand Down Expand Up @@ -130,7 +131,7 @@ void shouldSuccessfullySaveNewObjective() {
}

@ParameterizedTest(name = "Should handle quarters correctly on updateEntity() when objectives and quarters get changed")
@ValueSource(booleans = { false, true })
@ValueSource(booleans = {false, true})
void shouldHandleQuarterCorrectlyUsingUpdateEntity(boolean hasKeyResultAnyCheckIns) {
Long id = 27L;
String title = "Received Objective";
Expand Down Expand Up @@ -178,7 +179,7 @@ void shouldHandleQuarterCorrectlyUsingUpdateEntity(boolean hasKeyResultAnyCheckI

assertEquals(hasKeyResultAnyCheckIns, isImUsed);
assertEquals(hasKeyResultAnyCheckIns ? savedObjective.getQuarter() : changedObjective.getQuarter(),
updatedEntity.getQuarter());
updatedEntity.getQuarter());
assertEquals(changedObjective.getDescription(), updatedEntity.getDescription());
assertEquals(changedObjective.getTitle(), updatedEntity.getTitle());
}
Expand Down Expand Up @@ -236,9 +237,9 @@ void shouldDuplicateObjective() {

Objective duplicatedObjective = objectiveBusinessService
.duplicateObjective(sourceObjective.getId(),
newObjective,
authorizationUser,
keyResults.stream().map(KeyResult::getId).toList());
newObjective,
authorizationUser,
keyResults.stream().map(KeyResult::getId).toList());

// assert
assertNotEquals(sourceObjective.getId(), duplicatedObjective.getId());
Expand Down Expand Up @@ -284,16 +285,27 @@ void shouldDuplicateActionList() {
KeyResult oldKeyResult = KeyResultMetric.Builder.builder().withId(1L).build();
KeyResult newKeyResult = KeyResultMetric.Builder.builder().withId(2L).build();

Action action1 = Action.Builder.builder().withKeyResult(oldKeyResult).withPriority(1).withVersion(1).build();
Action action2 = Action.Builder.builder().withKeyResult(oldKeyResult).withPriority(2).withVersion(2).build();
Action action = Action.Builder.builder().withKeyResult(oldKeyResult).withPriority(1).withVersion(1)
.isChecked(true).withAction("Action Point 1").build();

when(oldKeyResult.getActionList()).thenReturn(List.of(action1, action2));
oldKeyResult.setActionList(List.of(action));

newKeyResult.setActionList(objectiveBusinessService.duplicateActionList(oldKeyResult, newKeyResult));

//assert that id changes to new key result
assertNotEquals(newKeyResult.getActionList().getFirst().getKeyResult().getId(),
oldKeyResult.getActionList().getFirst().getKeyResult().getId());
assertNotEquals(newKeyResult.getActionList().getLast().getKeyResult(),
oldKeyResult.getActionList().getLast().getKeyResult());
oldKeyResult.getActionList().getFirst().getKeyResult().getId());

//assert that all other attributes stay the same
assertThat(newKeyResult.getActionList().getFirst())
.extracting("priority", "version", "checked", "actionPoint")
.containsExactly(
oldKeyResult.getActionList().getFirst().getPriority(),
oldKeyResult.getActionList().getFirst().getVersion(),
oldKeyResult.getActionList().getFirst().isChecked(),
oldKeyResult.getActionList().getFirst().getActionPoint()
);

}

@DisplayName("Should get all key result associated with the objective on getAllKeyResultsByObjective()")
Expand Down

0 comments on commit dc85487

Please sign in to comment.