utbilling - forceBillingSettings - imediateBilling ON/OFF
MODIFY
test/api/BillingStripeIntegrationTest.ts
test/api/BillingStripeIntegrationTest.ts
@@ -23,8 +23,10 @@ describe('Billing Stripe Service', function() {
await testData.initialize();
});
- describe('Where the admin user', () => {
+ describe('immediate billing OFF', () => {
before(async () => {
+ const immediateBilling = false;
+ await testData.forceBillingSettings(immediateBilling);
});
after(async () => {
@@ -40,17 +42,24 @@ describe('Billing Stripe Service', function() {
await testData.checkBusinessProcessBillToPay();
});
+ });
+
+ describe('immediate billing ON', () => {
+ before(async () => {
+ /* ------------------------------------------------------
+ Billing settings are forced to check the complete flow
+ Invoice State - DRAFT => OPEN => PAID
+ -------------------------------------------------------*/
+ const immediateBilling = true;
+ await testData.forceBillingSettings(immediateBilling);
+ });
+
it('Should add a different payment method to BILLING-TEST user', async () => {
await testData.assignPaymentMethod('tok_fr');
});
- // it('Should set VAT tax rate to 20% (non inclusive)', async () => {
- // await testData.assignTaxRate(20);
- // });
-
it('should create and pay a second invoice for BILLING-TEST user', async () => {
- await testData.checkBusinessProcessBillToPay(true);
- await testData.checkDownloadInvoiceAsPdf();
+ await testData.checkImmediateBillingWithTaxes();
});
});

MODIFY
test/api/BillingStripeTestData.ts
test/api/BillingStripeTestData.ts
@@ -57,8 +57,12 @@ export default class StripeIntegrationTestData {
assert(userData && userData.id, 'response should not be null');
// Let's get the newly created user
this.dynamicUser = await UserStorage.getUser(this.getTenantID(), userData.id);
+ }
+
+ public async forceBillingSettings(immediateBilling: boolean): Promise<void> {
+ // The tests requires some settings to be forced
+ this.billingImpl = await this.setBillingSystemValidCredentials(immediateBilling);
// Let's get access to the STRIPE implementation - StripeBillingIntegration instance
- this.billingImpl = await this.setBillingSystemValidCredentials(false);
this.billingUser = await this.billingImpl.getBillingUserByInternalID(this.getCustomerID());
expect(this.billingUser, 'Billing user should not ber null');
}
@@ -180,6 +184,34 @@ export default class StripeIntegrationTestData {
return nbDraftInvoice;
}
+ public async checkImmediateBillingWithTaxes() : Promise<void> {
+ // Inputs / Expected Outputs
+ const transactionPrice = 4 /* EUR */;
+ const tax20percent = 20 /* VAT 20 % */;
+ const expectedTotal = 480; /* in cents, including taxes */
+ // PREREQUISITE - immediateBillingAllowed MUST BE ON!
+ const taxRate: Stripe.TaxRate = await this.assignTaxRate(tax20percent);
+ const taxId = taxRate.id;
+ // The user should have no DRAFT invoices
+ await this.checkForDraftInvoices(this.dynamicUser.id, 0);
+ // Let's create an Invoice with a first Item
+ const dynamicInvoice = await this.billInvoiceItem(500 /* kW.h */, transactionPrice /* EUR */, taxId);
+ assert(dynamicInvoice, 'Invoice should not be null');
+ // User should have a PAID invoice
+ const paidInvoices = await this.getInvoicesByState(this.dynamicUser.id, BillingInvoiceStatus.PAID);
+ assert(paidInvoices, 'User should have at least a paid invoice');
+ // The last invoice should be the one that has just been created
+ const lastPaidInvoice: BillingInvoice = paidInvoices[0];
+ expect(lastPaidInvoice.amount).to.be.eq(expectedTotal); // 480 cents - TODO - Billing Invoice exposing cents???
+ // TODO - check the date?
+ // TODO - convert amount from cents to euros?
+ const downloadResponse = await this.adminUserService.billingApi.downloadInvoiceDocument({ ID: lastPaidInvoice.id });
+ expect(downloadResponse.headers['content-type']).to.be.eq('application/pdf');
+ // User should not have any DRAFT invoices
+ const nbDraftInvoice:number = await this.checkForDraftInvoices(this.dynamicUser.id, 0);
+ expect(nbDraftInvoice).to.be.eql(0);
+ }
+
public async billInvoiceItem(quantity: number, amount: number, taxId?: string) : Promise<BillingInvoice> {
assert(this.billingUser, 'Billing user cannot be null');
const price = amount / quantity;

utbilling - forceBillingSettings - imediateBilling ON/OFF