From bbde93a3c74ba2811d1771d998a9bfe2ea257eb0 Mon Sep 17 00:00:00 2001 From: Ehren Kret Date: Wed, 13 Oct 2021 11:46:20 -0500 Subject: [PATCH] Enable unwrapping of CompletionStage --- .../textsecuregcm/WhisperServerService.java | 7 +- .../SubscriptionControllerTest.java | 97 +++++++++++++++++++ 2 files changed, 102 insertions(+), 2 deletions(-) create mode 100644 service/src/test/java/org/whispersystems/textsecuregcm/controllers/SubscriptionControllerTest.java diff --git a/service/src/main/java/org/whispersystems/textsecuregcm/WhisperServerService.java b/service/src/main/java/org/whispersystems/textsecuregcm/WhisperServerService.java index f1fb4bde3..a9c1415e9 100644 --- a/service/src/main/java/org/whispersystems/textsecuregcm/WhisperServerService.java +++ b/service/src/main/java/org/whispersystems/textsecuregcm/WhisperServerService.java @@ -53,6 +53,7 @@ import javax.servlet.DispatcherType; import javax.servlet.FilterRegistration; import javax.servlet.ServletRegistration; import org.eclipse.jetty.servlets.CrossOriginFilter; +import org.glassfish.jersey.server.ServerProperties; import org.jdbi.v3.core.Jdbi; import org.signal.zkgroup.ServerSecretParams; import org.signal.zkgroup.auth.ServerZkAuthOperations; @@ -675,11 +676,13 @@ public class WhisperServerService extends Application(Set.of( + AuthenticatedAccount.class, DisabledPermittedAuthenticatedAccount.class))) + .setMapper(SystemMapper.getMapper()) + .setTestContainerFactory(new GrizzlyWebTestContainerFactory()) + .addResource(SUBSCRIPTION_CONTROLLER) + .build(); + + @AfterEach + void tearDown() { + reset(CLOCK, SUBSCRIPTION_CONFIG, SUBSCRIPTION_MANAGER, STRIPE_MANAGER, ZK_OPS, ISSUED_RECEIPTS_MANAGER); + } + + @Test + void getLevels() { + when(SUBSCRIPTION_CONFIG.getLevels()).thenReturn(Map.of( + 1L, new SubscriptionLevelConfiguration("B1", "P1", Map.of("USD", new SubscriptionPriceConfiguration("R1", BigDecimal.valueOf(100)))), + 2L, new SubscriptionLevelConfiguration("B2", "P2", Map.of("USD", new SubscriptionPriceConfiguration("R2", BigDecimal.valueOf(200)))), + 3L, new SubscriptionLevelConfiguration("B3", "P3", Map.of("USD", new SubscriptionPriceConfiguration("R3", BigDecimal.valueOf(300)))) + )); + + GetLevelsResponse response = RESOURCE_EXTENSION.target("/v1/subscription/levels") + .request() + .get(GetLevelsResponse.class); + + assertThat(response.getLevels()).containsKeys(1L, 2L, 3L).satisfies(longLevelMap -> { + assertThat(longLevelMap).extractingByKey(1L).satisfies(level -> { + assertThat(level.getBadgeId()).isEqualTo("B1"); + assertThat(level.getCurrencies()).containsKeys("USD").extractingByKey("USD").satisfies(price -> { + assertThat(price.getAmount()).isEqualTo("100"); + }); + }); + assertThat(longLevelMap).extractingByKey(2L).satisfies(level -> { + assertThat(level.getBadgeId()).isEqualTo("B2"); + assertThat(level.getCurrencies()).containsKeys("USD").extractingByKey("USD").satisfies(price -> { + assertThat(price.getAmount()).isEqualTo("200"); + }); + }); + assertThat(longLevelMap).extractingByKey(3L).satisfies(level -> { + assertThat(level.getBadgeId()).isEqualTo("B3"); + assertThat(level.getCurrencies()).containsKeys("USD").extractingByKey("USD").satisfies(price -> { + assertThat(price.getAmount()).isEqualTo("300"); + }); + }); + }); + } +}