Skip to content

Commit

Permalink
Merge pull request #3714 from alphagov/PP-13515-refactor_queue_msg_pa…
Browse files Browse the repository at this point in the history
…ct_test_handling

PP-13515 refactor queue msg pact tests
  • Loading branch information
SandorArpa authored Jan 23, 2025
2 parents 5284c65 + df1532b commit 7310344
Show file tree
Hide file tree
Showing 19 changed files with 75 additions and 71 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -81,17 +81,17 @@ public void fromShouldConvertEventDigestToTransactionEntity() {
assertThat(transactionEntity.getSource(), is(notNullValue()));
assertThat(transactionEntity.isLive(), is(true));
assertThat(transactionEntity.getGatewayPayoutId(), is("payout-id"));
assertThat(transactionEntity.getAgreementId(), is("an-agreement-id"));
assertThat(transactionEntity.getAgreementId(), is("an-agreement-external-id"));

JsonObject transactionDetails = JsonParser.parseString(transactionEntity.getTransactionDetails()).getAsJsonObject();
assertThat(transactionDetails.get("language").getAsString(), is("en"));
assertThat(transactionDetails.get("payment_provider").getAsString(), is("sandbox"));
assertThat(transactionDetails.get("expiry_date").getAsString(), is("11/21"));
assertThat(transactionDetails.get("address_line1").getAsString(), is("12 Rouge Avenue"));
assertThat(transactionDetails.get("address_postcode").getAsString(), is("N1 3QU"));
assertThat(transactionDetails.get("expiry_date").getAsString(), is("12/99"));
assertThat(transactionDetails.get("address_line1").getAsString(), is("125 Kingsway"));
assertThat(transactionDetails.get("address_postcode").getAsString(), is("WC2B 6NH"));
assertThat(transactionDetails.get("address_country").getAsString(), is("GB"));
assertThat(transactionDetails.get("delayed_capture").getAsBoolean(), is(false));
assertThat(transactionDetails.get("return_url").getAsString(), is("https://example.org"));
assertThat(transactionDetails.get("return_url").getAsString(), is("http://return.invalid"));
assertThat(transactionDetails.get("corporate_surcharge").getAsInt(), is(5));
assertThat(transactionDetails.get("gateway_transaction_id").getAsString(), is(eventDigest.getEventAggregate().get("gateway_transaction_id")));
assertThat(transactionDetails.get("external_metadata").getAsJsonObject().get("key").getAsString(), is("value"));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ public class CancelledByUserEventQueueConsumerIT {
private String externalId = "externalId";
private ZonedDateTime eventDate = ZonedDateTime.parse("2018-03-12T16:25:01.123456Z");
private String gatewayAccountId = "gateway_account_id";
private String gatewayTransactionId = "validGatewayTransactionId";
private String gatewayTransactionId = "gateway_transaction_id";

@Pact(provider = "connector", consumer = "ledger")
public MessagePact createCancelledByUserEventPact(MessagePactBuilder builder) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -115,7 +115,7 @@ public void test() throws JsonProcessingException {
assertThat(eventData.get("amount").asLong(), is(amount));
assertThat(eventData.get("gateway_account_id").asText(), is(gatewayAccountId));
assertThat(eventData.get("reason").asText(), is(reason));
assertThat(eventData.get("evidence_due_date").asText(), is("2022-02-14T23:59:59.000Z"));
assertThat(eventData.get("evidence_due_date").asText(), is("2022-02-14T23:59:59.000000Z"));

TransactionDao transactionDao = new TransactionDao(appRule.getJdbi(), mock(LedgerConfig.class));

Expand All @@ -129,7 +129,7 @@ public void test() throws JsonProcessingException {

Map<String, String> transactionDetails = gson.fromJson(transaction.get().getTransactionDetails(), Map.class);
assertThat(transactionDetails.get("reason"), is("duplicate"));
assertThat(transactionDetails.get("evidence_due_date"), is("2022-02-14T23:59:59.000Z"));
assertThat(transactionDetails.get("evidence_due_date"), is("2022-02-14T23:59:59.000000Z"));
}

public void setMessage(byte[] messageContents) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,7 @@ public void test() {

assertThat(transaction.isPresent(), is(true));
assertThat(transaction.get().getExternalId(), is(externalId));
assertThat(transaction.get().getTransactionDetails(), containsString("\"exemption3ds\": \"HONOURED\""));
assertThat(transaction.get().getTransactionDetails(), containsString("\"exemption3ds\": \"EXEMPTION_HONOURED\""));
}

public void setMessage(byte[] messageContents) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,7 @@ public void test() {

assertThat(transaction.isPresent(), is(true));
assertThat(transaction.get().getExternalId(), is(externalId));
assertThat(transaction.get().getTransactionDetails(), containsString("\"version_3ds\": \"1.2.1\""));
assertThat(transaction.get().getTransactionDetails(), containsString("\"version_3ds\": \"2.1.0\""));
assertThat(transaction.get().getTransactionDetails(), containsString("\"requires_3ds\": true"));
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ public class PaymentCreatedEventQueueConsumerIT {
private byte[] currentMessage;
private String externalId = "created_externalId";
private ZonedDateTime eventDate = ZonedDateTime.parse("2018-03-12T16:25:01.123456Z");
private String gatewayAccountId = "gateway_account_id";
private String gatewayAccountId = "1";
private String credentialExternalId = "credential-external-id-1";

@Pact(provider = "connector", consumer = "ledger")
Expand Down Expand Up @@ -79,18 +79,18 @@ public void test() {
assertThat(transaction.isPresent(), is(true));
assertThat(transaction.get().getExternalId(), is(externalId));
assertThat(transaction.get().getAmount(), is(1000L));
assertThat(transaction.get().getDescription(), is("a description"));
assertThat(transaction.get().getReference(), is("aref"));
assertThat(transaction.get().getDescription(), is("This is a description"));
assertThat(transaction.get().getReference(), is("This is a reference"));
assertThat(transaction.get().getGatewayAccountId(), is(gatewayAccountId));
assertThat(transaction.get().getTransactionDetails(), containsString("\"return_url\": \"https://example.org\""));
assertThat(transaction.get().getTransactionDetails(), containsString("\"return_url\": \"http://return.invalid\""));
assertThat(transaction.get().getTransactionDetails(), containsString("\"payment_provider\": \"sandbox\""));
assertThat(transaction.get().getTransactionDetails(), containsString("\"language\": \"en\""));
assertThat(transaction.get().getTransactionDetails(), containsString("\"delayed_capture\": false"));
assertThat(transaction.get().getTransactionDetails(), containsString("\"external_metadata\": {\"key\": \"value\"}"));
assertThat(transaction.get().getEmail(), is("j.doe@example.org"));
assertThat(transaction.get().getCardholderName(), is("J citizen"));
assertThat(transaction.get().getTransactionDetails(), containsString("\"address_line1\": \"12 Rouge Avenue\""));
assertThat(transaction.get().getTransactionDetails(), containsString("\"address_postcode\": \"N1 3QU\""));
assertThat(transaction.get().getEmail(), is("test@email.invalid"));
assertThat(transaction.get().getCardholderName(), is("Mr Test"));
assertThat(transaction.get().getTransactionDetails(), containsString("\"address_line1\": \"125 Kingsway\""));
assertThat(transaction.get().getTransactionDetails(), containsString("\"address_postcode\": \"WC2B 6NH\""));
assertThat(transaction.get().getTransactionDetails(), containsString("\"address_city\": \"London\""));
assertThat(transaction.get().getTransactionDetails(), containsString("\"address_country\": \"GB\""));
assertThat(transaction.get().getTransactionDetails(), containsString("\"credential_external_id\": \"" + credentialExternalId + "\""));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ public MessagePact createPaymentDetailsEnteredEventPact(MessagePactBuilder build
.withResourceExternalId(externalId)
.withEventDate(eventDate)
.withEventType(paymentDetailsEnteredEventName)
.withGatewayAccountId("I0YI1")
.withGatewayAccountId("gateway_transaction_id")
.withDefaultEventDataForEventType(paymentDetailsEnteredEventName)
.withLive(true);

Expand Down Expand Up @@ -82,11 +82,11 @@ public void test() {
assertThat(transaction.get().getCardBrand(), is("visa"));
assertThat(transaction.get().getFirstDigitsCardNumber(), is("424242"));
assertThat(transaction.get().getLastDigitsCardNumber(), is("4242"));
assertThat(transaction.get().getCardholderName(), is("J citizen"));
assertThat(transaction.get().getCardholderName(), is("Mr Test"));
assertThat(transaction.get().getTransactionDetails(), containsString("\"corporate_surcharge\": 5"));
assertThat(transaction.get().getTransactionDetails(), containsString("\"expiry_date\": \"11/21\""));
assertThat(transaction.get().getTransactionDetails(), containsString("\"address_line1\": \"12 Rouge Avenue\""));
assertThat(transaction.get().getTransactionDetails(), containsString("\"address_postcode\": \"N1 3QU\""));
assertThat(transaction.get().getTransactionDetails(), containsString("\"expiry_date\": \"12/99\""));
assertThat(transaction.get().getTransactionDetails(), containsString("\"address_line1\": \"125 Kingsway\""));
assertThat(transaction.get().getTransactionDetails(), containsString("\"address_postcode\": \"WC2B 6NH\""));
assertThat(transaction.get().getTransactionDetails(), containsString("\"address_city\": \"London\""));
assertThat(transaction.get().getTransactionDetails(), containsString("\"address_country\": \"GB\""));
assertThat(transaction.get().getTotalAmount(), is(1005L));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -82,8 +82,8 @@ public void test() {
assertThat(transaction.get().getCardBrand(), is("visa"));
assertThat(transaction.get().getFirstDigitsCardNumber(), is("424242"));
assertThat(transaction.get().getLastDigitsCardNumber(), is("4242"));
assertThat(transaction.get().getCardholderName(), is("J citizen"));
assertThat(transaction.get().getTransactionDetails(), containsString("\"expiry_date\": \"11/21\""));
assertThat(transaction.get().getCardholderName(), is("Mr Test"));
assertThat(transaction.get().getTransactionDetails(), containsString("\"expiry_date\": \"12/99\""));
}

private void setupTransaction(TransactionDao transactionDao) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ public class PaymentIncludedInPayoutEventQueueConsumerIT {

private byte[] currentMessage;
private String paymentExternalId = "payment-external-id";
private String payoutId = "po_12345";
private String payoutId = "po_1234567890";
private ZonedDateTime eventDate = ZonedDateTime.parse("2018-03-12T16:25:01.123456Z");

@Pact(provider = "connector", consumer = "ledger")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -84,22 +84,22 @@ public void test() {
assertThat(transaction.get().getCardBrand(), is("visa"));
assertThat(transaction.get().getFirstDigitsCardNumber(), is("424242"));
assertThat(transaction.get().getLastDigitsCardNumber(), is("4242"));
assertThat(transaction.get().getCardholderName(), is("J citizen"));
assertThat(transaction.get().getReference(), is("MRPC12345"));
assertThat(transaction.get().getCardholderName(), is("Mr Test"));
assertThat(transaction.get().getReference(), is("This is a reference"));
assertThat(transaction.get().getCardBrand(), is("visa"));
assertThat(transaction.get().getDescription(), is("New passport application"));
assertThat(transaction.get().getDescription(), is("This is a description"));
assertThat(transaction.get().getTransactionDetails(), containsString("\"gateway_transaction_id\": \"providerId\""));
assertThat(transaction.get().getTransactionDetails(), containsString("\"amount\": 1000"));
assertThat(transaction.get().getTransactionDetails(), containsString("\"expiry_date\": \"11/21\""));
assertThat(transaction.get().getTransactionDetails(), containsString("\"expiry_date\": \"12/99\""));
assertThat(transaction.get().getTransactionDetails(), containsString("\"status\": \"success\""));
assertThat(transaction.get().getTransactionDetails(), containsString("\"auth_code\": \"authCode\""));
assertThat(transaction.get().getTransactionDetails(), containsString("\"auth_code\": \"012345\""));
assertThat(transaction.get().getTransactionDetails(), containsString("\"processor_id\": \"processorId\""));
assertThat(transaction.get().getTransactionDetails(), containsString("\"telephone_number\": \"+447700900796\""));
assertThat(transaction.get().getTransactionDetails(), containsString("\"authorised_date\": \"2018-02-21T16:05:33Z\""));
assertThat(transaction.get().getTransactionDetails(), containsString("\"created_date\": \"2018-02-21T15:05:13Z\""));
assertThat(transaction.get().getTransactionDetails(), containsString("\"card_brand_label\": \"Visa\""));
assertThat(transaction.get().getTransactionDetails(), containsString("\"payment_provider\": \"sandbox\""));
assertThat(transaction.get().getTransactionDetails(), containsString("\"expiry_date\": \"11/21\""));
assertThat(transaction.get().getTransactionDetails(), containsString("\"expiry_date\": \"12/99\""));
assertThat(transaction.get().getTransactionDetails(), containsString("\"credential_external_id\": \"" + credentialExternalId + "\""));
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ public class PayoutPaidEventQueueConsumerIT {

private byte[] currentMessage;
private String gatewayPayoutId = "po_paid_1234567890";
private ZonedDateTime eventDate = parse("2020-05-13T18:50:00Z");
private ZonedDateTime eventDate = parse("2020-05-13T18:45:33.000000Z");
private String eventType = "PAYOUT_PAID";

@Pact(provider = "connector", consumer = "ledger")
Expand Down Expand Up @@ -72,7 +72,7 @@ public void test() {
Optional<PayoutEntity> payoutEntity = payoutDao.findByGatewayPayoutId(gatewayPayoutId);
assertThat(payoutEntity.isPresent(), is(true));
assertThat(payoutEntity.get().getGatewayPayoutId(), is(gatewayPayoutId));
assertThat(payoutEntity.get().getPaidOutDate().toString(), is("2020-05-13T18:50Z"));
assertThat(payoutEntity.get().getPaidOutDate().toString(), is("2020-05-13T18:45:33Z"));
assertThat(payoutEntity.get().getState(), is(PAID_OUT));

Map<String, Object> payoutDetails = new Gson().fromJson(payoutEntity.get().getPayoutDetails(), Map.class);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ public class RefundCreatedByUserEventQueueConsumerIT {
private QueueRefundEventFixture refundFixture = aQueueRefundEventFixture()
.withResourceType(ResourceType.REFUND)
.withEventType("REFUND_CREATED_BY_USER")
.withRefundedBy("a_user_id")
.withRefundedBy("user_external_id")
.withUserEmail("test@example.com")
.withDefaultEventDataForEventType("REFUND_CREATED_BY_USER");

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ public class RefundIncludedInPayoutEventQueueConsumerIT {

private byte[] currentMessage;
private String refundExternalId = "refund-external-id";
private String payoutId = "po_12345";
private String payoutId = "po_1234567890";
private ZonedDateTime eventDate = ZonedDateTime.parse("2018-03-12T16:25:01.123456Z");
private QueueRefundEventFixture refundFixture;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -218,18 +218,18 @@ public void shouldHandleRefundEvent() throws InterruptedException {

Optional<TransactionEntity> mayBeRefund = transactionDao.findTransactionByExternalId(resourceExternalId);
TransactionEntity refund = mayBeRefund.get();
assertThat(refund.getCardholderName(), is("J citizen"));
assertThat(refund.getEmail(), is("j.doe@example.org"));
assertThat(refund.getCardholderName(), is("Mr Test"));
assertThat(refund.getEmail(), is("test@email.invalid"));
assertThat(refund.getCardBrand(), is("visa"));
assertThat(refund.getDescription(), is("a description"));
assertThat(refund.getDescription(), is("This is a description"));
assertThat(refund.getLastDigitsCardNumber(), is("4242"));
assertThat(refund.getFirstDigitsCardNumber(), is("424242"));
assertThat(refund.getReference(), is("aref"));
assertThat(refund.getReference(), is("This is a reference"));
Map<String, Object> transactionDetails = new Gson().fromJson(refund.getTransactionDetails(), Map.class);
Map<String, String> paymentDetails = (Map<String, String>) transactionDetails.get("payment_details");

assertThat(paymentDetails.get("card_brand_label"), is("Visa"));
assertThat(paymentDetails.get("expiry_date"), is("11/21"));
assertThat(paymentDetails.get("expiry_date"), is("12/99"));
assertThat(paymentDetails.get("card_type"), is("DEBIT"));
}

Expand Down Expand Up @@ -416,13 +416,13 @@ public void shouldHandleDisputeTypeEvent() throws InterruptedException, JsonProc
assertThat(dispute, hasEntry("fee", null));
assertThat(dispute, hasEntry("net_amount", null));

assertThat(dispute, hasEntry("cardholder_name", "J citizen"));
assertThat(dispute, hasEntry("email", "j.doe@example.org"));
assertThat(dispute, hasEntry("cardholder_name", "Mr Test"));
assertThat(dispute, hasEntry("email", "test@email.invalid"));
assertThat(dispute, hasEntry("card_brand", "visa"));
assertThat(dispute, hasEntry("description", "a description"));
assertThat(dispute, hasEntry("description", "This is a description"));
assertThat(dispute, hasEntry("last_digits_card_number", "4242"));
assertThat(dispute, hasEntry("first_digits_card_number", "424242"));
assertThat(dispute, hasEntry("reference", "aref"));
assertThat(dispute, hasEntry("reference", "This is a reference"));
}

@Test
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,7 @@ public QueueDisputeEventFixture withDefaultEventDataForEventType(String eventTyp
.put("gateway_account_id", "a-gateway-account-id")
.put("amount", 6500)
.put("reason", "duplicate")
.put("evidence_due_date", "2022-02-14T23:59:59.000Z")
.put("evidence_due_date", "2022-02-14T23:59:59.000000Z")
.build());
break;
case "DISPUTE_LOST":
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,11 @@ private static PactDslJsonBody getNestedPact(JsonObject eventData) {
} else if (value.isBoolean()) {
dslJsonBody.booleanType(e.getKey(), value.getAsBoolean());
} else {
dslJsonBody.stringType(e.getKey(), value.getAsString());
if (e.getKey().contains("id") || e.getKey().contains("date")) {
dslJsonBody.stringType(e.getKey(), value.getAsString());
} else {
dslJsonBody.stringValue(e.getKey(), value.getAsString());
}
}
} else if (e.getValue().isJsonArray()) {
// We're currently only adding a single example from an array to the pact, and then in the
Expand Down
Loading

0 comments on commit 7310344

Please sign in to comment.