Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

DTSSTCI-73 #1810

Merged
merged 8 commits into from
Jul 16, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
import static net.javacrumbs.jsonunit.core.Option.IGNORING_EXTRA_FIELDS;
import static org.assertj.core.api.Assertions.assertThat;
import static org.springframework.http.HttpStatus.OK;
import static uk.gov.hmcts.sptribs.ciccase.model.LanguagePreference.WELSH;
import static uk.gov.hmcts.sptribs.testutil.CaseDataUtil.caseData;
import static uk.gov.hmcts.sptribs.testutil.TestConstants.ABOUT_TO_SUBMIT_URL;
import static uk.gov.hmcts.sptribs.testutil.TestConstants.SUBMITTED_URL;
Expand Down Expand Up @@ -58,6 +59,19 @@ public void shouldReceiveNotificationWhenSubmittedCallbackIsInvoked() throws Exc
.isEqualTo("# Application Received \\n## A notification has been sent to: Subject, Representative");
}

@Disabled ("Skipped to unblock WA - New case needs to be created before updating supplementary data")
@Test
public void shouldReceiveWelshNotificationWhenSubmittedCallbackIsInvoked() throws Exception {
final Map<String, Object> caseData = caseData(REQUEST_SUBMITTED);
caseData.put("dssCaseDataLanguagePreference", WELSH);
final Response response = triggerCallback(caseData, CITIZEN_SUBMIT_CASE_EVENT_ID, SUBMITTED_URL);

assertThat(response.getStatusCode()).isEqualTo(OK.value());
assertThatJson(response.asString())
.inPath(CONFIRMATION_HEADER)
.isEqualTo("# Application Received \\n## A notification has been sent to: Subject, Representative");
}

