Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
29 changes: 29 additions & 0 deletions tests/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
This test suite is quite large and can occasionally be flaky for certain endpoints, such as when AB returns a server error response.
To mitigate these issues, the suite has been parallelized, allowing for faster reruns when necessary.

To execute the tests, provide the following environment variables:
- `SUBDOMAINS` - A list of subdomains your tests will use. Locally, a single site should suffice.
- `API_KEYS` - A list of API keys corresponding to the subdomains. The order of keys must match the order of the subdomains.
- `SITE_ID` - (optional): Used only for site-specific assertions. Not required unless you are testing the site endpoint.
- `PRECONFIGURED_SUBDOMAIN` - A subdomain with a preconfigured state.
- `PRECONFIGURED_API_KEY` - The API key for the subdomain in a preconfigured state.


### Preconfigured site

Most tests require setting up resources beforehand. After the test suite finishes, a cleanup process is triggered.
However, not all resources can be set up using the API.

For tests that require such resources, a Preconfigured Site is used—a special site where resources are manually configured and are not cleared after each test run.

To use the Preconfigured Site, retrieve a client for it with the following method:
```
TestClientProvider.getPreconfiguredSiteClient()
```

### Notes on parallelism

- Each subdomain specified in the `SUBDOMAINS` environment variable is assigned a single thread.
- All test cases within a specific test class are executed on the same thread (and therefore the same subdomain) to prevent concurrent execution for the same site, which could result in test failures. This is also because most test classes have a single setup method that runs before all the tests in the class.
- Avoid using static fields in test classes - Some tests override static fields in base classes, which can interfere with other test runs.

Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,7 @@ void teardown() throws IOException, ApiException {
@Test
void shouldReturn201onIssueAdvanceInvoice() throws IOException, ApiException {
// given
ZonedDateTime beforeDateTime = ZonedDateTime.now().truncatedTo(ChronoUnit.SECONDS);
ZonedDateTime beforeDateTime = ZonedDateTime.now().plusSeconds(5).truncatedTo(ChronoUnit.SECONDS);
LocalDate beforeDate = LocalDate.now();

// when
Expand Down Expand Up @@ -167,7 +167,7 @@ void shouldReturn201onIssueAdvanceInvoice() throws IOException, ApiException {
() -> assertThat(invoiceLineItem.getTotalAmount()).isEqualTo("12.5"),
() -> assertThat(invoiceLineItem.getTieredUnitPrice()).isFalse(),
() -> assertThat(invoiceLineItem.getPeriodRangeStart()).isEqualTo(beforeDate.plusMonths(1)),
() -> assertThat(invoiceLineItem.getPeriodRangeEnd()).isEqualTo(beforeDate.plusMonths(2)),
() -> assertThat(invoiceLineItem.getPeriodRangeEnd()).isEqualTo(beforeDate.plusMonths(1).plusMonths(1)),
() -> assertThat(invoiceLineItem.getProductId()).isEqualTo(product.getId()),
() -> assertThat(invoiceLineItem.getProductVersion()).isEqualTo(product.getVersionNumber()),
() -> assertThat(invoiceLineItem.getProductPricePointId()).isEqualTo(product.getProductPricePointId()),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -166,7 +166,7 @@ void shouldReturn200onReadAdvanceInvoice() throws IOException, ApiException {
() -> assertThat(invoiceLineItem.getTotalAmount()).isEqualTo("12.5"),
() -> assertThat(invoiceLineItem.getTieredUnitPrice()).isFalse(),
() -> assertThat(invoiceLineItem.getPeriodRangeStart()).isEqualTo(beforeDate.plusMonths(1)),
() -> assertThat(invoiceLineItem.getPeriodRangeEnd()).isEqualTo(beforeDate.plusMonths(2)),
() -> assertThat(invoiceLineItem.getPeriodRangeEnd()).isEqualTo(beforeDate.plusMonths(1).plusMonths(1)),
() -> assertThat(invoiceLineItem.getProductId()).isEqualTo(product.getId()),
() -> assertThat(invoiceLineItem.getProductVersion()).isEqualTo(product.getVersionNumber()),
() -> assertThat(invoiceLineItem.getProductPricePointId()).isEqualTo(product.getProductPricePointId()),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -174,7 +174,7 @@ void shouldReturn201onVoidAdvanceInvoice() throws IOException, ApiException {
() -> assertThat(invoiceLineItem.getTotalAmount()).isEqualTo("12.5"),
() -> assertThat(invoiceLineItem.getTieredUnitPrice()).isFalse(),
() -> assertThat(invoiceLineItem.getPeriodRangeStart()).isEqualTo(beforeDate.plusMonths(1)),
() -> assertThat(invoiceLineItem.getPeriodRangeEnd()).isEqualTo(beforeDate.plusMonths(2)),
() -> assertThat(invoiceLineItem.getPeriodRangeEnd()).isEqualTo(beforeDate.plusMonths(1).plusMonths(1)),
() -> assertThat(invoiceLineItem.getProductId()).isEqualTo(product.getId()),
() -> assertThat(invoiceLineItem.getProductVersion()).isEqualTo(product.getVersionNumber()),
() -> assertThat(invoiceLineItem.getProductPricePointId()).isEqualTo(product.getProductPricePointId()),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@
import org.junit.jupiter.api.Test;

import java.io.IOException;
import java.time.LocalDate;
import java.util.List;
import java.util.stream.Collectors;

Expand Down Expand Up @@ -95,7 +96,7 @@ void shouldReturnListOfSubscriptionsForCustomer() throws IOException, ApiExcepti
.customerId(customerId)
.paymentType(PaymentType.CREDIT_CARD)
.expirationMonth(CreatePaymentProfileExpirationMonth.fromNumber(10))
.expirationYear(CreatePaymentProfileExpirationYear.fromNumber(2025))
.expirationYear(CreatePaymentProfileExpirationYear.fromNumber(LocalDate.now().getYear() + 10))
.fullNumber("5424000000000015")
.build())
)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -82,6 +82,7 @@ void shouldReadCreditCardPaymentProfile() throws IOException, ApiException {
.match(new PaymentProfileResponsePaymentProfileGetter<CreditCardPaymentProfile>())
)
.usingRecursiveComparison()
.ignoringFields("additionalProperties")
.isEqualTo(new CreditCardPaymentProfile.Builder()
.maskedCardNumber("XXXX-XXXX-XXXX-1111")
.id(creditCardPaymentProfile.getId())
Expand Down Expand Up @@ -117,6 +118,7 @@ void shouldReadBankAccountPaymentProfile() throws IOException, ApiException {
.match(new PaymentProfileResponsePaymentProfileGetter<BankAccountPaymentProfile>())
)
.usingRecursiveComparison()
.ignoringFields("additionalProperties")
.isEqualTo(new BankAccountPaymentProfile.Builder()
.id(bankAccountPaymentProfile.getId())
.firstName(customer.getFirstName())
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -109,7 +109,7 @@ protected CreateSubscription getCreateSubscription(Customer customer, Component
.cardType(CardType.VISA)
.cvv("123")
.expirationMonth(PaymentProfileAttributesExpirationMonth.fromNumber(5))
.expirationYear(PaymentProfileAttributesExpirationYear.fromNumber(2050))
.expirationYear(PaymentProfileAttributesExpirationYear.fromNumber(LocalDate.now().getYear() + 10))
.build()
)
.build();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,10 @@ class SitesControllerTest {
@Test
void shouldReadSite() throws Exception {
// when
// bug: idle connection can be closed.
try {
Site site = sitesController.readSite().getSite();
} catch (Exception ignored) {}
Site site = sitesController.readSite().getSite();

// then
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,7 @@
import org.junit.jupiter.api.Test;

import java.io.IOException;
import java.time.LocalDate;
import java.time.ZoneOffset;
import java.time.ZonedDateTime;
import java.util.List;
Expand Down Expand Up @@ -140,7 +141,7 @@ void shouldCreateSubscriptionWithCreditCard() throws IOException, ApiException {
.cardType(CardType.VISA)
.cvv("123")
.expirationMonth(PaymentProfileAttributesExpirationMonth.fromNumber(5))
.expirationYear(PaymentProfileAttributesExpirationYear.fromNumber(2050))
.expirationYear(PaymentProfileAttributesExpirationYear.fromNumber(LocalDate.now().getYear() + 10))
.build())
.build()
)).getSubscription();
Expand All @@ -159,7 +160,7 @@ void shouldCreateSubscriptionWithCreditCard() throws IOException, ApiException {
assertThat(creditCard.getMaskedCardNumber()).isEqualTo("XXXX-XXXX-XXXX-1111");
assertThat(creditCard.getCardType()).isEqualTo(CardType.VISA);
assertThat(creditCard.getExpirationMonth()).isEqualTo(5);
assertThat(creditCard.getExpirationYear()).isEqualTo(2050);
assertThat(creditCard.getExpirationYear()).isEqualTo(LocalDate.now().getYear() + 10);
assertThat(creditCard.getCurrentVault()).isEqualTo(CreditCardVault.BOGUS);
assertThat(creditCard.getVaultToken()).isNotEmpty();
assertThat(creditCard.getBillingAddress()).isEqualTo("My Billing Address");
Expand Down Expand Up @@ -255,7 +256,7 @@ void shouldCreateSubscriptionWithCoupon() throws IOException, ApiException {
.cardType(CardType.VISA)
.cvv("123")
.expirationMonth(PaymentProfileAttributesExpirationMonth.fromNumber(5))
.expirationYear(PaymentProfileAttributesExpirationYear.fromNumber(2050))
.expirationYear(PaymentProfileAttributesExpirationYear.fromNumber(LocalDate.now().getYear() + 10))
.build()
)
.customPrice(new SubscriptionCustomPrice.Builder()
Expand Down Expand Up @@ -319,7 +320,7 @@ void shouldCreateSubscriptionWithComponents() throws IOException, ApiException {
.cardType(CardType.VISA)
.cvv("123")
.expirationMonth(PaymentProfileAttributesExpirationMonth.fromNumber(5))
.expirationYear(PaymentProfileAttributesExpirationYear.fromNumber(2050))
.expirationYear(PaymentProfileAttributesExpirationYear.fromNumber(LocalDate.now().getYear() + 10))
.build()
)
.customPrice(new SubscriptionCustomPrice.Builder()
Expand Down Expand Up @@ -382,7 +383,7 @@ void shouldCreateSubscriptionWithCustomPrice() throws IOException, ApiException
.cardType(CardType.VISA)
.cvv("123")
.expirationMonth(PaymentProfileAttributesExpirationMonth.fromNumber(5))
.expirationYear(PaymentProfileAttributesExpirationYear.fromNumber(2050))
.expirationYear(PaymentProfileAttributesExpirationYear.fromNumber(LocalDate.now().getYear() + 10))
.build()
)
.customPrice(new SubscriptionCustomPrice.Builder()
Expand Down Expand Up @@ -479,7 +480,7 @@ void shouldCreateSubscriptionWithGroup() throws IOException, ApiException {
.cardType(CardType.VISA)
.cvv("123")
.expirationMonth(PaymentProfileAttributesExpirationMonth.fromNumber(5))
.expirationYear(PaymentProfileAttributesExpirationYear.fromNumber(2050))
.expirationYear(PaymentProfileAttributesExpirationYear.fromNumber(LocalDate.now().getYear() + 10))
.build()
)
.build()
Expand Down Expand Up @@ -550,7 +551,7 @@ void shouldCreateSubscriptionWithPrepaidConfiguration() throws IOException, ApiE
.cardType(CardType.VISA)
.cvv("123")
.expirationMonth(PaymentProfileAttributesExpirationMonth.fromNumber(5))
.expirationYear(PaymentProfileAttributesExpirationYear.fromNumber(2050))
.expirationYear(PaymentProfileAttributesExpirationYear.fromNumber(LocalDate.now().getYear() + 10))
.build()
)
.components(List.of(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
import org.junit.jupiter.api.BeforeAll;

import java.io.IOException;
import java.time.LocalDate;

abstract class SubscriptionStatusControllerTestBase {

Expand Down Expand Up @@ -47,7 +48,7 @@ Subscription createSubscription() throws IOException, ApiException {
.creditCardAttributes(
new PaymentProfileAttributes.Builder()
.expirationMonth(PaymentProfileAttributesExpirationMonth.fromNumber(12))
.expirationYear(PaymentProfileAttributesExpirationYear.fromNumber(2050))
.expirationYear(PaymentProfileAttributesExpirationYear.fromNumber(LocalDate.now().getYear() + 10))
.fullNumber("1")
.build()
)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -411,7 +411,7 @@ public Subscription createSubscription(Customer customer, Product product,
.cardType(CardType.VISA)
.cvv("123")
.expirationMonth(PaymentProfileAttributesExpirationMonth.fromNumber(5))
.expirationYear(PaymentProfileAttributesExpirationYear.fromNumber(2050));
.expirationYear(PaymentProfileAttributesExpirationYear.fromNumber(LocalDate.now().getYear() + 10));
paymentProfileCustomizer.accept(paymentProfileBuilder);

CreateSubscription.Builder subscriptionBuilder = new CreateSubscription.Builder()
Expand Down