Search in sources :

Example 76 with Service

use of uk.gov.pay.adminusers.model.Service in project pay-adminusers by alphagov.

the class UserResourceGetMultipleIT method shouldReturnPartialResponse_whenGetUsers_whereSomeNonExistentExternalIds.

@Test
public void shouldReturnPartialResponse_whenGetUsers_whereSomeNonExistentExternalIds() {
    String gatewayAccount1 = valueOf(nextInt());
    String gatewayAccount2 = valueOf(nextInt());
    Service service = serviceDbFixture(databaseHelper).withGatewayAccountIds(gatewayAccount1, gatewayAccount2).insertService();
    Role role = roleDbFixture(databaseHelper).insertRole();
    String username = randomUuid();
    String email = username + "@example.com";
    User existingUser = userDbFixture(databaseHelper).withServiceRole(service.getId(), role.getId()).withUsername(username).withEmail(email).insertUser();
    givenSetup().when().contentType(JSON).accept(JSON).get(USERS_RESOURCE + "?ids=" + existingUser.getExternalId() + ",NON-EXISTENT-USER").then().statusCode(200).body("[0].external_id", is(existingUser.getExternalId())).body("[0].username", is(existingUser.getUsername())).body("[0].password", nullValue()).body("[0].email", is(existingUser.getEmail())).body("[0].service_roles", hasSize(1)).body("[0].service_roles[0].service.external_id", is(service.getExternalId())).body("[0].service_roles[0].service.name", is(service.getName())).body("[0].telephone_number", is(existingUser.getTelephoneNumber())).body("[0].otp_key", is(existingUser.getOtpKey())).body("[0].login_counter", is(0)).body("[0].disabled", is(false)).body("[0].service_roles[0].role.name", is(role.getName())).body("[0].service_roles[0].role.description", is(role.getDescription())).body("[0].service_roles[0].role.permissions", hasSize(role.getPermissions().size())).body("[0]._links", hasSize(1)).body("[0]._links[0].href", is("http://localhost:8080/v1/api/users/" + existingUser.getExternalId())).body("[0]._links[0].method", is("GET")).body("[0]._links[0].rel", is("self")).body("size()", is(1));
}
Also used : Role(uk.gov.pay.adminusers.model.Role) User(uk.gov.pay.adminusers.model.User) Service(uk.gov.pay.adminusers.model.Service) Test(org.junit.jupiter.api.Test)

Example 77 with Service

use of uk.gov.pay.adminusers.model.Service in project pay-adminusers by alphagov.

the class UserResourceGetMultipleIT method shouldReturnMultipleUsers_whenGetUsersWithMultipleIds_whenIdsAreRepeated.

@Test
public void shouldReturnMultipleUsers_whenGetUsersWithMultipleIds_whenIdsAreRepeated() {
    String gatewayAccount1 = valueOf(nextInt());
    String gatewayAccount2 = valueOf(nextInt());
    Service service = serviceDbFixture(databaseHelper).withGatewayAccountIds(gatewayAccount1, gatewayAccount2).insertService();
    String serviceExternalId = service.getExternalId();
    Role role = roleDbFixture(databaseHelper).insertRole();
    String username1 = randomUuid();
    String email1 = username1 + "@example.com";
    User user1 = userDbFixture(databaseHelper).withServiceRole(service.getId(), role.getId()).withUsername(username1).withEmail(email1).insertUser();
    givenSetup().when().contentType(JSON).accept(JSON).get(USERS_RESOURCE + "?ids=" + user1.getExternalId() + "," + user1.getExternalId()).then().statusCode(200).body("[0].external_id", is(user1.getExternalId())).body("[0].username", is(user1.getUsername())).body("[0].password", nullValue()).body("[0].email", is(user1.getEmail())).body("[0].service_roles", hasSize(1)).body("[0].service_roles[0].service.external_id", is(serviceExternalId)).body("[0].service_roles[0].service.name", is(service.getName())).body("[0].telephone_number", is(user1.getTelephoneNumber())).body("[0].otp_key", is(user1.getOtpKey())).body("[0].login_counter", is(0)).body("[0].disabled", is(false)).body("[0].service_roles[0].role.name", is(role.getName())).body("[0].service_roles[0].role.description", is(role.getDescription())).body("[0].service_roles[0].role.permissions", hasSize(role.getPermissions().size())).body("[0]._links", hasSize(1)).body("[0]._links[0].href", is("http://localhost:8080/v1/api/users/" + user1.getExternalId())).body("[0]._links[0].method", is("GET")).body("[0]._links[0].rel", is("self")).body("size()", is(1));
}
Also used : Role(uk.gov.pay.adminusers.model.Role) User(uk.gov.pay.adminusers.model.User) Service(uk.gov.pay.adminusers.model.Service) Test(org.junit.jupiter.api.Test)

Example 78 with Service

use of uk.gov.pay.adminusers.model.Service in project pay-adminusers by alphagov.

the class ServiceResourceUpdateCustomBrandingIT method shouldReturn400_whenUpdatingServiceCustomisations_ifPayloadNotJson.

