-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
68b7d87
commit 48f4cfc
Showing
6 changed files
with
453 additions
and
104 deletions.
There are no files selected for viewing
74 changes: 74 additions & 0 deletions
74
...ling/controllers/proformainvoices/ProformaInvoicesControllerCreateSignupProformaTest.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,74 @@ | ||
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.CreateSubscription; | ||
import com.maxio.advancedbilling.models.CreateSubscriptionRequest; | ||
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; | ||
import org.junit.jupiter.api.BeforeAll; | ||
import org.junit.jupiter.api.Test; | ||
|
||
import java.io.IOException; | ||
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(); | ||
|
||
private static Customer customer; | ||
|
||
@BeforeAll | ||
static void setUp() throws IOException, ApiException { | ||
customer = TEST_SETUP.createCustomer(); | ||
} | ||
|
||
@AfterAll | ||
static void teardown() throws IOException, ApiException { | ||
new TestTeardown().deleteCustomer(customer); | ||
} | ||
|
||
@Test | ||
void shouldCreateSignupProforma() throws IOException, ApiException { | ||
// given-when | ||
ProformaInvoicesCreator proformaInvoicesCreator = new ProformaInvoicesCreator(); | ||
ProformaInvoicesCreator.ProformaInvoiceWithComponents invoiceWithData = | ||
proformaInvoicesCreator.createSignupProformaInvoice(customer); | ||
|
||
// then | ||
proformaInvoicesCreator.assertProformaInvoice(customer, invoiceWithData, true, true); | ||
} | ||
|
||
@Test | ||
void shouldReturn422WhenCreatingProformaInvoiceWithInvalidData() { | ||
// when - then | ||
CommonAssertions | ||
.assertThatErrorArrayMapResponse(() -> PROFORMA_INVOICES_CONTROLLER.createSignupProformaInvoice( | ||
new CreateSubscriptionRequest(new CreateSubscription.Builder() | ||
.productId(11) | ||
.build() | ||
) | ||
) | ||
) | ||
.isUnprocessableEntity() | ||
.hasErrorMap(Map.of("base", List.of("Couldn't find Product by 11"))); | ||
} | ||
|
||
@Test | ||
void shouldReturn401WhenProvidingInvalidCredentials() { | ||
// when - then | ||
CommonAssertions.assertUnauthorized(() -> TestClient.createInvalidCredentialsClient().getProformaInvoicesController() | ||
.createSignupProformaInvoice(null) | ||
); | ||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
84 changes: 84 additions & 0 deletions
84
...ing/controllers/proformainvoices/ProformaInvoicesControllerPreviewSignupProformaTest.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,84 @@ | ||
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.CreateSubscription; | ||
import com.maxio.advancedbilling.models.CreateSubscriptionRequest; | ||
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; | ||
import org.junit.jupiter.api.BeforeAll; | ||
import org.junit.jupiter.api.Test; | ||
|
||
import java.io.IOException; | ||
import java.util.List; | ||
import java.util.Map; | ||
|
||
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(); | ||
|
||
private static Customer customer; | ||
|
||
@BeforeAll | ||
static void setUp() throws IOException, ApiException { | ||
customer = TEST_SETUP.createCustomer(); | ||
} | ||
|
||
@AfterAll | ||
static void teardown() throws IOException, ApiException { | ||
new TestTeardown().deleteCustomer(customer); | ||
} | ||
|
||
@Test | ||
void shouldPreviewSignupProformaWithNextProforma() throws IOException, ApiException { | ||
// given-when | ||
ProformaInvoicesCreator proformaInvoicesCreator = new ProformaInvoicesCreator(); | ||
ProformaInvoicesCreator.SignupProformaPreviewWithComponents previewWithData = | ||
proformaInvoicesCreator.previewSignupProformaInvoice(customer); | ||
|
||
// then | ||
proformaInvoicesCreator.assertProformaInvoice(customer, | ||
new ProformaInvoicesCreator.ProformaInvoiceWithComponents(previewWithData.preview().getCurrentProformaInvoice(), | ||
previewWithData.quantityBasedComponent(), previewWithData.meteredComponent()), | ||
false, true); | ||
|
||
assertThat(previewWithData.preview().getNextProformaInvoice()).usingRecursiveComparison() | ||
.ignoringFields("subtotalAmount", "totalAmount", "uid", "lineItems", "deliveryDate", "dueAmount") | ||
.isEqualTo(previewWithData.preview().getCurrentProformaInvoice()); | ||
} | ||
|
||
@Test | ||
void shouldReturn422WhenCreatingProformaInvoiceWithInvalidData() { | ||
// when - then | ||
CommonAssertions | ||
.assertThatErrorArrayMapResponse(() -> PROFORMA_INVOICES_CONTROLLER.previewSignupProformaInvoice( | ||
null, | ||
new CreateSubscriptionRequest(new CreateSubscription.Builder() | ||
.productId(11) | ||
.build() | ||
) | ||
) | ||
) | ||
.isUnprocessableEntity() | ||
.hasErrorMap(Map.of("base", List.of("Couldn't find Product by 11"))); | ||
} | ||
|
||
@Test | ||
void shouldReturn401WhenProvidingInvalidCredentials() { | ||
// when - then | ||
CommonAssertions.assertUnauthorized(() -> TestClient.createInvalidCredentialsClient().getProformaInvoicesController() | ||
.previewSignupProformaInvoice(null, null) | ||
); | ||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
80 changes: 80 additions & 0 deletions
80
...illing/controllers/proformainvoices/ProformaInvoicesControllerSubscriptionGroupsTest.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,80 @@ | ||
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.ListProformaInvoicesResponse; | ||
import com.maxio.advancedbilling.models.Product; | ||
import com.maxio.advancedbilling.models.ProductFamily; | ||
import com.maxio.advancedbilling.models.SubscriptionGroupSignupResponse; | ||
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; | ||
import org.junit.jupiter.api.BeforeAll; | ||
import org.junit.jupiter.api.Test; | ||
|
||
import java.io.IOException; | ||
|
||
import static org.assertj.core.api.Assertions.assertThat; | ||
|
||
/** | ||
* This class tests both `Create Consolidated Proforma Invoices` and `List Subscription Group Proforma Invoices` | ||
* operations, as the Creation response is asynchronous and has no specific response, but it's needed to execute listing. | ||
*/ | ||
public class ProformaInvoicesControllerSubscriptionGroupsTest { | ||
|
||
private static final TestSetup TEST_SETUP = new TestSetup(); | ||
private static final AdvancedBillingClient CLIENT = TestClient.createClient(); | ||
private static final ProformaInvoicesController PROFORMA_INVOICES_CONTROLLER = CLIENT | ||
.getProformaInvoicesController(); | ||
|
||
private static SubscriptionGroupSignupResponse groupSignup; | ||
|
||
@BeforeAll | ||
static void setUp() throws IOException, ApiException, InterruptedException { | ||
ProductFamily productFamily = TEST_SETUP.createProductFamily(); | ||
Product product = TEST_SETUP.createProduct(productFamily, b -> b.priceInCents(1250)); | ||
Component meteredComponent = TEST_SETUP.createMeteredComponent(productFamily, 11.5); | ||
|
||
groupSignup = TEST_SETUP.signupWithSubscriptionGroup(product, meteredComponent); | ||
PROFORMA_INVOICES_CONTROLLER.createConsolidatedProformaInvoice(groupSignup.getUid()); | ||
|
||
Thread.sleep(5000); | ||
} | ||
|
||
@AfterAll | ||
static void teardown() throws IOException, ApiException { | ||
TestTeardown testTeardown = new TestTeardown(); | ||
testTeardown.deleteSubscriptionGroup(groupSignup); | ||
} | ||
|
||
@Test | ||
void shouldListGroupProformas() throws IOException, ApiException { | ||
// given-when | ||
ListProformaInvoicesResponse listProformaInvoicesResponse = PROFORMA_INVOICES_CONTROLLER | ||
.listSubscriptionGroupProformaInvoices(groupSignup.getUid()); | ||
|
||
// then | ||
assertThat(listProformaInvoicesResponse.getProformaInvoices()).isNotEmpty(); | ||
} | ||
|
||
@Test | ||
void shouldReturn404WhenCreatingConsolidatedProformaInvoiceForNonGroup() { | ||
// when - then | ||
CommonAssertions.assertNotFound( | ||
() -> PROFORMA_INVOICES_CONTROLLER.createConsolidatedProformaInvoice("123") | ||
); | ||
} | ||
|
||
@Test | ||
void shouldReturn401WhenProvidingInvalidCredentials() { | ||
// when - then | ||
CommonAssertions.assertUnauthorized(() -> TestClient.createInvalidCredentialsClient().getProformaInvoicesController() | ||
.createConsolidatedProformaInvoice("123") | ||
); | ||
} | ||
|
||
} |
Oops, something went wrong.