Search in sources :

Example 6 with MerchantDetailsEntity

use of uk.gov.pay.adminusers.persistence.entity.MerchantDetailsEntity in project pay-adminusers by alphagov.

the class ServiceUpdaterTest method shouldUpdateMerchantDetailsAddressLine1Successfully_WhenExistingMerchantDetails.

@Test
public void shouldUpdateMerchantDetailsAddressLine1Successfully_WhenExistingMerchantDetails() {
    String updatedAddressLine1 = "1 Spider Lane";
    ServiceUpdateRequest request = serviceUpdateRequest("replace", "merchant_details/address_line1", updatedAddressLine1);
    MerchantDetailsEntity merchantDetails = aMerchantDetailsEntity().build();
    ServiceEntity serviceEntity = aServiceEntity().withMerchantDetailsEntity(merchantDetails).build();
    when(serviceDao.findByExternalId(SERVICE_ID)).thenReturn(of(serviceEntity));
    Optional<Service> maybeService = updater.doUpdate(SERVICE_ID, request);
    assertThat(maybeService.isPresent(), is(true));
    verify(serviceDao).merge(serviceEntity);
    assertThat(maybeService.get().getMerchantDetails().getName(), is("test-name"));
    assertThat(maybeService.get().getMerchantDetails().getAddressLine1(), is(updatedAddressLine1));
}
Also used : MerchantDetailsEntity(uk.gov.pay.adminusers.persistence.entity.MerchantDetailsEntity) MerchantDetailsEntityBuilder.aMerchantDetailsEntity(uk.gov.pay.adminusers.persistence.entity.MerchantDetailsEntityBuilder.aMerchantDetailsEntity) ServiceUpdateRequest(uk.gov.pay.adminusers.model.ServiceUpdateRequest) ServiceEntity(uk.gov.pay.adminusers.persistence.entity.ServiceEntity) ServiceEntityBuilder.aServiceEntity(uk.gov.pay.adminusers.persistence.entity.ServiceEntityBuilder.aServiceEntity) Service(uk.gov.pay.adminusers.model.Service) Test(org.junit.jupiter.api.Test)

Example 7 with MerchantDetailsEntity

use of uk.gov.pay.adminusers.persistence.entity.MerchantDetailsEntity in project pay-adminusers by alphagov.

the class ServiceUpdaterTest method shouldSuccess_updateMerchantDetails.

@Test
public void shouldSuccess_updateMerchantDetails() throws ServiceNotFoundException {
    String name = "name";
    String telephoneNumber = "03069990000";
    String addressLine1 = "something";
    String addressLine2 = "something";
    String addressCity = "something";
    String addressPostcode = "something";
    String addressCountry = "something";
    String email = "dd-merchant@example.com";
    String url = "https://merchant.example.com";
    MerchantDetailsEntity toUpdate = new MerchantDetailsEntity(name, telephoneNumber, addressLine1, addressLine2, addressCity, addressPostcode, addressCountry, email, url);
    UpdateMerchantDetailsRequest request = new UpdateMerchantDetailsRequest(name, telephoneNumber, addressLine1, addressLine2, addressCity, addressPostcode, addressCountry, email, url);
    ServiceEntity serviceEntity = mock(ServiceEntity.class);
    when(serviceDao.findByExternalId(SERVICE_ID)).thenReturn(of(serviceEntity));
    when(serviceEntity.toService()).thenReturn(Service.from());
    Service service = updater.doUpdateMerchantDetails(SERVICE_ID, request);
    assertNotNull(service);
    verify(serviceEntity).setMerchantDetailsEntity(toUpdate);
    verify(serviceDao).merge(serviceEntity);
}
Also used : MerchantDetailsEntity(uk.gov.pay.adminusers.persistence.entity.MerchantDetailsEntity) MerchantDetailsEntityBuilder.aMerchantDetailsEntity(uk.gov.pay.adminusers.persistence.entity.MerchantDetailsEntityBuilder.aMerchantDetailsEntity) UpdateMerchantDetailsRequest(uk.gov.pay.adminusers.model.UpdateMerchantDetailsRequest) ServiceEntity(uk.gov.pay.adminusers.persistence.entity.ServiceEntity) ServiceEntityBuilder.aServiceEntity(uk.gov.pay.adminusers.persistence.entity.ServiceEntityBuilder.aServiceEntity) Service(uk.gov.pay.adminusers.model.Service) Test(org.junit.jupiter.api.Test)

Example 8 with MerchantDetailsEntity

use of uk.gov.pay.adminusers.persistence.entity.MerchantDetailsEntity 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 9 with MerchantDetailsEntity

use of uk.gov.pay.adminusers.persistence.entity.MerchantDetailsEntity 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)

Example 10 with MerchantDetailsEntity

use of uk.gov.pay.adminusers.persistence.entity.MerchantDetailsEntity in project pay-adminusers by alphagov.

the class EmailServiceTest method shouldSendAnEmailForOneOffPaymentConfirmed.

@Test
public void shouldSendAnEmailForOneOffPaymentConfirmed() 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);
    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, 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)

Aggregations

MerchantDetailsEntity (uk.gov.pay.adminusers.persistence.entity.MerchantDetailsEntity)14 Test (org.junit.jupiter.api.Test)11 Map (java.util.Map)9 EmailTemplate (uk.gov.pay.adminusers.resources.EmailTemplate)8 ServiceEntity (uk.gov.pay.adminusers.persistence.entity.ServiceEntity)5 Service (uk.gov.pay.adminusers.model.Service)3 MerchantDetailsEntityBuilder.aMerchantDetailsEntity (uk.gov.pay.adminusers.persistence.entity.MerchantDetailsEntityBuilder.aMerchantDetailsEntity)2 ServiceEntityBuilder.aServiceEntity (uk.gov.pay.adminusers.persistence.entity.ServiceEntityBuilder.aServiceEntity)2 InvalidMerchantDetailsException (uk.gov.pay.adminusers.resources.InvalidMerchantDetailsException)2 Timestamp (java.sql.Timestamp)1 Timestamp.from (java.sql.Timestamp.from)1 OTHER (java.sql.Types.OTHER)1 ZoneId (java.time.ZoneId)1 ZonedDateTime (java.time.ZonedDateTime)1 List (java.util.List)1 Jdbi (org.jdbi.v3.core.Jdbi)1 PGobject (org.postgresql.util.PGobject)1 ForgottenPassword (uk.gov.pay.adminusers.model.ForgottenPassword)1 MerchantDetails (uk.gov.pay.adminusers.model.MerchantDetails)1 Permission (uk.gov.pay.adminusers.model.Permission)1