From 2f21e930e2bc7f5e9a27f0df986d29bec8f6f0a5 Mon Sep 17 00:00:00 2001 From: Chris Eager Date: Fri, 2 Dec 2022 12:14:38 -0600 Subject: [PATCH] Add `minimum` one-time donation amont to validation error map --- .../controllers/SubscriptionController.java | 4 +++- .../SubscriptionControllerTest.java | 20 +++++++++++++------ 2 files changed, 17 insertions(+), 7 deletions(-) diff --git a/service/src/main/java/org/whispersystems/textsecuregcm/controllers/SubscriptionController.java b/service/src/main/java/org/whispersystems/textsecuregcm/controllers/SubscriptionController.java index 1a24ed0f8..58a53df5e 100644 --- a/service/src/main/java/org/whispersystems/textsecuregcm/controllers/SubscriptionController.java +++ b/service/src/main/java/org/whispersystems/textsecuregcm/controllers/SubscriptionController.java @@ -777,7 +777,9 @@ public class SubscriptionController { minCurrencyAmountMajorUnits); if (minCurrencyAmountMinorUnits.compareTo(amount) > 0) { throw new BadRequestException(Response.status(Status.BAD_REQUEST) - .entity(Map.of("error", "amount_below_currency_minimum")).build()); + .entity(Map.of( + "error", "amount_below_currency_minimum", + "minimum", minCurrencyAmountMajorUnits.toString())).build()); } } diff --git a/service/src/test/java/org/whispersystems/textsecuregcm/controllers/SubscriptionControllerTest.java b/service/src/test/java/org/whispersystems/textsecuregcm/controllers/SubscriptionControllerTest.java index 41a0a62a2..c4d9efe7f 100644 --- a/service/src/test/java/org/whispersystems/textsecuregcm/controllers/SubscriptionControllerTest.java +++ b/service/src/test/java/org/whispersystems/textsecuregcm/controllers/SubscriptionControllerTest.java @@ -128,16 +128,24 @@ class SubscriptionControllerTest { @Test void testCreateBoostPaymentIntentAmountBelowCurrencyMinimum() { when(STRIPE_MANAGER.convertConfiguredAmountToStripeAmount(any(), any())).thenReturn(new BigDecimal(250)); + when(STRIPE_MANAGER.supportsCurrency("usd")).thenReturn(true); final Response response = RESOURCE_EXTENSION.target("/v1/subscription/boost/create") .request() .post(Entity.json(""" - { - "currency": "USD", - "amount": 249, - "level": null - } - """)); + { + "currency": "USD", + "amount": 249, + "level": null + } + """)); assertThat(response.getStatus()).isEqualTo(400); + assertThat(response.hasEntity()).isTrue(); + assertThat(response.readEntity(Map.class)) + .isNotNull() + .containsAllEntriesOf(Map.of( + "error", "amount_below_currency_minimum", + "minimum", "2.50" + )); } @Test