mirror of
https://github.com/signalapp/Signal-Server
synced 2026-04-22 23:38:07 +01:00
Handle potentially null payment method when canceling subscription
This commit is contained in:
@@ -0,0 +1,52 @@
|
||||
/*
|
||||
* Copyright 2023 Signal Messenger, LLC
|
||||
* SPDX-License-Identifier: AGPL-3.0-only
|
||||
*/
|
||||
|
||||
package org.whispersystems.textsecuregcm.subscriptions;
|
||||
|
||||
import static org.junit.jupiter.api.Assertions.assertTimeoutPreemptively;
|
||||
import static org.mockito.ArgumentMatchers.anyString;
|
||||
import static org.mockito.Mockito.mock;
|
||||
import static org.mockito.Mockito.when;
|
||||
|
||||
import com.braintreegateway.BraintreeGateway;
|
||||
import com.braintreegateway.Customer;
|
||||
import com.braintreegateway.CustomerGateway;
|
||||
import java.time.Duration;
|
||||
import java.util.Map;
|
||||
import java.util.Set;
|
||||
import java.util.concurrent.Executors;
|
||||
import org.junit.jupiter.api.BeforeEach;
|
||||
import org.junit.jupiter.api.Test;
|
||||
|
||||
class BraintreeManagerTest {
|
||||
|
||||
private BraintreeGateway braintreeGateway;
|
||||
private BraintreeManager braintreeManager;
|
||||
|
||||
@BeforeEach
|
||||
void setup() {
|
||||
braintreeGateway = mock(BraintreeGateway.class);
|
||||
braintreeManager = new BraintreeManager(braintreeGateway,
|
||||
Set.of("usd"),
|
||||
Map.of("usd", "usdMerchant"),
|
||||
mock(BraintreeGraphqlClient.class),
|
||||
Executors.newSingleThreadExecutor());
|
||||
}
|
||||
|
||||
@Test
|
||||
void cancelAllActiveSubscriptions_nullDefaultPaymentMethod() {
|
||||
|
||||
final Customer customer = mock(Customer.class);
|
||||
when(customer.getDefaultPaymentMethod()).thenReturn(null);
|
||||
|
||||
final CustomerGateway customerGateway = mock(CustomerGateway.class);
|
||||
when(customerGateway.find(anyString())).thenReturn(customer);
|
||||
|
||||
when(braintreeGateway.customer()).thenReturn(customerGateway);
|
||||
|
||||
assertTimeoutPreemptively(Duration.ofSeconds(5), () ->
|
||||
braintreeManager.cancelAllActiveSubscriptions("customerId")).join();
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user