Search in sources :

Example 1 with EmailTemplate

use of uk.gov.pay.adminusers.resources.EmailTemplate in project pay-adminusers by alphagov.

the class EmailServiceTest method shouldThrowAnExceptionIfMerchantDetailsAreMissing.

@Test
public void shouldThrowAnExceptionIfMerchantDetailsAreMissing() {
    // reset mocks as these are not used here and Mockito can continue enforcing strict stubs
    Mockito.reset(mockNotificationService, mockNotifyDirectDebitConfiguration, mockServiceEntity, mockCountryConverter);
    EmailTemplate template = EmailTemplate.MANDATE_FAILED;
    Map<String, String> personalisation = Map.of("field 1", "theValueOfField1", "field 2", "theValueOfField2");
    MerchantDetailsEntity merchantDetails = new MerchantDetailsEntity(null, TELEPHONE_NUMBER, ADDRESS_LINE_1, "address line 2", CITY, POSTCODE, ADDRESS_COUNTRY_CODE, MERCHANT_EMAIL, null);
    given(mockServiceEntity.getMerchantDetailsEntity()).willReturn(merchantDetails);
    InvalidMerchantDetailsException exception = assertThrows(InvalidMerchantDetailsException.class, () -> emailService.sendEmail(EMAIL_ADDRESS, GATEWAY_ACCOUNT_ID, template, personalisation));
    assertThat(exception.getMessage(), is("Merchant details are missing mandatory fields: can't send email for account " + GATEWAY_ACCOUNT_ID));
}
Also used : MerchantDetailsEntity(uk.gov.pay.adminusers.persistence.entity.MerchantDetailsEntity) InvalidMerchantDetailsException(uk.gov.pay.adminusers.resources.InvalidMerchantDetailsException) EmailTemplate(uk.gov.pay.adminusers.resources.EmailTemplate) Test(org.junit.jupiter.api.Test)

Example 2 with EmailTemplate

use of uk.gov.pay.adminusers.resources.EmailTemplate in project pay-adminusers by alphagov.

the class EmailServiceTest method shouldSendAnEmailForOnDemandPaymentConfirmed.

@Test
public void shouldSendAnEmailForOnDemandPaymentConfirmed() throws InvalidMerchantDetailsException {
    EmailTemplate template = EmailTemplate.ON_DEMAND_PAYMENT_CONFIRMED;
    Map<String, String> personalisation = Map.of("field 1", "theValueOfField1", "field 2", "theValueOfField2");
    MerchantDetailsEntity merchantDetails = new MerchantDetailsEntity(MERCHANT_NAME, TELEPHONE_NUMBER, ADDRESS_LINE_1, null, CITY, POSTCODE, ADDRESS_COUNTRY_CODE, MERCHANT_EMAIL, null);
    given(mockServiceEntity.getMerchantDetailsEntity()).willReturn(merchantDetails);
    ArgumentCaptor<Map<String, String>> personalisationCaptor = forClass(Map.class);
    emailService.sendEmail(EMAIL_ADDRESS, GATEWAY_ACCOUNT_ID, template, personalisation);
    verify(mockNotificationService).sendEmail(eq("NOTIFY_ON_DEMAND_PAYMENT_CONFIRMED_EMAIL_TEMPLATE_ID_VALUE"), eq(EMAIL_ADDRESS), personalisationCaptor.capture());
    Map<String, String> allContent = personalisationCaptor.getValue();
    assertThat(allContent.get("field 1"), is("theValueOfField1"));
    assertThat(allContent.get("field 2"), is("theValueOfField2"));
    assertThat(allContent.get("service name"), is("a service"));
    assertThat(allContent.get("organisation name"), is(MERCHANT_NAME));
    assertThat(allContent.get("organisation address"), is("address line 1, city, postcode, Cake Land"));
    assertThat(allContent.get("organisation phone number"), is(TELEPHONE_NUMBER));
    assertThat(allContent.get("organisation email address"), is(MERCHANT_EMAIL));
}
Also used : MerchantDetailsEntity(uk.gov.pay.adminusers.persistence.entity.MerchantDetailsEntity) EmailTemplate(uk.gov.pay.adminusers.resources.EmailTemplate) Map(java.util.Map) Test(org.junit.jupiter.api.Test)

Example 3 with EmailTemplate

use of uk.gov.pay.adminusers.resources.EmailTemplate in project pay-adminusers by alphagov.

the class EmailServiceTest method shouldSendAnEmailForMandateFailed.

@Test
public void shouldSendAnEmailForMandateFailed() throws InvalidMerchantDetailsException {
    EmailTemplate template = EmailTemplate.MANDATE_FAILED;
    Map<String, String> personalisation = Map.of("field 1", "theValueOfField1", "field 2", "theValueOfField2");
    MerchantDetailsEntity merchantDetails = new MerchantDetailsEntity(MERCHANT_NAME, TELEPHONE_NUMBER, ADDRESS_LINE_1, "address line 2", CITY, POSTCODE, ADDRESS_COUNTRY_CODE, MERCHANT_EMAIL, null);
    given(mockServiceEntity.getMerchantDetailsEntity()).willReturn(merchantDetails);
    ArgumentCaptor<Map<String, String>> personalisationCaptor = forClass(Map.class);
    emailService.sendEmail(EMAIL_ADDRESS, GATEWAY_ACCOUNT_ID, template, personalisation);
    verify(mockNotificationService).sendEmail(eq("NOTIFY_MANDATE_FAILED_EMAIL_TEMPLATE_ID_VALUE"), eq(EMAIL_ADDRESS), personalisationCaptor.capture());
    Map<String, String> allContent = personalisationCaptor.getValue();
    assertThat(allContent.get("field 1"), is("theValueOfField1"));
    assertThat(allContent.get("field 2"), is("theValueOfField2"));
    assertThat(allContent.get("organisation name"), is(MERCHANT_NAME));
    assertThat(allContent.get("organisation phone number"), is(TELEPHONE_NUMBER));
    assertThat(allContent.get("organisation email address"), is(MERCHANT_EMAIL));
}
Also used : MerchantDetailsEntity(uk.gov.pay.adminusers.persistence.entity.MerchantDetailsEntity) EmailTemplate(uk.gov.pay.adminusers.resources.EmailTemplate) Map(java.util.Map) Test(org.junit.jupiter.api.Test)

