Search in sources :

Example 1 with TransactionFixture

use of uk.gov.pay.ledger.util.fixture.TransactionFixture in project pay-ledger by alphagov.

the class ContractTest method createThreePaymentsWithPaidoutDates.

@State("three payments with payout dates exists")
public void createThreePaymentsWithPaidoutDates(Map<String, String> params) {
    String gatewayAccountId = params.get("account_id");
    if (isBlank(gatewayAccountId)) {
        gatewayAccountId = "123456";
    }
    String gatewayPayoutId1 = randomAlphanumeric(20);
    String gatewayPayoutId2 = randomAlphanumeric(20);
    String gatewayPayoutId3 = randomAlphanumeric(20);
    String gatewayPayoutId4 = randomAlphanumeric(20);
    TransactionFixture refundParentFixture = aTransactionFixture().withTransactionType("PAYMENT").withGatewayAccountId(gatewayAccountId).withGatewayPayoutId(gatewayPayoutId1).insert(app.getJdbi());
    aTransactionFixture().withTransactionType("PAYMENT").withGatewayAccountId(gatewayAccountId).withGatewayPayoutId(gatewayPayoutId2).insert(app.getJdbi());
    aTransactionFixture().withTransactionType("PAYMENT").withGatewayAccountId(gatewayAccountId).withGatewayPayoutId(gatewayPayoutId3).insert(app.getJdbi());
    aTransactionFixture().withTransactionType("REFUND").withParentExternalId(refundParentFixture.getExternalId()).withGatewayAccountId(gatewayAccountId).withGatewayPayoutId(gatewayPayoutId4).insert(app.getJdbi());
    aPayoutFixture().withGatewayPayoutId(gatewayPayoutId1).withGatewayAccountId(gatewayAccountId).withPaidOutDate(ZonedDateTime.parse("2020-09-19T10:15:30Z")).build().insert(app.getJdbi());
    aPayoutFixture().withGatewayPayoutId(gatewayPayoutId2).withGatewayAccountId(gatewayAccountId).withPaidOutDate(ZonedDateTime.parse("2020-09-18T23:59:59.999Z")).build().insert(app.getJdbi());
    aPayoutFixture().withGatewayPayoutId(gatewayPayoutId3).withGatewayAccountId(gatewayAccountId).withPaidOutDate(ZonedDateTime.parse("2020-09-21T00:00:00Z")).build().insert(app.getJdbi());
    aPayoutFixture().withGatewayPayoutId(gatewayPayoutId4).withGatewayAccountId(gatewayAccountId).withPaidOutDate(ZonedDateTime.parse("2020-09-19T19:05:00Z")).build().insert(app.getJdbi());
}
Also used : TransactionFixture(uk.gov.pay.ledger.util.fixture.TransactionFixture) TransactionFixture.aTransactionFixture(uk.gov.pay.ledger.util.fixture.TransactionFixture.aTransactionFixture) State(au.com.dius.pact.provider.junit.State) TransactionState(uk.gov.pay.ledger.transaction.state.TransactionState) PayoutState(uk.gov.pay.ledger.payout.state.PayoutState)

Example 2 with TransactionFixture

use of uk.gov.pay.ledger.util.fixture.TransactionFixture in project pay-ledger by alphagov.

the class TransactionDaoSearchIT method shouldFilterByGatewayPayoutIdWhenSpecified.

