-
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.
[DE-676] Proforma invoices tests 2 (#121)
- Loading branch information
1 parent
8bf6795
commit ce4007e
Showing
10 changed files
with
797 additions
and
371 deletions.
There are no files selected for viewing
79 changes: 79 additions & 0 deletions
79
...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,79 @@ | ||
package com.maxio.advancedbilling.controllers.proformainvoices; | ||
|
||
import com.maxio.advancedbilling.TestClient; | ||
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.models.ProformaInvoice; | ||
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 extends ProformaInvoicesTestBase { | ||
|
||
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 | ||
ProformaInvoiceWithComponents invoiceWithData = createSignupProformaInvoice(customer); | ||
|
||
// then | ||
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) | ||
); | ||
} | ||
|
||
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); | ||
} | ||
|
||
} |
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
93 changes: 93 additions & 0 deletions
93
...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,93 @@ | ||
package com.maxio.advancedbilling.controllers.proformainvoices; | ||
|
||
import com.maxio.advancedbilling.TestClient; | ||
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.models.SignupProformaPreview; | ||
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 extends ProformaInvoicesTestBase { | ||
|
||
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 | ||
SignupProformaPreviewWithComponents previewWithData = previewSignupProformaInvoice(customer); | ||
|
||
// then | ||
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", | ||
"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) | ||
); | ||
} | ||
|
||
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); | ||
} | ||
|
||
} |
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
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
Oops, something went wrong.