Skip to content

Commit

Permalink
set CHN and CCN as null if orgType of the submission is Local authori…
Browse files Browse the repository at this point in the history
…ty or Individual
  • Loading branch information
a-lor-cab committed Feb 19, 2024
1 parent a924329 commit 3c2fe88
Show file tree
Hide file tree
Showing 2 changed files with 117 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,9 @@
import java.time.Instant;
import java.util.UUID;

import static gov.cabinetoffice.gap.applybackend.enums.GrantMandatoryQuestionOrgType.INDIVIDUAL;
import static gov.cabinetoffice.gap.applybackend.enums.GrantMandatoryQuestionOrgType.LOCAL_AUTHORITY;

@RequiredArgsConstructor
@RestController
@RequestMapping("/grant-mandatory-questions")
Expand Down Expand Up @@ -143,6 +146,13 @@ public ResponseEntity<String> updateMandatoryQuestion(@PathVariable final UUID m
grantMandatoryQuestions.setStatus(GrantMandatoryQuestionStatus.COMPLETED);
}

if (mandatoryQuestionDto.getOrgType() != null && mandatoryQuestionDto.getOrgType().isPresent() &&
(mandatoryQuestionDto.getOrgType().get().equals(LOCAL_AUTHORITY.toString())
|| mandatoryQuestionDto.getOrgType().get().equals(INDIVIDUAL.toString()))) {
grantMandatoryQuestions.setCharityCommissionNumber(null);
grantMandatoryQuestions.setCompaniesHouseNumber(null);
}

grantMandatoryQuestions.setLastUpdatedBy(applicant);
grantMandatoryQuestions.setLastUpdated(Instant.now());

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@
import java.util.UUID;

