Search in sources :

Example 1 with Service

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

the class ServiceResourceCreateTest method shouldSuccess_whenCreateAServiceWithoutParameters.

@Test
public void shouldSuccess_whenCreateAServiceWithoutParameters() {
    Service service = buildService(Collections.emptyList(), Collections.emptyMap());
    given(mockedServiceCreator.doCreate(Collections.emptyList(), Collections.emptyMap())).willReturn(service);
    Response response = RESOURCES.target(SERVICES_RESOURCE).request(MediaType.APPLICATION_JSON).post(Entity.json(PAYLOAD_MAP), Response.class);
    assertThat(response.getStatus(), is(201));
    String body = response.readEntity(String.class);
    JsonPath json = JsonPath.from(body);
    assertThat(json.get("name"), is("System Generated"));
    assertThat(json.get("external_id"), is(notNullValue()));
    assertThat(json.get("redirect_to_service_immediately_on_terminal_state"), is(false));
    assertThat(json.get("collect_billing_address"), is(true));
    assertThat(json.get("default_billing_address_country"), is("GB"));
    assertThat(json.getMap("service_name"), not(hasKey("cy")));
    assertEnServiceNameJson("System Generated", json);
    assertLinks(json.get("external_id"), json);
}
Also used : Response(javax.ws.rs.core.Response) Service(uk.gov.pay.adminusers.model.Service) StripeAgreementService(uk.gov.pay.adminusers.service.StripeAgreementService) SendLiveAccountCreatedEmailService(uk.gov.pay.adminusers.service.SendLiveAccountCreatedEmailService) GovUkPayAgreementService(uk.gov.pay.adminusers.service.GovUkPayAgreementService) JsonPath(io.restassured.path.json.JsonPath) Test(org.junit.jupiter.api.Test)

Example 2 with Service

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

the class ServiceResourceCreateTest method shouldSuccess_whenCreateAServiceWithNameOnly.

@Test
public void shouldSuccess_whenCreateAServiceWithNameOnly() {
    PAYLOAD_MAP.put("service_name", Map.of(SupportedLanguage.ENGLISH.toString(), EN_SERVICE_NAME));
    Service service = buildService(Collections.emptyList(), Map.of(SupportedLanguage.ENGLISH, EN_SERVICE_NAME));
    given(mockedServiceCreator.doCreate(Collections.emptyList(), Map.of(SupportedLanguage.ENGLISH, EN_SERVICE_NAME))).willReturn(service);
    Response response = RESOURCES.target(SERVICES_RESOURCE).request(MediaType.APPLICATION_JSON).post(Entity.json(PAYLOAD_MAP), Response.class);
    assertThat(response.getStatus(), is(201));
    String body = response.readEntity(String.class);
    JsonPath json = JsonPath.from(body);
    assertThat(json.get("external_id"), is(notNullValue()));
    assertThat(json.get("name"), is(EN_SERVICE_NAME));
    assertEnServiceNameJson(EN_SERVICE_NAME, json);
    assertThat(json.getMap("service_name"), not(hasKey("cy")));
    assertLinks(json.get("external_id"), json);
}
Also used : Response(javax.ws.rs.core.Response) Service(uk.gov.pay.adminusers.model.Service) StripeAgreementService(uk.gov.pay.adminusers.service.StripeAgreementService) SendLiveAccountCreatedEmailService(uk.gov.pay.adminusers.service.SendLiveAccountCreatedEmailService) GovUkPayAgreementService(uk.gov.pay.adminusers.service.GovUkPayAgreementService) JsonPath(io.restassured.path.json.JsonPath) Test(org.junit.jupiter.api.Test)

Example 3 with Service

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

the class ServiceResourceCreateTest method shouldSuccess_whenCreateAServiceWithName_andGatewayAccountIds_andServiceNameVariants_englishAndCymru.

