Skip to content

Commit

Permalink
[DE-676] Applied code review suggestions for proforma invoices tests
Browse files Browse the repository at this point in the history
  • Loading branch information
maciej-nedza committed Mar 5, 2024
1 parent 83114e8 commit f5b9e2e
Show file tree
Hide file tree
Showing 9 changed files with 29 additions and 39 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -21,9 +21,6 @@ public class ProformaInvoicesControllerCreateSignupProformaTest extends Proforma

private static Customer customer;

ProformaInvoicesControllerCreateSignupProformaTest() throws IOException, ApiException {
}

@BeforeAll
static void setUp() throws IOException, ApiException {
customer = TEST_SETUP.createCustomer();
Expand All @@ -36,7 +33,7 @@ static void teardown() throws IOException, ApiException {

@Test
void shouldCreateSignupProforma() throws IOException, ApiException {
// given-when
// given - when
ProformaInvoiceWithComponents invoiceWithData = createSignupProformaInvoice(customer);

// then
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,9 +15,6 @@ public class ProformaInvoicesControllerCreateTest extends ProformaInvoicesTestBa

private static Customer customer;

ProformaInvoicesControllerCreateTest() throws IOException, ApiException {
}

@BeforeAll
static void setUp() throws IOException, ApiException {
customer = TEST_SETUP.createCustomer();
Expand All @@ -30,7 +27,7 @@ static void teardown() throws IOException, ApiException {

@Test
void shouldCreateProformaInvoice() throws IOException, ApiException {
// given-when
// given - when
ProformaInvoiceWithComponents invoiceWithData = createProformaInvoiceWithComponents(customer);

// then
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,9 +24,6 @@ public class ProformaInvoicesControllerPreviewSignupProformaTest extends Proform

private static Customer customer;

ProformaInvoicesControllerPreviewSignupProformaTest() throws IOException, ApiException {
}

@BeforeAll
static void setUp() throws IOException, ApiException {
customer = TEST_SETUP.createCustomer();
Expand All @@ -39,13 +36,15 @@ static void teardown() throws IOException, ApiException {

@Test
void shouldPreviewSignupProformaWithNextProforma() throws IOException, ApiException {
// given-when
// given - when
SignupProformaPreviewWithComponents previewWithData = previewSignupProformaInvoice(customer);

// then
assertProformaInvoice(customer, new ProformaInvoiceWithComponents(previewWithData.preview().getCurrentProformaInvoice(),
previewWithData.quantityBasedComponent(), previewWithData.meteredComponent()),
false, true);
ProformaInvoiceWithComponents proformaInvoiceWithComponents = new ProformaInvoiceWithComponents(
previewWithData.preview().getCurrentProformaInvoice(),
previewWithData.quantityBasedComponent(), previewWithData.meteredComponent()
);
assertProformaInvoice(customer, proformaInvoiceWithComponents, false, true);

assertThat(previewWithData.preview().getNextProformaInvoice()).usingRecursiveComparison()
.ignoringFields("createdAt", "subtotalAmount", "totalAmount", "uid", "lineItems",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,9 +17,6 @@ public class ProformaInvoicesControllerPreviewTest extends ProformaInvoicesTestB

private static Customer customer;

ProformaInvoicesControllerPreviewTest() throws IOException, ApiException {
}

@BeforeAll
static void setUp() throws IOException, ApiException {
customer = TEST_SETUP.createCustomer();
Expand All @@ -32,7 +29,7 @@ static void teardown() throws IOException, ApiException {

@Test
void shouldPreviewProformaInvoice() throws IOException, ApiException {
// given-when
// given - when
ProformaInvoiceWithComponents invoiceWithData = previewProformaInvoiceWithComponents(customer);

// then
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,9 +19,6 @@ public class ProformaInvoicesControllerReadTest extends ProformaInvoicesTestBase

private static Customer customer;

ProformaInvoicesControllerReadTest() throws IOException, ApiException {
}

@BeforeAll
static void setUp() throws IOException, ApiException {
customer = TEST_SETUP.createCustomer();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -63,13 +63,12 @@ static void setUp() throws IOException, ApiException, InterruptedException {

@AfterAll
static void teardown() throws IOException, ApiException {
TestTeardown testTeardown = new TestTeardown();
testTeardown.deleteSubscriptionGroup(groupSignup);
new TestTeardown().deleteSubscriptionGroup(groupSignup);
}

@Test
void shouldListGroupProformas() throws IOException, ApiException {
// given-when
void shouldListSubscriptionGroupProformaInvoices() throws IOException, ApiException {
// given - when
ListProformaInvoicesResponse listProformaInvoicesResponse = PROFORMA_INVOICES_CONTROLLER
.listSubscriptionGroupProformaInvoices(new ListSubscriptionGroupProformaInvoicesInput.Builder()
.uid(groupSignup.getUid())
Expand All @@ -92,10 +91,10 @@ void shouldListGroupProformas() throws IOException, ApiException {
assertThat(invoiceBillingAddress.getAdditionalProperties()).isEmpty();
assertAll(
() -> assertThat(invoiceBillingAddress).isNotNull(),
() -> assertThat(invoiceBillingAddress.getStreet()).isNull(),
() -> assertThat(invoiceBillingAddress.getStreet()).isEqualTo("1703 Edsel Road"),
() -> assertThat(invoiceBillingAddress.getLine2()).isNull(),
() -> assertThat(invoiceBillingAddress.getCity()).isNull(),
() -> assertThat(invoiceBillingAddress.getState()).isNull(),
() -> assertThat(invoiceBillingAddress.getCity()).isEqualTo("Los Angeles"),
() -> assertThat(invoiceBillingAddress.getState()).isEqualTo("CA"),
() -> assertThat(invoiceBillingAddress.getZip()).isNull(),
() -> assertThat(invoiceBillingAddress.getCountry()).isNull()
);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,9 +22,6 @@ public class ProformaInvoicesControllerVoidTest extends ProformaInvoicesTestBase

private static Customer customer;

ProformaInvoicesControllerVoidTest() throws IOException, ApiException {
}

@BeforeAll
static void setUp() throws IOException, ApiException {
customer = TEST_SETUP.createCustomer();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@
import static org.assertj.core.api.Assertions.assertThat;
import static org.junit.jupiter.api.Assertions.assertAll;

public abstract class ProformaInvoicesTestBase {
abstract class ProformaInvoicesTestBase {

protected static final TestSetup TEST_SETUP = new TestSetup();
protected static final AdvancedBillingClient CLIENT = TestClient.createClient();
Expand All @@ -58,9 +58,13 @@ public abstract class ProformaInvoicesTestBase {
protected final Product product;
protected final ProductFamily productFamily;

ProformaInvoicesTestBase() throws IOException, ApiException {
productFamily = TEST_SETUP.createProductFamily();
product = TEST_SETUP.createProduct(productFamily, b -> b.priceInCents(1250));
ProformaInvoicesTestBase() {
try {
productFamily = TEST_SETUP.createProductFamily();
product = TEST_SETUP.createProduct(productFamily, b -> b.priceInCents(1250));
} catch (IOException | ApiException e) {
throw new RuntimeException(e);
}
}

protected ProformaInvoiceWithComponents createProformaInvoiceWithComponents(Customer customer) throws IOException, ApiException {
Expand Down Expand Up @@ -141,7 +145,7 @@ protected Subscription setupSubscription(Customer customer, Component quantityBa
void assertProformaInvoice(Customer customer,
ProformaInvoiceWithComponents invoiceWithData,
boolean assertPreservationDataNonEmpty,
// signup proforma won't contain service credits and subscription id and it's periods
// signup proforma won't contain service credits and subscription id and its periods
// won't be shifted
boolean isSignup) {
ProformaInvoice proformaInvoice = invoiceWithData.invoice();
Expand Down Expand Up @@ -366,10 +370,10 @@ static String formatDescriptionDate(LocalDate localDate) {
}

protected record ProformaInvoiceWithComponents(ProformaInvoice invoice, Component quantityBasedComponent,
Component meteredComponent) {
Component meteredComponent) {
}

record SignupProformaPreviewWithComponents(SignupProformaPreview preview, Component quantityBasedComponent,
protected record SignupProformaPreviewWithComponents(SignupProformaPreview preview, Component quantityBasedComponent,
Component meteredComponent) {
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -455,6 +455,9 @@ public SubscriptionGroupSignupResponse signupWithSubscriptionGroup(Product produ
.fullNumber(SubscriptionGroupCreditCardFullNumber.fromString("4111 1111 1111 1111"))
.expirationMonth(SubscriptionGroupCreditCardExpirationMonth.fromNumber(11))
.expirationYear(SubscriptionGroupCreditCardExpirationYear.fromNumber(LocalDate.now().getYear() + 1))
.billingAddress("1703 Edsel Road")
.billingCity("Los Angeles")
.billingState("CA")
.build())
.payerAttributes(new PayerAttributes.Builder()
.firstName("Payer")
Expand Down

0 comments on commit f5b9e2e

Please sign in to comment.