Search in sources :

Example 6 with Service

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));
}
Also used : Service(uk.gov.pay.adminusers.model.Service) Test(org.junit.jupiter.api.Test)

Example 7 with Service

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));
}
Also used : ValidatableResponse(io.restassured.response.ValidatableResponse) Service(uk.gov.pay.adminusers.model.Service) Collections.emptyMap(java.util.Collections.emptyMap) Map(java.util.Map) Test(org.junit.jupiter.api.Test)

Example 8 with Service

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());
}
Also used : Role(uk.gov.pay.adminusers.model.Role) User(uk.gov.pay.adminusers.model.User) ServiceName(uk.gov.pay.adminusers.model.ServiceName) Permission(uk.gov.pay.adminusers.model.Permission) Service(uk.gov.pay.adminusers.model.Service)

Example 9 with Service

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);
}
Also used : Service(uk.gov.pay.adminusers.model.Service) Test(org.junit.jupiter.api.Test)

Example 10 with Service

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"));
}
Also used : Service(uk.gov.pay.adminusers.model.Service) Test(org.junit.jupiter.api.Test)

Aggregations

Service (uk.gov.pay.adminusers.model.Service)80 Test (org.junit.jupiter.api.Test)66 ServiceEntity (uk.gov.pay.adminusers.persistence.entity.ServiceEntity)26 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 JsonNode (com.fasterxml.jackson.databind.JsonNode)4 Map (java.util.Map)4 StripeAgreementEntity (uk.gov.pay.adminusers.persistence.entity.StripeAgreementEntity)4 State (au.com.dius.pact.provider.junit.State)3 ZonedDateTime (java.time.ZonedDateTime)3 Matchers.emptyString (org.hamcrest.Matchers.emptyString)3