Move some level configuration to an enum

This commit is contained in:
Ravi Khadiwala authored and ravi-signal committed 2026-08-07 14:39:13 -05:00
1 parent 3e5ccb82de
commit 1ebb4177fe
37 files changed
+195 -169

No files matched your search

@@ -61,7 +61,6 @@ import org.whispersystems.textsecuregcm.util.TestRandomUtil;
class DeviceCheckControllerTest {
private final static Duration REDEMPTION_DURATION = Duration.ofDays(5);
private final static long REDEMPTION_LEVEL = 201L;
private static final AccountsManager accountsManager = mock(AccountsManager.class);
private final static BackupAuthManager backupAuthManager = mock(BackupAuthManager.class);
private final static AppleDeviceCheckManager appleDeviceCheckManager = mock(AppleDeviceCheckManager.class);
@@ -78,7 +77,7 @@ class DeviceCheckControllerTest {
.setMapper(SystemMapper.jsonMapper())
.setTestContainerFactory(new GrizzlyWebTestContainerFactory())
.addResource(new DeviceCheckController(clock, accountsManager, backupAuthManager, appleDeviceCheckManager, rateLimiters,
REDEMPTION_LEVEL, REDEMPTION_DURATION))
REDEMPTION_DURATION))
.build();
@BeforeEach
@@ -55,6 +55,7 @@ import org.whispersystems.textsecuregcm.storage.DonationPermits;
import org.whispersystems.textsecuregcm.storage.DonationPermitsManager;
import org.whispersystems.textsecuregcm.storage.RedeemedReceiptsManager;
import org.whispersystems.textsecuregcm.subscriptions.ReceiptCredentialPresentationFactory;
import org.whispersystems.textsecuregcm.subscriptions.ReceiptLevel;
import org.whispersystems.textsecuregcm.tests.util.AccountsHelper;
import org.whispersystems.textsecuregcm.tests.util.AuthHelper;
import org.whispersystems.textsecuregcm.util.TestClock;
@@ -75,7 +76,7 @@ class DonationControllerTest {
List.of(new BadgeSvg("sl", "sd"), new BadgeSvg("ml", "md"), new BadgeSvg("ll", "ld"))),
new BadgeConfiguration("TEST3", "testing", List.of("l", "m", "h", "x", "xx", "xxx"), "SVG",
List.of(new BadgeSvg("sl", "sd"), new BadgeSvg("ml", "md"), new BadgeSvg("ll", "ld")))),
Map.of(1L, "TEST1", 2L, "TEST2", 3L, "TEST3"));
Map.of(ReceiptLevel.ONE_TIME_DONATION, "TEST1", ReceiptLevel.ONE_TIME_GIFT_DONATION, "TEST2", ReceiptLevel.SUBSCRIPTION_HIGH, "TEST3"));
}
private final TestClock clock = TestClock.pinned(Instant.ofEpochSecond(nowEpochSeconds));
@@ -54,6 +54,7 @@ import org.whispersystems.textsecuregcm.subscriptions.PaymentDetails;
import org.whispersystems.textsecuregcm.subscriptions.PaymentMethod;
import org.whispersystems.textsecuregcm.subscriptions.PaymentProvider;
import org.whispersystems.textsecuregcm.subscriptions.PaymentStatus;
import org.whispersystems.textsecuregcm.subscriptions.ReceiptLevel;
import org.whispersystems.textsecuregcm.subscriptions.SubscriptionInvalidAmountException;
import org.whispersystems.textsecuregcm.subscriptions.SubscriptionProcessorException;
import org.whispersystems.textsecuregcm.tests.util.AuthHelper;
@@ -342,7 +343,7 @@ class OneTimeDonationControllerTest extends AbstractV1SubscriptionControllerTest
when(ONE_TIME_DONATIONS_MANAGER.getPaidAt(any(), anyString(), any())).thenReturn(Instant.now());
when(STRIPE_MANAGER.claimOneTimePurchase(any())).thenReturn(Optional.of(new PaymentDetails(
"id",
ONETIME_CONFIG.boost().level(),
ReceiptLevel.ONE_TIME_DONATION,
PaymentStatus.SUCCEEDED,
Instant.now(),
null)));
@@ -111,6 +111,7 @@ import org.whispersystems.textsecuregcm.storage.DeviceCapability;
import org.whispersystems.textsecuregcm.storage.DynamicConfigurationManager;
import org.whispersystems.textsecuregcm.storage.ProfilesManager;
import org.whispersystems.textsecuregcm.storage.VersionedProfileV1;
import org.whispersystems.textsecuregcm.subscriptions.ReceiptLevel;
import org.whispersystems.textsecuregcm.tests.util.AccountsHelper;
import org.whispersystems.textsecuregcm.tests.util.AuthHelper;
import org.whispersystems.textsecuregcm.tests.util.ProfileTestHelper;
@@ -186,7 +187,10 @@ class ProfileControllerTest {
new BadgeConfiguration("TEST1", "testing", List.of("l", "m", "h", "x", "xx", "xxx"), "SVG", List.of(new BadgeSvg("sl", "sd"), new BadgeSvg("ml", "md"), new BadgeSvg("ll", "ld"))),
new BadgeConfiguration("TEST2", "testing", List.of("l", "m", "h", "x", "xx", "xxx"), "SVG", List.of(new BadgeSvg("sl", "sd"), new BadgeSvg("ml", "md"), new BadgeSvg("ll", "ld"))),
new BadgeConfiguration("TEST3", "testing", List.of("l", "m", "h", "x", "xx", "xxx"), "SVG", List.of(new BadgeSvg("sl", "sd"), new BadgeSvg("ml", "md"), new BadgeSvg("ll", "ld")))
), Map.of(1L, "TEST1", 2L, "TEST2", 3L, "TEST3")),
), Map.of(
ReceiptLevel.ONE_TIME_DONATION, "TEST1",
ReceiptLevel.SUBSCRIPTION_MEDIUM, "TEST2",
ReceiptLevel.SUBSCRIPTION_HIGH, "TEST3")),
postPolicyGenerator,
serverSecretParams,
zkProfileOperations,
@@ -81,6 +81,7 @@ import org.whispersystems.textsecuregcm.subscriptions.LevelConfiguration;
import org.whispersystems.textsecuregcm.subscriptions.PaymentMethod;
import org.whispersystems.textsecuregcm.subscriptions.PaymentProvider;
import org.whispersystems.textsecuregcm.subscriptions.ProcessorCustomer;
import org.whispersystems.textsecuregcm.subscriptions.ReceiptLevel;
import org.whispersystems.textsecuregcm.subscriptions.SubscriptionChargeFailurePaymentRequiredException;
import org.whispersystems.textsecuregcm.subscriptions.SubscriptionException;
import org.whispersystems.textsecuregcm.subscriptions.SubscriptionInvalidArgumentsException;
@@ -111,7 +112,7 @@ class SubscriptionControllerTest extends AbstractV1SubscriptionControllerTest {
private static final BadgeTranslator BADGE_TRANSLATOR = mock(BadgeTranslator.class);
private static final BankMandateTranslator BANK_MANDATE_TRANSLATOR = mock(BankMandateTranslator.class);
private static final LoginPurchaseConfiguration LOGIN_PURCHASE_CONFIG =
new LoginPurchaseConfiguration(300L, "testLoginPlayProductId", "testLoginAppStoreProductId");
new LoginPurchaseConfiguration("testLoginPlayProductId", "testLoginAppStoreProductId");
private final static SubscriptionController SUBSCRIPTION_CONTROLLER = new SubscriptionController(CLOCK,
SUBSCRIPTION_CONFIG, ONETIME_CONFIG, LOGIN_PURCHASE_CONFIG,
new SubscriptionManager(SUBSCRIPTIONS, List.of(STRIPE_MANAGER, BRAINTREE_MANAGER, PLAY_MANAGER, APPSTORE_MANAGER),
@@ -1077,7 +1078,7 @@ class SubscriptionControllerTest extends AbstractV1SubscriptionControllerTest {
});
assertThat(response.backup().freeTierMediaDays()).isEqualTo(30);
assertThat(response.login().level()).isEqualTo(LOGIN_PURCHASE_CONFIG.level());
assertThat(response.login().level()).isEqualTo(ReceiptLevel.LOGIN.getValue());
assertThat(response.login().playProductId()).isEqualTo(LOGIN_PURCHASE_CONFIG.playProductId());
assertThat(response.login().appStoreProductId()).isEqualTo(LOGIN_PURCHASE_CONFIG.appStoreProductId());
@@ -48,6 +48,7 @@ import org.whispersystems.textsecuregcm.storage.DonationPermits;
import org.whispersystems.textsecuregcm.storage.DonationPermitsManager;
import org.whispersystems.textsecuregcm.storage.RedeemedReceiptsManager;
import org.whispersystems.textsecuregcm.subscriptions.ReceiptCredentialPresentationFactory;
import org.whispersystems.textsecuregcm.subscriptions.ReceiptLevel;
import org.whispersystems.textsecuregcm.tests.util.AccountsHelper;
import org.whispersystems.textsecuregcm.util.TestClock;
import org.whispersystems.textsecuregcm.util.TestRandomUtil;
@@ -95,8 +96,8 @@ class DonationsGrpcServiceTest extends SimpleBaseGrpcTest<DonationsGrpcService,
} catch (final InvalidInputException e) {
throw new RuntimeException(e);
}
when(receiptCredentialPresentation.getReceiptLevel()).thenReturn(1L);
when(badgesConfiguration.getReceiptLevels()).thenReturn(Map.of(1L, "testBadge"));
when(receiptCredentialPresentation.getReceiptLevel()).thenReturn(ReceiptLevel.ONE_TIME_DONATION.getValue());
when(badgesConfiguration.getReceiptLevels()).thenReturn(Map.of(ReceiptLevel.ONE_TIME_DONATION, "testBadge"));
when(receiptCredentialPresentation.getReceiptExpirationTime()).thenReturn(EXPIRATION_TIME_EPOCH_SECONDS);
when(receiptCredentialPresentation.getReceiptSerial()).thenReturn(receiptSerial);
@@ -64,6 +64,7 @@ import org.whispersystems.textsecuregcm.subscriptions.ChargeFailure;
import org.whispersystems.textsecuregcm.subscriptions.PayPalDonationsTranslator;
import org.whispersystems.textsecuregcm.subscriptions.PaymentDetails;
import org.whispersystems.textsecuregcm.subscriptions.PaymentStatus;
import org.whispersystems.textsecuregcm.subscriptions.ReceiptLevel;
import org.whispersystems.textsecuregcm.subscriptions.StripeManager;
import org.whispersystems.textsecuregcm.subscriptions.SubscriptionInvalidAmountException;
import org.whispersystems.textsecuregcm.subscriptions.SubscriptionProcessorException;
@@ -306,7 +307,7 @@ public class OneTimeDonationsGrpcServiceTest extends
when(oneTimeDonationsManager.getPaidAt(any(), anyString(), any())).thenReturn(clock.instant());
when(stripeManager.claimOneTimePurchase(any())).thenReturn(
Optional.of(new PaymentDetails("id", oneTimeDonationConfiguration.boost().level(),
Optional.of(new PaymentDetails("id", ReceiptLevel.ONE_TIME_DONATION,
PaymentStatus.SUCCEEDED, clock.instant(), null)));
doThrow(WriteConflictException.class).when(issuedReceiptsManager)
.recordOneTimeIssuance(any(), any(), any(), any());
@@ -26,6 +26,7 @@ import org.whispersystems.textsecuregcm.configuration.LoginPurchaseConfiguration
import org.whispersystems.textsecuregcm.configuration.OneTimeDonationConfiguration;
import org.whispersystems.textsecuregcm.configuration.SubscriptionConfiguration;
import org.whispersystems.textsecuregcm.subscriptions.BraintreeManager;
import org.whispersystems.textsecuregcm.subscriptions.ReceiptLevel;
import org.whispersystems.textsecuregcm.subscriptions.StripeManager;
import org.whispersystems.textsecuregcm.tests.util.SubscriptionConfigTestHelper;
@@ -39,7 +40,7 @@ public class ProductConfigurationGrpcServiceTest extends
SubscriptionConfigTestHelper.getOneTimeConfig();
private static final LoginPurchaseConfiguration LOGIN_PURCHASE_CONFIGURATION =
new LoginPurchaseConfiguration(300L, "testLoginPlayProductId", "testLoginAppStoreProductId");
new LoginPurchaseConfiguration("testLoginPlayProductId", "testLoginAppStoreProductId");
@Mock
private StripeManager stripeManager;
@@ -132,7 +133,7 @@ public class ProductConfigurationGrpcServiceTest extends
assertEquals("GIFT", configuration.getBadgeLevelsOrThrow(100L).getBadgeId());
assertTrue(configuration.getBadgeLevelsOrThrow(100L).getBadgeDurationSeconds() > 0);
assertEquals(LOGIN_PURCHASE_CONFIGURATION.level(), configuration.getLogin().getLevel());
assertEquals(ReceiptLevel.LOGIN.getValue(), configuration.getLogin().getLevel());
assertEquals(LOGIN_PURCHASE_CONFIGURATION.playProductId(), configuration.getLogin().getPlayProductId());
assertEquals(LOGIN_PURCHASE_CONFIGURATION.appStoreProductId(), configuration.getLogin().getAppStoreProductId());
}
@@ -103,6 +103,7 @@ import org.whispersystems.textsecuregcm.storage.ProfilesManager;
import org.whispersystems.textsecuregcm.storage.VersionedProfile;
import org.whispersystems.textsecuregcm.storage.VersionedProfileV1;
import org.whispersystems.textsecuregcm.storage.WriteConflictException;
import org.whispersystems.textsecuregcm.subscriptions.ReceiptLevel;
import org.whispersystems.textsecuregcm.tests.util.AuthHelper;
import org.whispersystems.textsecuregcm.tests.util.ProfileTestHelper;
import org.whispersystems.textsecuregcm.util.MockUtils;
@@ -167,7 +168,7 @@ public class ProfileGrpcServiceTest extends SimpleBaseGrpcTest<ProfileGrpcServic
new BadgeSvg("ll", "ld")
)
)),
Map.of(1L, "TEST1", 2L, "TEST2", 3L, "TEST3")
Map.of(ReceiptLevel.ONE_TIME_DONATION, "TEST1", ReceiptLevel.ONE_TIME_GIFT_DONATION, "TEST2", ReceiptLevel.SUBSCRIPTION_HIGH, "TEST3")
);
final RateLimiters rateLimiters = mock(RateLimiters.class);
final String phoneNumber = PhoneNumberUtil.getInstance().format(
@@ -41,13 +41,13 @@ import org.whispersystems.textsecuregcm.controllers.RateLimitExceededException;
class AppleAppStoreManagerTest {
private final static long LEVEL = 123L;
private final static String ORIGINAL_TX_ID = "originalTxIdTest";
private final static String TRANSACTION_ID = "txIdTest";
private final static String SUBSCRIPTION_GROUP_ID = "subscriptionGroupIdTest";
private final static String SIGNED_RENEWAL_INFO = "signedRenewalInfoTest";
private final static String SIGNED_TX_INFO = "signedRenewalInfoTest";
private final static String PRODUCT_ID = "productIdTest";
private final static String SUBSCRIPTION_PRODUCT_ID = "subscriptionProductIdTest";
private final static String ONE_TIME_PRODUCT_ID = "oneTimeProductIdTest";
private final static String WEB_ORDER_LINE_ITEM = "webOrderLineItemTest";
private final AppStoreServerAPIClient apiClient = mock(AppStoreServerAPIClient.class);
@@ -57,10 +57,11 @@ class AppleAppStoreManagerTest {
@BeforeEach
public void setup() {
reset(apiClient, signedDataVerifier);
appleAppStoreManager = new AppleAppStoreManager(new AppleAppStoreClient(Environment.PRODUCTION,
signedDataVerifier, apiClient,
signedDataVerifier, apiClient, null),
SUBSCRIPTION_GROUP_ID, Map.of(PRODUCT_ID, LEVEL));
appleAppStoreManager = new AppleAppStoreManager(
new AppleAppStoreClient(Environment.PRODUCTION, signedDataVerifier, apiClient, signedDataVerifier, apiClient,
null),
SUBSCRIPTION_GROUP_ID,
Map.of(ONE_TIME_PRODUCT_ID, ReceiptLevel.LOGIN, SUBSCRIPTION_PRODUCT_ID, ReceiptLevel.BACKUP_PAID));
}
@Test
@@ -70,7 +71,7 @@ class AppleAppStoreManagerTest {
assertThat(info.active()).isTrue();
assertThat(info.paymentProcessing()).isFalse();
assertThat(info.level()).isEqualTo(LEVEL);
assertThat(info.level()).isEqualTo(ReceiptLevel.BACKUP_PAID.getValue());
assertThat(info.cancelAtPeriodEnd()).isFalse();
assertThat(info.status()).isEqualTo(SubscriptionStatus.ACTIVE);
assertThat(info.price().amount().compareTo(new BigDecimal("150"))).isEqualTo(0); // 150 cents
@@ -80,7 +81,8 @@ class AppleAppStoreManagerTest {
public void validateTransaction()
throws VerificationException, APIException, IOException, SubscriptionException, RateLimitExceededException {
mockValidSubscription();
assertThat(appleAppStoreManager.validateTransaction(ORIGINAL_TX_ID)).isEqualTo(LEVEL);
assertThat(appleAppStoreManager.validateTransaction(ORIGINAL_TX_ID))
.isEqualTo(ReceiptLevel.BACKUP_PAID.getValue());
}
@Test
@@ -88,7 +90,7 @@ class AppleAppStoreManagerTest {
throws VerificationException, APIException, IOException, SubscriptionException, RateLimitExceededException {
mockValidSubscription();
final SubscriptionPaymentProcessor.ReceiptItem receipt = appleAppStoreManager.getReceiptItem(ORIGINAL_TX_ID);
assertThat(receipt.level()).isEqualTo(LEVEL);
assertThat(receipt.level()).isEqualTo(ReceiptLevel.BACKUP_PAID.getValue());
assertThat(receipt.paymentTime().receiptExpiration(Duration.ofDays(1), Duration.ZERO))
.isEqualTo(Instant.EPOCH.plus(Duration.ofDays(2)));
assertThat(receipt.itemId()).isEqualTo(WEB_ORDER_LINE_ITEM);
@@ -111,14 +113,14 @@ class AppleAppStoreManagerTest {
assertThat(info.active()).isTrue();
assertThat(info.paymentProcessing()).isFalse();
assertThat(info.level()).isEqualTo(LEVEL);
assertThat(info.level()).isEqualTo(ReceiptLevel.BACKUP_PAID.getValue());
assertThat(info.status()).isEqualTo(SubscriptionStatus.ACTIVE);
}
@Test
public void lookupMultipleProducts() throws APIException, IOException, VerificationException, RateLimitExceededException, SubscriptionException {
// The lookup should select the transaction at i=1
final List<String> products = List.of("otherProduct1", PRODUCT_ID, "otherProduct3");
final List<String> products = List.of("otherProduct1", SUBSCRIPTION_PRODUCT_ID, "otherProduct3");
when(apiClient.getAllSubscriptionStatuses(ORIGINAL_TX_ID, new Status[]{}))
.thenReturn(new StatusResponse().data(List.of(new SubscriptionGroupIdentifierItem()
@@ -170,7 +172,8 @@ class AppleAppStoreManagerTest {
.signedTransactionInfo(SIGNED_TX_INFO))))
.environment(Environment.PRODUCTION));
mockDecode(AutoRenewStatus.ON);
assertThat(appleAppStoreManager.validateTransaction(ORIGINAL_TX_ID)).isEqualTo(LEVEL);
assertThat(appleAppStoreManager.validateTransaction(ORIGINAL_TX_ID))
.isEqualTo(ReceiptLevel.BACKUP_PAID.getValue());
}
@Test
@@ -201,7 +204,7 @@ class AppleAppStoreManagerTest {
.thenReturn(new TransactionInfoResponse().signedTransactionInfo(SIGNED_TX_INFO));
final JWSTransactionDecodedPayload payload = new JWSTransactionDecodedPayload()
.transactionId(TRANSACTION_ID)
.productId(PRODUCT_ID)
.productId(ONE_TIME_PRODUCT_ID)
.type(Type.CONSUMABLE)
.inAppOwnershipType(InAppOwnershipType.PURCHASED)
.purchaseDate(Instant.EPOCH.plus(Duration.ofDays(1)).toEpochMilli());
@@ -211,7 +214,7 @@ class AppleAppStoreManagerTest {
// PURCHASED payment
final PaymentDetails paymentDetails = appleAppStoreManager.claimOneTimePurchase(TRANSACTION_ID).orElseThrow();
assertThat(paymentDetails.id()).isEqualTo(TRANSACTION_ID);
assertThat(paymentDetails.level()).isEqualTo(LEVEL);
assertThat(paymentDetails.level()).isEqualTo(ReceiptLevel.LOGIN);
assertThat(paymentDetails.created()).isEqualTo(Instant.EPOCH.plus(Duration.ofDays(1)));
assertThat(paymentDetails.chargeFailure()).isNull();
assertThat(paymentDetails.status()).isEqualTo(PaymentStatus.SUCCEEDED);
@@ -247,7 +250,7 @@ class AppleAppStoreManagerTest {
private void mockDecode(final AutoRenewStatus autoRenewStatus) throws VerificationException {
when(signedDataVerifier.verifyAndDecodeTransaction(SIGNED_TX_INFO))
.thenReturn(new JWSTransactionDecodedPayload()
.productId(PRODUCT_ID)
.productId(SUBSCRIPTION_PRODUCT_ID)
.currency("usd").price(1500L) // $1.50
.originalPurchaseDate(Instant.EPOCH.toEpochMilli())
.expiresDate(Instant.EPOCH.plus(Duration.ofDays(1)).toEpochMilli())
@@ -49,7 +49,8 @@ import org.whispersystems.textsecuregcm.util.MutableClock;
class GooglePlayBillingManagerTest {
private static final String PRODUCT_ID = "productId";
private static final String SUBSCRIPTION_PRODUCT_ID = "subscriptionProductId";
private static final String ONE_TIME_PRODUCT_ID = "oneTimeProductId";
private static final String PACKAGE_NAME = "package.name";
private static final String PURCHASE_TOKEN = "purchaseToken";
private static final String ORDER_ID = "orderId";
@@ -96,9 +97,9 @@ class GooglePlayBillingManagerTest {
AndroidPublisher.Purchases.Subscriptions subscriptions = mock(AndroidPublisher.Purchases.Subscriptions.class);
when(purchases.subscriptions()).thenReturn(subscriptions);
when(subscriptions.acknowledge(eq(PACKAGE_NAME), eq(PRODUCT_ID), eq(PURCHASE_TOKEN), any()))
when(subscriptions.acknowledge(eq(PACKAGE_NAME), any(), eq(PURCHASE_TOKEN), any()))
.thenReturn(acknowledge);
when(subscriptions.cancel(PACKAGE_NAME, PRODUCT_ID, PURCHASE_TOKEN))
when(subscriptions.cancel(eq(PACKAGE_NAME), any(), eq(PURCHASE_TOKEN)))
.thenReturn(cancel);
AndroidPublisher.Purchases.Productsv2 productsv2 = mock(AndroidPublisher.Purchases.Productsv2.class);
@@ -107,10 +108,11 @@ class GooglePlayBillingManagerTest {
AndroidPublisher.Purchases.Products products = mock(AndroidPublisher.Purchases.Products.class);
when(purchases.products()).thenReturn(products);
when(products.consume(PACKAGE_NAME, PRODUCT_ID, PURCHASE_TOKEN)).thenReturn(consume);
when(products.consume(PACKAGE_NAME, ONE_TIME_PRODUCT_ID, PURCHASE_TOKEN)).thenReturn(consume);
googlePlayBillingManager = new GooglePlayBillingManager(
androidPublisher, clock, PACKAGE_NAME, Map.of(PRODUCT_ID, 201L));
googlePlayBillingManager = new GooglePlayBillingManager(androidPublisher, clock, PACKAGE_NAME, Map.of(
SUBSCRIPTION_PRODUCT_ID, ReceiptLevel.BACKUP_PAID,
ONE_TIME_PRODUCT_ID, ReceiptLevel.LOGIN));
}
@Test
@@ -120,7 +122,7 @@ class GooglePlayBillingManagerTest {
.setSubscriptionState(GooglePlayBillingManager.SubscriptionState.ACTIVE.apiString())
.setLineItems(List.of(new SubscriptionPurchaseLineItem()
.setExpiryTime(Instant.now().plus(Duration.ofDays(1)).toString())
.setProductId(PRODUCT_ID))));
.setProductId(SUBSCRIPTION_PRODUCT_ID))));
final GooglePlayBillingManager.ValidatedToken result = googlePlayBillingManager.validateToken(PURCHASE_TOKEN);
@@ -137,7 +139,7 @@ class GooglePlayBillingManagerTest {
.setSubscriptionState(subscriptionState.apiString())
.setLineItems(List.of(new SubscriptionPurchaseLineItem()
.setExpiryTime(Instant.now().plus(Duration.ofDays(1)).toString())
.setProductId(PRODUCT_ID))));
.setProductId(SUBSCRIPTION_PRODUCT_ID))));
switch (subscriptionState) {
case ACTIVE, IN_GRACE_PERIOD, CANCELED -> assertThatNoException()
@@ -154,7 +156,7 @@ class GooglePlayBillingManagerTest {
.setSubscriptionState(GooglePlayBillingManager.SubscriptionState.ACTIVE.apiString())
.setLineItems(List.of(new SubscriptionPurchaseLineItem()
.setExpiryTime(Instant.now().plus(Duration.ofDays(1)).toString())
.setProductId(PRODUCT_ID))));
.setProductId(SUBSCRIPTION_PRODUCT_ID))));
final GooglePlayBillingManager.ValidatedToken result = googlePlayBillingManager.validateToken(PURCHASE_TOKEN);
@@ -171,7 +173,7 @@ class GooglePlayBillingManagerTest {
.setSubscriptionState(subscriptionState.apiString())
.setLineItems(List.of(new SubscriptionPurchaseLineItem()
.setExpiryTime(Instant.now().plus(Duration.ofDays(1)).toString())
.setProductId(PRODUCT_ID))));
.setProductId(SUBSCRIPTION_PRODUCT_ID))));
assertThatNoException().isThrownBy(() ->
googlePlayBillingManager.cancelAllActiveSubscriptions(PURCHASE_TOKEN));
final int wanted = switch (subscriptionState) {
@@ -207,7 +209,7 @@ class GooglePlayBillingManagerTest {
.setSubscriptionState(GooglePlayBillingManager.SubscriptionState.ACTIVE.apiString())
.setLineItems(List.of(new SubscriptionPurchaseLineItem()
.setExpiryTime(Instant.now().plus(Duration.ofDays(1)).toString())
.setProductId(PRODUCT_ID))));
.setProductId(SUBSCRIPTION_PRODUCT_ID))));
assertThatExceptionOfType(IllegalStateException.class).isThrownBy(() ->
googlePlayBillingManager.getReceiptItem(PURCHASE_TOKEN));
}
@@ -224,7 +226,7 @@ class GooglePlayBillingManagerTest {
.setLatestOrderId(ORDER_ID)
.setLineItems(List.of(new SubscriptionPurchaseLineItem()
.setExpiryTime(day10.toString().toString())
.setProductId(PRODUCT_ID))));
.setProductId(SUBSCRIPTION_PRODUCT_ID))));
clock.setTimeInstant(day9);
SubscriptionPaymentProcessor.ReceiptItem item = googlePlayBillingManager.getReceiptItem(PURCHASE_TOKEN);
@@ -260,7 +262,7 @@ class GooglePlayBillingManagerTest {
.setAutoRenewingPlan(new AutoRenewingPlan()
.setAutoRenewEnabled(null)
.setRecurringPrice(new Money().setCurrencyCode("USD").setUnits(1L).setNanos(750_000_000)))
.setProductId(PRODUCT_ID)
.setProductId(SUBSCRIPTION_PRODUCT_ID)
.setOfferDetails(new OfferDetails().setBasePlanId(basePlanId)))));
final SubscriptionInformation info = googlePlayBillingManager.getSubscriptionInformation(PURCHASE_TOKEN);
@@ -300,7 +302,7 @@ class GooglePlayBillingManagerTest {
purchaseState.apiString(),
consumptionState.apiString(),
Instant.EPOCH.plus(Duration.ofDays(3)),
PRODUCT_ID));
ONE_TIME_PRODUCT_ID));
final PaymentStatus expected = switch (purchaseState) {
case PURCHASED -> PaymentStatus.SUCCEEDED;
@@ -312,7 +314,7 @@ class GooglePlayBillingManagerTest {
assertThat(googlePlayBillingManager.claimOneTimePurchase(PURCHASE_TOKEN)).hasValueSatisfying(details -> {
assertThat(details.status()).isEqualTo(expected);
assertThat(details.id()).isEqualTo(PURCHASE_TOKEN);
assertThat(details.level()).isEqualTo(201L);
assertThat(details.level()).isEqualTo(ReceiptLevel.LOGIN);
});
final boolean expectConsume = purchaseState == GooglePlayBillingManager.PurchaseState.PURCHASED &&
@@ -44,7 +44,6 @@ class LoginPurchaseManagerTest {
private static final PaymentProvider PROVIDER = PaymentProvider.APPLE_APP_STORE;
private static final String PURCHASE_ID = "purchaseId";
private static final long LEVEL = 123L;
private static final Instant PURCHASED_AT = Instant.now().minus(Duration.ofHours(3));
private static final ChargeFailure CHARGE_FAILURE =
new ChargeFailure("generic_decline", "some failure message", null, null, null);
@@ -70,14 +69,13 @@ class LoginPurchaseManagerTest {
loginPurchaseManager = new LoginPurchaseManager(
Map.of(PROVIDER, paymentProcessor),
issuedReceiptsManager,
new ServerZkReceiptOperations(SERVER_SECRET_PARAMS),
LEVEL);
new ServerZkReceiptOperations(SERVER_SECRET_PARAMS));
}
@Test
void generateReceiptSuccess() throws Exception {
when(paymentProcessor.claimOneTimePurchase(PURCHASE_ID))
.thenReturn(Optional.of(new PaymentDetails(PURCHASE_ID, LEVEL, PaymentStatus.SUCCEEDED, PURCHASED_AT, null)));
.thenReturn(Optional.of(new PaymentDetails(PURCHASE_ID, ReceiptLevel.LOGIN, PaymentStatus.SUCCEEDED, PURCHASED_AT, null)));
final ReceiptCredentialResponse receipt =
loginPurchaseManager.generateReceipt(PROVIDER, PURCHASE_ID, receiptCredentialRequestContext.getRequest());
@@ -88,7 +86,7 @@ class LoginPurchaseManagerTest {
.plus(LoginPurchaseManager.LOGIN_EXPIRATION)
.truncatedTo(ChronoUnit.DAYS);
assertThat(receiptCredential.getReceiptLevel()).isEqualTo(LEVEL);
assertThat(receiptCredential.getReceiptLevel()).isEqualTo(ReceiptLevel.LOGIN.getValue());
assertThat(receiptCredential.getReceiptExpirationTime()).isEqualTo(expectedExpiration.getEpochSecond());
verify(issuedReceiptsManager).recordOneTimeIssuance(
@@ -99,15 +97,15 @@ class LoginPurchaseManagerTest {
return Stream.of(
Arguments.of(Optional.empty(), SubscriptionNotFoundException.class),
Arguments.of(
Optional.of(new PaymentDetails(PURCHASE_ID, LEVEL, PaymentStatus.PROCESSING, PURCHASED_AT, null)),
Optional.of(new PaymentDetails(PURCHASE_ID, ReceiptLevel.LOGIN, PaymentStatus.PROCESSING, PURCHASED_AT, null)),
SubscriptionReceiptRequestedForOpenPaymentException.class),
Arguments.of(
Optional.of(new PaymentDetails(PURCHASE_ID, LEVEL, PaymentStatus.FAILED, PURCHASED_AT, CHARGE_FAILURE)),
Optional.of(new PaymentDetails(PURCHASE_ID, ReceiptLevel.LOGIN, PaymentStatus.FAILED, PURCHASED_AT, CHARGE_FAILURE)),
SubscriptionChargeFailurePaymentRequiredException.class),
Arguments.of(
Optional.of(new PaymentDetails(PURCHASE_ID, LEVEL, PaymentStatus.FAILED, PURCHASED_AT, null)),
Optional.of(new PaymentDetails(PURCHASE_ID, ReceiptLevel.LOGIN, PaymentStatus.FAILED, PURCHASED_AT, null)),
SubscriptionPaymentRequiredException.class),
Arguments.of(Optional.of(new PaymentDetails(PURCHASE_ID, LEVEL, PaymentStatus.UNKNOWN, PURCHASED_AT, null)),
Arguments.of(Optional.of(new PaymentDetails(PURCHASE_ID, ReceiptLevel.LOGIN, PaymentStatus.UNKNOWN, PURCHASED_AT, null)),
SubscriptionPaymentRequiredException.class));
}
@@ -132,7 +130,7 @@ class LoginPurchaseManagerTest {
@Test
void generateReceiptNonLoginLevel() throws Exception {
when(paymentProcessor.claimOneTimePurchase(PURCHASE_ID))
.thenReturn(Optional.of(new PaymentDetails(PURCHASE_ID, LEVEL + 1, PaymentStatus.SUCCEEDED, PURCHASED_AT, null)));
.thenReturn(Optional.of(new PaymentDetails(PURCHASE_ID, ReceiptLevel.ONE_TIME_DONATION, PaymentStatus.SUCCEEDED, PURCHASED_AT, null)));
assertThatExceptionOfType(SubscriptionInvalidArgumentsException.class).isThrownBy(() ->
loginPurchaseManager.generateReceipt(PROVIDER, PURCHASE_ID, receiptCredentialRequestContext.getRequest()));
verifyNoInteractions(issuedReceiptsManager);
@@ -141,7 +139,7 @@ class LoginPurchaseManagerTest {
@Test
void generateReceiptAlreadyRedeemed() throws Exception {
when(paymentProcessor.claimOneTimePurchase(PURCHASE_ID))
.thenReturn(Optional.of(new PaymentDetails(PURCHASE_ID, LEVEL, PaymentStatus.SUCCEEDED, PURCHASED_AT, null)));
.thenReturn(Optional.of(new PaymentDetails(PURCHASE_ID, ReceiptLevel.LOGIN, PaymentStatus.SUCCEEDED, PURCHASED_AT, null)));
doThrow(new WriteConflictException())
.when(issuedReceiptsManager).recordOneTimeIssuance(any(), any(), any(), any());
assertThatExceptionOfType(SubscriptionReceiptAlreadyRedeemedException.class).isThrownBy(() ->