Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

task/JM-8185 Investigate how juror can have no active pools #766

Open
wants to merge 3 commits into
base: release2
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -94,7 +94,8 @@ public enum ErrorCode {
JUROR_HAS_BEEN_DEFERRED_BEFORE,
COULD_NOT_FIND_ENOUGH_VOTERS,
COULD_NOT_FIND_ENOUGH_ELIGIBLE_VOTERS,
DAY_ALREADY_CONFIRMED
DAY_ALREADY_CONFIRMED,
CANNOT_DEFER_TO_EXISTING_POOL
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -176,6 +176,8 @@ public void processJurorDeferral(BureauJwtPayload payload, String jurorNumber,
JurorPool jurorPool = jurorPoolService.getJurorPoolFromUser(jurorNumber);
JurorPoolUtils.checkOwnershipForCurrentUser(jurorPool, payload.getOwner());

validateJurorPool(deferralReasonDto, jurorPool);

// if not empty then we need to move the juror to the active pool
if (!StringUtils.isEmpty(deferralReasonDto.poolNumber)) {
// update old record
Expand Down Expand Up @@ -224,6 +226,9 @@ public void changeJurorDeferralDate(BureauJwtPayload payload, String jurorNumber
DeferralReasonRequestDto deferralReasonDto) {
String auditorUsername = payload.getLogin();
JurorPool jurorPool = jurorPoolService.getJurorPoolFromUser(jurorNumber);

validateJurorPool(deferralReasonDto, jurorPool);

JurorPoolUtils.checkOwnershipForCurrentUser(jurorPool, payload.getOwner());

// if not empty then we need to move the juror to the active pool
Expand Down Expand Up @@ -647,6 +652,13 @@ public void setDeletedDeferralJurorPool(JurorPool jurorPool, String auditorUsern
jurorRepository.save(juror);
}

private void validateJurorPool(DeferralReasonRequestDto deferralReasonDto, JurorPool jurorPool) {
if (jurorPool.getPoolNumber().equalsIgnoreCase(deferralReasonDto.getPoolNumber())) {
throw new MojException.BusinessRuleViolation("Cannot change deferral to the existing pool",
MojException.BusinessRuleViolation.ErrorCode.CANNOT_DEFER_TO_EXISTING_POOL);
}
}

private void printDeferralLetter(String owner, JurorPool jurorPool) {
// send letter via bulk print for Bureau users only
if (JurorDigitalApplication.JUROR_OWNER.equals(owner)) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
import com.querydsl.core.types.Predicate;
import com.querydsl.core.types.dsl.BooleanExpression;
import org.junit.jupiter.api.AfterEach;
import org.junit.jupiter.api.Assertions;
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.DisplayName;
import org.junit.jupiter.api.Nested;
Expand Down Expand Up @@ -726,7 +727,7 @@ void useCourtDeferralsDeferralsUsedNoJurorPool() {

@Test
@SuppressWarnings("PMD.JUnitAssertionsShouldIncludeMessage")
void useCourtDeferrals_deferralsUsed_noPoolRequest() {
void useCourtDeferralsDeferralsUsedNoPoolRequest() {
String courtLocation = "415";
LocalDate newAttendanceDate = LocalDate.now();

Expand Down Expand Up @@ -774,7 +775,7 @@ void useCourtDeferrals_deferralsUsed_noPoolRequest() {
}

@Test
void useBureauDeferrals_deferralsUsed_happyPath() {
void useBureauDeferralsDeferralsUsedHappyPath() {
LocalDate oldAttendanceDate = LocalDate.of(2022, 6, 6);
LocalDate newAttendanceDate = LocalDate.now();
String courtLocation = "415";
Expand Down Expand Up @@ -830,7 +831,7 @@ void useBureauDeferrals_deferralsUsed_happyPath() {
}

@Test
void useBureauDeferrals_deferralsUsed_noJurorPool() {
void useBureauDeferralsDeferralsUsedNoJurorPool() {
LocalDate oldAttendanceDate = LocalDate.of(2022, 6, 6);
LocalDate newAttendanceDate = LocalDate.now();
String courtLocation = "415";
Expand Down Expand Up @@ -876,7 +877,7 @@ void useBureauDeferrals_deferralsUsed_noJurorPool() {
}

@Test
void useBureauDeferrals_deferralsUsed_noPoolRequest() {
void useBureauDeferralsDeferralsUsedNoPoolRequest() {
String courtLocation = "415";
LocalDate newAttendanceDate = LocalDate.now();

Expand Down Expand Up @@ -972,7 +973,7 @@ private void verifyLettersHappyPathTest() {
}

@Test
void processJuror_deferral_digital_happy_path_moveToActivePool() {
void processJurorDeferralDigitalHappyPathMoveToActivePool() {
TestUtils.mockBureauUser();
LocalDate newAttendanceDate = LocalDate.now();
LocalDate oldAttendanceDate = LocalDate.of(2022, 6, 6);
Expand Down Expand Up @@ -1010,8 +1011,48 @@ void processJuror_deferral_digital_happy_path_moveToActivePool() {

}


@Test
void processJurorDeferralDigitalUnhappyMoveToCurrentPool() {
TestUtils.mockBureauUser();
LocalDate oldAttendanceDate = LocalDate.of(2022, 6, 6);
final BureauJwtPayload bureauPayload = TestUtils.createJwt("400", "BUREAU_USER");
String jurorNumber = "123456789";
final PoolRequest oldPoolRequest = createPoolRequest("400", "111111112", "415",
oldAttendanceDate
);
Juror juror = new Juror();
juror.setJurorNumber(jurorNumber);
JurorPool jurorPool = createJurorPool(jurorNumber);
jurorPool.setOwner("400");
jurorPool.setPool(oldPoolRequest);
jurorPool.setJuror(juror);

JurorStatus jurorStatus = new JurorStatus();
jurorStatus.setStatus(IJurorStatus.RESPONDED);

DigitalResponse digitalResponse = new DigitalResponse();
digitalResponse.setJurorNumber(jurorNumber);

DeferralReasonRequestDto dto = createDeferralReasonRequestDtoToActivePool(ReplyMethod.DIGITAL);
dto.setReplyMethod(ReplyMethod.DIGITAL);
dto.setPoolNumber(oldPoolRequest.getPoolNumber());

when(jurorPoolService.getJurorPoolFromUser(jurorNumber)).thenReturn(jurorPool);

MojException.BusinessRuleViolation exception = Assertions.assertThrows(MojException.BusinessRuleViolation.class,
() -> manageDeferralsService.processJurorDeferral(bureauPayload, jurorNumber, dto),
"Exception should be thrown");

assertThat(exception).isNotNull();
assertThat(exception.getErrorCode()).isEqualTo(MojException.BusinessRuleViolation
.ErrorCode.CANNOT_DEFER_TO_EXISTING_POOL);
assertThat(exception.getMessage()).isEqualTo(
"Cannot change deferral to the existing pool");
}

@Test
void changeDeferralDate_happy_path_moveToActivePool() {
void changeDeferralDateHappyPathMoveToActivePool() {
TestUtils.mockBureauUser();
LocalDate newAttendanceDate = LocalDate.now();
LocalDate oldAttendanceDate = LocalDate.of(2022, 6, 6);
Expand Down Expand Up @@ -1044,6 +1085,46 @@ void changeDeferralDate_happy_path_moveToActivePool() {
verifyMoveToActivePoolTest();
}

@Test
void changeDeferralDateUnhappyMoveToCurrentPool() {
TestUtils.mockBureauUser();
LocalDate oldAttendanceDate = LocalDate.of(2022, 6, 6);
final BureauJwtPayload bureauPayload = TestUtils.createJwt("400", "BUREAU_USER");
String jurorNumber = "123456789";
final PoolRequest oldPoolRequest = createPoolRequest("400",
"111111111", "415", oldAttendanceDate
);
Juror juror = new Juror();
juror.setJurorNumber(jurorNumber);
JurorPool jurorPool = createJurorPool(jurorNumber);
jurorPool.setOwner("400");
jurorPool.setPool(oldPoolRequest);
jurorPool.setJuror(juror);

JurorStatus jurorStatus = new JurorStatus();
jurorStatus.setStatus(IJurorStatus.RESPONDED);

DigitalResponse digitalResponse = new DigitalResponse();
digitalResponse.setJurorNumber(jurorNumber);

DeferralReasonRequestDto dto = createDeferralReasonRequestDtoToActivePool(ReplyMethod.DIGITAL);
dto.setReplyMethod(ReplyMethod.DIGITAL);
dto.setPoolNumber(oldPoolRequest.getPoolNumber());

when(jurorPoolService.getJurorPoolFromUser(jurorNumber)).thenReturn(jurorPool);

MojException.BusinessRuleViolation exception = assertThrows(MojException.BusinessRuleViolation.class,
() -> manageDeferralsService.changeJurorDeferralDate(bureauPayload, jurorNumber, dto),
"Exception should be thrown");

assertThat(exception).isNotNull();
assertThat(exception.getErrorCode()).isEqualTo(MojException.BusinessRuleViolation
.ErrorCode.CANNOT_DEFER_TO_EXISTING_POOL);
assertThat(exception.getMessage()).isEqualTo(
"Cannot change deferral to the existing pool");

}

@Test
void changeDeferralDate_happy_path_moveToActivePool_RemoveFromDeferralMaintenance() {
TestUtils.mockBureauUser();
Expand Down Expand Up @@ -1081,7 +1162,7 @@ void changeDeferralDate_happy_path_moveToActivePool_RemoveFromDeferralMaintenanc
}

@Test
void changeDeferralDate_happy_path_moveToDeferralMaintenance() {
void changeDeferralDateHappyPathMoveToDeferralMaintenance() {
TestUtils.mockBureauUser();
final BureauJwtPayload bureauPayload = TestUtils.createJwt("400", "BUREAU_USER");
String jurorNumber = "123456789";
Expand Down