Skip to content

Commit

Permalink
GAP-2096 | conditionally don't reset section status to in progress (#88)
Browse files Browse the repository at this point in the history
* GAP-2096 | conditionally don't reset section status to in progress

* GAP-2096 | rename sectionComplete to shouldUpdateSectionStatus

* GAP-2096 | add tests for resetting submission section status to IN_PROGRESS based on parameter

---------

Co-authored-by: conor <[email protected]>
  • Loading branch information
ConorFayleTCO and ConorFayleAND authored Jan 19, 2024
1 parent 5062dc2 commit 96d1617
Show file tree
Hide file tree
Showing 3 changed files with 144 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -14,4 +14,5 @@ public class CreateQuestionResponseDto {
private String questionId;
private String response;
private String[] multiResponse;
private Boolean shouldUpdateSectionStatus;
}
Original file line number Diff line number Diff line change
Expand Up @@ -122,12 +122,16 @@ public void saveQuestionResponse(final CreateQuestionResponseDto questionRespons

if (questionResponse.getResponse() != null) {
submissionQuestion.setResponse(questionResponse.getResponse());
submissionSection.setSectionStatus(SubmissionSectionStatus.IN_PROGRESS);
if (questionResponse.getShouldUpdateSectionStatus()) {
submissionSection.setSectionStatus(SubmissionSectionStatus.IN_PROGRESS);
}
}

if (questionResponse.getMultiResponse() != null) {
submissionQuestion.setMultiResponse(questionResponse.getMultiResponse());
submissionSection.setSectionStatus(SubmissionSectionStatus.IN_PROGRESS);
if (questionResponse.getShouldUpdateSectionStatus()) {
submissionSection.setSectionStatus(SubmissionSectionStatus.IN_PROGRESS);
}
}

if (sectionId.equals(ELIGIBILITY)) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -463,12 +463,13 @@ void getQuestionByQuestionId_returnsExpectedQuestion() {
@Nested
class saveQuestionResponse {
@Test
void saveQuestionResponse_SavesResponse() {
void saveQuestionResponse_SavesResponse_WhenShouldSetSectionStatus_IsTrue() {

final CreateQuestionResponseDto organisationNameResponse = CreateQuestionResponseDto.builder()
.questionId(QUESTION_ID)
.submissionId(SUBMISSION_ID)
.response("AND Digital")
.shouldUpdateSectionStatus(true)
.build();

doReturn(submission)
Expand Down Expand Up @@ -508,13 +509,142 @@ void saveQuestionResponse_SavesResponse() {
);
}

@Test
void saveQuestionResponse_ResetsSectionStatusToInProgress_IfShouldUpdateSectionStatus_IsTrue() {

// set the scheme to version 2
submission.getApplication().getGrantScheme().setVersion(2);

// remove surplus sections
submission.getDefinition()
.getSections()
.removeIf(section -> section.getSectionStatus() != SubmissionSectionStatus.IN_PROGRESS);

submission.getDefinition()
.getSections()
.forEach(section -> section.setSectionStatus(SubmissionSectionStatus.COMPLETED));

final CreateQuestionResponseDto questionResponse = CreateQuestionResponseDto.builder()
.questionId("APPLICANT_ORG_NAME")
.submissionId(SUBMISSION_ID)
.response("New name")
.shouldUpdateSectionStatus(true)
.build();

doReturn(submission)
.when(serviceUnderTest).getSubmissionFromDatabaseBySubmissionId(userId, SUBMISSION_ID);

final ArgumentCaptor<Submission> submissionCaptor = ArgumentCaptor.forClass(Submission.class);

serviceUnderTest.saveQuestionResponse(questionResponse, userId, SUBMISSION_ID, "ESSENTIAL");


verify(submissionRepository).save(submissionCaptor.capture());

// organisation details and funding details should be set to in progress
submissionCaptor.getValue()
.getDefinition()
.getSections()
.stream()
.filter(section -> section.getSectionId().equals("ESSENTIAL"))
.findFirst()
.ifPresentOrElse(
capturedSectionResponse -> {
assertThat(capturedSectionResponse.getSectionStatus()).isEqualTo(SubmissionSectionStatus.IN_PROGRESS);

// Check if the question with the specified questionId and response is present
boolean isQuestionPresent = capturedSectionResponse.getQuestions().stream()
.anyMatch(question -> question.getQuestionId().equals("APPLICANT_ORG_NAME") && question.getResponse().equals("New name"));

assertThat(isQuestionPresent).isTrue();
},
() -> fail("No section with ID 'ESSENTIAL' found")
);

submissionCaptor.getValue()
.getDefinition()
.getSections()
.stream()
.filter(section -> section.getSectionId().equals("ELIGIBILITY"))
.findFirst()
.ifPresentOrElse(
capturedSectionResponse -> assertThat(capturedSectionResponse.getSectionStatus()).isEqualTo(SubmissionSectionStatus.COMPLETED),
() -> fail("No section with ID 'ELIGIBILITY' found")
);
}

@Test
void saveQuestionResponse_DoesNotResetSectionStatusToInProgress_IfShouldUpdateSectionStatus_IsFalse() {

// set the scheme to version 2
submission.getApplication().getGrantScheme().setVersion(2);

// remove surplus sections
submission.getDefinition()
.getSections()
.removeIf(section -> section.getSectionStatus() != SubmissionSectionStatus.IN_PROGRESS);

submission.getDefinition()
.getSections()
.forEach(section -> section.setSectionStatus(SubmissionSectionStatus.COMPLETED));

final CreateQuestionResponseDto questionResponse = CreateQuestionResponseDto.builder()
.questionId("APPLICANT_ORG_NAME")
.submissionId(SUBMISSION_ID)
.response("New name")
.shouldUpdateSectionStatus(false)
.build();

doReturn(submission)
.when(serviceUnderTest).getSubmissionFromDatabaseBySubmissionId(userId, SUBMISSION_ID);

final ArgumentCaptor<Submission> submissionCaptor = ArgumentCaptor.forClass(Submission.class);

serviceUnderTest.saveQuestionResponse(questionResponse, userId, SUBMISSION_ID, "ESSENTIAL");


verify(submissionRepository).save(submissionCaptor.capture());

// organisation details and funding details should be set to in progress
submissionCaptor.getValue()
.getDefinition()
.getSections()
.stream()
.filter(section -> section.getSectionId().equals("ESSENTIAL"))
.findFirst()
.ifPresentOrElse(
capturedSectionResponse -> {
assertThat(capturedSectionResponse.getSectionStatus()).isEqualTo(SubmissionSectionStatus.COMPLETED);

// Check if the question with the specified questionId and response is present
boolean isQuestionPresent = capturedSectionResponse.getQuestions().stream()
.anyMatch(question -> question.getQuestionId().equals("APPLICANT_ORG_NAME") && question.getResponse().equals("New name"));

assertThat(isQuestionPresent).isTrue();
},
() -> fail("No section with ID 'ESSENTIAL' found")
);

submissionCaptor.getValue()
.getDefinition()
.getSections()
.stream()
.filter(section -> section.getSectionId().equals("ELIGIBILITY"))
.findFirst()
.ifPresentOrElse(
capturedSectionResponse -> assertThat(capturedSectionResponse.getSectionStatus()).isEqualTo(SubmissionSectionStatus.COMPLETED),
() -> fail("No section with ID 'ELIGIBILITY' found")
);
}

@Test
void saveEligibilityResponseToYesAltersStatus_SavesResponse() {

final CreateQuestionResponseDto questionResponse = CreateQuestionResponseDto.builder()
.questionId("ELIGIBILITY")
.submissionId(SUBMISSION_ID)
.response("Yes")
.shouldUpdateSectionStatus(true)
.build();

doReturn(submission)
Expand Down Expand Up @@ -594,6 +724,7 @@ void saveQuestionResponse_HandlesV2Schemes_WhenEligibilityResponse_IsYes() {
.questionId("ELIGIBILITY")
.submissionId(SUBMISSION_ID)
.response("Yes")
.shouldUpdateSectionStatus(true)
.build();

doReturn(submission)
Expand Down Expand Up @@ -687,6 +818,7 @@ void saveQuestionResponse_DoesNotReAssignSectionStatus_IfSectionStatusIsNot_Cann
.questionId("ELIGIBILITY")
.submissionId(SUBMISSION_ID)
.response("Yes")
.shouldUpdateSectionStatus(true)
.build();

doReturn(submission)
Expand Down Expand Up @@ -753,6 +885,7 @@ void saveEligibilityResponseToNoAltersStatus_SavesResponse() {
.questionId("ELIGIBILITY")
.submissionId(SUBMISSION_ID)
.response("No")
.shouldUpdateSectionStatus(true)
.build();

doReturn(submission)
Expand Down Expand Up @@ -809,6 +942,7 @@ void saveQuestionResponse_HandlesV2Schemes_WhenEligibilityResponse_IsNo() {
.questionId("ELIGIBILITY")
.submissionId(SUBMISSION_ID)
.response("No")
.shouldUpdateSectionStatus(true)
.build();

doReturn(submission)
Expand Down Expand Up @@ -862,6 +996,7 @@ void saveQuestionResponse_ThrowsNotFoundException_IfQuestionNotFound() {
.questionId("AN-INVALID-QUESTION-ID")
.submissionId(SUBMISSION_ID)
.response("AND Digital")
.shouldUpdateSectionStatus(true)
.build();

doReturn(submission)
Expand All @@ -877,6 +1012,7 @@ void saveQuestionResponse_ThrowsNotFoundException_IfSectionNotFound() {
.questionId("AN-INVALID-QUESTION-ID")
.submissionId(SUBMISSION_ID)
.response("AND Digital")
.shouldUpdateSectionStatus(true)
.build();

doReturn(submission)
Expand Down

0 comments on commit 96d1617

Please sign in to comment.