@Disabled ("Skipped to unblock WA - New case needs to be created before updating supplementary data")
@Test
public void shouldNotSendApplicationReceivedNotificationWhenNotifyPartiesNotFound() throws Exception {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
"dssCaseDataSubjectDateOfBirth": null,
"dssCaseDataSubjectEmailAddress": "citizen@test.com",
"dssCaseDataSubjectContactNumber": null,
"dssCaseDataSubjectLanguagePreference": "english",
"dssCaseDataSubjectAgreeContact": null,
"dssCaseDataRepresentation": "Yes",
"dssCaseDataRepresentationQualified": "Yes",
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,220 @@
package uk.gov.hmcts.sptribs.citizen.event;

import com.fasterxml.jackson.databind.ObjectMapper;
import org.junit.jupiter.api.AfterAll;
import org.junit.jupiter.api.BeforeAll;
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Test;
import org.junit.jupiter.api.extension.ExtendWith;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.test.autoconfigure.web.servlet.AutoConfigureMockMvc;
import org.springframework.boot.test.context.SpringBootTest;
import org.springframework.boot.test.mock.mockito.MockBean;
import org.springframework.test.annotation.DirtiesContext;
import org.springframework.test.context.ContextConfiguration;
import org.springframework.test.context.junit.jupiter.SpringExtension;
import org.springframework.test.web.servlet.MockMvc;
import uk.gov.hmcts.sptribs.ciccase.model.CaseData;
import uk.gov.hmcts.sptribs.ciccase.model.DssCaseData;
import uk.gov.hmcts.sptribs.common.config.EmailTemplatesConfigCIC;
import uk.gov.hmcts.sptribs.common.config.WebMvcConfig;
import uk.gov.hmcts.sptribs.common.service.CcdSupplementaryDataService;
import uk.gov.hmcts.sptribs.testutil.IdamWireMock;
import uk.gov.service.notify.NotificationClient;

import java.util.HashMap;
import java.util.Map;

import static org.mockito.ArgumentMatchers.anyString;
import static org.mockito.ArgumentMatchers.eq;
import static org.mockito.Mockito.verify;
import static org.mockito.Mockito.when;
import static org.springframework.http.MediaType.APPLICATION_JSON;
import static org.springframework.test.web.servlet.request.MockMvcRequestBuilders.post;
import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.status;
import static uk.gov.hmcts.sptribs.caseworker.util.EventConstants.CITIZEN_CIC_SUBMIT_CASE;
import static uk.gov.hmcts.sptribs.ciccase.model.LanguagePreference.ENGLISH;
import static uk.gov.hmcts.sptribs.ciccase.model.LanguagePreference.WELSH;
import static uk.gov.hmcts.sptribs.common.CommonConstants.CIC_CASE_NUMBER;
import static uk.gov.hmcts.sptribs.common.CommonConstants.CIC_CASE_REPRESENTATIVE_NAME;
import static uk.gov.hmcts.sptribs.common.CommonConstants.CIC_CASE_SUBJECT_NAME;
import static uk.gov.hmcts.sptribs.common.CommonConstants.CONTACT_NAME;
import static uk.gov.hmcts.sptribs.common.CommonConstants.CONTACT_PARTY_INFO;
import static uk.gov.hmcts.sptribs.common.CommonConstants.TRIBUNAL_NAME;
import static uk.gov.hmcts.sptribs.common.ccd.CcdCaseType.CIC;
import static uk.gov.hmcts.sptribs.testutil.IdamWireMock.ST_CIC_CASEWORKER;
import static uk.gov.hmcts.sptribs.testutil.IdamWireMock.stubForIdamDetails;
import static uk.gov.hmcts.sptribs.testutil.TestConstants.AUTHORIZATION;
import static uk.gov.hmcts.sptribs.testutil.TestConstants.CASEWORKER_USER_ID;
import static uk.gov.hmcts.sptribs.testutil.TestConstants.SERVICE_AUTHORIZATION;
import static uk.gov.hmcts.sptribs.testutil.TestConstants.SUBMITTED_URL;
import static uk.gov.hmcts.sptribs.testutil.TestConstants.TEST_AUTHORIZATION_TOKEN;
import static uk.gov.hmcts.sptribs.testutil.TestConstants.TEST_CASE_ID_HYPHENATED;
import static uk.gov.hmcts.sptribs.testutil.TestDataHelper.callbackRequest;
import static uk.gov.hmcts.sptribs.testutil.TestDataHelper.caseData;

@ExtendWith(SpringExtension.class)
@SpringBootTest(webEnvironment = SpringBootTest.WebEnvironment.RANDOM_PORT)
@AutoConfigureMockMvc
@ContextConfiguration(initializers = {IdamWireMock.PropertiesInitializer.class})
@DirtiesContext(classMode = DirtiesContext.ClassMode.BEFORE_EACH_TEST_METHOD)
public class CicSubmitCaseEventIT {

@Autowired
private MockMvc mockMvc;

@Autowired
private ObjectMapper objectMapper;

@MockBean
private WebMvcConfig webMvcConfig;

@MockBean
private NotificationClient notificationClient;

@MockBean
private EmailTemplatesConfigCIC emailTemplatesConfig;

@MockBean
private CcdSupplementaryDataService ccdSupplementaryDataService;

@BeforeAll
static void setUp() {
IdamWireMock.start();
}

@AfterAll
static void tearDown() {
IdamWireMock.stopAndReset();
}

@BeforeEach
void setTestData() {
Map<String, String> templatesCIC = new HashMap<>();
templatesCIC.put("APPLICATION_RECEIVED", "5385bfc6-eb33-41f6-ad2b-590a4f427606");
templatesCIC.put("APPLICATION_RECEIVED_CY", "2a434482-a070-457c-935d-12b49f2ac223");

when(emailTemplatesConfig.getTemplatesCIC()).thenReturn(templatesCIC);
}

@Test
void shouldSendSubjectEmailInEnglishWhenLanguagePreferenceIsEnglish() throws Exception {
final CaseData caseData = caseData();
final DssCaseData dssCaseData = DssCaseData.builder()
.subjectFullName("Test Subject")
.subjectEmailAddress("test@subject.com")
.notifyPartyMessage("A message")
.languagePreference(ENGLISH)
.build();
caseData.setDssCaseData(dssCaseData);
caseData.setHyphenatedCaseRef(TEST_CASE_ID_HYPHENATED);

stubForIdamDetails(TEST_AUTHORIZATION_TOKEN, CASEWORKER_USER_ID, ST_CIC_CASEWORKER);

mockMvc.perform(post(SUBMITTED_URL)
.contentType(APPLICATION_JSON)
.header(SERVICE_AUTHORIZATION, TEST_AUTHORIZATION_TOKEN)
.header(AUTHORIZATION, TEST_AUTHORIZATION_TOKEN)
.content(objectMapper.writeValueAsString(
callbackRequest(
caseData,
CITIZEN_CIC_SUBMIT_CASE)))
.accept(APPLICATION_JSON))
.andExpect(
status().isOk());

verify(notificationClient).sendEmail(
eq("5385bfc6-eb33-41f6-ad2b-590a4f427606"),
eq("test@subject.com"),
eq(Map.of(
TRIBUNAL_NAME, CIC,
CONTACT_PARTY_INFO, "A message",
CIC_CASE_SUBJECT_NAME, "Test Subject",
CONTACT_NAME, "Test Subject",
CIC_CASE_NUMBER, TEST_CASE_ID_HYPHENATED
)),
anyString()
);
}

@Test
void shouldSendSubjectEmailInWelshWhenLanguagePreferenceIsWelsh() throws Exception {
final CaseData caseData = caseData();
final DssCaseData dssCaseData = DssCaseData.builder()
.subjectFullName("Test Subject")
.subjectEmailAddress("test@subject.com")
.notifyPartyMessage("A message")
.languagePreference(WELSH)
.build();
caseData.setDssCaseData(dssCaseData);
caseData.setHyphenatedCaseRef(TEST_CASE_ID_HYPHENATED);

stubForIdamDetails(TEST_AUTHORIZATION_TOKEN, CASEWORKER_USER_ID, ST_CIC_CASEWORKER);

mockMvc.perform(post(SUBMITTED_URL)
.contentType(APPLICATION_JSON)
.header(SERVICE_AUTHORIZATION, TEST_AUTHORIZATION_TOKEN)
.header(AUTHORIZATION, TEST_AUTHORIZATION_TOKEN)
.content(objectMapper.writeValueAsString(
callbackRequest(
caseData,
CITIZEN_CIC_SUBMIT_CASE)))
.accept(APPLICATION_JSON))
.andExpect(
status().isOk());

verify(notificationClient).sendEmail(
eq("2a434482-a070-457c-935d-12b49f2ac223"),
eq("test@subject.com"),
eq(Map.of(
TRIBUNAL_NAME, CIC,
CONTACT_PARTY_INFO, "A message",
CIC_CASE_SUBJECT_NAME, "Test Subject",
CONTACT_NAME, "Test Subject",
CIC_CASE_NUMBER, TEST_CASE_ID_HYPHENATED
)),
anyString()
);
}

@Test
void shouldSendRepresentativeEmail() throws Exception {
final CaseData caseData = caseData();
final DssCaseData dssCaseData = DssCaseData.builder()
.subjectFullName("Test Subject")
.representativeFullName("Test Representative")
.representativeEmailAddress("test@representative.com")
.notifyPartyMessage("A message")
.build();
caseData.setDssCaseData(dssCaseData);
caseData.setHyphenatedCaseRef(TEST_CASE_ID_HYPHENATED);

stubForIdamDetails(TEST_AUTHORIZATION_TOKEN, CASEWORKER_USER_ID, ST_CIC_CASEWORKER);

mockMvc.perform(post(SUBMITTED_URL)
.contentType(APPLICATION_JSON)
.header(SERVICE_AUTHORIZATION, TEST_AUTHORIZATION_TOKEN)
.header(AUTHORIZATION, TEST_AUTHORIZATION_TOKEN)
.content(objectMapper.writeValueAsString(
callbackRequest(
caseData,
CITIZEN_CIC_SUBMIT_CASE)))
.accept(APPLICATION_JSON))
.andExpect(
status().isOk());

verify(notificationClient).sendEmail(
eq("5385bfc6-eb33-41f6-ad2b-590a4f427606"),
eq("test@representative.com"),
eq(Map.of(
TRIBUNAL_NAME, CIC,
CONTACT_PARTY_INFO, "A message",
CIC_CASE_SUBJECT_NAME, "Test Subject",
CIC_CASE_REPRESENTATIVE_NAME, "Test Representative",
CONTACT_NAME, "Test Representative",
CIC_CASE_NUMBER, TEST_CASE_ID_HYPHENATED
)),
anyString()
);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -175,4 +175,10 @@ public class DssCaseData implements MappableObject {
access = {DefaultAccess.class, CaseworkerWithCAAAccess.class, CitizenAccess.class}
)
private YesOrNo isRepresentativePresent;

@CCD(
label = "Language preference",
access = {DefaultAccess.class, CitizenAccess.class}
)
private LanguagePreference languagePreference;
}
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;
import uk.gov.hmcts.sptribs.ciccase.model.DssCaseData;
import uk.gov.hmcts.sptribs.ciccase.model.LanguagePreference;
import uk.gov.hmcts.sptribs.ciccase.model.NotificationResponse;
import uk.gov.hmcts.sptribs.notification.DssNotificationHelper;
import uk.gov.hmcts.sptribs.notification.NotificationServiceCIC;
Expand All @@ -13,9 +14,12 @@

import java.util.Map;

import static uk.gov.hmcts.sptribs.ciccase.model.LanguagePreference.ENGLISH;
import static uk.gov.hmcts.sptribs.common.CommonConstants.CIC_CASE_REPRESENTATIVE_NAME;
import static uk.gov.hmcts.sptribs.common.CommonConstants.CIC_CASE_SUBJECT_NAME;
import static uk.gov.hmcts.sptribs.common.CommonConstants.CONTACT_PARTY_INFO;
import static uk.gov.hmcts.sptribs.notification.TemplateName.APPLICATION_RECEIVED;
import static uk.gov.hmcts.sptribs.notification.TemplateName.APPLICATION_RECEIVED_CY;

@Component
@Setter
Expand All @@ -33,7 +37,11 @@ public void sendToSubject(final DssCaseData dssCaseData, final String caseNumber
templateVarsSubject.put(CIC_CASE_SUBJECT_NAME, dssCaseData.getSubjectFullName());
templateVarsSubject.put(CONTACT_PARTY_INFO, dssCaseData.getNotifyPartyMessage());

NotificationResponse notificationResponse = sendEmailNotification(templateVarsSubject, dssCaseData.getSubjectEmailAddress());
NotificationResponse notificationResponse = sendEmailNotification(
templateVarsSubject,
dssCaseData.getSubjectEmailAddress(),
dssCaseData.getLanguagePreference()
);
dssCaseData.setSubjectNotificationResponse(notificationResponse);
}

Expand All @@ -43,13 +51,20 @@ public void sendToRepresentative(final DssCaseData dssCaseData, final String cas
templateVarsRep.put(CIC_CASE_REPRESENTATIVE_NAME, dssCaseData.getRepresentativeFullName());
templateVarsRep.put(CONTACT_PARTY_INFO, dssCaseData.getNotifyPartyMessage());

NotificationResponse notificationResponse = sendEmailNotification(templateVarsRep, dssCaseData.getRepresentativeEmailAddress());
NotificationResponse notificationResponse = sendEmailNotification(
templateVarsRep,
dssCaseData.getRepresentativeEmailAddress(),
ENGLISH
);
dssCaseData.setRepNotificationResponse(notificationResponse);
}

private NotificationResponse sendEmailNotification(final Map<String, Object> templateVars, String toEmail) {
NotificationRequest request = dssNotificationHelper.buildEmailNotificationRequest(
toEmail, templateVars, TemplateName.APPLICATION_RECEIVED);
private NotificationResponse sendEmailNotification(final Map<String, Object> templateVars,
String toEmail,
LanguagePreference languagePreference) {
TemplateName templateName = ENGLISH.equals(languagePreference) ? APPLICATION_RECEIVED : APPLICATION_RECEIVED_CY;
NotificationRequest request =
dssNotificationHelper.buildEmailNotificationRequest(toEmail, templateVars, templateName);
return notificationService.sendEmail(request);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
import uk.gov.hmcts.ccd.sdk.type.ListValue;
import uk.gov.hmcts.ccd.sdk.type.YesOrNo;
import uk.gov.hmcts.sptribs.ciccase.model.DssCaseData;
import uk.gov.hmcts.sptribs.ciccase.model.LanguagePreference;
import uk.gov.hmcts.sptribs.document.model.EdgeCaseDocument;

import java.time.LocalDate;
Expand Down Expand Up @@ -58,6 +59,8 @@ public class DssCaseDataRequest {

private YesOrNo dssCaseDataIsRepresentativePresent;

private LanguagePreference dssCaseDataLanguagePreference;

public static DssCaseDataRequest convertDssCaseDataToRequest(DssCaseData dssCaseData) {
return DssCaseDataRequest.builder()
.dssCaseDataCaseTypeOfApplication(dssCaseData.getCaseTypeOfApplication())
Expand All @@ -79,6 +82,7 @@ public static DssCaseDataRequest convertDssCaseDataToRequest(DssCaseData dssCase
.dssCaseDataSupportingDocuments(dssCaseData.getSupportingDocuments())
.dssCaseDataOtherInfoDocuments(dssCaseData.getOtherInfoDocuments())
.dssCaseDataIsRepresentativePresent(dssCaseData.getIsRepresentativePresent())
.dssCaseDataLanguagePreference(dssCaseData.getLanguagePreference())
.build();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
public enum TemplateName {
RESPONDENT_SOLICITOR_HAS_NOT_RESPONDED,
APPLICATION_RECEIVED,
APPLICATION_RECEIVED_CY,
APPLICATION_NEW_ORDER_ISSUED,
CASE_CANCEL_HEARING_EMAIL,
CASE_CANCEL_HEARING_POST,
Expand Down
1 change: 1 addition & 0 deletions src/main/resources/application.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,7 @@ uk:
templatesCIC:
APPLICATION_NEW_ORDER_ISSUED: 'e451a469-e61d-4daf-95c3-e405448ececf'
APPLICATION_RECEIVED: '5385bfc6-eb33-41f6-ad2b-590a4f427606'
APPLICATION_RECEIVED_CY: '2a434482-a070-457c-935d-12b49f2ac223'
CASE_REINSTATED_EMAIL: '1f41595f-1ab8-4e41-a240-026c61ecd852'
CASE_REINSTATED_POST: '313e8992-8538-4485-a461-a244cc893bb3'
CASE_STAYED_EMAIL: 'ce3e6749-0400-47fd-aa96-33e348c860ad'
Expand Down
Loading