bp - test reorg
MODIFY
test/api/BillingPlatformTest.ts
test/api/BillingPlatformTest.ts
@@ -42,58 +42,11 @@ describeif(isBillingProperlyConfigured)('Billing', () => {
describe('Billing Service (utbillingplatform)', () => {
beforeAll(async () => {
await stripeTestHelper.initialize(ContextDefinition.TENANT_CONTEXTS.TENANT_BILLING_PLATFORM);
+ // TODO - This is ugly and confusing - rethink that part (merge BillingTestHelper and StripeTestHelper methods)
await billingTestHelper.initialize(ContextDefinition.TENANT_CONTEXTS.TENANT_BILLING_PLATFORM);
- const immediateBilling = false;
- await stripeTestHelper.forceBillingSettings(immediateBilling);
- });
-
- describe('Where admin user', () => {
- // eslint-disable-next-line @typescript-eslint/require-await
- beforeAll(async () => {
- billingTestHelper.initUserContextAsAdmin();
- // Initialize the charging station context
- await billingTestHelper.initChargingStationContext2TestChargingTime();
- });
+ // Initialize the Billing module
+ await billingTestHelper.setBillingSystemValidCredentials(true, false /* immediateBillingAllowed OFF, so periodicBilling ON */);
- xit('should create an invoice, and get transfers generated', async () => {
- // -------------------------------------------------------------------------------------------------------------
- // -------------------------------------------------------------------------------------------------------------
- // -------------------------------------------------------------------------------------------------------------
- // -------------------------------------------------------------------------------------------------------------
- // TO DO - GENERATE SEVERAL TRANSACTIONS
- // -------------------------------------------------------------------------------------------------------------
- // - create and onboard two accounts
- // - assign a account at a company level (with a platform fee strategy)
- // - Override the account at a site level (with a distinct platform fee strategy)
- // - Generate several transactions
- // - Make sure to select the periodic billing mode and generate DRAFT invoices
- // - Make sure to have several sessions per invoices
- // - Make sure each invoices targets SEVERAL SUB-ACCOUNTS
- // - force the periodic billing and thus GENERATE SEVERAL TRANSFERS
- // - finalize the transfers!!!!
- // - send the transfers to STRIPE to generate the real transfer of funds
- // -------------------------------------------------------------------------------------------------------------
- await billingTestHelper.userService.billingApi.forceSynchronizeUser({ id: billingTestHelper.userContext.id });
- const userWithBillingData = await billingTestHelper.billingImpl.getUser(billingTestHelper.userContext);
- await billingTestHelper.assignPaymentMethod(userWithBillingData, 'tok_fr');
- const transactionID = await billingTestHelper.generateTransaction(billingTestHelper.userContext);
- assert(transactionID, 'transactionID should not be null');
- // Check that we have a new invoice with an invoiceID and but no invoiceNumber yet
- await billingTestHelper.checkTransactionBillingData(transactionID, BillingInvoiceStatus.DRAFT);
- // Let's simulate the periodic billing operation
- const taskConfiguration: BillingPeriodicOperationTaskConfig = {
- onlyProcessUnpaidInvoices: false,
- forceOperation: true
- };
- const operationResult: BillingChargeInvoiceAction = await billingTestHelper.billingImpl.chargeInvoices(taskConfiguration);
- assert(operationResult.inSuccess > 0, 'The operation should have been able to process at least one invoice');
- assert(operationResult.inError === 0, 'The operation should detect any errors');
- // The transaction should now have a different status and know the final invoice number
- await billingTestHelper.checkTransactionBillingData(transactionID, BillingInvoiceStatus.PAID);
- // The user should have no DRAFT invoices
- const nbDraftInvoices = await billingTestHelper.checkForDraftInvoices();
- assert(nbDraftInvoices === 0, 'The expected number of DRAFT invoices is not correct');
- });
});
describe('Connected Accounts', () => {
@@ -292,12 +245,61 @@ describeif(isBillingProperlyConfigured)('Billing', () => {
});
});
+ describe('Where admin user', () => {
+ // eslint-disable-next-line @typescript-eslint/require-await
+ beforeAll(async () => {
+ billingTestHelper.initUserContextAsAdmin();
+ // Initialize the charging station context
+ await billingTestHelper.initChargingStationContext2TestChargingTime();
+ });
+
+ it('should create an invoice, and get transfers generated', async () => {
+ // -------------------------------------------------------------------------------------------------------------
+ // -------------------------------------------------------------------------------------------------------------
+ // -------------------------------------------------------------------------------------------------------------
+ // -------------------------------------------------------------------------------------------------------------
+ // TO DO - GENERATE SEVERAL TRANSACTIONS
+ // -------------------------------------------------------------------------------------------------------------
+ // - create and onboard two accounts
+ // - assign a account at a company level (with a platform fee strategy)
+ // - Override the account at a site level (with a distinct platform fee strategy)
+ // - Generate several transactions
+ // - Make sure to select the periodic billing mode and generate DRAFT invoices
+ // - Make sure to have several sessions per invoices
+ // - Make sure each invoices targets SEVERAL SUB-ACCOUNTS
+ // - force the periodic billing and thus GENERATE SEVERAL TRANSFERS
+ // - finalize the transfers!!!!
+ // - send the transfers to STRIPE to generate the real transfer of funds
+ // -------------------------------------------------------------------------------------------------------------
+ await billingTestHelper.userService.billingApi.forceSynchronizeUser({ id: billingTestHelper.userContext.id });
+ const userWithBillingData = await billingTestHelper.billingImpl.getUser(billingTestHelper.userContext);
+ await billingTestHelper.assignPaymentMethod(userWithBillingData, 'tok_fr');
+ const transactionID = await billingTestHelper.generateTransaction(billingTestHelper.userContext);
+ assert(transactionID, 'transactionID should not be null');
+ // Check that we have a new invoice with an invoiceID and but no invoiceNumber yet
+ await billingTestHelper.checkTransactionBillingData(transactionID, BillingInvoiceStatus.DRAFT);
+ // Let's simulate the periodic billing operation
+ const taskConfiguration: BillingPeriodicOperationTaskConfig = {
+ onlyProcessUnpaidInvoices: false,
+ forceOperation: true
+ };
+ const operationResult: BillingChargeInvoiceAction = await billingTestHelper.billingImpl.chargeInvoices(taskConfiguration);
+ assert(operationResult.inSuccess > 0, 'The operation should have been able to process at least one invoice');
+ assert(operationResult.inError === 0, 'The operation should detect any errors');
+ // The transaction should now have a different status and know the final invoice number
+ await billingTestHelper.checkTransactionBillingData(transactionID, BillingInvoiceStatus.PAID);
+ // The user should have no DRAFT invoices
+ const nbDraftInvoices = await billingTestHelper.checkForDraftInvoices();
+ assert(nbDraftInvoices === 0, 'The expected number of DRAFT invoices is not correct');
+ });
+ });
+
});
describe('Where basic user', () => {
beforeAll(async () => {
- billingTestHelper.billingImpl = await billingTestHelper.setBillingSystemValidCredentials();
+ await billingTestHelper.setBillingSystemValidCredentials();
billingTestHelper.userContext = billingTestHelper.tenantContext.getUserContext(ContextDefinition.USER_CONTEXTS.BASIC_USER);
billingTestHelper.userService = new CentralServerService(
billingTestHelper.tenantContext.getTenant().subdomain,

MODIFY
test/api/BillingTest.ts
test/api/BillingTest.ts
@@ -129,7 +129,7 @@ describeif(isBillingProperlyConfigured)('Billing', () => {
beforeAll(async () => {
billingTestHelper.initUserContextAsAdmin();
// Initialize the Billing module with transaction billing ON
- billingTestHelper.billingImpl = await billingTestHelper.setBillingSystemValidCredentials(false);
+ await billingTestHelper.setBillingSystemValidCredentials(false);
});
it('Should be able to invoke Billing Settings endpoints', async () => {
@@ -195,7 +195,7 @@ describeif(isBillingProperlyConfigured)('Billing', () => {
beforeAll(async () => {
billingTestHelper.initUserContextAsAdmin();
// Initialize the Billing module with transaction billing ON
- billingTestHelper.billingImpl = await billingTestHelper.setBillingSystemValidCredentials();
+ await billingTestHelper.setBillingSystemValidCredentials();
});
it('Should be able to invoke Billing Settings endpoints', async () => {
@@ -275,7 +275,7 @@ describeif(isBillingProperlyConfigured)('Billing', () => {
// Initialize the charing station context
await billingTestHelper.initChargingStationContext();
// Initialize the Billing module
- billingTestHelper.billingImpl = await billingTestHelper.setBillingSystemValidCredentials();
+ await billingTestHelper.setBillingSystemValidCredentials();
// Make sure the required users are in sync
const adminUser: User = billingTestHelper.tenantContext.getUserContext(ContextDefinition.USER_CONTEXTS.DEFAULT_ADMIN);
const basicUser: User = billingTestHelper.tenantContext.getUserContext(ContextDefinition.USER_CONTEXTS.BASIC_USER);
@@ -392,7 +392,7 @@ describeif(isBillingProperlyConfigured)('Billing', () => {
describe('Where basic user', () => {
beforeAll(async () => {
- billingTestHelper.billingImpl = await billingTestHelper.setBillingSystemValidCredentials();
+ await billingTestHelper.setBillingSystemValidCredentials();
billingTestHelper.userContext = billingTestHelper.tenantContext.getUserContext(ContextDefinition.USER_CONTEXTS.BASIC_USER);
billingTestHelper.userService = new CentralServerService(
billingTestHelper.tenantContext.getTenant().subdomain,
@@ -471,7 +471,7 @@ describeif(isBillingProperlyConfigured)('Billing', () => {
afterAll(async () => {
// Restore VALID STRIPE credentials
- billingTestHelper.billingImpl = await billingTestHelper.setBillingSystemValidCredentials();
+ await billingTestHelper.setBillingSystemValidCredentials();
});
it('Should recover after a synchronization issue', async () => {
@@ -479,14 +479,14 @@ describeif(isBillingProperlyConfigured)('Billing', () => {
...Factory.user.build(),
} as User;
fakeUser.issuer = true;
- billingTestHelper.billingImpl = await billingTestHelper.setBillingSystemInvalidCredentials();
+ await billingTestHelper.setBillingSystemInvalidCredentials();
assert(billingTestHelper.billingImpl, 'Billing implementation should not be null');
await billingTestHelper.userService.createEntity(
billingTestHelper.userService.userApi,
fakeUser
);
billingTestHelper.createdUsers.push(fakeUser);
- billingTestHelper.billingImpl = await billingTestHelper.setBillingSystemValidCredentials();
+ await billingTestHelper.setBillingSystemValidCredentials();
const billingUser = await billingTestHelper.billingImpl.synchronizeUser(fakeUser);
expect(billingUser).to.be.not.null;
const userExists = await billingTestHelper.billingImpl.isUserSynchronized(fakeUser);
@@ -499,13 +499,13 @@ describeif(isBillingProperlyConfigured)('Billing', () => {
beforeAll(async () => {
billingTestHelper.initUserContextAsAdmin();
// Force INVALID STRIPE credentials
- billingTestHelper.billingImpl = await billingTestHelper.setBillingSystemInvalidCredentials();
+ await billingTestHelper.setBillingSystemInvalidCredentials();
assert(billingTestHelper.billingImpl, 'Billing implementation should not be null');
});
afterAll(async () => {
// Restore VALID STRIPE credentials
- billingTestHelper.billingImpl = await billingTestHelper.setBillingSystemValidCredentials();
+ await billingTestHelper.setBillingSystemValidCredentials();
});
it('Should not be able to start a transaction', async () => {
@@ -520,7 +520,7 @@ describeif(isBillingProperlyConfigured)('Billing', () => {
beforeAll(async () => {
billingTestHelper.initUserContextAsAdmin();
// Set STRIPE credentials
- billingTestHelper.billingImpl = await billingTestHelper.setBillingSystemInvalidCredentials();
+ await billingTestHelper.setBillingSystemInvalidCredentials();
});
afterAll(async () => {
@@ -541,7 +541,7 @@ describeif(isBillingProperlyConfigured)('Billing', () => {
expect(billingTestHelper.userContext).to.not.be.null;
await billingTestHelper.initChargingStationContext();
// Initialize the Billing module
- billingTestHelper.billingImpl = await billingTestHelper.setBillingSystemValidCredentials(false);
+ await billingTestHelper.setBillingSystemValidCredentials(false);
});
describe('Where admin user', () => {
@@ -573,7 +573,7 @@ describeif(isBillingProperlyConfigured)('Billing', () => {
beforeAll(async () => {
billingTestHelper.initUserContextAsAdmin();
// Initialize the Billing module
- billingTestHelper.billingImpl = await billingTestHelper.setBillingSystemValidCredentials(true, true /* immediateBillingAllowed ON */);
+ await billingTestHelper.setBillingSystemValidCredentials(true, true /* immediateBillingAllowed ON */);
});
describe('FF + CT', () => {
@@ -801,7 +801,7 @@ describeif(isBillingProperlyConfigured)('Billing', () => {
beforeAll(async () => {
// Initialize the charging station context
await billingTestHelper.initChargingStationContext();
- billingTestHelper.billingImpl = await billingTestHelper.setBillingSystemValidCredentials();
+ await billingTestHelper.setBillingSystemValidCredentials();
billingTestHelper.adminUserContext = await billingTestHelper.tenantContext.getUserContext(ContextDefinition.USER_CONTEXTS.DEFAULT_ADMIN);
expect(billingTestHelper.adminUserContext).to.not.be.null;
billingTestHelper.userContext = billingTestHelper.tenantContext.getUserContext(ContextDefinition.USER_CONTEXTS.BASIC_USER);
@@ -843,7 +843,7 @@ describeif(isBillingProperlyConfigured)('Billing', () => {
beforeAll(async () => {
// Initialize the charging station context
await billingTestHelper.initChargingStationContext();
- billingTestHelper.billingImpl = await billingTestHelper.setBillingSystemValidCredentials();
+ await billingTestHelper.setBillingSystemValidCredentials();
billingTestHelper.adminUserContext = await billingTestHelper.tenantContext.getUserContext(ContextDefinition.USER_CONTEXTS.DEFAULT_ADMIN);
expect(billingTestHelper.adminUserContext).to.not.be.null;
billingTestHelper.userContext = billingTestHelper.tenantContext.getUserContext(ContextDefinition.USER_CONTEXTS.BASIC_USER);
@@ -883,7 +883,7 @@ describeif(isBillingProperlyConfigured)('Billing', () => {
beforeAll(async () => {
billingTestHelper.initUserContextAsAdmin();
// Initialize the Billing module
- billingTestHelper.billingImpl = await billingTestHelper.setBillingSystemValidCredentials(true, false /* immediateBillingAllowed OFF, so periodicBilling ON */);
+ await billingTestHelper.setBillingSystemValidCredentials(true, false /* immediateBillingAllowed OFF, so periodicBilling ON */);
});
describe('Where admin user', () => {
@@ -935,7 +935,7 @@ describeif(isBillingProperlyConfigured)('Billing', () => {
beforeAll(async () => {
billingTestHelper.initUserContextAsAdmin();
// Initialize the Billing module
- billingTestHelper.billingImpl = await billingTestHelper.setBillingSystemValidCredentials(true, true /* immediateBillingAllowed ON */);
+ await billingTestHelper.setBillingSystemValidCredentials(true, true /* immediateBillingAllowed ON */);
await billingTestHelper.initChargingStationContext2TestChargingTime();
});

MODIFY
test/api/BillingTestHelper.ts
test/api/BillingTestHelper.ts
@@ -410,7 +410,7 @@ export default class BillingTestHelper {
return this.chargingStationContext;
}
- public async setBillingSystemValidCredentials(activateTransactionBilling = true, immediateBillingAllowed = false) : Promise<StripeBillingIntegration> {
+ public async setBillingSystemValidCredentials(activateTransactionBilling = true, immediateBillingAllowed = false) : Promise<void> {
const billingSettings = this.getLocalSettings(immediateBillingAllowed);
// Here we switch ON or OFF the billing of charging sessions
billingSettings.billing.isTransactionBillingActivated = activateTransactionBilling;
@@ -421,10 +421,10 @@ export default class BillingTestHelper {
billingSettings.stripe.secretKey = await Cypher.encrypt(tenant, billingSettings.stripe.secretKey);
const billingImpl = StripeBillingIntegration.getInstance(tenant, billingSettings);
assert(billingImpl, 'Billing implementation should not be null');
- return billingImpl;
+ this.billingImpl = billingImpl;
}
- public async setBillingSystemInvalidCredentials() : Promise<StripeBillingIntegration> {
+ public async setBillingSystemInvalidCredentials() : Promise<void> {
const billingSettings = this.getLocalSettings(false);
const tenant = this.tenantContext?.getTenant();
assert(!!tenant, 'Tenant cannot be null');
@@ -432,7 +432,7 @@ export default class BillingTestHelper {
await this.saveBillingSettings(billingSettings);
const billingImpl = StripeBillingIntegration.getInstance(tenant, billingSettings);
assert(billingImpl, 'Billing implementation should not be null');
- return billingImpl;
+ this.billingImpl = billingImpl;
}
public getLocalSettings(immediateBillingAllowed: boolean): BillingSettings {

bp - test reorg