Skip to content

Commit

Permalink
coverage
Browse files Browse the repository at this point in the history
  • Loading branch information
tom-saunders-cts committed Dec 4, 2024
1 parent 50edefa commit 7cda969
Show file tree
Hide file tree
Showing 4 changed files with 113 additions and 5 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -430,7 +430,7 @@ private Document getGeneratedSentEmailDocument(SendEmailResponse response, Strin
return pdfManagementService.generateAndUpload(sentEmail, docType);
}

private String rerenderAsXhtml(String textToEscape) {
String rerenderAsXhtml(String textToEscape) {
final Safelist safelist = Safelist.relaxed();

final org.jsoup.nodes.Document.OutputSettings outputSettings = new org.jsoup.nodes.Document.OutputSettings()
Expand All @@ -441,7 +441,7 @@ private String rerenderAsXhtml(String textToEscape) {
return Jsoup.clean(textToEscape, "", safelist, outputSettings);
}

private Document getGeneratedDocument(
Document getGeneratedDocument(
final TemplatePreview response,
final String emailAddress,
final DocumentType docType) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -95,9 +95,7 @@ public Document generateAndUpload(CaveatCallbackRequest callbackRequest, Documen
}

public Document generateAndUpload(SentEmail sentEmail, DocumentType documentType) {
final String json = toJson(sentEmail, documentType);
log.info("json:\n\n{}\n\n", json);
return generateAndUpload(json, documentType);
return generateAndUpload(toJson(sentEmail, documentType), documentType);
}

private Document generateAndUpload(String json, DocumentType documentType) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -414,6 +414,37 @@ void shouldSendEmailPreview() {
assertThat(stringResponseEntity.getStatusCode(), is(HttpStatus.OK));
}

@Test
void shouldHandleFailureToPreview() throws NotificationClientException {
CaseDetails caseDetails = new CaseDetails(CaseData.builder()
.applicationType(SOLICITOR)
.registryLocation("Manchester")
.solsSolicitorEmail("[email protected]")
.solsSolicitorAppReference("1234-5678-9012")
.languagePreferenceWelsh("No")
.removedRepresentative(RemovedRepresentative.builder()
.solicitorEmail("[email protected]")
.solicitorFirstName("FirstName")
.solicitorLastName("LastName").build())
.build(), LAST_MODIFIED, ID);
callbackRequest = new CallbackRequest(caseDetails);
document = Document.builder()
.documentDateAdded(LocalDate.now())
.documentFileName("fileName")
.documentGeneratedBy("generatedBy")
.documentLink(
DocumentLink.builder().documentUrl("url").documentFilename("file")
.documentBinaryUrl("binary").build())
.documentType(DocumentType.SENT_EMAIL)
.build();
callbackResponse = CallbackResponse.builder().errors(Collections.EMPTY_LIST).build();
when(informationRequestService.emailPreview(any())).thenReturn(document);
when(notificationService.emailPreviewAlt(any())).thenThrow(NotificationClientException.class);
ResponseEntity<CallbackResponse> stringResponseEntity =
notificationController.emailPreview(callbackRequest);
assertThat(stringResponseEntity.getStatusCode(), is(HttpStatus.OK));
}

@Test
void shouldNotSendNocEmailForBulkScanCaseFirstNoc() throws NotificationClientException {
setUpMocks(NOC);
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package uk.gov.hmcts.probate.service;

import org.json.JSONObject;
import org.junit.jupiter.api.AfterEach;
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Test;
Expand All @@ -9,6 +10,7 @@
import uk.gov.hmcts.probate.config.notifications.EmailAddresses;
import uk.gov.hmcts.probate.config.notifications.NotificationTemplates;
import uk.gov.hmcts.probate.config.properties.registries.RegistriesProperties;
import uk.gov.hmcts.probate.model.DocumentType;
import uk.gov.hmcts.probate.service.documentmanagement.DocumentManagementService;
import uk.gov.hmcts.probate.service.notification.CaveatPersonalisationService;
import uk.gov.hmcts.probate.service.notification.GrantOfRepresentationPersonalisationService;
Expand All @@ -23,13 +25,15 @@
import uk.gov.hmcts.reform.authorisation.generators.AuthTokenGenerator;
import uk.gov.service.notify.NotificationClient;
import uk.gov.service.notify.NotificationClientException;
import uk.gov.service.notify.TemplatePreview;

import java.util.Collections;
import java.util.List;
import java.util.Map;

import static org.junit.jupiter.api.Assertions.assertEquals;
import static org.junit.jupiter.api.Assertions.assertThrows;
import static org.mockito.ArgumentMatchers.any;
import static org.mockito.Mockito.when;

class NotificationServiceTest {
Expand Down Expand Up @@ -138,4 +142,79 @@ void givenPersonalisationWithNoIssue_whenCommonValidation_thenReturnsAllOk() thr

assertEquals(CommonNotificationResult.ALL_OK, result);
}

@Test
void testRerender() {
notificationService.rerenderAsXhtml("");
}

@Test
void testGetDocument_master() {
final JSONObject templateData = new JSONObject();
templateData.put("id", "00000000-0000-0000-0000-000000000000");
templateData.put("type", "email");
templateData.put("version", 1);
templateData.put("body", "body");
templateData.put("subject", "subject");
templateData.put("html", "html");
final TemplatePreview templatePreview = new TemplatePreview(templateData);


when(featureToggleServiceMock.chooseDocGen()).thenReturn(FeatureToggleService.DocGen.MASTER);
when(markdownTransformationServiceMock.toHtml(any())).thenReturn("");

notificationService.getGeneratedDocument(templatePreview, "emailAddr", DocumentType.SENT_EMAIL);
}

@Test
void testGetDocument_pr() {
final JSONObject templateData = new JSONObject();
templateData.put("id", "00000000-0000-0000-0000-000000000000");
templateData.put("type", "email");
templateData.put("version", 1);
templateData.put("body", "body");
templateData.put("subject", "subject");
templateData.put("html", "html");
final TemplatePreview templatePreview = new TemplatePreview(templateData);


when(featureToggleServiceMock.chooseDocGen()).thenReturn(FeatureToggleService.DocGen.PR);
when(sentEmailPersonalisationServiceMock.getPersonalisation(any())).thenReturn(Map.of());

notificationService.getGeneratedDocument(templatePreview, "emailAddr", DocumentType.SENT_EMAIL);
}

@Test
void testGetDocument_html() {
final JSONObject templateData = new JSONObject();
templateData.put("id", "00000000-0000-0000-0000-000000000000");
templateData.put("type", "email");
templateData.put("version", 1);
templateData.put("body", "body");
templateData.put("subject", "subject");
templateData.put("html", "html");
final TemplatePreview templatePreview = new TemplatePreview(templateData);


when(featureToggleServiceMock.chooseDocGen()).thenReturn(FeatureToggleService.DocGen.HTML);

notificationService.getGeneratedDocument(templatePreview, "emailAddr", DocumentType.SENT_EMAIL);
}

@Test
void testGetDocument_htmlProc() {
final JSONObject templateData = new JSONObject();
templateData.put("id", "00000000-0000-0000-0000-000000000000");
templateData.put("type", "email");
templateData.put("version", 1);
templateData.put("body", "body");
templateData.put("subject", "subject");
templateData.put("html", "html");
final TemplatePreview templatePreview = new TemplatePreview(templateData);


when(featureToggleServiceMock.chooseDocGen()).thenReturn(FeatureToggleService.DocGen.HTML_PROC);

notificationService.getGeneratedDocument(templatePreview, "emailAddr", DocumentType.SENT_EMAIL);
}
}

0 comments on commit 7cda969

Please sign in to comment.