billing - test - clear test data on live account
MODIFY
test/api/BillingStripeTestData.ts
test/api/BillingStripeTestData.ts
@@ -63,22 +63,30 @@ export default class StripeIntegrationTestData {
this.dynamicUser = await UserStorage.getUser(this.getTenantID(), userData.id);
}
- public async forceBillingSettings(immediateBilling: boolean, forceUser = true): Promise<void> {
+ public async forceBillingSettings(immediateBilling: boolean): Promise<void> {
// The tests requires some settings to be forced
- this.billingImpl = await this.setBillingSystemValidCredentials(immediateBilling);
- if (forceUser) {
+ await this.setBillingSystemValidCredentials(immediateBilling);
this.billingUser = await this.billingImpl.getUser(this.dynamicUser);
if (!this.billingUser && !FeatureToggles.isFeatureActive(Feature.BILLING_SYNC_USER)) {
this.billingUser = await this.billingImpl.forceSynchronizeUser(this.dynamicUser);
}
assert(this.billingUser, 'Billing user should not be null');
}
- }
- public async setBillingSystemValidCredentials(immediateBilling: boolean) : Promise<StripeBillingIntegration> {
+ public async setBillingSystemValidCredentials(immediateBilling: boolean) : Promise<void> {
const billingSettings = this.getLocalSettings(immediateBilling);
await this.saveBillingSettings(billingSettings);
billingSettings.stripe.secretKey = await Cypher.encrypt(this.getTenantID(), billingSettings.stripe.secretKey);
+ this.billingImpl = StripeBillingIntegration.getInstance(this.getTenant(), billingSettings);
+ assert(this.billingImpl, 'Billing implementation should not be null');
+ }
+
+ public async fakeLiveBillingSettings() : Promise<StripeBillingIntegration> {
+ const billingSettings = this.getLocalSettings(true);
+ const mode = 'live';
+ billingSettings.stripe.secretKey = `sk_${mode}_0234567890`;
+ billingSettings.stripe.publicKey = `pk_${mode}_0234567890`;
+ await this.saveBillingSettings(billingSettings);
const billingImpl = StripeBillingIntegration.getInstance(this.getTenant(), billingSettings);
assert(billingImpl, 'Billing implementation should not be null');
return billingImpl;
@@ -368,9 +376,10 @@ export default class StripeIntegrationTestData {
expect(corruptedBillingData.customerID).to.not.be.eq(billingUser.billingData.customerID);
}
- public async checkTestDataCleanup(): Promise<void> {
+ public async checkTestDataCleanup(successExpected: boolean): Promise<void> {
// await this.billingImpl.clearTestData();
const response = await this.adminUserService.billingApi.clearBillingTestData();
+ if (successExpected) {
// Check the response
expect(response?.data?.succeeded).to.be.eq(true);
expect(response?.data?.internalData).not.to.be.null;
@@ -385,5 +394,8 @@ export default class StripeIntegrationTestData {
await this.checkNoInvoices();
// Check the users
await this.checkNoUsersWithTestData();
+ } else {
+ expect(response?.data?.succeeded).to.be.eq(false);
+ }
}
}

MODIFY
test/api/BillingTestDataCleanupTest.ts
test/api/BillingTestDataCleanupTest.ts
@@ -21,16 +21,26 @@ describe('Billing Test Data Cleanup', function() {
global.database = new MongoDBStorage(config.get('storage'));
await global.database.start();
await testData.initialize();
- await testData.forceBillingSettings(true, false /* forceUser=false */);
});
- after(async () => {
- // Cleanup of the utbilling tenant is useless
- // Anyway, there is no way to cleanup the utbilling stripe account!
+ describe('with a STRIPE live account (a fake one!)', () => {
+ before(async () => {
+ await testData.fakeLiveBillingSettings();
});
it('should cleanup all billing test data', async () => {
- await testData.checkTestDataCleanup();
+ await testData.checkTestDataCleanup(false);
+ });
+ });
+
+ describe('with a STRIPE test account', () => {
+ before(async () => {
+ await testData.setBillingSystemValidCredentials(true);
+ });
+
+ it('should cleanup all billing test data', async () => {
+ await testData.checkTestDataCleanup(true);
+ });
});
});

billing - test - clear test data on live account