Search in sources :

Example 26 with JsonPatchRequest

use of uk.gov.service.payments.commons.model.jsonpatch.JsonPatchRequest in project pay-connector by alphagov.

the class GatewayAccountCredentialsServiceTest method shouldChangeStateToActive_whenCredentialsInCreatedStateUpdated_andOnlyOneCredential.

@Test
void shouldChangeStateToActive_whenCredentialsInCreatedStateUpdated_andOnlyOneCredential() {
    GatewayAccountEntity gatewayAccountEntity = aGatewayAccountEntity().build();
    GatewayAccountCredentialsEntity credentialsEntity = aGatewayAccountCredentialsEntity().withGatewayAccountEntity(gatewayAccountEntity).withState(CREATED).build();
    gatewayAccountEntity.setGatewayAccountCredentials(List.of(credentialsEntity));
    JsonPatchRequest patchRequest = JsonPatchRequest.from(objectMapper.valueToTree(Map.of("path", "credentials", "op", "replace", "value", Map.of("merchant_id", "new-merchant-id"))));
    gatewayAccountCredentialsService.updateGatewayAccountCredentials(credentialsEntity, Collections.singletonList(patchRequest));
    assertThat(credentialsEntity.getState(), is(ACTIVE));
}
Also used : JsonPatchRequest(uk.gov.service.payments.commons.model.jsonpatch.JsonPatchRequest) GatewayAccountEntityFixture.aGatewayAccountEntity(uk.gov.pay.connector.gatewayaccount.model.GatewayAccountEntityFixture.aGatewayAccountEntity) GatewayAccountEntity(uk.gov.pay.connector.gatewayaccount.model.GatewayAccountEntity) GatewayAccountCredentialsEntity(uk.gov.pay.connector.gatewayaccountcredentials.model.GatewayAccountCredentialsEntity) GatewayAccountCredentialsEntityFixture.aGatewayAccountCredentialsEntity(uk.gov.pay.connector.gatewayaccountcredentials.model.GatewayAccountCredentialsEntityFixture.aGatewayAccountCredentialsEntity) Test(org.junit.jupiter.api.Test) ParameterizedTest(org.junit.jupiter.params.ParameterizedTest)

Example 27 with JsonPatchRequest

use of uk.gov.service.payments.commons.model.jsonpatch.JsonPatchRequest in project pay-connector by alphagov.

the class GatewayAccountServiceTest method shouldUpdateSendPayerEmailToGatewayToFalse.

@Test
public void shouldUpdateSendPayerEmailToGatewayToFalse() {
    JsonPatchRequest request = JsonPatchRequest.from(objectMapper.valueToTree(Map.of("op", "replace", "path", "send_payer_email_to_gateway", "value", false)));
    when(mockGatewayAccountDao.findById(GATEWAY_ACCOUNT_ID)).thenReturn(Optional.of(mockGatewayAccountEntity));
    Optional<GatewayAccount> optionalGatewayAccount = gatewayAccountService.doPatch(GATEWAY_ACCOUNT_ID, request);
    assertThat(optionalGatewayAccount.isPresent(), is(true));
    verify(mockGatewayAccountEntity).setSendPayerEmailToGateway(false);
    verify(mockGatewayAccountDao).merge(mockGatewayAccountEntity);
}
Also used : JsonPatchRequest(uk.gov.service.payments.commons.model.jsonpatch.JsonPatchRequest) GatewayAccount(uk.gov.pay.connector.gatewayaccount.model.GatewayAccount) Test(org.junit.jupiter.api.Test)

Example 28 with JsonPatchRequest

use of uk.gov.service.payments.commons.model.jsonpatch.JsonPatchRequest in project pay-connector by alphagov.

the class GatewayAccountServiceTest method shouldThrowWrongGatewayAccountExceptionWhenAccountIsNotWorldpay.

@Test
public void shouldThrowWrongGatewayAccountExceptionWhenAccountIsNotWorldpay() {
    JsonPatchRequest request = JsonPatchRequest.from(objectMapper.valueToTree(Map.of("op", "replace", "path", FIELD_WORLDPAY_EXEMPTION_ENGINE_ENABLED, "value", true)));
    when(mockGatewayAccountEntity.getGatewayName()).thenReturn(EPDQ.getName());
    when(mockGatewayAccountDao.findById(GATEWAY_ACCOUNT_ID)).thenReturn(Optional.of(mockGatewayAccountEntity));
    var thrown = assertThrows(NotSupportedGatewayAccountException.class, () -> gatewayAccountService.doPatch(GATEWAY_ACCOUNT_ID, request));
    assertThat(thrown.getMessage(), is(BAD_REQUEST_MESSAGE));
}
Also used : JsonPatchRequest(uk.gov.service.payments.commons.model.jsonpatch.JsonPatchRequest) Test(org.junit.jupiter.api.Test)

