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

PUB-1567 Add email for crime inactive user #458

Merged
merged 3 commits into from
Sep 20, 2024
Merged
Show file tree
Hide file tree
Changes from 1 commit
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 @@ -15,4 +15,5 @@ public class PersonalisationLinks {
private String mediaVerificationPageLink;
private String adminDashboardLink;
private String cftSignInPageLink;
private String crimeSignInPageLink;
}
Original file line number Diff line number Diff line change
Expand Up @@ -86,6 +86,11 @@ public enum Templates {
"Inactive IDAM account notification email",
EmailLimit.STANDARD,
new InactiveUserNotificationEmailGenerator()),

INACTIVE_USER_NOTIFICATION_EMAIL_CRIME("710a1ea4-226d-4e94-a8f7-5a102bb31612",
"Inactive IDAM account notification email",
KianKwa marked this conversation as resolved.
Show resolved Hide resolved
EmailLimit.STANDARD,
new InactiveUserNotificationEmailGenerator()),
DELETE_LOCATION_SUBSCRIPTION("929276e1-da85-4f21-9ed4-53492bedff68",
"Location deletion notification email",
EmailLimit.HIGH,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -126,7 +126,9 @@ public String mediaUserRejectionEmailRequest(MediaRejectionEmail body) {
public String inactiveUserNotificationEmailRequest(InactiveUserNotificationEmail body) {
Templates emailTemplate = UserProvenances.PI_AAD.name().equals(body.getUserProvenance())
? Templates.INACTIVE_USER_NOTIFICATION_EMAIL_AAD
: Templates.INACTIVE_USER_NOTIFICATION_EMAIL_CFT;
: UserProvenances.CFT_IDAM.name().equals(body.getUserProvenance())
? Templates.INACTIVE_USER_NOTIFICATION_EMAIL_CFT
KianKwa marked this conversation as resolved.
Show resolved Hide resolved
: Templates.INACTIVE_USER_NOTIFICATION_EMAIL_CRIME;

EmailToSend email = emailService.handleEmailGeneration(new InactiveUserNotificationEmailData(body),
emailTemplate);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@

import static uk.gov.hmcts.reform.pip.publication.services.notify.Templates.INACTIVE_USER_NOTIFICATION_EMAIL_AAD;
import static uk.gov.hmcts.reform.pip.publication.services.notify.Templates.INACTIVE_USER_NOTIFICATION_EMAIL_CFT;
import static uk.gov.hmcts.reform.pip.publication.services.notify.Templates.INACTIVE_USER_NOTIFICATION_EMAIL_CRIME;

@Service
/**
Expand All @@ -25,7 +26,9 @@ public EmailToSend buildEmail(EmailData email, PersonalisationLinks personalisat
InactiveUserNotificationEmailData emailData = (InactiveUserNotificationEmailData) email;
Templates emailTemplate = UserProvenances.PI_AAD.name().equals(emailData.getUserProvenance())
? INACTIVE_USER_NOTIFICATION_EMAIL_AAD
: INACTIVE_USER_NOTIFICATION_EMAIL_CFT;
: UserProvenances.CFT_IDAM.name().equals(emailData.getUserProvenance())
? INACTIVE_USER_NOTIFICATION_EMAIL_CFT
KianKwa marked this conversation as resolved.
Show resolved Hide resolved
: INACTIVE_USER_NOTIFICATION_EMAIL_CRIME;

return generateEmail(emailData.getEmail(), emailTemplate.getTemplate(),
buildEmailPersonalisation(emailData, personalisationLinks));
Expand All @@ -38,6 +41,7 @@ private Map<String, Object> buildEmailPersonalisation(InactiveUserNotificationEm
personalisation.put("last_signed_in_date", emailData.getLastSignedInDate());
personalisation.put("sign_in_page_link", personalisationLinks.getAadAdminSignInPageLink());
personalisation.put("cft_sign_in_link", personalisationLinks.getCftSignInPageLink());
personalisation.put("crime_sign_in_link", personalisationLinks.getCrimeSignInPageLink());
return personalisation;
}
}
1 change: 1 addition & 0 deletions src/main/resources/application.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,7 @@ notify:
media-verification-page-link: ${MEDIA_VERIFICATION_PAGE_LINK:https://pip-frontend.staging.platform.hmcts.net/media-verification?p=B2C_1_SignInMediaVerification}
admin-dashboard-link: ${ADMIN_DASHBOARD_LINK:https://pip-frontend.staging.platform.hmcts.net/admin-dashboard}
cft-sign-in-page-link: ${NOTIFY_CFT_SIGN_IN_LINK:https://pip-frontend.staging.platform.hmcts.net/cft-login}
crime-sign-in-page-link: ${NOTIFY_CRIME_SIGN_IN_LINK:https://pip-frontend.staging.platform.hmcts.net/crime-login}
pi-team-email: ${PI_TEAM_EMAIL:teamEmail@email.com}

error-handling:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
import static uk.gov.hmcts.reform.pip.publication.services.notify.Templates.EXISTING_USER_WELCOME_EMAIL;
import static uk.gov.hmcts.reform.pip.publication.services.notify.Templates.INACTIVE_USER_NOTIFICATION_EMAIL_AAD;
import static uk.gov.hmcts.reform.pip.publication.services.notify.Templates.INACTIVE_USER_NOTIFICATION_EMAIL_CFT;
import static uk.gov.hmcts.reform.pip.publication.services.notify.Templates.INACTIVE_USER_NOTIFICATION_EMAIL_CRIME;
import static uk.gov.hmcts.reform.pip.publication.services.notify.Templates.MEDIA_APPLICATION_REPORTING_EMAIL;
import static uk.gov.hmcts.reform.pip.publication.services.notify.Templates.MEDIA_USER_VERIFICATION_EMAIL;

Expand All @@ -21,6 +22,8 @@ class TemplatesTest {
private static final String MEDIA_VERIFICATION_EMAIL_TEMPLATE = "1dea6b4b-48b6-4eb1-8b86-7031de5502d9";
private static final String INACTIVE_USER_NOTIFICATION_EMAIL_AAD_TEMPLATE = "8f1e82a9-7016-4b28-8473-20c70f9f11ba";
private static final String INACTIVE_USER_NOTIFICATION_EMAIL_CFT_TEMPLATE = "cca7ea18-4e6f-406f-b4d3-9e017cb53ee9";
private static final String INACTIVE_USER_NOTIFICATION_EMAIL_CRIME_TEMPLATE =
"710a1ea4-226d-4e94-a8f7-5a102bb31612";

@Test
void testGetExistingUserWelcomeEmailTemplate() {
Expand Down Expand Up @@ -58,6 +61,13 @@ void testGetInactiveUserNotificationTemplateCft() {
SHOULD_MATCH_MESSAGE);
}

@Test
void testGetInactiveUserNotificationTemplateCrime() {
assertEquals(INACTIVE_USER_NOTIFICATION_EMAIL_CRIME_TEMPLATE,
INACTIVE_USER_NOTIFICATION_EMAIL_CRIME.getTemplate(),
SHOULD_MATCH_MESSAGE);
}

@Test
void testGetEnumFromTemplate() {
assertEquals(EXISTING_USER_WELCOME_EMAIL, Templates.get(EXISTING_USER_WELCOME_EMAIL.getTemplate()),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -82,6 +82,9 @@ class UserNotificationServiceTest extends RedisConfigurationTestBase {
private static final InactiveUserNotificationEmail INACTIVE_USER_NOTIFICATION_EMAIL_CFT =
new InactiveUserNotificationEmail(EMAIL, FULL_NAME, "CFT_IDAM", LAST_SIGNED_IN_DATE);

private static final InactiveUserNotificationEmail INACTIVE_USER_NOTIFICATION_EMAIL_CRIME =
new InactiveUserNotificationEmail(EMAIL, FULL_NAME, "CRIME_IDAM", LAST_SIGNED_IN_DATE);

private static final String SUCCESS_REF_ID = "successRefId";

private final EmailToSend validEmailBodyForEmailClient = new EmailToSend(
Expand Down Expand Up @@ -210,6 +213,18 @@ void testValidPayloadReturnsSuccessInactiveUserNotificationForCft() {
);
}

@Test
void testValidPayloadReturnsSuccessInactiveUserNotificationForCrime() {
when(emailService.handleEmailGeneration(any(InactiveUserNotificationEmailData.class),
eq(Templates.INACTIVE_USER_NOTIFICATION_EMAIL_CRIME)))
.thenReturn(validEmailBodyForEmailClient);

assertEquals(SUCCESS_REF_ID, userNotificationService.inactiveUserNotificationEmailRequest(
INACTIVE_USER_NOTIFICATION_EMAIL_CRIME),
"Inactive user notification should return successful reference ID"
);
}

@Test
void testMediaUserRejectionEmailRequestWithValidData() {
MediaRejectionEmail mediaRejectionEmail = new MediaRejectionEmail(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@

import static uk.gov.hmcts.reform.pip.publication.services.notify.Templates.INACTIVE_USER_NOTIFICATION_EMAIL_AAD;
import static uk.gov.hmcts.reform.pip.publication.services.notify.Templates.INACTIVE_USER_NOTIFICATION_EMAIL_CFT;
import static uk.gov.hmcts.reform.pip.publication.services.notify.Templates.INACTIVE_USER_NOTIFICATION_EMAIL_CRIME;

@SpringBootTest
@DirtiesContext
Expand All @@ -27,12 +28,14 @@ class InactiveUserNotificationEmailGeneratorTest extends RedisConfigurationTestB
private static final String FULL_NAME = "Full name";
private static final String AAD_USER_PROVENANCE = "PI_AAD";
private static final String CFT_IDAM_USER_PROVENANCE = "CFT_IDAM";
private static final String CRIME_IDAM_USER_PROVENANCE = "CRIME_IDAM";
private static final String LAST_SIGN_IN_DATE = "01/05/2024";

private static final String FULL_NAME_PERSONALISATION = "full_name";
private static final String LAST_SIGN_IN_DATE_PERSONALISATION = "last_signed_in_date";
private static final String AAD_SIGN_IN_PAGE_LINK = "sign_in_page_link";
private static final String CFT_SIGN_IN_PAGE_LINK = "cft_sign_in_link";
private static final String CRIME_SIGN_IN_PAGE_LINK = "crime_sign_in_link";

private static final String EMAIL_ADDRESS_MESSAGE = "Email address does not match";
private static final String NOTIFY_TEMPLATE_MESSAGE = "Notify template does not match";
Expand Down Expand Up @@ -97,6 +100,29 @@ void testBuildInactiveCftUserNotificationEmail() {
softly.assertAll();
}

@Test
void testBuildInactiveCrimeUserNotificationEmail() {
InactiveUserNotificationEmail notificationEmail = new InactiveUserNotificationEmail(
EMAIL, FULL_NAME, CRIME_IDAM_USER_PROVENANCE, LAST_SIGN_IN_DATE
);
InactiveUserNotificationEmailData emailData = new InactiveUserNotificationEmailData(notificationEmail);

EmailToSend result = emailGenerator.buildEmail(emailData, personalisationLinks);

SoftAssertions softly = new SoftAssertions();

softly.assertThat(result.getEmailAddress())
.as(EMAIL_ADDRESS_MESSAGE)
.isEqualTo(EMAIL);

softly.assertThat(result.getTemplate())
.as(NOTIFY_TEMPLATE_MESSAGE)
.isEqualTo(INACTIVE_USER_NOTIFICATION_EMAIL_CRIME.getTemplate());

verifyPersonalisation(softly, result.getPersonalisation());
softly.assertAll();
}

private void verifyPersonalisation(SoftAssertions softly, Map<String, Object> personalisation) {
softly.assertThat(personalisation.get(FULL_NAME_PERSONALISATION))
.as(PERSONALISATION_MESSAGE)
Expand All @@ -113,5 +139,9 @@ private void verifyPersonalisation(SoftAssertions softly, Map<String, Object> pe
softly.assertThat(personalisation.get(CFT_SIGN_IN_PAGE_LINK))
.as(PERSONALISATION_MESSAGE)
.isEqualTo(personalisationLinks.getCftSignInPageLink());

softly.assertThat(personalisation.get(CRIME_SIGN_IN_PAGE_LINK))
.as(PERSONALISATION_MESSAGE)
.isEqualTo(personalisationLinks.getCrimeSignInPageLink());
}
}