Skip to content

Commit ad8e912

Browse files
authored
Merge pull request #947 from alphagov/PP-7223-fix_query_bug_for_priviliged_accounts
PP-7223 fix query bug for priviliged accounts
2 parents 99b45f0 + 0620398 commit ad8e912

3 files changed

Lines changed: 54 additions & 3 deletions

File tree

src/main/java/uk/gov/pay/ledger/transaction/dao/TransactionDao.java

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,6 @@
1515
import java.util.function.BiConsumer;
1616
import java.util.stream.Collectors;
1717

18-
import static org.apache.commons.lang3.StringUtils.isBlank;
1918
import static org.apache.commons.lang3.StringUtils.isNotBlank;
2019

2120
public class TransactionDao {
@@ -228,7 +227,7 @@ public Optional<TransactionEntity> findTransactionByExternalId(String externalId
228227
public Optional<TransactionEntity> findTransactionByExternalIdAndGatewayAccountId(String externalId, String gatewayAccountId) {
229228
String query = FIND_TRANSACTION_BY_EXTERNAL_ID
230229
.replace(":payoutJoinOnGatewayIdField",
231-
isBlank(gatewayAccountId)
230+
isNotBlank(gatewayAccountId)
232231
? SEARCH_CLAUSE_TRANSACTION_WITH_PAYOUT : "");
233232
return jdbi.withHandle(handle ->
234233
handle.createQuery(query)
@@ -251,7 +250,7 @@ public List<TransactionEntity> findTransactionByExternalOrParentIdAndGatewayAcco
251250
public List<TransactionEntity> findTransactionByParentIdAndGatewayAccountId(String parentExternalId, String gatewayAccountId) {
252251
String query = FIND_TRANSACTIONS_BY_PARENT_EXT_ID_AND_GATEWAY_ACCOUNT_ID
253252
.replace(":payoutJoinOnGatewayIdField",
254-
isBlank(gatewayAccountId)
253+
isNotBlank(gatewayAccountId)
255254
? SEARCH_CLAUSE_TRANSACTION_WITH_PAYOUT : "");
256255
return jdbi.withHandle(handle ->
257256
handle.createQuery(query)

src/test/java/uk/gov/pay/ledger/transaction/dao/TransactionDaoIT.java

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -105,6 +105,30 @@ public void shouldRetrieveTransactionByExternalIdAndGatewayAccount() {
105105
assertThat(retrievedTransaction.getPayoutEntity().get().getPaidOutDate(), is(paidOutDate));
106106
}
107107

108+
@Test
109+
public void shouldRetrieveTransactionWithPayoutDateByExternalIdAndNoGatewayAccount() {
110+
ZonedDateTime paidOutDate = ZonedDateTime.parse("2019-12-12T10:00:00Z");
111+
String payOutId = randomAlphanumeric(20);
112+
113+
TransactionFixture fixture = aTransactionFixture()
114+
.withDefaultCardDetails()
115+
.withExternalMetadata(ImmutableMap.of("key1", "value1", "anotherKey", ImmutableMap.of("nestedKey", "value")))
116+
.withDefaultTransactionDetails()
117+
.withGatewayPayoutId(payOutId)
118+
.insert(rule.getJdbi());
119+
aPayoutFixture()
120+
.withGatewayAccountId(fixture.getGatewayAccountId())
121+
.withGatewayPayoutId(payOutId)
122+
.withPaidOutDate(paidOutDate)
123+
.build()
124+
.insert(rule.getJdbi());
125+
126+
TransactionEntity retrievedTransaction = transactionDao.findTransactionByExternalId(fixture.getExternalId()).get();
127+
128+
assertThat(retrievedTransaction.getPayoutEntity().isPresent(), is(true));
129+
assertThat(retrievedTransaction.getPayoutEntity().get().getPaidOutDate(), is(paidOutDate));
130+
}
131+
108132
private void assertTransactionEntity(TransactionEntity transaction, TransactionFixture fixture) {
109133
assertThat(transaction.getId(), notNullValue());
110134
assertThat(transaction.getGatewayAccountId(), is(fixture.getGatewayAccountId()));

src/test/java/uk/gov/pay/ledger/transaction/dao/TransactionDaoSearchIT.java

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -769,6 +769,34 @@ public void shouldGetAndMapTransactionWithPaidOutDateCorrectly() {
769769
assertThat(total, is(1L));
770770
}
771771

772+
@Test
773+
public void shouldGetAndMapTransactionWithPaidOutDateCorrectlyWhenNoGatewayAccount() {
774+
String gatewayPayoutId = randomAlphanumeric(15);
775+
776+
transactionFixture = aTransactionFixture()
777+
.withDefaultCardDetails()
778+
.withMoto(true)
779+
.withGatewayPayoutId(gatewayPayoutId)
780+
.insert(rule.getJdbi());
781+
782+
var payoutFixture = aPayoutFixture()
783+
.withGatewayAccountId(transactionFixture.getGatewayAccountId())
784+
.withGatewayPayoutId(gatewayPayoutId)
785+
.build()
786+
.insert(rule.getJdbi())
787+
.toEntity();
788+
789+
List<TransactionEntity> transactionList = transactionDao.searchTransactions(searchParams);
790+
791+
assertThat(transactionList.size(), Matchers.is(1));
792+
TransactionEntity transaction = transactionList.get(0);
793+
794+
assertThat(transaction.getPayoutEntity().get().getPaidOutDate(), is(payoutFixture.getPaidOutDate()));
795+
796+
Long total = transactionDao.getTotalForSearch(searchParams);
797+
assertThat(total, is(1L));
798+
}
799+
772800
@Test
773801
public void searchTransactionsByCursorWithPaidoutDate() {
774802
String gatewayPayoutId = randomAlphanumeric(15);

0 commit comments

Comments
 (0)