Search in sources :

Example 1 with TransactionSearchParams

use of uk.gov.pay.api.ledger.model.TransactionSearchParams in project pay-publicapi by alphagov.

the class TransactionSearchServiceTest method shouldThrowBadRequestException.

@Test
public void shouldThrowBadRequestException() {
    TransactionSearchParams searchParams = mock(TransactionSearchParams.class);
    when(searchParams.getQueryMap()).thenReturn(Map.of("not_supported", "hello"));
    BadRequestException badRequestException = assertThrows(BadRequestException.class, () -> transactionSearchService.doSearch(new Account("1", TokenPaymentType.CARD, "a-token-link"), searchParams));
    assertThat(badRequestException, aBadRequestExceptionWithError("P0401", "Invalid parameters: not_supported. See Public API documentation for the correct data formats"));
}
Also used : Account(uk.gov.pay.api.auth.Account) TransactionSearchParams(uk.gov.pay.api.ledger.model.TransactionSearchParams) BadRequestException(uk.gov.pay.api.exception.BadRequestException) Test(org.junit.Test)

Example 2 with TransactionSearchParams

use of uk.gov.pay.api.ledger.model.TransactionSearchParams in project pay-publicapi by alphagov.

the class TransactionSearchServiceTest method testSearchTransaction.

@Test
@PactVerification({ "ledger" })
@Pacts(pacts = { "publicapi-ledger-search-transaction" })
public void testSearchTransaction() {
    Account account = new Account(ACCOUNT_ID, TokenPaymentType.CARD, "a-token-link");
    TransactionSearchParams searchParams = new TransactionSearchParams();
    TransactionSearchResults searchResults = transactionSearchService.doSearch(account, searchParams);
    PaymentForSearchResult payment = searchResults.getResults().get(0);
    assertThat(payment.getAmount(), is(1000L));
    assertThat(payment.getState(), is(new PaymentState("created", false)));
    assertThat(payment.getDescription(), is("Test description"));
    assertThat(payment.getReference(), is("aReference"));
    assertThat(payment.getLanguage(), is(SupportedLanguage.ENGLISH));
    assertThat(payment.getPaymentId(), is(CHARGE_ID));
    assertThat(payment.getReturnUrl().get(), is("https://example.org"));
    assertThat(payment.getEmail().get(), is("someone@example.org"));
    assertThat(payment.getPaymentProvider(), is("sandbox"));
    assertThat(payment.getCreatedDate(), is("2018-09-22T10:13:16.067Z"));
    assertThat(payment.getDelayedCapture(), is(false));
    assertThat(payment.getCardDetails().get().getCardHolderName(), is("J. Smith"));
    assertThat(payment.getCardDetails().get().getCardBrand(), is(""));
    Address address = payment.getCardDetails().get().getBillingAddress().get();
    assertThat(address.getLine1(), is("line1"));
    assertThat(address.getLine2(), is("line2"));
    assertThat(address.getPostcode(), is("AB1 2CD"));
    assertThat(address.getCity(), is("London"));
    assertThat(address.getCountry(), is("GB"));
    assertThat(payment.getLinks().getSelf().getHref(), containsString("v1/payments/" + CHARGE_ID));
    assertThat(payment.getLinks().getSelf().getMethod(), is("GET"));
    assertThat(payment.getLinks().getRefunds().getHref(), containsString("v1/payments/" + CHARGE_ID + "/refunds"));
    assertThat(payment.getLinks().getRefunds().getMethod(), is("GET"));
    assertThat(searchResults.getCount(), is(1));
    assertThat(searchResults.getTotal(), is(1));
    assertThat(searchResults.getPage(), is(1));
    assertThat(searchResults.getLinks().getSelf().getHref(), containsString("/v1/transactions?display_size=500&page=1"));
    assertThat(searchResults.getLinks().getFirstPage().getHref(), containsString("/v1/transactions?display_size=500&page=1"));
    assertThat(searchResults.getLinks().getLastPage().getHref(), containsString("/v1/transactions?display_size=500&page=1"));
}
Also used : Account(uk.gov.pay.api.auth.Account) TransactionSearchParams(uk.gov.pay.api.ledger.model.TransactionSearchParams) Address(uk.gov.pay.api.model.Address) PaymentForSearchResult(uk.gov.pay.api.model.search.card.PaymentForSearchResult) PaymentState(uk.gov.pay.api.model.PaymentState) TransactionSearchResults(uk.gov.pay.api.ledger.model.TransactionSearchResults) PactVerification(au.com.dius.pact.consumer.PactVerification) Test(org.junit.Test) Pacts(uk.gov.service.payments.commons.testing.pact.consumers.Pacts)

Aggregations

Test (org.junit.Test)2 Account (uk.gov.pay.api.auth.Account)2 TransactionSearchParams (uk.gov.pay.api.ledger.model.TransactionSearchParams)2 PactVerification (au.com.dius.pact.consumer.PactVerification)1 BadRequestException (uk.gov.pay.api.exception.BadRequestException)1 TransactionSearchResults (uk.gov.pay.api.ledger.model.TransactionSearchResults)1 Address (uk.gov.pay.api.model.Address)1 PaymentState (uk.gov.pay.api.model.PaymentState)1 PaymentForSearchResult (uk.gov.pay.api.model.search.card.PaymentForSearchResult)1 Pacts (uk.gov.service.payments.commons.testing.pact.consumers.Pacts)1