Search in sources :

Example 1 with ServiceEntity

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"));
}
Also used : WebApplicationException(javax.ws.rs.WebApplicationException) InviteEntity(uk.gov.pay.adminusers.persistence.entity.InviteEntity) ServiceEntity(uk.gov.pay.adminusers.persistence.entity.ServiceEntity) UserEntity(uk.gov.pay.adminusers.persistence.entity.UserEntity) Test(org.junit.jupiter.api.Test)

Example 2 with ServiceEntity

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"));
}
Also used : WebApplicationException(javax.ws.rs.WebApplicationException) InviteEntity(uk.gov.pay.adminusers.persistence.entity.InviteEntity) ServiceEntity(uk.gov.pay.adminusers.persistence.entity.ServiceEntity) UserEntity(uk.gov.pay.adminusers.persistence.entity.UserEntity) Test(org.junit.jupiter.api.Test)

Example 3 with ServiceEntity

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);
}
Also used : Response(javax.ws.rs.core.Response) ServiceEntity(uk.gov.pay.adminusers.persistence.entity.ServiceEntity) JsonPath(io.restassured.path.json.JsonPath) Test(org.junit.jupiter.api.Test)

Example 4 with ServiceEntity

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));
}
Also used : Response(javax.ws.rs.core.Response) ServiceEntity(uk.gov.pay.adminusers.persistence.entity.ServiceEntity) JsonPath(io.restassured.path.json.JsonPath) Test(org.junit.jupiter.api.Test)

Example 5 with ServiceEntity

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));
}
Also used : Response(javax.ws.rs.core.Response) ServiceEntity(uk.gov.pay.adminusers.persistence.entity.ServiceEntity) JsonPath(io.restassured.path.json.JsonPath) Test(org.junit.jupiter.api.Test)

Aggregations

ServiceEntity (uk.gov.pay.adminusers.persistence.entity.ServiceEntity)101 Test (org.junit.jupiter.api.Test)83 Service (uk.gov.pay.adminusers.model.Service)29 UserEntity (uk.gov.pay.adminusers.persistence.entity.UserEntity)27 RoleEntity (uk.gov.pay.adminusers.persistence.entity.RoleEntity)22 JsonPath (io.restassured.path.json.JsonPath)21 Response (javax.ws.rs.core.Response)21 ServiceEntityBuilder.aServiceEntity (uk.gov.pay.adminusers.persistence.entity.ServiceEntityBuilder.aServiceEntity)20 ServiceRoleEntity (uk.gov.pay.adminusers.persistence.entity.ServiceRoleEntity)20 ServiceUpdateRequest (uk.gov.pay.adminusers.model.ServiceUpdateRequest)18 InviteEntity (uk.gov.pay.adminusers.persistence.entity.InviteEntity)18 WebApplicationException (javax.ws.rs.WebApplicationException)11 ZonedDateTime (java.time.ZonedDateTime)10 Map (java.util.Map)9 InOrder (org.mockito.InOrder)8 User (uk.gov.pay.adminusers.model.User)8 GatewayAccountIdEntity (uk.gov.pay.adminusers.persistence.entity.GatewayAccountIdEntity)8 Role (uk.gov.pay.adminusers.model.Role)7 MerchantDetailsEntity (uk.gov.pay.adminusers.persistence.entity.MerchantDetailsEntity)7 Transactional (com.google.inject.persist.Transactional)6