Skip to content

Commit

Permalink
[ACL-174] Improve retry payments acceptance tests (#303)
Browse files Browse the repository at this point in the history
  • Loading branch information
tl-luca-baggi authored Aug 1, 2024
1 parent f48eb82 commit c5e057a
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 7 deletions.
2 changes: 1 addition & 1 deletion build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -112,7 +112,7 @@ dependencies {

// Mocking libraries
testImplementation group: 'org.mockito', name: 'mockito-core', version: '5.12.0'
testImplementation group: 'org.wiremock', name: 'wiremock', version: '3.9.0'
testImplementation group: 'org.wiremock', name: 'wiremock', version: '3.9.1'

// Wait test utility
testImplementation group: 'org.awaitility', name: 'awaitility', version: '4.2.1'
Expand Down
2 changes: 1 addition & 1 deletion gradle.properties
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
# Main properties
group=com.truelayer
archivesBaseName=truelayer-java
version=13.1.0
version=13.1.1

# Artifacts properties
sonatype_repository_url=https://s01.oss.sonatype.org/service/local/
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -413,6 +413,9 @@ public void shouldReturnAttemptFailedPaymentStatusIfAuthorizationIsRejectedWithR
.resource(HeadlessResource.PAYMENTS)
.build());

// sometimes status change event has a bit of delay
waitForPaymentStatusUpdate(createPaymentResponse.getData().getId(), Status.ATTEMPT_FAILED);

// get by id
ApiResponse<PaymentDetail> getPaymentByIdResponse = tlClient.payments()
.getPayment(createPaymentResponse.getData().getId())
Expand Down Expand Up @@ -467,7 +470,7 @@ public void shouldCreateAPaymentRefundAndGetRefundDetails() {
.resource(HeadlessResource.PAYMENTS)
.build());

waitForPaymentToBeSettled(paymentId);
waitForPaymentStatusUpdate(paymentId, Status.SETTLED);

// Create full payment refund
CreatePaymentRefundRequest createPaymentRefundRequest = CreatePaymentRefundRequest.builder()
Expand Down Expand Up @@ -636,16 +639,15 @@ private void assertCanBrowseLink(URI link) {
assertTrue(hppResponse.isSuccessful());
}

private void waitForPaymentToBeSettled(String paymentId) {
private void waitForPaymentStatusUpdate(String paymentId, Status paymentStatus) {
await().with()
.conditionEvaluationListener(new ConditionEvaluationListener() {
@Override
public void conditionEvaluated(EvaluatedCondition condition) {}

@Override
public void onTimeout(TimeoutEvent timeoutEvent) {
Logger.warn(
"Payment is taking too much time to settle, status polling timed out. Refunds test cannot be evaluated without a settled payment");
Logger.warn("Payment is taking too much time to update its status, status polling timed out.");
}
})
.pollInterval(1, TimeUnit.SECONDS)
Expand All @@ -655,7 +657,7 @@ public void onTimeout(TimeoutEvent timeoutEvent) {
ApiResponse<PaymentDetail> getPaymentResponse =
tlClient.payments().getPayment(paymentId).get();
assertNotError(getPaymentResponse);
return getPaymentResponse.getData().getStatus().equals(Status.SETTLED);
return getPaymentResponse.getData().getStatus().equals(paymentStatus);
});
}

Expand Down

0 comments on commit c5e057a

Please sign in to comment.