billing test - check behavior of the test data cleanup
MODIFY
test/api/BillingStripeTestData.ts
test/api/BillingStripeTestData.ts
@@ -289,6 +289,13 @@ export default class StripeIntegrationTestData {
return customerID;
}
+ public async checkNoInvoices() : Promise<void> {
+ const paging = TestConstants.DEFAULT_PAGING;
+ const ordering = [{ field: '-createdOn' }];
+ const response = await this.adminUserService.billingApi.readInvoices({}, paging, ordering);
+ assert(response?.data?.result.length === 0, 'There should be no invoices anymore');
+ }
+
public async checkForDraftInvoices(userId: string, expectedValue: number): Promise<number> {
const result = await this.getInvoicesByState(userId, BillingInvoiceStatus.DRAFT);
assert(result?.length === expectedValue, 'The number of invoice is not the expected one');
@@ -343,4 +350,9 @@ export default class StripeIntegrationTestData {
const billingUser: BillingUser = await this.billingImpl.forceSynchronizeUser(user);
expect(corruptedBillingData.customerID).to.not.be.eq(billingUser.billingData.customerID);
}
+
+ public async checkTestDataCleanup(): Promise<void> {
+ await this.billingImpl.clearTestData();
+ await this.checkNoInvoices();
+ }
}

ADD
test/api/BillingTestDataCleanupTest.ts
+import MongoDBStorage from '../../src/storage/mongodb/MongoDBStorage';
+import StripeIntegrationTestData from './BillingStripeTestData';
+import chai from 'chai';
+import chaiSubset from 'chai-subset';
+import config from '../config';
+import global from '../../src/types/GlobalType';
+import responseHelper from '../helpers/responseHelper';
+
+chai.use(chaiSubset);
+chai.use(responseHelper);
+
+const testData: StripeIntegrationTestData = new StripeIntegrationTestData();
+
+describe('Billing Test Data Cleanup', function() {
+ // Do not run the tests when the settings are not properly set
+ this.pending = !testData.isBillingProperlyConfigured();
+ this.timeout(1000000);
+
+ describe('With component Billing (tenant utbilling)', () => {
+ before(async () => {
+ global.database = new MongoDBStorage(config.get('storage'));
+ await global.database.start();
+ await testData.initialize();
+ await testData.forceBillingSettings(true);
+ });
+
+ after(async () => {
+ // Cleanup of the utbilling tenant is useless
+ // Anyway, there is no way to cleanup the utbilling stripe account!
+ });
+
+ it('should cleanup all billing test data', async () => {
+ await testData.checkTestDataCleanup();
+ });
+ });
+
+});

billing test - check behavior of the test data cleanup