Example 4 with EmailTemplate

use of uk.gov.pay.adminusers.resources.EmailTemplate in project pay-adminusers by alphagov.

the class EmailServiceTest method shouldSendAnEmailForPaymentFailed.

@Test
public void shouldSendAnEmailForPaymentFailed() throws InvalidMerchantDetailsException {
    EmailTemplate template = EmailTemplate.PAYMENT_FAILED;
    Map<String, String> personalisation = Map.of("field 1", "theValueOfField1", "field 2", "theValueOfField2");
    MerchantDetailsEntity merchantDetails = new MerchantDetailsEntity(MERCHANT_NAME, TELEPHONE_NUMBER, ADDRESS_LINE_1, null, CITY, POSTCODE, ADDRESS_COUNTRY_CODE, MERCHANT_EMAIL, null);
    given(mockServiceEntity.getMerchantDetailsEntity()).willReturn(merchantDetails);
    ArgumentCaptor<Map<String, String>> personalisationCaptor = forClass(Map.class);
    emailService.sendEmail(EMAIL_ADDRESS, GATEWAY_ACCOUNT_ID, template, personalisation);
    verify(mockNotificationService).sendEmail(eq("NOTIFY_PAYMENT_FAILED_EMAIL_TEMPLATE_ID_VALUE"), eq(EMAIL_ADDRESS), personalisationCaptor.capture());
    Map<String, String> allContent = personalisationCaptor.getValue();
    assertThat(allContent.get("field 1"), is("theValueOfField1"));
    assertThat(allContent.get("field 2"), is("theValueOfField2"));
    assertThat(allContent.get("organisation name"), is(MERCHANT_NAME));
    assertThat(allContent.get("organisation phone number"), is(TELEPHONE_NUMBER));
}
Also used : MerchantDetailsEntity(uk.gov.pay.adminusers.persistence.entity.MerchantDetailsEntity) EmailTemplate(uk.gov.pay.adminusers.resources.EmailTemplate) Map(java.util.Map) Test(org.junit.jupiter.api.Test)

Example 5 with EmailTemplate

use of uk.gov.pay.adminusers.resources.EmailTemplate in project pay-adminusers by alphagov.

the class EmailServiceTest method shouldNotDisplayCountryNameForInvalidCountryCode.

@Test
public void shouldNotDisplayCountryNameForInvalidCountryCode() throws InvalidMerchantDetailsException {
    EmailTemplate template = EmailTemplate.ONE_OFF_PAYMENT_CONFIRMED;
    Map<String, String> personalisation = Map.of("field 1", "theValueOfField1", "field 2", "theValueOfField2");
    MerchantDetailsEntity merchantDetails = new MerchantDetailsEntity(MERCHANT_NAME, TELEPHONE_NUMBER, ADDRESS_LINE_1, null, CITY, POSTCODE, ADDRESS_COUNTRY_CODE, MERCHANT_EMAIL, null);
    given(mockServiceEntity.getMerchantDetailsEntity()).willReturn(merchantDetails);
    given(mockCountryConverter.getCountryNameFrom(ADDRESS_COUNTRY_CODE)).willReturn(Optional.empty());
    ArgumentCaptor<Map<String, String>> personalisationCaptor = forClass(Map.class);
    emailService.sendEmail(EMAIL_ADDRESS, GATEWAY_ACCOUNT_ID, template, personalisation);
    verify(mockNotificationService).sendEmail(eq("NOTIFY_ONE_OFF_MANDATE_AND_PAYMENT_CREATED_EMAIL_TEMPLATE_ID_VALUE"), eq(EMAIL_ADDRESS), personalisationCaptor.capture());
    Map<String, String> allContent = personalisationCaptor.getValue();
    assertThat(allContent.get("field 1"), is("theValueOfField1"));
    assertThat(allContent.get("field 2"), is("theValueOfField2"));
    assertThat(allContent.get("service name"), is("a service"));
    assertThat(allContent.get("organisation name"), is(MERCHANT_NAME));
    assertThat(allContent.get("organisation address"), is("address line 1, city, postcode"));
    assertThat(allContent.get("organisation phone number"), is(TELEPHONE_NUMBER));
    assertThat(allContent.get("organisation email address"), is(MERCHANT_EMAIL));
}
Also used : MerchantDetailsEntity(uk.gov.pay.adminusers.persistence.entity.MerchantDetailsEntity) EmailTemplate(uk.gov.pay.adminusers.resources.EmailTemplate) Map(java.util.Map) Test(org.junit.jupiter.api.Test)

Aggregations

Test (org.junit.jupiter.api.Test)8 MerchantDetailsEntity (uk.gov.pay.adminusers.persistence.entity.MerchantDetailsEntity)8 EmailTemplate (uk.gov.pay.adminusers.resources.EmailTemplate)8 Map (java.util.Map)7 InvalidMerchantDetailsException (uk.gov.pay.adminusers.resources.InvalidMerchantDetailsException)1