use of uk.gov.pay.adminusers.model.Service in project pay-adminusers by alphagov.
the class ServiceEntityTest method shouldCreateEntity_withNotStartedAsDefault.
@Test
public void shouldCreateEntity_withNotStartedAsDefault() {
Service service = ServiceEntityBuilder.aServiceEntity().build().toService();
assertThat(service.getGoLiveStage(), is(GoLiveStage.NOT_STARTED));
}
use of uk.gov.pay.adminusers.model.Service in project pay-adminusers by alphagov.
the class UserResourceCreateIT method shouldCreateAUser_withinAService_IfServiceExternalIdsExists.
@Test
public void shouldCreateAUser_withinAService_IfServiceExternalIdsExists() throws Exception {
String gatewayAccount1 = valueOf(nextInt());
String gatewayAccount2 = valueOf(nextInt());
Service service = serviceDbFixture(databaseHelper).withGatewayAccountIds(gatewayAccount1, gatewayAccount2).insertService();
String serviceExternalId = service.getExternalId();
String username = randomUuid();
Map<Object, Object> userPayload = Map.of("username", username, "email", "user-" + username + "@example.com", "service_external_ids", new String[] { valueOf(serviceExternalId) }, "telephone_number", "+441134960000", "otp_key", "34f34", "role_name", "admin");
ValidatableResponse response = givenSetup().when().body(mapper.writeValueAsString(userPayload)).contentType(JSON).accept(JSON).post(USERS_RESOURCE_URL).then();
String externalId = response.extract().path("external_id");
response.statusCode(201).body("id", nullValue()).body("external_id", is(externalId)).body("username", is(username)).body("password", nullValue()).body("email", is("user-" + username + "@example.com")).body("service_roles", hasSize(1)).body("service_roles[0].service.external_id", is(serviceExternalId)).body("service_roles[0].service.name", is(service.getName())).body("telephone_number", is("+441134960000")).body("otp_key", is("34f34")).body("login_counter", is(0)).body("disabled", is(false)).body("service_roles[0].role.name", is("admin")).body("service_roles[0].role.description", is("Administrator")).body("service_roles[0].role.permissions.size()", is(greaterThan(1)));
response.body("_links", hasSize(1)).body("_links[0].href", is("http://localhost:8080/v1/api/users/" + externalId)).body("_links[0].method", is("GET")).body("_links[0].rel", is("self"));
// TODO - WIP This will be removed when PP-1612 is done.
// This is an extra check to verify that new created user gateways are registered withing the new Services Model as well as in users table
List<Map<String, Object>> userByExternalId = databaseHelper.findUserByExternalId(externalId);
List<Map<String, Object>> servicesAssociatedToUser = databaseHelper.findUserServicesByUserId((Integer) userByExternalId.get(0).get("id"));
assertThat(servicesAssociatedToUser.size(), is(1));
}
use of uk.gov.pay.adminusers.model.Service in project pay-adminusers by alphagov.
the class ServiceDaoIT method setupUsersForServiceAndRole.
private void setupUsersForServiceAndRole(String externalId, int roleId, int noOfUsers) {
Permission perm1 = aPermission();
Permission perm2 = aPermission();
databaseHelper.add(perm1).add(perm2);
Role role = role(roleId, "role-" + roleId, "role-desc-" + roleId);
role.setPermissions(Set.of(perm1, perm2));
databaseHelper.add(role);
String gatewayAccountId1 = randomInt().toString();
Service service1 = Service.from(randomInt(), externalId, new ServiceName(Service.DEFAULT_NAME_VALUE));
databaseHelper.addService(service1, gatewayAccountId1);
range(0, noOfUsers - 1).forEach(i -> {
String username = randomUuid();
String email = username + "@example.com";
UserDbFixture.userDbFixture(databaseHelper).withServiceRole(service1, roleId).withUsername(username).withEmail(email).insertUser();
});
// unmatching service
String gatewayAccountId2 = randomInt().toString();
Integer serviceId2 = randomInt();
String externalId2 = randomUuid();
Service service2 = Service.from(serviceId2, externalId2, new ServiceName(Service.DEFAULT_NAME_VALUE));
databaseHelper.addService(service2, gatewayAccountId2);
// same user 2 diff services - should count only once
String username3 = randomUuid();
String email3 = username3 + "@example.com";
User user3 = UserDbFixture.userDbFixture(databaseHelper).withServiceRole(service1, roleId).withUsername(username3).withEmail(email3).insertUser();
databaseHelper.addUserServiceRole(user3.getId(), serviceId2, role.getId());
}
use of uk.gov.pay.adminusers.model.Service in project pay-adminusers by alphagov.
the class ServiceResourceSendLiveAccountCreatedEmailIT method shouldSendEmail.
@Test
public void shouldSendEmail() {
Service service = serviceDbFixture(databaseHelper).insertService();
govUkPayAgreementDbFixture(databaseHelper).withServiceId(service.getId()).insert();
givenSetup().when().post(format("/v1/api/services/%s/send-live-email", service.getExternalId())).then().statusCode(200);
}
use of uk.gov.pay.adminusers.model.Service in project pay-adminusers by alphagov.
the class ServiceResourceSendLiveAccountCreatedEmailIT method shouldReturn_409_whenAgreementNotSigned.
@Test
public void shouldReturn_409_whenAgreementNotSigned() {
Service service = serviceDbFixture(databaseHelper).insertService();
givenSetup().when().post(format("/v1/api/services/%s/send-live-email", service.getExternalId())).then().statusCode(409).body("errors", hasSize(1)).body("errors[0]", is("Nobody from this service is on record as having agreed to the legal terms"));
}
Aggregations