import static gov.cabinetoffice.gap.applybackend.enums.GrantMandatoryQuestionFundingLocation.SCOTLAND;
import static gov.cabinetoffice.gap.applybackend.enums.GrantMandatoryQuestionOrgType.*;
import static org.assertj.core.api.Assertions.assertThat;
import static org.mockito.Mockito.verify;
import static org.mockito.Mockito.when;
Expand Down Expand Up @@ -130,7 +131,7 @@ void getGrantMandatoryQuestionsById_ReturnsExpectedMandatoryQuestions() {
.postcode("G2 7EZ")
.fundingLocation(fundingLocations)
.companiesHouseNumber("08761455")
.orgType(GrantMandatoryQuestionOrgType.LIMITED_COMPANY)
.orgType(LIMITED_COMPANY)
.build();

final GetGrantMandatoryQuestionDto mandatoryQuestionsDto = GetGrantMandatoryQuestionDto.builder()
Expand Down Expand Up @@ -178,7 +179,7 @@ void updateMandatoryQuestion_UpdatesExpectedFields_AndSavesChanges() {
.postcode("G2 7EZ")
.fundingLocation(fundingLocations)
.companiesHouseNumber("08761455")
.orgType(GrantMandatoryQuestionOrgType.LIMITED_COMPANY)
.orgType(LIMITED_COMPANY)
.build();

when(grantApplicantService.getApplicantById(jwtPayload.getSub()))
Expand Down Expand Up @@ -291,6 +292,109 @@ void updateMandatoryQuestion_SetsStatusToComplete() {

}


@Test
void updateMandatoryQuestion_setCharityAndCommissionNumberAsNullIfOrgTypeIsLocalAuthority() {
final GrantMandatoryQuestionOrgType localAuthority = LOCAL_AUTHORITY;
final UpdateGrantMandatoryQuestionDto updateDto = UpdateGrantMandatoryQuestionDto.builder()
.orgType(Optional.of("Local authority"))
.build();

final GrantMandatoryQuestions mandatoryQuestionsBefore = GrantMandatoryQuestions.builder()
.id(MANDATORY_QUESTION_ID)
.createdBy(applicant)
.grantScheme(scheme)
.name("AND Digital")
.companiesHouseNumber("08761455")
.charityCommissionNumber("123456")
.build();

final GrantMandatoryQuestions mandatoryQuestionsAfter = GrantMandatoryQuestions.builder()
.id(MANDATORY_QUESTION_ID)
.createdBy(applicant)
.grantScheme(scheme)
.name("AND Digital")
.orgType(localAuthority)
.companiesHouseNumber(null)
.charityCommissionNumber(null)
.build();

when(grantApplicantService.getApplicantById(jwtPayload.getSub()))
.thenReturn(applicant);

when(grantMandatoryQuestionService.getGrantMandatoryQuestionById(MANDATORY_QUESTION_ID, jwtPayload.getSub()))
.thenReturn(mandatoryQuestionsBefore);

when(grantMandatoryQuestionMapper.mapUpdateGrantMandatoryQuestionDtoToGrantMandatoryQuestion(updateDto, mandatoryQuestionsBefore))
.thenReturn(mandatoryQuestionsBefore);

when(grantMandatoryQuestionService.updateMandatoryQuestion(mandatoryQuestionsBefore, applicant))
.thenReturn(mandatoryQuestionsAfter);

when(grantMandatoryQuestionService.generateNextPageUrl("url", MANDATORY_QUESTION_ID, jwtPayload.getSub()))
.thenReturn("nextPageUrl");


final ResponseEntity<String> methodResponse = controllerUnderTest.updateMandatoryQuestion(MANDATORY_QUESTION_ID, updateDto, "url");

verify(grantMandatoryQuestionService).addMandatoryQuestionsToSubmissionObject(mandatoryQuestionsBefore);
verify(grantMandatoryQuestionService).updateMandatoryQuestion(mandatoryQuestionsBefore, applicant);
assertThat(methodResponse.getStatusCode()).isEqualTo(HttpStatus.OK);
assertThat(methodResponse.getBody()).isEqualTo("nextPageUrl");

}

@Test
void updateMandatoryQuestion_setCharityAndCommissionNumberAsNullIfOrgTypeIsIndividual() {
final GrantMandatoryQuestionOrgType individual = INDIVIDUAL;
final UpdateGrantMandatoryQuestionDto updateDto = UpdateGrantMandatoryQuestionDto.builder()
.orgType(Optional.of("I am applying as an individual"))
.build();

final GrantMandatoryQuestions mandatoryQuestionsBefore = GrantMandatoryQuestions.builder()
.id(MANDATORY_QUESTION_ID)
.createdBy(applicant)
.grantScheme(scheme)
.name("AND Digital")
.companiesHouseNumber("08761455")
.charityCommissionNumber("123456")
.build();

final GrantMandatoryQuestions mandatoryQuestionsAfter = GrantMandatoryQuestions.builder()
.id(MANDATORY_QUESTION_ID)
.createdBy(applicant)
.grantScheme(scheme)
.name("AND Digital")
.orgType(individual)
.companiesHouseNumber(null)
.charityCommissionNumber(null)
.build();

when(grantApplicantService.getApplicantById(jwtPayload.getSub()))
.thenReturn(applicant);

when(grantMandatoryQuestionService.getGrantMandatoryQuestionById(MANDATORY_QUESTION_ID, jwtPayload.getSub()))
.thenReturn(mandatoryQuestionsBefore);

when(grantMandatoryQuestionMapper.mapUpdateGrantMandatoryQuestionDtoToGrantMandatoryQuestion(updateDto, mandatoryQuestionsBefore))
.thenReturn(mandatoryQuestionsBefore);

when(grantMandatoryQuestionService.updateMandatoryQuestion(mandatoryQuestionsBefore, applicant))
.thenReturn(mandatoryQuestionsAfter);

when(grantMandatoryQuestionService.generateNextPageUrl("url", MANDATORY_QUESTION_ID, jwtPayload.getSub()))
.thenReturn("nextPageUrl");


final ResponseEntity<String> methodResponse = controllerUnderTest.updateMandatoryQuestion(MANDATORY_QUESTION_ID, updateDto, "url");

verify(grantMandatoryQuestionService).addMandatoryQuestionsToSubmissionObject(mandatoryQuestionsBefore);
verify(grantMandatoryQuestionService).updateMandatoryQuestion(mandatoryQuestionsBefore, applicant);
assertThat(methodResponse.getStatusCode()).isEqualTo(HttpStatus.OK);
assertThat(methodResponse.getBody()).isEqualTo("nextPageUrl");

}

@Test
void shouldReturnMandatoryQuestionsIfValidSchemeAndUserIdIsGiven() {
final GrantMandatoryQuestions mandatoryQuestions = GrantMandatoryQuestions.builder()
Expand All @@ -303,7 +407,7 @@ void shouldReturnMandatoryQuestionsIfValidSchemeAndUserIdIsGiven() {
.city("Glasgow")
.postcode("G2 7EZ")
.companiesHouseNumber("08761455")
.orgType(GrantMandatoryQuestionOrgType.LIMITED_COMPANY)
.orgType(LIMITED_COMPANY)
.build();

final GetGrantMandatoryQuestionDto mandatoryQuestionsDto = GetGrantMandatoryQuestionDto.builder()
Expand Down

0 comments on commit 3c2fe88

Please sign in to comment.