Search in sources :

Example 1 with PaymentNavigationLinksFixture

use of uk.gov.pay.api.it.fixtures.PaymentNavigationLinksFixture in project pay-publicapi by alphagov.

the class PaymentResourceSearchIT method searchPayments_getsPaginatedResults.

@Test
public void searchPayments_getsPaginatedResults() {
    PaymentNavigationLinksFixture links = new PaymentNavigationLinksFixture().withPrevLink("http://server:port/path?query=prev&from_date=2016-01-01T23:59:59Z").withNextLink("http://server:port/path?query=next&from_date=2016-01-01T23:59:59Z").withSelfLink("http://server:port/path?query=self&from_date=2016-01-01T23:59:59Z").withFirstLink("http://server:port/path?query=first&from_date=2016-01-01T23:59:59Z").withLastLink("http://server:port/path?query=last&from_date=2016-01-01T23:59:59Z");
    String payments = aPaginatedPaymentSearchResult().withCount(10).withPage(2).withTotal(40).withPayments(aSuccessfulSearchPayment().withReference(TEST_REFERENCE).withInProgressState(TEST_STATE).withCreatedDateBetween(TEST_FROM_DATE, TEST_TO_DATE).withNumberOfResults(10).withEmail(TEST_EMAIL).getResults()).withLinks(links).build();
    ledgerMockClient.respondOk_whenSearchCharges(payments);
    ImmutableMap<String, String> queryParams = ImmutableMap.of("reference", TEST_REFERENCE, "state", TEST_STATE, "email", TEST_EMAIL, "page", "2", "display_size", "10");
    ValidatableResponse response = searchPayments(queryParams).statusCode(200).contentType(JSON).body("results.size()", equalTo(10)).body("total", is(40)).body("count", is(10)).body("page", is(2)).body("_links.next_page.href", is(expectedChargesLocationFor("?from_date=2016-01-01T23%3A59%3A59Z&query=next"))).body("_links.prev_page.href", is(expectedChargesLocationFor("?from_date=2016-01-01T23%3A59%3A59Z&query=prev"))).body("_links.first_page.href", is(expectedChargesLocationFor("?from_date=2016-01-01T23%3A59%3A59Z&query=first"))).body("_links.last_page.href", is(expectedChargesLocationFor("?from_date=2016-01-01T23%3A59%3A59Z&query=last"))).body("_links.self.href", is(expectedChargesLocationFor("?from_date=2016-01-01T23%3A59%3A59Z&query=self")));
    List<Map<String, Object>> results = response.extract().body().jsonPath().getList("results");
    assertThat(results, matchesField("reference", TEST_REFERENCE));
    assertThat(results, matchesField("email", TEST_EMAIL));
    assertThat(results, matchesState(TEST_STATE));
    assertThat(results, matchesCreatedDateInBetween(TEST_FROM_DATE, TEST_TO_DATE));
}
Also used : ValidatableResponse(io.restassured.response.ValidatableResponse) PaymentNavigationLinksFixture(uk.gov.pay.api.it.fixtures.PaymentNavigationLinksFixture) Map(java.util.Map) ImmutableMap(com.google.common.collect.ImmutableMap) Test(org.junit.Test)

Example 2 with PaymentNavigationLinksFixture

use of uk.gov.pay.api.it.fixtures.PaymentNavigationLinksFixture in project pay-publicapi by alphagov.

the class TransactionsResourceIT method shouldReturnAListOfTransactions.