@Test
public void shouldFilterByGatewayPayoutIdWhenSpecified() {
    String gatewayAccountId = "account-id-" + nextLong();
    String gatewayPayoutId = "payout-id-" + nextLong();
    TransactionFixture transaction = aTransactionFixture().withGatewayAccountId(gatewayAccountId).withGatewayPayoutId(gatewayPayoutId).withCreatedDate(now().minusDays(1)).withTransactionType("PAYMENT").insert(rule.getJdbi());
    TransactionFixture refund = aTransactionFixture().withGatewayAccountId(gatewayAccountId).withGatewayPayoutId(gatewayPayoutId).withTransactionType("REFUND").insert(rule.getJdbi());
    aTransactionFixture().withGatewayAccountId(gatewayAccountId).withGatewayPayoutId(gatewayPayoutId + "different-id").withTransactionType("PAYMENT").insert(rule.getJdbi());
    TransactionSearchParams searchParams = new TransactionSearchParams();
    searchParams.setGatewayPayoutId(gatewayPayoutId);
    List<TransactionEntity> transactionList = transactionDao.searchTransactions(searchParams);
    assertThat(transactionList.size(), Matchers.is(2));
    assertThat(transactionList.get(0).getExternalId(), is(refund.getExternalId()));
    assertThat(transactionList.get(0).getGatewayPayoutId(), is(refund.getGatewayPayoutId()));
    assertThat(transactionList.get(1).getExternalId(), is(transaction.getExternalId()));
    assertThat(transactionList.get(1).getGatewayPayoutId(), is(transaction.getGatewayPayoutId()));
}
Also used : TransactionFixture(uk.gov.pay.ledger.util.fixture.TransactionFixture) TransactionFixture.aTransactionFixture(uk.gov.pay.ledger.util.fixture.TransactionFixture.aTransactionFixture) TransactionSearchParams(uk.gov.pay.ledger.transaction.search.common.TransactionSearchParams) TransactionEntity(uk.gov.pay.ledger.transaction.entity.TransactionEntity) Test(org.junit.jupiter.api.Test)

Example 3 with TransactionFixture

use of uk.gov.pay.ledger.util.fixture.TransactionFixture in project pay-ledger by alphagov.

the class TransactionDaoSearchIT method shouldFilterByGatewayAccountIdWhenSpecified.

@Test
public void shouldFilterByGatewayAccountIdWhenSpecified() {
    String gatewayAccountId = "account-id-" + nextLong();
    TransactionFixture transaction = aTransactionFixture().withGatewayAccountId(gatewayAccountId).withTransactionType("PAYMENT").insert(rule.getJdbi());
    aTransactionFixture().withGatewayAccountId(gatewayAccountId + "different_account").withTransactionType("PAYMENT").insert(rule.getJdbi());
    TransactionSearchParams searchParams = new TransactionSearchParams();
    searchParams.setAccountIds(List.of(gatewayAccountId));
    List<TransactionEntity> transactionList = transactionDao.searchTransactions(searchParams);
    assertThat(transactionList.size(), Matchers.is(1));
    assertThat(transactionList.get(0).getExternalId(), is(transaction.getExternalId()));
}
Also used : TransactionFixture(uk.gov.pay.ledger.util.fixture.TransactionFixture) TransactionFixture.aTransactionFixture(uk.gov.pay.ledger.util.fixture.TransactionFixture.aTransactionFixture) TransactionSearchParams(uk.gov.pay.ledger.transaction.search.common.TransactionSearchParams) TransactionEntity(uk.gov.pay.ledger.transaction.entity.TransactionEntity) Test(org.junit.jupiter.api.Test)

Example 4 with TransactionFixture

use of uk.gov.pay.ledger.util.fixture.TransactionFixture in project pay-ledger by alphagov.

the class TransactionDaoSearchIT method shouldNotFilterByGatewayAccountIdWhenNotSpecified.

@Test
public void shouldNotFilterByGatewayAccountIdWhenNotSpecified() {
    String gatewayAccountId = "account-id-" + nextLong();
    TransactionFixture mostRecent = aTransactionFixture().withGatewayAccountId(gatewayAccountId).withTransactionType("PAYMENT").withCreatedDate(now()).insert(rule.getJdbi());
    TransactionFixture earlier = aTransactionFixture().withGatewayAccountId(gatewayAccountId + "different_account").withTransactionType("PAYMENT").withCreatedDate(now().minusHours(1)).insert(rule.getJdbi());
    TransactionSearchParams searchParams = new TransactionSearchParams();
    List<TransactionEntity> transactionList = transactionDao.searchTransactions(searchParams);
    assertThat(transactionList.size(), Matchers.is(2));
    assertThat(transactionList.get(0).getExternalId(), is(mostRecent.getExternalId()));
    assertThat(transactionList.get(1).getExternalId(), is(earlier.getExternalId()));
}
Also used : TransactionFixture(uk.gov.pay.ledger.util.fixture.TransactionFixture) TransactionFixture.aTransactionFixture(uk.gov.pay.ledger.util.fixture.TransactionFixture.aTransactionFixture) TransactionSearchParams(uk.gov.pay.ledger.transaction.search.common.TransactionSearchParams) TransactionEntity(uk.gov.pay.ledger.transaction.entity.TransactionEntity) Test(org.junit.jupiter.api.Test)