Example 29 with JsonPatchRequest

use of uk.gov.service.payments.commons.model.jsonpatch.JsonPatchRequest in project pay-connector by alphagov.

the class GatewayAccountServiceTest method shouldUpdateSendReferenceToGatewayToTrue.

@Test
public void shouldUpdateSendReferenceToGatewayToTrue() {
    JsonPatchRequest request = JsonPatchRequest.from(objectMapper.valueToTree(Map.of("op", "replace", "path", "send_reference_to_gateway", "value", true)));
    when(mockGatewayAccountDao.findById(GATEWAY_ACCOUNT_ID)).thenReturn(Optional.of(mockGatewayAccountEntity));
    Optional<GatewayAccount> optionalGatewayAccount = gatewayAccountService.doPatch(GATEWAY_ACCOUNT_ID, request);
    assertThat(optionalGatewayAccount.isPresent(), is(true));
    verify(mockGatewayAccountEntity).setSendReferenceToGateway(true);
    verify(mockGatewayAccountDao).merge(mockGatewayAccountEntity);
}
Also used : JsonPatchRequest(uk.gov.service.payments.commons.model.jsonpatch.JsonPatchRequest) GatewayAccount(uk.gov.pay.connector.gatewayaccount.model.GatewayAccount) Test(org.junit.jupiter.api.Test)

Example 30 with JsonPatchRequest

use of uk.gov.service.payments.commons.model.jsonpatch.JsonPatchRequest in project pay-connector by alphagov.

the class GatewayAccountServiceTest method shouldUpdateIntegrationVersion3ds.

@Test
public void shouldUpdateIntegrationVersion3ds() {
    JsonPatchRequest request = JsonPatchRequest.from(objectMapper.valueToTree(Map.of("op", "replace", "path", "integration_version_3ds", "value", 2)));
    when(mockGatewayAccountDao.findById(GATEWAY_ACCOUNT_ID)).thenReturn(Optional.of(mockGatewayAccountEntity));
    Optional<GatewayAccount> optionalGatewayAccount = gatewayAccountService.doPatch(GATEWAY_ACCOUNT_ID, request);
    assertThat(optionalGatewayAccount.isPresent(), is(true));
    verify(mockGatewayAccountEntity).setIntegrationVersion3ds(2);
    verify(mockGatewayAccountDao).merge(mockGatewayAccountEntity);
}
Also used : JsonPatchRequest(uk.gov.service.payments.commons.model.jsonpatch.JsonPatchRequest) GatewayAccount(uk.gov.pay.connector.gatewayaccount.model.GatewayAccount) Test(org.junit.jupiter.api.Test)

Aggregations

JsonPatchRequest (uk.gov.service.payments.commons.model.jsonpatch.JsonPatchRequest)39 Test (org.junit.jupiter.api.Test)36 GatewayAccount (uk.gov.pay.connector.gatewayaccount.model.GatewayAccount)28 GatewayAccountEntity (uk.gov.pay.connector.gatewayaccount.model.GatewayAccountEntity)5 ParameterizedTest (org.junit.jupiter.params.ParameterizedTest)4 GatewayAccountEntityFixture.aGatewayAccountEntity (uk.gov.pay.connector.gatewayaccount.model.GatewayAccountEntityFixture.aGatewayAccountEntity)4 GatewayAccountCredentialsEntity (uk.gov.pay.connector.gatewayaccountcredentials.model.GatewayAccountCredentialsEntity)4 GatewayAccountCredentialsEntityFixture.aGatewayAccountCredentialsEntity (uk.gov.pay.connector.gatewayaccountcredentials.model.GatewayAccountCredentialsEntityFixture.aGatewayAccountCredentialsEntity)4 InOrder (org.mockito.InOrder)3 Test (org.junit.Test)2 JsonNode (com.fasterxml.jackson.databind.JsonNode)1 Transactional (com.google.inject.persist.Transactional)1 GatewayAccountCredentials (uk.gov.pay.connector.gatewayaccount.model.GatewayAccountCredentials)1 ProductEntityFixture.aProductEntity (uk.gov.pay.products.fixtures.ProductEntityFixture.aProductEntity)1 Product (uk.gov.pay.products.model.Product)1 ProductEntity (uk.gov.pay.products.persistence.entity.ProductEntity)1