Skip to content

Commit

Permalink
Merge pull request #947 from alphagov/PP-7223-fix_query_bug_for_privi…
Browse files Browse the repository at this point in the history
…liged_accounts

PP-7223 fix query bug for priviliged accounts
  • Loading branch information
SandorArpa authored Sep 28, 2020
2 parents 99b45f0 + 0620398 commit ad8e912
Show file tree
Hide file tree
Showing 3 changed files with 54 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,6 @@
import java.util.function.BiConsumer;
import java.util.stream.Collectors;

import static org.apache.commons.lang3.StringUtils.isBlank;
import static org.apache.commons.lang3.StringUtils.isNotBlank;

public class TransactionDao {
Expand Down Expand Up @@ -228,7 +227,7 @@ public Optional<TransactionEntity> findTransactionByExternalId(String externalId
public Optional<TransactionEntity> findTransactionByExternalIdAndGatewayAccountId(String externalId, String gatewayAccountId) {
String query = FIND_TRANSACTION_BY_EXTERNAL_ID
.replace(":payoutJoinOnGatewayIdField",
isBlank(gatewayAccountId)
isNotBlank(gatewayAccountId)
? SEARCH_CLAUSE_TRANSACTION_WITH_PAYOUT : "");
return jdbi.withHandle(handle ->
handle.createQuery(query)
Expand All @@ -251,7 +250,7 @@ public List<TransactionEntity> findTransactionByExternalOrParentIdAndGatewayAcco
public List<TransactionEntity> findTransactionByParentIdAndGatewayAccountId(String parentExternalId, String gatewayAccountId) {
String query = FIND_TRANSACTIONS_BY_PARENT_EXT_ID_AND_GATEWAY_ACCOUNT_ID
.replace(":payoutJoinOnGatewayIdField",
isBlank(gatewayAccountId)
isNotBlank(gatewayAccountId)
? SEARCH_CLAUSE_TRANSACTION_WITH_PAYOUT : "");
return jdbi.withHandle(handle ->
handle.createQuery(query)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -105,6 +105,30 @@ public void shouldRetrieveTransactionByExternalIdAndGatewayAccount() {
assertThat(retrievedTransaction.getPayoutEntity().get().getPaidOutDate(), is(paidOutDate));
}

@Test
public void shouldRetrieveTransactionWithPayoutDateByExternalIdAndNoGatewayAccount() {
ZonedDateTime paidOutDate = ZonedDateTime.parse("2019-12-12T10:00:00Z");
String payOutId = randomAlphanumeric(20);

TransactionFixture fixture = aTransactionFixture()
.withDefaultCardDetails()
.withExternalMetadata(ImmutableMap.of("key1", "value1", "anotherKey", ImmutableMap.of("nestedKey", "value")))
.withDefaultTransactionDetails()
.withGatewayPayoutId(payOutId)
.insert(rule.getJdbi());
aPayoutFixture()
.withGatewayAccountId(fixture.getGatewayAccountId())
.withGatewayPayoutId(payOutId)
.withPaidOutDate(paidOutDate)
.build()
.insert(rule.getJdbi());

TransactionEntity retrievedTransaction = transactionDao.findTransactionByExternalId(fixture.getExternalId()).get();

assertThat(retrievedTransaction.getPayoutEntity().isPresent(), is(true));
assertThat(retrievedTransaction.getPayoutEntity().get().getPaidOutDate(), is(paidOutDate));
}

private void assertTransactionEntity(TransactionEntity transaction, TransactionFixture fixture) {
assertThat(transaction.getId(), notNullValue());
assertThat(transaction.getGatewayAccountId(), is(fixture.getGatewayAccountId()));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -769,6 +769,34 @@ public void shouldGetAndMapTransactionWithPaidOutDateCorrectly() {
assertThat(total, is(1L));
}

@Test
public void shouldGetAndMapTransactionWithPaidOutDateCorrectlyWhenNoGatewayAccount() {
String gatewayPayoutId = randomAlphanumeric(15);

transactionFixture = aTransactionFixture()
.withDefaultCardDetails()
.withMoto(true)
.withGatewayPayoutId(gatewayPayoutId)
.insert(rule.getJdbi());

var payoutFixture = aPayoutFixture()
.withGatewayAccountId(transactionFixture.getGatewayAccountId())
.withGatewayPayoutId(gatewayPayoutId)
.build()
.insert(rule.getJdbi())
.toEntity();

List<TransactionEntity> transactionList = transactionDao.searchTransactions(searchParams);

assertThat(transactionList.size(), Matchers.is(1));
TransactionEntity transaction = transactionList.get(0);

assertThat(transaction.getPayoutEntity().get().getPaidOutDate(), is(payoutFixture.getPaidOutDate()));

Long total = transactionDao.getTotalForSearch(searchParams);
assertThat(total, is(1L));
}

@Test
public void searchTransactionsByCursorWithPaidoutDate() {
String gatewayPayoutId = randomAlphanumeric(15);
Expand Down

0 comments on commit ad8e912

Please sign in to comment.