@Test
public void shouldReturnAListOfTransactions() {
    Address billingAddress = new Address("line1", null, "AB1 CD2", "London", "GB");
    CardDetails cardDetails = new CardDetails(null, null, "J. Doe", null, billingAddress, "", null);
    PaymentNavigationLinksFixture fixture = new PaymentNavigationLinksFixture();
    fixture.withSelfLink("https://ledger/v1/transaction?account_id=1&reference=reference&page=1&display_size=500");
    fixture.withFirstLink("https://ledger/v1/transaction?account_id=1&reference=reference&page=1&display_size=500");
    fixture.withLastLink("https://ledger/v1/transaction?account_id=1&reference=reference&page=1&display_size=500");
    String transactions = aPaginatedTransactionSearchResult().withCount(2).withPage(1).withTotal(2).withLinks(fixture).withPayments(aSuccessfulSearchPayment().withInProgressState("created").withReference("reference").withCardDetails(cardDetails).withNumberOfResults(2).withEmail("j.doe@example.org").withAuthorisationSummary(new AuthorisationSummary(new ThreeDSecure(true))).getResults()).build();
    ledgerMockClient.respondOk_whenSearchCharges(transactions);
    searchTransactions(ImmutableMap.of("reference", "reference")).statusCode(200).contentType(JSON).body("results[0].created_date", is(DEFAULT_CREATED_DATE)).body("results[0].reference", is("reference")).body("results[0].email", is("j.doe@example.org")).body("results[0].return_url", is(DEFAULT_RETURN_URL)).body("results[0].description", is("description-0")).body("results[0].state.status", is("created")).body("results[0].amount", is(DEFAULT_AMOUNT)).body("results[0].payment_provider", is("worldpay")).body("results[0].payment_id", is("0")).body("results[0].language", is("en")).body("results[0].delayed_capture", is(false)).body("results[0]._links.self.method", is("GET")).body("results[0]._links.self.href", is(paymentLocationFor(configuration.getBaseUrl(), "0"))).body("results[0]._links.events.href", is(paymentEventsLocationFor("0"))).body("results[0]._links.events.method", is("GET")).body("results[0]._links.cancel.href", is(paymentCancelLocationFor("0"))).body("results[0]._links.cancel.method", is("POST")).body("results[0]._links.refunds.href", is(paymentRefundsLocationFor("0"))).body("results[0]._links.refunds.method", is("GET")).body("results[0].card_details.cardholder_name", is("J. Doe")).body("results[0].card_details.expiry_date", is(nullValue())).body("results[0].card_details.last_digits_card_number", is(nullValue())).body("results[0].card_details.first_digits_card_number", is(nullValue())).body("results[0].card_details.billing_address.line1", is("line1")).body("results[0].card_details.billing_address.line2", is(nullValue())).body("results[0].card_details.billing_address.postcode", is("AB1 CD2")).body("results[0].card_details.billing_address.country", is("GB")).body("results[0].card_details.card_brand", is(emptyString())).body("results[0].authorisation_summary", is(notNullValue())).body("results[0].authorisation_summary.three_d_secure", is(notNullValue())).body("results[0].authorisation_summary.three_d_secure.required", is(true)).body("_links.self.href", is(expectedChargesLocationFor("?reference=reference&display_size=500&page=1"))).body("_links.first_page.href", is(expectedChargesLocationFor("?reference=reference&display_size=500&page=1"))).body("_links.last_page.href", is(expectedChargesLocationFor("?reference=reference&display_size=500&page=1")));
}
Also used : AuthorisationSummary(uk.gov.pay.api.model.AuthorisationSummary) Address(uk.gov.pay.api.model.Address) ThreeDSecure(uk.gov.pay.api.model.ThreeDSecure) PaymentNavigationLinksFixture(uk.gov.pay.api.it.fixtures.PaymentNavigationLinksFixture) Matchers.emptyString(org.hamcrest.Matchers.emptyString) CardDetails(uk.gov.pay.api.model.CardDetails) Test(org.junit.Test)

Aggregations

Test (org.junit.Test)2 PaymentNavigationLinksFixture (uk.gov.pay.api.it.fixtures.PaymentNavigationLinksFixture)2 ImmutableMap (com.google.common.collect.ImmutableMap)1 ValidatableResponse (io.restassured.response.ValidatableResponse)1 Map (java.util.Map)1 Matchers.emptyString (org.hamcrest.Matchers.emptyString)1 Address (uk.gov.pay.api.model.Address)1 AuthorisationSummary (uk.gov.pay.api.model.AuthorisationSummary)1 CardDetails (uk.gov.pay.api.model.CardDetails)1 ThreeDSecure (uk.gov.pay.api.model.ThreeDSecure)1