@Test
public void shouldReturn400_whenUpdatingServiceCustomisations_ifPayloadNotJson() throws Exception {
    String serviceExternalId = randomUuid();
    Service service = Service.from(randomInt(), serviceExternalId, new ServiceName("existing-name"));
    Map<String, Object> customBranding = Map.of("css_url", "existing css", "image_url", "existing image");
    service.setCustomBranding(customBranding);
    databaseHelper.addService(service, randomInt().toString());
    Map<String, Object> payload = Map.of("path", "custom_branding", "op", "replace", "value", "blah");
    givenSetup().when().contentType(JSON).accept(JSON).body(mapper.writeValueAsString(payload)).patch(format(SERVICE_RESOURCE, serviceExternalId)).then().statusCode(400);
}
Also used : ServiceName(uk.gov.pay.adminusers.model.ServiceName) Service(uk.gov.pay.adminusers.model.Service) Test(org.junit.jupiter.api.Test)

Example 79 with Service

use of uk.gov.pay.adminusers.model.Service in project pay-adminusers by alphagov.

the class ServiceResourceUpdateCustomBrandingIT method shouldReplaceWithEmpty_whenUpdatingCustomBranding_withEmptyObject.

@Test
public void shouldReplaceWithEmpty_whenUpdatingCustomBranding_withEmptyObject() throws Exception {
    String serviceExternalId = randomUuid();
    Map<String, Object> existingBranding = Map.of("css_url", "existing css", "image_url", "existing image");
    Service service = Service.from(randomInt(), serviceExternalId, new ServiceName("existing-name"));
    service.setCustomBranding(existingBranding);
    Map<String, Object> payloadWithEmptyBranding = Map.of("path", "custom_branding", "op", "replace", "value", emptyMap());
    databaseHelper.addService(service, randomInt().toString());
    givenSetup().when().contentType(JSON).accept(JSON).body(mapper.writeValueAsString(payloadWithEmptyBranding)).patch(format(SERVICE_RESOURCE, serviceExternalId)).then().statusCode(200).body("custom_branding", is(nullValue()));
}
Also used : ServiceName(uk.gov.pay.adminusers.model.ServiceName) Service(uk.gov.pay.adminusers.model.Service) Test(org.junit.jupiter.api.Test)

Example 80 with Service

use of uk.gov.pay.adminusers.model.Service in project pay-adminusers by alphagov.

the class ServiceResourceUpdateCustomBrandingIT method shouldSuccess_whenUpdatingCustomBranding.

@Test
public void shouldSuccess_whenUpdatingCustomBranding() throws Exception {
    String serviceExternalId = randomUuid();
    Service service = Service.from(randomInt(), serviceExternalId, new ServiceName("existing-name"));
    databaseHelper.addService(service, randomInt().toString());
    Map<String, Object> payload = Map.of("path", "custom_branding", "op", "replace", "value", Map.of("image_url", "image url", "css_url", "css url"));
    givenSetup().when().contentType(JSON).accept(JSON).body(mapper.writeValueAsString(payload)).patch(format(SERVICE_RESOURCE, serviceExternalId)).then().statusCode(200).body("custom_branding.image_url", is("image url")).body("custom_branding.css_url", is("css url"));
}
Also used : ServiceName(uk.gov.pay.adminusers.model.ServiceName) Service(uk.gov.pay.adminusers.model.Service) Test(org.junit.jupiter.api.Test)

Aggregations

Service (uk.gov.pay.adminusers.model.Service)85 Test (org.junit.jupiter.api.Test)69 ServiceEntity (uk.gov.pay.adminusers.persistence.entity.ServiceEntity)27 Role (uk.gov.pay.adminusers.model.Role)19 ServiceEntityBuilder.aServiceEntity (uk.gov.pay.adminusers.persistence.entity.ServiceEntityBuilder.aServiceEntity)18 ServiceUpdateRequest (uk.gov.pay.adminusers.model.ServiceUpdateRequest)17 User (uk.gov.pay.adminusers.model.User)15 ServiceName (uk.gov.pay.adminusers.model.ServiceName)11 InOrder (org.mockito.InOrder)8 GovUkPayAgreementService (uk.gov.pay.adminusers.service.GovUkPayAgreementService)8 SendLiveAccountCreatedEmailService (uk.gov.pay.adminusers.service.SendLiveAccountCreatedEmailService)8 StripeAgreementService (uk.gov.pay.adminusers.service.StripeAgreementService)8 JsonPath (io.restassured.path.json.JsonPath)6 Response (javax.ws.rs.core.Response)6 Map (java.util.Map)5 JsonNode (com.fasterxml.jackson.databind.JsonNode)4 Matchers.emptyString (org.hamcrest.Matchers.emptyString)4 StripeAgreementEntity (uk.gov.pay.adminusers.persistence.entity.StripeAgreementEntity)4 State (au.com.dius.pact.provider.junit.State)3 ZonedDateTime (java.time.ZonedDateTime)3