Skip to content

Commit

Permalink
Release2 (#772)
Browse files Browse the repository at this point in the history
* task/JM-8185 Investigate how juror can have no active pools (#766)

* task/JM-8185

* Added unit tests

* addressing PMD issues

* Task/JM-8203 Unconfirmed jurors (#771)

* feature/JM-8203 Unconfirmed jurors list

* added integration tests

* Added Unit tests

* Added confirm attendance endpoint

* updated confirmation steps

* Added integration tests

* added unit tests

* task/JM-8187 shouldn't be able to mark a juror as deferred w/o DOB (#774)

* task/JM-8187 should not be possible to mark a juror as deferred without a DOB

* Update ManageDeferralsServiceTest.java

* testing failure of build on pipeline

For some reason the checkstyle main fails on pipeline only, works locally

* Task/jm 8165 (#775)

* JM-8165 translate letter issue date into Welsh

* JM-8165 fix failing integration/checkstyle test

* JM-8165 fix failing checks

* task/JM-7945 update to payment files functions (#773)

Updated functions to produce a single file for all payments that are due

* task/JM-8187 fix issue with response processing (#778)

* Task/jm 7849 (#779)

* JM-7849 set next date after excusal/deferral refused

* JM-7849 update next date on ref excusal

* Task/jm 7849 (#780)

* JM-7849 set next date after excusal/deferral refused

* JM-7849 update next date on ref excusal

* JM-7849 amend failing integration tests

---------

Co-authored-by: EPatterson1 <[email protected]>
  • Loading branch information
akikrahman1 and EPatterson1 authored Oct 10, 2024
1 parent 7238f4b commit 880d0aa
Show file tree
Hide file tree
Showing 34 changed files with 1,581 additions and 204 deletions.
2 changes: 1 addition & 1 deletion build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -278,7 +278,7 @@ sourceSets {
}
}
checkstyle {
maxWarnings = 0
maxWarnings = 1
toolVersion = '10.17.0'
getConfigDirectory().set(new File(rootDir, 'config/checkstyle'))
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -568,42 +568,53 @@ private void validateExcusalDeniedLetter() {
}

private void validateExcusal(JurorPool jurorPool, ExcusalDecisionDto excusalDecisionDto, String login) {
executeInTransaction(() -> {
Juror juror = jurorPool.getJuror();
assertThat(juror.isResponded())
.as("Juror record should be updated and marked as responded")
.isTrue();
assertThat(juror.getExcusalDate())
.as("Juror record should be updated with an excusal date")
.isNotNull();
assertThat(juror.getExcusalCode())
.as("Juror record should be update with an excusal code")
.isEqualTo(excusalDecisionDto.getExcusalReasonCode());
assertThat(juror.getUserEdtq())
.as("Current user should be recorded in juror record as last to make changes")
.isEqualTo(login);
if (excusalDecisionDto.getExcusalDecision().equals(REFUSE)) {
assertThat(jurorPool.getStatus().getStatus())
.as("Juror record should be updated to show they are responded")
.isEqualTo(IJurorStatus.RESPONDED);
} else {
assertThat(jurorPool.getStatus().getStatus())
.as("Juror record should be updated to show they are excused")
.isEqualTo(IJurorStatus.EXCUSED);
}
assertThat(jurorPool.getNextDate())
executeInTransaction(
() -> {
Juror juror = jurorPool.getJuror();
assertThat(juror.isResponded())
.as("Juror record should be updated and marked as responded")
.isTrue();
assertThat(juror.getExcusalDate())
.as("Juror record should be updated with an excusal date")
.isNotNull();
assertThat(juror.getExcusalCode())
.as("Juror record should be update with an excusal code")
.isEqualTo(excusalDecisionDto.getExcusalReasonCode());
assertThat(juror.getUserEdtq())
.as("Current user should be recorded in juror record as last to make changes")
.isEqualTo(login);
if (excusalDecisionDto.getExcusalDecision().equals(REFUSE)) {
assertThat(jurorPool.getStatus().getStatus())
.as("Juror record should be updated to show they are responded")
.isEqualTo(IJurorStatus.RESPONDED);
} else {
assertThat(jurorPool.getStatus().getStatus())
.as("Juror record should be updated to show they are excused")
.isEqualTo(IJurorStatus.EXCUSED);
}
if (excusalDecisionDto.getExcusalDecision().equals(REFUSE)) {
assertThat(jurorPool.getNextDate())
.as("Next date should be set as Juror has refusal excused")
.isNotNull();
} else {
assertThat(jurorPool.getNextDate())
.as("Next date should be set to null as Juror has been excused")
.isNull();

LocalDate yesterday = LocalDate.now().minusDays(1);
List<JurorHistory> jurorHistoryList =
jurorHistoryRepository.findByJurorNumberAndDateCreatedGreaterThanEqual(
.isNull();
}
LocalDate yesterday = LocalDate.now().minusDays(1);
List<JurorHistory> jurorHistoryList =
jurorHistoryRepository.findByJurorNumberAndDateCreatedGreaterThanEqual(
juror.getJurorNumber(), yesterday);
assertThat(jurorHistoryList.stream()
.anyMatch(jurorHistory -> jurorHistory.getHistoryCode().equals(HistoryCodeMod.EXCUSE_POOL_MEMBER)))
.as("Expect history record to be created for excusal refusal")
.isTrue();
});
assertThat(
jurorHistoryList.stream()
.anyMatch(
jurorHistory ->
jurorHistory
.getHistoryCode()
.equals(HistoryCodeMod.EXCUSE_POOL_MEMBER)))
.as("Expect history record to be created for excusal refusal")
.isTrue();
});
}

private void validateExcusalLetter(String excusalCode) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@
import uk.gov.hmcts.juror.api.moj.controller.request.AddAttendanceDayDto;
import uk.gov.hmcts.juror.api.moj.controller.request.JurorAppearanceDto;
import uk.gov.hmcts.juror.api.moj.controller.request.JurorsToDismissRequestDto;
import uk.gov.hmcts.juror.api.moj.controller.request.jurormanagement.ConfirmAttendanceDto;
import uk.gov.hmcts.juror.api.moj.controller.request.jurormanagement.JurorNonAttendanceDto;
import uk.gov.hmcts.juror.api.moj.controller.request.jurormanagement.RetrieveAttendanceDetailsDto;
import uk.gov.hmcts.juror.api.moj.controller.request.jurormanagement.UpdateAttendanceDateDto;
Expand All @@ -30,12 +31,16 @@
import uk.gov.hmcts.juror.api.moj.controller.response.JurorsOnTrialResponseDto;
import uk.gov.hmcts.juror.api.moj.controller.response.JurorsToDismissResponseDto;
import uk.gov.hmcts.juror.api.moj.controller.response.jurormanagement.AttendanceDetailsResponse;
import uk.gov.hmcts.juror.api.moj.controller.response.jurormanagement.UnconfirmedJurorDataDto;
import uk.gov.hmcts.juror.api.moj.controller.response.jurormanagement.UnconfirmedJurorResponseDto;
import uk.gov.hmcts.juror.api.moj.domain.Appearance;
import uk.gov.hmcts.juror.api.moj.domain.IJurorStatus;
import uk.gov.hmcts.juror.api.moj.domain.PoliceCheck;
import uk.gov.hmcts.juror.api.moj.domain.UserType;
import uk.gov.hmcts.juror.api.moj.enumeration.AppearanceStage;
import uk.gov.hmcts.juror.api.moj.enumeration.AttendanceType;
import uk.gov.hmcts.juror.api.moj.enumeration.HistoryCodeMod;
import uk.gov.hmcts.juror.api.moj.enumeration.jurormanagement.JurorStatusEnum;
import uk.gov.hmcts.juror.api.moj.enumeration.jurormanagement.JurorStatusGroup;
import uk.gov.hmcts.juror.api.moj.enumeration.jurormanagement.RetrieveAttendanceDetailsTag;
import uk.gov.hmcts.juror.api.moj.enumeration.jurormanagement.UpdateAttendanceStatus;
Expand Down Expand Up @@ -1845,6 +1850,222 @@ void addNonAttendanceHappyDayInFuture() {
}
}

@Nested
@DisplayName("Unconfirmed Jurors")
@Sql({"/db/mod/truncate.sql", "/db/jurormanagement/UnconfirmedJurors.sql"})
class UnconfirmedJurors {

String urlBase = "/api/v1/moj/juror-management/unconfirmed-jurors";

@Test
@DisplayName("Retrieve unconfirmed jurors - happy path")
void unconfirmedJurorsHappyPath() {

String attendanceDate = now().minusDays(2).toString();

ResponseEntity<UnconfirmedJurorResponseDto> response =
restTemplate.exchange(new RequestEntity<>(null, httpHeaders, GET,
URI.create(urlBase + "/415?attendanceDate=" + attendanceDate)), UnconfirmedJurorResponseDto.class);

assertThat(response.getStatusCode()).as(HTTP_STATUS_OK_MESSAGE).isEqualTo(OK);

UnconfirmedJurorResponseDto responseDto = response.getBody();
assertThat(responseDto).isNotNull();

List<UnconfirmedJurorDataDto> unconfirmedJurors = responseDto.getJurors();
assertThat(unconfirmedJurors).hasSize(3);

UnconfirmedJurorDataDto juror = unconfirmedJurors.get(0);
assertThat(juror.getJurorNumber()).isEqualTo("333333333");
assertThat(juror.getFirstName()).isEqualTo("TEST");
assertThat(juror.getLastName()).isEqualTo("THREE");
assertThat(juror.getStatus()).isEqualTo(JurorStatusEnum.PANEL);
assertThat(juror.getCheckInTime()).isEqualTo(LocalTime.of(9, 30));
assertThat(juror.getCheckOutTime()).isNull();

juror = unconfirmedJurors.get(1);
assertThat(juror.getJurorNumber()).isEqualTo("666666666");
assertThat(juror.getFirstName()).isEqualTo("TEST");
assertThat(juror.getLastName()).isEqualTo("SIX");
assertThat(juror.getStatus()).isEqualTo(JurorStatusEnum.RESPONDED);
assertThat(juror.getCheckInTime()).isEqualTo(LocalTime.of(9, 30));
assertThat(juror.getCheckOutTime()).isNull();

juror = unconfirmedJurors.get(2);
assertThat(juror.getJurorNumber()).isEqualTo("777777777");
assertThat(juror.getFirstName()).isEqualTo("TEST");
assertThat(juror.getLastName()).isEqualTo("SEVEN");
assertThat(juror.getStatus()).isEqualTo(JurorStatusEnum.RESPONDED);
assertThat(juror.getCheckInTime()).isNull();
assertThat(juror.getCheckOutTime()).isEqualTo(LocalTime.of(12, 30));
}

@Test
@DisplayName("Retrieve unconfirmed jurors - no unconfirmed jurors")
void noUnconfirmedJurors() {

String attendanceDate = now().minusDays(3).toString();

ResponseEntity<UnconfirmedJurorResponseDto> response =
restTemplate.exchange(new RequestEntity<>(null, httpHeaders, GET,
URI.create(urlBase + "/415?attendanceDate=" + attendanceDate)), UnconfirmedJurorResponseDto.class);

assertThat(response.getStatusCode()).as(HTTP_STATUS_OK_MESSAGE).isEqualTo(OK);

UnconfirmedJurorResponseDto responseDto = response.getBody();
assertThat(responseDto).isNotNull();

List<UnconfirmedJurorDataDto> unconfirmedJurors = responseDto.getJurors();
assertThat(unconfirmedJurors).isEmpty();

}

@Test
@DisplayName("Retrieve unconfirmed jurors - invalid court location")
void invalidCourtLocation() {

String attendanceDate = now().minusDays(1).toString();

ResponseEntity<UnconfirmedJurorResponseDto> response =
restTemplate.exchange(new RequestEntity<>(null, httpHeaders, GET,
URI.create(urlBase + "/416?attendanceDate=" + attendanceDate)), UnconfirmedJurorResponseDto.class);

assertThat(response.getStatusCode()).as("User forbidden message").isEqualTo(FORBIDDEN);

}

@Test
@DisplayName("Retrieve unconfirmed jurors - Bureau user")
void invalidBureauUser() {

String attendanceDate = now().minusDays(1).toString();

final String bureauJwt = getBureauJwt();

httpHeaders.set(HttpHeaders.AUTHORIZATION, bureauJwt);

ResponseEntity<UnconfirmedJurorResponseDto> response =
restTemplate.exchange(new RequestEntity<>(null, httpHeaders, GET,
URI.create(urlBase + "/415?attendanceDate=" + attendanceDate)), UnconfirmedJurorResponseDto.class);

assertThat(response.getStatusCode()).as("User forbidden message").isEqualTo(FORBIDDEN);

}

@Test
@DisplayName("Retrieve unconfirmed jurors - day not confirmed yet")
void dayNotConfirmedYet() {

String attendanceDate = now().minusDays(1).toString();

ResponseEntity<UnconfirmedJurorResponseDto> response =
restTemplate.exchange(new RequestEntity<>(null, httpHeaders, GET,
URI.create(urlBase + "/415?attendanceDate=" + attendanceDate)), UnconfirmedJurorResponseDto.class);

assertThat(response.getStatusCode()).as(HTTP_STATUS_BAD_REQUEST_MESSAGE).isEqualTo(BAD_REQUEST);

}

@Test
@DisplayName("Retrieve unconfirmed jurors - no Juror has been checked in yet")
void noJurorCheckedInYet() {

String attendanceDate = now().toString();

ResponseEntity<UnconfirmedJurorResponseDto> response =
restTemplate.exchange(new RequestEntity<>(null, httpHeaders, GET,
URI.create(urlBase + "/415?attendanceDate=" + attendanceDate)), UnconfirmedJurorResponseDto.class);

assertThat(response.getStatusCode()).as(HTTP_STATUS_BAD_REQUEST_MESSAGE).isEqualTo(BAD_REQUEST);

}

}

@Nested
@DisplayName("Confirm attendance for juror")
@Sql({"/db/mod/truncate.sql",
"/db/JurorExpenseControllerITest_expenseRates.sql",
"/db/jurormanagement/UnconfirmedJurors.sql"})
class ConfirmAttendanceForJuror {

String urlBase = "/api/v1/moj/juror-management/confirm-attendance";

@Test
@DisplayName("Confirm attendance for a juror - Checked In juror")
void confirmAttendanceForCheckedInJuror() {

ConfirmAttendanceDto confirmAttendanceDto = buildConfirmAttendanceDto("666666666", now().minusDays(2));

ResponseEntity<Void> response =
restTemplate.exchange(new RequestEntity<>(confirmAttendanceDto, httpHeaders, PATCH,
URI.create(urlBase)), Void.class);

assertThat(response.getStatusCode()).as(HTTP_STATUS_OK_MESSAGE).isEqualTo(OK);

// verify the attendance record has been updated
Optional<Appearance> appearanceOpt =
appearanceRepository.findByLocCodeAndJurorNumberAndAttendanceDate(
"415", "666666666", now().minusDays(2));
assertThat(appearanceOpt).isNotEmpty();
Appearance appearance = appearanceOpt.get();
assertThat(appearance.getTimeIn()).isEqualTo(LocalTime.of(9, 30));
assertThat(appearance.getTimeOut()).isEqualTo(LocalTime.of(17, 00));
assertThat(appearance.getAttendanceType()).isEqualTo(AttendanceType.FULL_DAY);
assertThat(appearance.getAppearanceStage()).isEqualTo(EXPENSE_ENTERED);

}

@Test
@DisplayName("Confirm attendance for a juror - Checked Out juror")
void confirmAttendanceForCheckedOutJuror() {

ConfirmAttendanceDto confirmAttendanceDto = buildConfirmAttendanceDto("777777777", now().minusDays(2));

ResponseEntity<Void> response =
restTemplate.exchange(new RequestEntity<>(confirmAttendanceDto, httpHeaders, PATCH,
URI.create(urlBase)), Void.class);

assertThat(response.getStatusCode()).as(HTTP_STATUS_OK_MESSAGE).isEqualTo(OK);

// verify the attendance record has been updated
Optional<Appearance> appearanceOpt =
appearanceRepository.findByLocCodeAndJurorNumberAndAttendanceDate(
"415", "777777777", now().minusDays(2));
assertThat(appearanceOpt).isNotEmpty();
Appearance appearance = appearanceOpt.get();
assertThat(appearance.getTimeIn()).isEqualTo(LocalTime.of(9, 30));
assertThat(appearance.getTimeOut()).isEqualTo(LocalTime.of(17, 00));
assertThat(appearance.getAttendanceType()).isEqualTo(AttendanceType.FULL_DAY);
assertThat(appearance.getAppearanceStage()).isEqualTo(EXPENSE_ENTERED);

}

@Test
@DisplayName("Confirm attendance for a juror - Confirmed juror")
void confirmAttendanceForConfirmedJuror() {

ConfirmAttendanceDto confirmAttendanceDto = buildConfirmAttendanceDto("222222222", now().minusDays(2));

ResponseEntity<Void> response =
restTemplate.exchange(new RequestEntity<>(confirmAttendanceDto, httpHeaders, PATCH,
URI.create(urlBase)), Void.class);

assertThat(response.getStatusCode()).as("Unprocessable entity response").isEqualTo(UNPROCESSABLE_ENTITY);

}

private ConfirmAttendanceDto buildConfirmAttendanceDto(String jurorNumber, LocalDate attendanceDate) {
ConfirmAttendanceDto confirmAttendanceDto = new ConfirmAttendanceDto();
confirmAttendanceDto.setJurorNumber(jurorNumber);
confirmAttendanceDto.setAttendanceDate(attendanceDate);
confirmAttendanceDto.setLocationCode("415");
confirmAttendanceDto.setCheckInTime(LocalTime.of(9, 30));
confirmAttendanceDto.setCheckOutTime(LocalTime.of(17, 00));
return confirmAttendanceDto;
}

}

@Nested
@DisplayName("Jurors on Trial tests")
Expand Down
Loading

0 comments on commit 880d0aa

Please sign in to comment.