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));
}
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));
}
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);
}
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()));
}
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"));
}
Aggregations