Example 5 with TransactionFixture

use of uk.gov.pay.ledger.util.fixture.TransactionFixture in project pay-ledger by alphagov.

the class TransactionResourceCsvIT method shouldGetAllTransactionsForAGivenGatewayPayoutId.

@Test
public void shouldGetAllTransactionsForAGivenGatewayPayoutId() throws IOException {
    String targetGatewayAccountId = randomNumeric(5);
    String gatewayPayoutId = randomAlphanumeric(30);
    TransactionFixture transactionFixture = aTransactionFixture().withTransactionType("PAYMENT").withGatewayAccountId(targetGatewayAccountId).withCreatedDate(now()).withGatewayPayoutId(gatewayPayoutId).insert(rule.getJdbi());
    TransactionFixture transactionFixtureWithoutGatewayPayoutId = aTransactionFixture().withTransactionType("PAYMENT").withGatewayAccountId(targetGatewayAccountId).insert(rule.getJdbi());
    TransactionFixture refundFixture = aTransactionFixture().withTransactionType("REFUND").withCreatedDate(now().plusDays(1)).withParentExternalId(transactionFixtureWithoutGatewayPayoutId.getExternalId()).withGatewayAccountId(targetGatewayAccountId).withGatewayPayoutId(gatewayPayoutId).insert(rule.getJdbi());
    InputStream csvResponseStream = given().port(port).accept("text/csv").get("/v1/transaction?" + "account_id=" + targetGatewayAccountId + "&gateway_payout_id=" + gatewayPayoutId).then().statusCode(Response.Status.OK.getStatusCode()).contentType("text/csv").extract().asInputStream();
    List<CSVRecord> csvRecords = CSVParser.parse(csvResponseStream, UTF_8, RFC4180.withFirstRecordAsHeader()).getRecords();
    assertThat(csvRecords.size(), is(2));
    CSVRecord refundRecord = csvRecords.get(0);
    assertThat(refundRecord.get("GOV.UK Payment ID"), is(transactionFixtureWithoutGatewayPayoutId.getExternalId()));
    CSVRecord paymentRecord = csvRecords.get(1);
    assertThat(paymentRecord.get("GOV.UK Payment ID"), is(transactionFixture.getExternalId()));
}
Also used : TransactionFixture(uk.gov.pay.ledger.util.fixture.TransactionFixture) TransactionFixture.aTransactionFixture(uk.gov.pay.ledger.util.fixture.TransactionFixture.aTransactionFixture) InputStream(java.io.InputStream) CSVRecord(org.apache.commons.csv.CSVRecord) Test(org.junit.jupiter.api.Test)

Aggregations

TransactionFixture (uk.gov.pay.ledger.util.fixture.TransactionFixture)27 TransactionFixture.aTransactionFixture (uk.gov.pay.ledger.util.fixture.TransactionFixture.aTransactionFixture)27 Test (org.junit.jupiter.api.Test)26 TransactionEntity (uk.gov.pay.ledger.transaction.entity.TransactionEntity)10 Matchers.containsString (org.hamcrest.Matchers.containsString)6 InputStream (java.io.InputStream)4 CSVRecord (org.apache.commons.csv.CSVRecord)4 TransactionSearchParams (uk.gov.pay.ledger.transaction.search.common.TransactionSearchParams)4 ZonedDateTime (java.time.ZonedDateTime)3 CoreMatchers.containsString (org.hamcrest.CoreMatchers.containsString)3 State (au.com.dius.pact.provider.junit.State)1 JsonObject (com.google.gson.JsonObject)1 PayoutState (uk.gov.pay.ledger.payout.state.PayoutState)1 TransactionState (uk.gov.pay.ledger.transaction.state.TransactionState)1