Skip to content

Commit

Permalink
Rework to take into account differing sols document names.
Browse files Browse the repository at this point in the history
  • Loading branch information
tom-saunders-cts committed Dec 23, 2024
1 parent 4128fa0 commit c3a6827
Show file tree
Hide file tree
Showing 7 changed files with 204 additions and 6 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -229,6 +229,9 @@ public void setUp() throws NotificationClientException {
.getDocument(any(CallbackRequest.class), eq(DocumentStatus.PREVIEW), eq(DocumentIssueType.GRANT)))
.thenReturn(welshDocumentDraft);

when(documentGeneratorService.getSolicitorSoTDocType(any()))
.thenCallRealMethod();

doReturn(CASEWORKER_USERINFO).when(userInfoService).getCaseworkerInfo();
}

Expand Down Expand Up @@ -922,8 +925,80 @@ void shouldAttachAmendedLegalStatement_PA() throws Exception {
}

@Test
void shouldAttachAmendedLegalStatement_PP() throws Exception {
String payload = testUtils.getStringFromFile("uploadAmendedLegalStatement_PP.json");
void shouldAttachAmendedLegalStatement_PP_probate() throws Exception {
String payload = testUtils.getStringFromFile("uploadAmendedLegalStatement_PP_probate.json");

final var request = post("/document/amendLegalStatement")
.header("authorization", "authToken")
.content(payload)
.contentType(MediaType.APPLICATION_JSON);

final String expectedDate = LocalDate.now()
.format(DateTimeFormatter.ofPattern("dd-MMM-yyyy"));
final String expectedFilename = new StringBuilder()
.append("amendedLegalStatementGrantOfProbate_")
.append(expectedDate)
.append(".pdf")
.toString();

final AmendedFilenameMatcher contentMatcher = new AmendedFilenameMatcher(expectedFilename);

mockMvc.perform(request)
.andExpect(status().isOk())
.andExpect(content().string(contentMatcher));
}

@Test
void shouldAttachAmendedLegalStatement_PP_intestacy() throws Exception {
String payload = testUtils.getStringFromFile("uploadAmendedLegalStatement_PP_intestacy.json");

final var request = post("/document/amendLegalStatement")
.header("authorization", "authToken")
.content(payload)
.contentType(MediaType.APPLICATION_JSON);

final String expectedDate = LocalDate.now()
.format(DateTimeFormatter.ofPattern("dd-MMM-yyyy"));
final String expectedFilename = new StringBuilder()
.append("amendedLegalStatementIntestacy_")
.append(expectedDate)
.append(".pdf")
.toString();

final AmendedFilenameMatcher contentMatcher = new AmendedFilenameMatcher(expectedFilename);

mockMvc.perform(request)
.andExpect(status().isOk())
.andExpect(content().string(contentMatcher));
}

@Test
void shouldAttachAmendedLegalStatement_PP_admon() throws Exception {
String payload = testUtils.getStringFromFile("uploadAmendedLegalStatement_PP_admon.json");

final var request = post("/document/amendLegalStatement")
.header("authorization", "authToken")
.content(payload)
.contentType(MediaType.APPLICATION_JSON);

final String expectedDate = LocalDate.now()
.format(DateTimeFormatter.ofPattern("dd-MMM-yyyy"));
final String expectedFilename = new StringBuilder()
.append("amendedLegalStatementAdmon_")
.append(expectedDate)
.append(".pdf")
.toString();

final AmendedFilenameMatcher contentMatcher = new AmendedFilenameMatcher(expectedFilename);

mockMvc.perform(request)
.andExpect(status().isOk())
.andExpect(content().string(contentMatcher));
}

@Test
void shouldAttachAmendedLegalStatement_PP_edgeCase() throws Exception {
String payload = testUtils.getStringFromFile("uploadAmendedLegalStatement_PP_edgeCase.json");

final var request = post("/document/amendLegalStatement")
.header("authorization", "authToken")
Expand Down Expand Up @@ -988,7 +1063,7 @@ public boolean matches(Object actual) {
*/
@Test
void shouldAcceptPdfValidateAmendLegalStatement() throws Exception {
String payload = testUtils.getStringFromFile("uploadAmendedLegalStatement_PP.json");
String payload = testUtils.getStringFromFile("uploadAmendedLegalStatement_PP_probate.json");

// unclear why when(sU.gST()).thenReturn("sA"); doesn't work, but this does.
doReturn("serviceAuth").when(securityUtils).generateServiceToken();
Expand Down Expand Up @@ -1038,7 +1113,7 @@ public boolean matches(Object actual) {
*/
@Test
void shouldRejectNonPdfValidateAmendLegalStatement() throws Exception {
String payload = testUtils.getStringFromFile("uploadAmendedLegalStatement_PP.json");
String payload = testUtils.getStringFromFile("uploadAmendedLegalStatement_PP_probate.json");

// unclear why when(sU.gST()).thenReturn("sA"); doesn't work, but this does.
doReturn("serviceAuth").when(securityUtils).generateServiceToken();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -70,8 +70,10 @@
import static uk.gov.hmcts.probate.model.State.GRANT_ISSUED;
import static uk.gov.hmcts.probate.model.State.GRANT_ISSUED_INTESTACY;
import static uk.gov.hmcts.probate.model.StateConstants.STATE_BO_CASE_STOPPED;
import static uk.gov.hmcts.reform.probate.model.cases.grantofrepresentation.GrantType.Constants.ADMON_WILL_NAME;
import static uk.gov.hmcts.reform.probate.model.cases.grantofrepresentation.GrantType.Constants.EDGE_CASE_NAME;
import static uk.gov.hmcts.reform.probate.model.cases.grantofrepresentation.GrantType.Constants.GRANT_OF_PROBATE_NAME;
import static uk.gov.hmcts.reform.probate.model.cases.grantofrepresentation.GrantType.Constants.INTESTACY_NAME;

@Slf4j
@RequiredArgsConstructor
Expand Down Expand Up @@ -494,7 +496,15 @@ public ResponseEntity<CallbackResponse> amendLegalStatement(

final String baseFileName = switch (applicationType) {
case PERSONAL -> "amendedLegalStatement";
case SOLICITOR -> "amendedLegalStatementGrantOfProbate";
case SOLICITOR -> {
final DocumentType solsDocType = documentGeneratorService.getSolicitorSoTDocType(callbackRequest);
final String solsBaseName = solsDocType.getTemplateName();
yield new StringBuilder()
.append("amended")
.append(solsBaseName.toUpperCase().substring(0,1))
.append(solsBaseName.substring(1))
.toString();
}
};

final String currentDate = LocalDate.now().format(DateTimeFormatter.ofPattern("dd-MMM-yyyy"));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -203,7 +203,7 @@ public Document generateLetter(CallbackRequest callbackRequest, boolean forFinal
}
}

private DocumentType getSolicitorSoTDocType(CallbackRequest callbackRequest) {
public DocumentType getSolicitorSoTDocType(CallbackRequest callbackRequest) {
DocumentType documentType;
switch (callbackRequest.getCaseDetails().getData().getCaseType()) {
case ADMON_WILL:
Expand Down
37 changes: 37 additions & 0 deletions src/test/resources/uploadAmendedLegalStatement_PP_admon.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
{
"case_details": {
"id": 1528365719153338,
"jurisdiction": "PROBATE",
"state": "BOCaseStopped",
"case_type_id": "GrantOfRepresentation",
"created_date": [
2018,
6,
7,
10,
1,
59,
151000000
],
"last_modified": [
2018,
6,
7,
10,
8,
8,
695000000
],
"case_data": {
"applicationType": "Solicitor",
"schemaVersion": "2.0.0",
"caseType": "admonWill",
"paperForm": "No",
"amendedLegalStatement": {
"document_url": "doc_url",
"document_filename": "upload.pdf",
"document_binary_url": "doc_bin_url"
}
}
}
}
37 changes: 37 additions & 0 deletions src/test/resources/uploadAmendedLegalStatement_PP_edgeCase.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
{
"case_details": {
"id": 1528365719153338,
"jurisdiction": "PROBATE",
"state": "BOCaseStopped",
"case_type_id": "GrantOfRepresentation",
"created_date": [
2018,
6,
7,
10,
1,
59,
151000000
],
"last_modified": [
2018,
6,
7,
10,
8,
8,
695000000
],
"case_data": {
"applicationType": "Solicitor",
"schemaVersion": "2.0.0",
"caseType": "edgeCase",
"paperForm": "No",
"amendedLegalStatement": {
"document_url": "doc_url",
"document_filename": "upload.pdf",
"document_binary_url": "doc_bin_url"
}
}
}
}
37 changes: 37 additions & 0 deletions src/test/resources/uploadAmendedLegalStatement_PP_intestacy.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
{
"case_details": {
"id": 1528365719153338,
"jurisdiction": "PROBATE",
"state": "BOCaseStopped",
"case_type_id": "GrantOfRepresentation",
"created_date": [
2018,
6,
7,
10,
1,
59,
151000000
],
"last_modified": [
2018,
6,
7,
10,
8,
8,
695000000
],
"case_data": {
"applicationType": "Solicitor",
"schemaVersion": "2.0.0",
"caseType": "intestacy",
"paperForm": "No",
"amendedLegalStatement": {
"document_url": "doc_url",
"document_filename": "upload.pdf",
"document_binary_url": "doc_bin_url"
}
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,8 @@
],
"case_data": {
"applicationType": "Solicitor",
"schemaVersion": "2.0.0",
"caseType": "gop",
"paperForm": "No",
"amendedLegalStatement": {
"document_url": "doc_url",
Expand Down

0 comments on commit c3a6827

Please sign in to comment.