@Test
public void shouldSuccess_whenCreateAServiceWithName_andGatewayAccountIds_andServiceNameVariants_englishAndCymru() {
    PAYLOAD_MAP.put(FIELD_NAME, EN_SERVICE_NAME);
    String anotherGatewayAccountId = "another-gateway-account-id";
    List<String> gatewayAccounts = List.of(GATEWAY_ACCOUNT_ID, anotherGatewayAccountId);
    PAYLOAD_MAP.put(FIELD_GATEWAY_ACCOUNT_IDS, gatewayAccounts);
    PAYLOAD_MAP.put("service_name", Map.of(SupportedLanguage.ENGLISH.toString(), EN_SERVICE_NAME, SupportedLanguage.WELSH.toString(), CY_SERVICE_NAME));
    Map<SupportedLanguage, String> serviceName = Map.of(SupportedLanguage.ENGLISH, EN_SERVICE_NAME, SupportedLanguage.WELSH, CY_SERVICE_NAME);
    Service service = buildService(gatewayAccounts, serviceName);
    given(mockedServiceCreator.doCreate(gatewayAccounts, serviceName)).willReturn(service);
    Response response = RESOURCES.target(SERVICES_RESOURCE).request(MediaType.APPLICATION_JSON).post(Entity.json(PAYLOAD_MAP), Response.class);
    assertThat(response.getStatus(), is(201));
    String body = response.readEntity(String.class);
    JsonPath json = JsonPath.from(body);
    assertThat(json.get("name"), is(EN_SERVICE_NAME));
    assertThat(json.get("external_id"), is(notNullValue()));
    assertEnServiceNameJson(EN_SERVICE_NAME, json);
    assertCyServiceNameJson(CY_SERVICE_NAME, json);
    assertLinks(json.get("external_id"), json);
    assertThat(json.getList("gateway_account_ids"), hasSize(2));
    assertThat(json.getList("gateway_account_ids"), containsInAnyOrder(GATEWAY_ACCOUNT_ID, anotherGatewayAccountId));
}
Also used : Response(javax.ws.rs.core.Response) SupportedLanguage(uk.gov.service.payments.commons.model.SupportedLanguage) Service(uk.gov.pay.adminusers.model.Service) StripeAgreementService(uk.gov.pay.adminusers.service.StripeAgreementService) SendLiveAccountCreatedEmailService(uk.gov.pay.adminusers.service.SendLiveAccountCreatedEmailService) GovUkPayAgreementService(uk.gov.pay.adminusers.service.GovUkPayAgreementService) JsonPath(io.restassured.path.json.JsonPath) Test(org.junit.jupiter.api.Test)

Example 4 with Service

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

the class UserInviteCompleterTest method aUser.

private User aUser(String email) {
    Service service = Service.from(serviceId, serviceExternalId, new ServiceName(Service.DEFAULT_NAME_VALUE));
    ServiceRole serviceRole = ServiceRole.from(service, role(ADMIN.getId(), "Admin", "Administrator"));
    return User.from(randomInt(), randomUuid(), "a-username", "random-password", email, "784rh", "8948924", Collections.singletonList(serviceRole), null, SecondFactorMethod.SMS, null, null, null);
}
Also used : ServiceRole(uk.gov.pay.adminusers.model.ServiceRole) ServiceName(uk.gov.pay.adminusers.model.ServiceName) Service(uk.gov.pay.adminusers.model.Service)

Example 5 with Service

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

the class UserDaoIT method shouldAddServiceRoleOfAnExistingUser_whenSettingANewServiceRole.

@Test
public void shouldAddServiceRoleOfAnExistingUser_whenSettingANewServiceRole() {
    Role role1 = roleDbFixture(databaseHelper).insertRole();
    Role role2 = roleDbFixture(databaseHelper).insertRole();
    String gatewayAccountId1 = randomInt().toString();
    String gatewayAccountId2 = randomInt().toString();
    Service service1 = serviceDbFixture(databaseHelper).withGatewayAccountIds(gatewayAccountId1).insertService();
    serviceDbFixture(databaseHelper).withGatewayAccountIds(gatewayAccountId2).insertService();
    String username = randomUuid();
    String email = username + "@example.com";
    userDbFixture(databaseHelper).withServiceRole(service1, role1.getId()).withUsername(username).withEmail(email).insertUser();
    UserEntity existingUser = userDao.findByUsername(username).get();
    assertThat(existingUser.getGatewayAccountId(), is(gatewayAccountId1));
    assertThat(existingUser.getRoles().size(), is(1));
    assertThat(existingUser.getRoles().get(0).getId(), is(role1.getId()));
    ServiceEntity serviceEntity2 = serviceDao.findByGatewayAccountId(gatewayAccountId2).get();
    RoleEntity roleEntity2 = roleDao.findByRoleName(role2.getName()).get();
    ServiceRoleEntity serviceRole = new ServiceRoleEntity(serviceEntity2, roleEntity2);
    serviceRole.setUser(existingUser);
    existingUser.addServiceRole(serviceRole);
    userDao.merge(existingUser);
    UserEntity changedUser = userDao.findByUsername(username).get();
    List<ServiceRoleEntity> servicesRoles = changedUser.getServicesRoles();
    assertThat(servicesRoles.size(), is(2));
    assertThat(servicesRoles.stream().map(sr -> sr.getService().getExternalId()).collect(toUnmodifiableList()), hasItems(service1.getExternalId(), serviceEntity2.getExternalId()));
    assertThat(servicesRoles.stream().map(sr -> sr.getRole().getName()).collect(toUnmodifiableList()), hasItems(role1.getName(), role2.getName()));
}
Also used : Role(uk.gov.pay.adminusers.model.Role) ServiceRoleEntity(uk.gov.pay.adminusers.persistence.entity.ServiceRoleEntity) RoleEntity(uk.gov.pay.adminusers.persistence.entity.RoleEntity) Service(uk.gov.pay.adminusers.model.Service) ServiceEntity(uk.gov.pay.adminusers.persistence.entity.ServiceEntity) ServiceRoleEntity(uk.gov.pay.adminusers.persistence.entity.ServiceRoleEntity) Matchers.emptyOrNullString(org.hamcrest.Matchers.emptyOrNullString) UserEntity(uk.gov.pay.adminusers.persistence.entity.UserEntity) 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