use of uk.gov.pay.adminusers.persistence.entity.ServiceEntity in project pay-adminusers by alphagov.
the class UserInviteCompleterTest method shouldError_whenSubscribingAServiceToAnExistingUser_ifInviteIsNotUserType.
@Test
public void shouldError_whenSubscribingAServiceToAnExistingUser_ifInviteIsNotUserType() {
ServiceEntity service = new ServiceEntity();
service.setId(serviceId);
service.setExternalId(serviceExternalId);
InviteEntity anInvite = createInvite();
anInvite.setType(InviteType.SERVICE);
anInvite.setService(service);
UserEntity user = UserEntity.from(aUser(anInvite.getEmail()));
when(mockInviteDao.findByCode(inviteCode)).thenReturn(Optional.of(anInvite));
when(mockUserDao.findByEmail(email)).thenReturn(Optional.of(user));
WebApplicationException webApplicationException = assertThrows(WebApplicationException.class, () -> userInviteCompleter.complete(inviteCode));
assertThat(webApplicationException.getMessage(), is("HTTP 500 Internal Server Error"));
}
use of uk.gov.pay.adminusers.persistence.entity.ServiceEntity in project pay-adminusers by alphagov.
the class UserInviteCompleterTest method shouldError_whenSubscribingAServiceToAnExistingUser_ifServiceIsNull.
@Test
public void shouldError_whenSubscribingAServiceToAnExistingUser_ifServiceIsNull() {
ServiceEntity service = new ServiceEntity();
service.setId(serviceId);
service.setExternalId(serviceExternalId);
InviteEntity anInvite = createInvite();
anInvite.setType(InviteType.USER);
anInvite.setService(null);
UserEntity user = UserEntity.from(aUser(anInvite.getEmail()));
when(mockInviteDao.findByCode(inviteCode)).thenReturn(Optional.of(anInvite));
when(mockUserDao.findByEmail(email)).thenReturn(Optional.of(user));
WebApplicationException webApplicationException = assertThrows(WebApplicationException.class, () -> userInviteCompleter.complete(inviteCode));
assertThat(webApplicationException.getMessage(), is("HTTP 500 Internal Server Error"));
}
use of uk.gov.pay.adminusers.persistence.entity.ServiceEntity in project pay-adminusers by alphagov.
the class ServiceResourceUpdateTest method shouldUpdateExistingCyServiceName.
@Test
public void shouldUpdateExistingCyServiceName() {
ServiceEntity thisServiceEntity = ServiceEntityBuilder.aServiceEntity().withServiceNameEntity(SupportedLanguage.WELSH, "old-cy-name").build();
String externalId = thisServiceEntity.getExternalId();
String jsonPayload = fixture("fixtures/resource/service/patch/array-replace-service-name-cy.json");
when(mockedServiceDao.findByExternalId(externalId)).thenReturn(Optional.of(thisServiceEntity));
when(mockedServiceDao.merge(thisServiceEntity)).thenReturn(thisServiceEntity);
Response response = RESOURCES.target(format(API_PATH, thisServiceEntity.getExternalId())).request().method("PATCH", Entity.json(jsonPayload));
assertThat(response.getStatus(), is(200));
String body = response.readEntity(String.class);
JsonPath json = JsonPath.from(body);
assertThat(json.get("name"), is("System Generated"));
assertEnServiceNameJson("System Generated", json);
assertCyServiceNameJson("new-cy-name", json);
}
use of uk.gov.pay.adminusers.persistence.entity.ServiceEntity in project pay-adminusers by alphagov.
the class ServiceResourceUpdateTest method shouldUpdateCollectBillingAddress_toFalse.
@Test
public void shouldUpdateCollectBillingAddress_toFalse() {
ServiceEntity thisServiceEntity = ServiceEntityBuilder.aServiceEntity().withCollectBillingAddress(true).build();
String externalId = thisServiceEntity.getExternalId();
String jsonPayload = fixture("fixtures/resource/service/patch/replace_collect_billing_address_to_false.json");
when(mockedServiceDao.findByExternalId(externalId)).thenReturn(Optional.of(thisServiceEntity));
when(mockedServiceDao.merge(thisServiceEntity)).thenReturn(thisServiceEntity);
Response response = RESOURCES.target(format(API_PATH, thisServiceEntity.getExternalId())).request().method("PATCH", Entity.json(jsonPayload));
assertThat(response.getStatus(), is(200));
String body = response.readEntity(String.class);
JsonPath json = JsonPath.from(body);
assertThat(json.get("collect_billing_address"), is(false));
}
use of uk.gov.pay.adminusers.persistence.entity.ServiceEntity in project pay-adminusers by alphagov.
the class ServiceResourceUpdateTest method shouldUpdateExperimentalFeaturesEnabled_toTrue.
@Test
public void shouldUpdateExperimentalFeaturesEnabled_toTrue() {
ServiceEntity thisServiceEntity = ServiceEntityBuilder.aServiceEntity().withExperimentalFeaturesEnabled(false).build();
String externalId = thisServiceEntity.getExternalId();
String jsonPayload = fixture("fixtures/resource/service/patch/replace_experimental_features_enabled_to_true.json");
when(mockedServiceDao.findByExternalId(externalId)).thenReturn(Optional.of(thisServiceEntity));
when(mockedServiceDao.merge(thisServiceEntity)).thenReturn(thisServiceEntity);
Response response = RESOURCES.target(format(API_PATH, thisServiceEntity.getExternalId())).request().method("PATCH", Entity.json(jsonPayload));
assertThat(response.getStatus(), is(200));
String body = response.readEntity(String.class);
JsonPath json = JsonPath.from(body);
assertThat(json.get("experimental_features_enabled"), is(true));
}
Aggregations