Skip to content

Commit

Permalink
[DE-676] Refactor proforma tests
Browse files Browse the repository at this point in the history
  • Loading branch information
maciej-nedza committed Mar 1, 2024
1 parent e577664 commit cf39e97
Show file tree
Hide file tree
Showing 8 changed files with 106 additions and 146 deletions.
Original file line number Diff line number Diff line change
@@ -1,13 +1,12 @@
package com.maxio.advancedbilling.controllers.proformainvoices;

import com.maxio.advancedbilling.AdvancedBillingClient;
import com.maxio.advancedbilling.TestClient;
import com.maxio.advancedbilling.controllers.ProformaInvoicesController;
import com.maxio.advancedbilling.exceptions.ApiException;
import com.maxio.advancedbilling.models.Component;
import com.maxio.advancedbilling.models.CreateSubscription;
import com.maxio.advancedbilling.models.CreateSubscriptionRequest;
import com.maxio.advancedbilling.models.Customer;
import com.maxio.advancedbilling.utils.TestSetup;
import com.maxio.advancedbilling.models.ProformaInvoice;
import com.maxio.advancedbilling.utils.TestTeardown;
import com.maxio.advancedbilling.utils.assertions.CommonAssertions;
import org.junit.jupiter.api.AfterAll;
Expand All @@ -18,15 +17,13 @@
import java.util.List;
import java.util.Map;

