billing - repair user - automated test
MODIFY
test/api/BillingStripeIntegrationTest.ts
test/api/BillingStripeIntegrationTest.ts
@@ -80,6 +80,11 @@ describe('Billing Stripe Service', function() {
const newSource = await testData.assignPaymentMethod('tok_fr');
await testData.checkDetachPaymentMethod(newSource.id);
});
+
+ it('should be able to repair a user', async () => {
+ await testData.checkRepairInconsistencies();
+ });
+
});
});

MODIFY
test/api/BillingStripeTestData.ts
test/api/BillingStripeTestData.ts
-import { BillingInvoice, BillingInvoiceItem, BillingInvoiceStatus, BillingPaymentMethodResult, BillingUser } from '../../src/types/Billing';
+import { BillingInvoice, BillingInvoiceItem, BillingInvoiceStatus, BillingPaymentMethodResult, BillingUser, BillingUserData } from '../../src/types/Billing';
import { BillingSettingsType, SettingDB, StripeBillingSetting } from '../../src/types/Setting';
import chai, { assert, expect } from 'chai';
@@ -312,4 +312,31 @@ export default class StripeIntegrationTestData {
expect(downloadResponse.headers['content-type']).to.be.eq('application/pdf');
}
+ public async checkRepairInconsistencies() : Promise<void> {
+ // Create a new user for testing stripe scenarios - BILLING-TEST
+ const user = {
+ ...Factory.user.build(),
+ name: 'RECOVERY-TEST',
+ firstName: 'Billing Recovery Tests',
+ issuer: true
+ } as User;
+ // Let's create a new user
+ const userData = await this.adminUserService.createEntity(
+ this.adminUserService.userApi,
+ user
+ );
+ assert(userData && userData.id, 'response should not be null');
+ // Let's get the newly created user
+ const testUser = await UserStorage.getUser(this.getTenantID(), userData.id);
+ expect(testUser.billingData).not.to.be.null;
+ const corruptedBillingData: BillingUserData = {
+ ...testUser.billingData,
+ customerID: 'cus_corrupted_data'
+ };
+ // Let's update the billing data with an inconsistent customer ID
+ await UserStorage.saveUserBillingData(this.getTenantID(), testUser.id, corruptedBillingData);
+ // Let's now try to repair the user data.
+ const billingUser: BillingUser = await this.billingImpl.forceSynchronizeUser(user);
+ expect(corruptedBillingData.customerID).to.not.be.eq(billingUser.billingData.customerID);
+ }
}

billing - repair user - automated test