From d10a132b0c5bf75b069265159587ae0c95fbaabc Mon Sep 17 00:00:00 2001 From: Jon Chambers Date: Tue, 19 Sep 2023 12:51:50 -0400 Subject: [PATCH] Remove unused methods in `SubscriptionController` --- .../controllers/SubscriptionController.java | 85 ------------------- .../SubscriptionControllerTest.java | 68 --------------- 2 files changed, 153 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 ba6530293..048859816 100644 --- a/service/src/main/java/org/whispersystems/textsecuregcm/controllers/SubscriptionController.java +++ b/service/src/main/java/org/whispersystems/textsecuregcm/controllers/SubscriptionController.java @@ -568,50 +568,6 @@ public class SubscriptionController { .thenApply(unused -> Response.ok(new SetSubscriptionLevelSuccessResponse(level)).build()); } - public static class GetLevelsResponse { - - public static class Level { - - private final String name; - private final Badge badge; - private final Map currencies; - - @JsonCreator - public Level( - @JsonProperty("name") String name, - @JsonProperty("badge") Badge badge, - @JsonProperty("currencies") Map currencies) { - this.name = name; - this.badge = badge; - this.currencies = currencies; - } - - public String getName() { - return name; - } - - public Badge getBadge() { - return badge; - } - - public Map getCurrencies() { - return currencies; - } - } - - private final Map levels; - - @JsonCreator - public GetLevelsResponse( - @JsonProperty("levels") Map levels) { - this.levels = levels; - } - - public Map getLevels() { - return levels; - } - } - /** * Comprehensive configuration for subscriptions and one-time donations * @@ -658,25 +614,6 @@ public class SubscriptionController { }); } - @GET - @Path("/levels") - @Produces(MediaType.APPLICATION_JSON) - @Deprecated // use /configuration - public CompletableFuture getLevels(@Context ContainerRequestContext containerRequestContext) { - return CompletableFuture.supplyAsync(() -> { - List acceptableLanguages = getAcceptableLanguagesForRequest(containerRequestContext); - GetLevelsResponse getLevelsResponse = new GetLevelsResponse( - subscriptionConfiguration.getLevels().entrySet().stream().collect(Collectors.toMap(Entry::getKey, - entry -> new GetLevelsResponse.Level( - levelTranslator.translate(acceptableLanguages, entry.getValue().getBadge()), - badgeTranslator.translate(acceptableLanguages, entry.getValue().getBadge()), - entry.getValue().getPrices().entrySet().stream().collect( - Collectors.toMap(levelEntry -> levelEntry.getKey().toUpperCase(Locale.ROOT), - levelEntry -> levelEntry.getValue().amount())))))); - return Response.ok(getLevelsResponse).build(); - }); - } - public static class GetBoostBadgesResponse { public static class Level { private final PurchasableBadge badge; @@ -727,28 +664,6 @@ public class SubscriptionController { }); } - @GET - @Path("/boost/amounts") - @Produces(MediaType.APPLICATION_JSON) - @Deprecated // use /configuration - public CompletableFuture getBoostAmounts() { - return CompletableFuture.supplyAsync(() -> Response.ok( - oneTimeDonationConfiguration.currencies().entrySet().stream().collect( - Collectors.toMap(entry -> entry.getKey().toUpperCase(Locale.ROOT), entry -> entry.getValue().boosts()))) - .build()); - } - - @GET - @Path("/boost/amounts/gift") - @Produces(MediaType.APPLICATION_JSON) - @Deprecated // use /configuration - public CompletableFuture getGiftAmounts() { - return CompletableFuture.supplyAsync(() -> Response.ok( - oneTimeDonationConfiguration.currencies().entrySet().stream().collect( - Collectors.toMap(entry -> entry.getKey().toUpperCase(Locale.ROOT), entry -> entry.getValue().gift()))) - .build()); - } - public static class CreateBoostRequest { @NotEmpty 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 4f6d5c086..298229f8f 100644 --- a/service/src/test/java/org/whispersystems/textsecuregcm/controllers/SubscriptionControllerTest.java +++ b/service/src/test/java/org/whispersystems/textsecuregcm/controllers/SubscriptionControllerTest.java @@ -59,7 +59,6 @@ import org.whispersystems.textsecuregcm.badges.BadgeTranslator; import org.whispersystems.textsecuregcm.badges.LevelTranslator; import org.whispersystems.textsecuregcm.configuration.OneTimeDonationConfiguration; import org.whispersystems.textsecuregcm.configuration.SubscriptionConfiguration; -import org.whispersystems.textsecuregcm.controllers.SubscriptionController.GetLevelsResponse; import org.whispersystems.textsecuregcm.controllers.SubscriptionController.GetSubscriptionConfigurationResponse; import org.whispersystems.textsecuregcm.entities.Badge; import org.whispersystems.textsecuregcm.entities.BadgeSvg; @@ -780,73 +779,6 @@ class SubscriptionControllerTest { }); } - @Test - void testGetBoostAmounts() { - final Map boostAmounts = RESOURCE_EXTENSION.target("/v1/subscription/boost/amounts") - .request() - .get(Map.class); - - assertThat(boostAmounts).isEqualTo(Map.of( - "USD", List.of(5.50, 6, 7, 8, 9, 10), - "JPY", List.of(550, 600, 700, 800, 900, 1000), - "BIF", List.of(5500, 6000, 7000, 8000, 9000, 10000) - )); - - final Map giftAmounts = RESOURCE_EXTENSION.target("/v1/subscription/boost/amounts/gift") - .request() - .get(Map.class); - - assertThat(giftAmounts).isEqualTo(Map.of( - "USD", 20, - "JPY", 2000, - "BIF", 20000 - )); - } - - @Test - void getLevels() { - when(BADGE_TRANSLATOR.translate(any(), eq("B1"))).thenReturn(new Badge("B1", "cat1", "name1", "desc1", - List.of("l", "m", "h", "x", "xx", "xxx"), "SVG", - List.of(new BadgeSvg("sl", "sd"), new BadgeSvg("ml", "md"), new BadgeSvg("ll", "ld")))); - when(BADGE_TRANSLATOR.translate(any(), eq("B2"))).thenReturn(new Badge("B2", "cat2", "name2", "desc2", - List.of("l", "m", "h", "x", "xx", "xxx"), "SVG", - List.of(new BadgeSvg("sl", "sd"), new BadgeSvg("ml", "md"), new BadgeSvg("ll", "ld")))); - when(BADGE_TRANSLATOR.translate(any(), eq("B3"))).thenReturn(new Badge("B3", "cat3", "name3", "desc3", - List.of("l", "m", "h", "x", "xx", "xxx"), "SVG", - List.of(new BadgeSvg("sl", "sd"), new BadgeSvg("ml", "md"), new BadgeSvg("ll", "ld")))); - when(LEVEL_TRANSLATOR.translate(any(), eq("B1"))).thenReturn("Z1"); - when(LEVEL_TRANSLATOR.translate(any(), eq("B2"))).thenReturn("Z2"); - when(LEVEL_TRANSLATOR.translate(any(), eq("B3"))).thenReturn("Z3"); - - GetLevelsResponse response = RESOURCE_EXTENSION.target("/v1/subscription/levels") - .request() - .get(GetLevelsResponse.class); - - assertThat(response.getLevels()).containsKeys(5L, 15L, 35L).satisfies(longLevelMap -> { - assertThat(longLevelMap).extractingByKey(5L).satisfies(level -> { - assertThat(level.getName()).isEqualTo("Z1"); - assertThat(level.getBadge().getId()).isEqualTo("B1"); - assertThat(level.getCurrencies()).containsKeys("USD").extractingByKey("USD").satisfies(price -> { - assertThat(price).isEqualTo("5"); - }); - }); - assertThat(longLevelMap).extractingByKey(15L).satisfies(level -> { - assertThat(level.getName()).isEqualTo("Z2"); - assertThat(level.getBadge().getId()).isEqualTo("B2"); - assertThat(level.getCurrencies()).containsKeys("USD").extractingByKey("USD").satisfies(price -> { - assertThat(price).isEqualTo("15"); - }); - }); - assertThat(longLevelMap).extractingByKey(35L).satisfies(level -> { - assertThat(level.getName()).isEqualTo("Z3"); - assertThat(level.getBadge().getId()).isEqualTo("B3"); - assertThat(level.getCurrencies()).containsKeys("USD").extractingByKey("USD").satisfies(price -> { - assertThat(price).isEqualTo("35"); - }); - }); - }); - } - /** * Encapsulates {@code static} configuration, to keep the class header simpler and avoid illegal forward references */