public class ProformaInvoicesControllerCreateSignupProformaTest {

private static final TestSetup TEST_SETUP = new TestSetup();
private static final AdvancedBillingClient CLIENT = TestClient.createClient();
private static final ProformaInvoicesController PROFORMA_INVOICES_CONTROLLER = CLIENT
.getProformaInvoicesController();
public class ProformaInvoicesControllerCreateSignupProformaTest extends ProformaInvoicesTestBase {

private static Customer customer;

ProformaInvoicesControllerCreateSignupProformaTest() throws IOException, ApiException {
}

@BeforeAll
static void setUp() throws IOException, ApiException {
customer = TEST_SETUP.createCustomer();
Expand All @@ -40,12 +37,10 @@ static void teardown() throws IOException, ApiException {
@Test
void shouldCreateSignupProforma() throws IOException, ApiException {
// given-when
ProformaInvoicesCreator proformaInvoicesCreator = new ProformaInvoicesCreator();
ProformaInvoicesCreator.ProformaInvoiceWithComponents invoiceWithData =
proformaInvoicesCreator.createSignupProformaInvoice(customer);
ProformaInvoiceWithComponents invoiceWithData = createSignupProformaInvoice(customer);

// then
proformaInvoicesCreator.assertProformaInvoice(customer, invoiceWithData, true, true);
assertProformaInvoice(customer, invoiceWithData, true, true);
}

@Test
Expand All @@ -71,4 +66,17 @@ void shouldReturn401WhenProvidingInvalidCredentials() {
);
}

private ProformaInvoiceWithComponents createSignupProformaInvoice(Customer customer) throws IOException, ApiException {
Component meteredComponent = TEST_SETUP.createMeteredComponent(productFamily, 11.5);
Component quantityBasedComponent = TEST_SETUP.createQuantityBasedComponent(productFamily.getId());

ProformaInvoice proformaInvoice = CLIENT.getProformaInvoicesController().createSignupProformaInvoice(
new CreateSubscriptionRequest(
getCreateSubscription(customer, meteredComponent, quantityBasedComponent)
)
);

return new ProformaInvoiceWithComponents(proformaInvoice, quantityBasedComponent, meteredComponent);
}

}
Original file line number Diff line number Diff line change
@@ -1,11 +1,8 @@
package com.maxio.advancedbilling.controllers.proformainvoices;

import com.maxio.advancedbilling.AdvancedBillingClient;
import com.maxio.advancedbilling.TestClient;
import com.maxio.advancedbilling.controllers.ProformaInvoicesController;
import com.maxio.advancedbilling.exceptions.ApiException;
import com.maxio.advancedbilling.models.Customer;
import com.maxio.advancedbilling.utils.TestSetup;
import com.maxio.advancedbilling.utils.TestTeardown;
import com.maxio.advancedbilling.utils.assertions.CommonAssertions;
import org.junit.jupiter.api.AfterAll;
Expand All @@ -14,15 +11,13 @@

import java.io.IOException;

public class ProformaInvoicesControllerCreateTest {

private static final TestSetup TEST_SETUP = new TestSetup();
private static final AdvancedBillingClient CLIENT = TestClient.createClient();
private static final ProformaInvoicesController PROFORMA_INVOICES_CONTROLLER = CLIENT
.getProformaInvoicesController();
public class ProformaInvoicesControllerCreateTest extends ProformaInvoicesTestBase {

private static Customer customer;

ProformaInvoicesControllerCreateTest() throws IOException, ApiException {
}

@BeforeAll
static void setUp() throws IOException, ApiException {
customer = TEST_SETUP.createCustomer();
Expand All @@ -36,13 +31,10 @@ static void teardown() throws IOException, ApiException {
@Test
void shouldCreateProformaInvoice() throws IOException, ApiException {
// given-when
ProformaInvoicesCreator proformaInvoicesCreator = new ProformaInvoicesCreator();
ProformaInvoicesCreator.ProformaInvoiceWithComponents invoiceWithData =
proformaInvoicesCreator.createProformaInvoiceWithComponents(customer);
ProformaInvoiceWithComponents invoiceWithData = createProformaInvoiceWithComponents(customer);

// then
proformaInvoicesCreator.assertProformaInvoice(customer, invoiceWithData,
true, false);
assertProformaInvoice(customer, invoiceWithData, true, false);
}

@Test
Expand Down
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
package com.maxio.advancedbilling.controllers.proformainvoices;

import com.maxio.advancedbilling.AdvancedBillingClient;
import com.maxio.advancedbilling.TestClient;
import com.maxio.advancedbilling.controllers.ProformaInvoicesController;
import com.maxio.advancedbilling.exceptions.ApiException;
import com.maxio.advancedbilling.models.Component;
import com.maxio.advancedbilling.models.CreateSignupProformaPreviewInclude;
import com.maxio.advancedbilling.models.CreateSubscription;
import com.maxio.advancedbilling.models.CreateSubscriptionRequest;
import com.maxio.advancedbilling.models.Customer;
import com.maxio.advancedbilling.utils.TestSetup;
import com.maxio.advancedbilling.models.SignupProformaPreview;
import com.maxio.advancedbilling.utils.TestTeardown;
import com.maxio.advancedbilling.utils.assertions.CommonAssertions;
import org.junit.jupiter.api.AfterAll;
Expand All @@ -20,15 +20,13 @@

import static org.assertj.core.api.Assertions.assertThat;

public class ProformaInvoicesControllerPreviewSignupProformaTest {

private static final TestSetup TEST_SETUP = new TestSetup();
private static final AdvancedBillingClient CLIENT = TestClient.createClient();
private static final ProformaInvoicesController PROFORMA_INVOICES_CONTROLLER = CLIENT
.getProformaInvoicesController();
public class ProformaInvoicesControllerPreviewSignupProformaTest extends ProformaInvoicesTestBase {

private static Customer customer;

ProformaInvoicesControllerPreviewSignupProformaTest() throws IOException, ApiException {
}

@BeforeAll
static void setUp() throws IOException, ApiException {
customer = TEST_SETUP.createCustomer();
Expand All @@ -42,13 +40,10 @@ static void teardown() throws IOException, ApiException {
@Test
void shouldPreviewSignupProformaWithNextProforma() throws IOException, ApiException {
// given-when
ProformaInvoicesCreator proformaInvoicesCreator = new ProformaInvoicesCreator();
ProformaInvoicesCreator.SignupProformaPreviewWithComponents previewWithData =
proformaInvoicesCreator.previewSignupProformaInvoice(customer);
SignupProformaPreviewWithComponents previewWithData = previewSignupProformaInvoice(customer);

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

Expand Down Expand Up @@ -82,4 +77,18 @@ void shouldReturn401WhenProvidingInvalidCredentials() {
);
}

private SignupProformaPreviewWithComponents previewSignupProformaInvoice(Customer customer) throws IOException, ApiException {
Component meteredComponent = TEST_SETUP.createMeteredComponent(productFamily, 11.5);
Component quantityBasedComponent = TEST_SETUP.createQuantityBasedComponent(productFamily.getId());

SignupProformaPreview signupProformaPreview = CLIENT.getProformaInvoicesController().previewSignupProformaInvoice(
CreateSignupProformaPreviewInclude.NEXT_PROFORMA_INVOICE,
new CreateSubscriptionRequest(
getCreateSubscription(customer, meteredComponent, quantityBasedComponent)
)
).getProformaInvoicePreview();

return new SignupProformaPreviewWithComponents(signupProformaPreview, quantityBasedComponent, meteredComponent);
}

}
Original file line number Diff line number Diff line change
@@ -1,11 +1,10 @@
package com.maxio.advancedbilling.controllers.proformainvoices;

import com.maxio.advancedbilling.AdvancedBillingClient;
import com.maxio.advancedbilling.TestClient;
import com.maxio.advancedbilling.controllers.ProformaInvoicesController;
import com.maxio.advancedbilling.exceptions.ApiException;
import com.maxio.advancedbilling.models.Component;
import com.maxio.advancedbilling.models.Customer;
import com.maxio.advancedbilling.utils.TestSetup;
import com.maxio.advancedbilling.models.Subscription;
import com.maxio.advancedbilling.utils.TestTeardown;
import com.maxio.advancedbilling.utils.assertions.CommonAssertions;
import org.junit.jupiter.api.AfterAll;
Expand All @@ -14,15 +13,13 @@

import java.io.IOException;

public class ProformaInvoicesControllerPreviewTest {

private static final TestSetup TEST_SETUP = new TestSetup();
private static final AdvancedBillingClient CLIENT = TestClient.createClient();
private static final ProformaInvoicesController PROFORMA_INVOICES_CONTROLLER = CLIENT
.getProformaInvoicesController();
public class ProformaInvoicesControllerPreviewTest extends ProformaInvoicesTestBase {

private static Customer customer;

ProformaInvoicesControllerPreviewTest() throws IOException, ApiException {
}

@BeforeAll
static void setUp() throws IOException, ApiException {
customer = TEST_SETUP.createCustomer();
Expand All @@ -36,13 +33,10 @@ static void teardown() throws IOException, ApiException {
@Test
void shouldPreviewProformaInvoice() throws IOException, ApiException {
// given-when
ProformaInvoicesCreator proformaInvoicesCreator = new ProformaInvoicesCreator();
ProformaInvoicesCreator.ProformaInvoiceWithComponents invoiceWithData =
proformaInvoicesCreator.previewProformaInvoiceWithComponents(customer);
ProformaInvoiceWithComponents invoiceWithData = previewProformaInvoiceWithComponents(customer);

// then
proformaInvoicesCreator.assertProformaInvoice(customer, invoiceWithData,
false, false);
assertProformaInvoice(customer, invoiceWithData, false, false);
}

@Test
Expand All @@ -61,4 +55,15 @@ void shouldReturn401WhenProvidingInvalidCredentials() {
);
}

private ProformaInvoiceWithComponents previewProformaInvoiceWithComponents(Customer customer) throws IOException, ApiException {
Component meteredComponent = TEST_SETUP.createMeteredComponent(productFamily, 11.5);
Component quantityBasedComponent = TEST_SETUP.createQuantityBasedComponent(productFamily.getId());
Subscription subscription = setupSubscription(customer, quantityBasedComponent, meteredComponent);

return new ProformaInvoiceWithComponents(
CLIENT.getProformaInvoicesController().previewProformaInvoice(subscription.getId()),
quantityBasedComponent, meteredComponent
);
}

}
Original file line number Diff line number Diff line change
@@ -1,12 +1,10 @@
package com.maxio.advancedbilling.controllers.proformainvoices;

import com.maxio.advancedbilling.AdvancedBillingClient;
import com.maxio.advancedbilling.TestClient;
import com.maxio.advancedbilling.controllers.ProformaInvoicesController;
import com.maxio.advancedbilling.exceptions.ApiException;
import com.maxio.advancedbilling.models.Customer;
import com.maxio.advancedbilling.models.ProformaInvoice;
import com.maxio.advancedbilling.utils.TestSetup;
import com.maxio.advancedbilling.utils.TestTeardown;
import com.maxio.advancedbilling.utils.assertions.CommonAssertions;
import org.junit.jupiter.api.AfterAll;
Expand All @@ -17,15 +15,13 @@

import static org.assertj.core.api.Assertions.assertThat;

public class ProformaInvoicesControllerReadTest {

private static final TestSetup TEST_SETUP = new TestSetup();
private static final AdvancedBillingClient CLIENT = TestClient.createClient();
private static final ProformaInvoicesController PROFORMA_INVOICES_CONTROLLER = CLIENT
.getProformaInvoicesController();
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 All @@ -39,8 +35,7 @@ static void teardown() throws IOException, ApiException {
@Test
void shouldReadProformaInvoice() throws IOException, ApiException {
// given
ProformaInvoice createdProformaInvoice = new ProformaInvoicesCreator()
.createProformaInvoiceWithComponents(customer).invoice();
ProformaInvoice createdProformaInvoice = createProformaInvoiceWithComponents(customer).invoice();

// when
ProformaInvoice proformaInvoice = PROFORMA_INVOICES_CONTROLLER.readProformaInvoice(createdProformaInvoice.getUid());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,8 +27,8 @@

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

import static com.maxio.advancedbilling.controllers.proformainvoices.ProformaInvoicesTestBase.formatDescriptionDate;
import static com.maxio.advancedbilling.models.ProformaInvoiceStatus.DRAFT;
import static com.maxio.advancedbilling.utils.TestFixtures.INVOICE_SELLER;
import static org.assertj.core.api.Assertions.assertThat;
Expand Down Expand Up @@ -201,14 +201,10 @@ void shouldReturn404WhenCreatingConsolidatedProformaInvoiceForNonExistentGroup()
@Test
void shouldReturn401WhenProvidingInvalidCredentials() {
// when - then
CommonAssertions.assertUnauthorized(() -> TestClient.createInvalidCredentialsClient().getProformaInvoicesController()
CommonAssertions.assertUnauthorized(() -> TestClient.createInvalidCredentialsClient()
.getProformaInvoicesController()
.createConsolidatedProformaInvoice("123")
);
}

private String formatDescriptionDate(LocalDate localDate) {
return localDate
.format(DateTimeFormatter.ofPattern("MM/dd/yyyy"));
}

}
Loading

0 comments on commit cf39e97

Please sign in to comment.