billing - test clear billing test data endpoint
MODIFY
src/integration/billing/BillingIntegration.ts
src/integration/billing/BillingIntegration.ts
@@ -570,7 +570,7 @@ export default abstract class BillingIntegration {
abstract checkTestDataCleanupPrerequisites() : Promise<void>;
- abstract resetConnectionSettings() : Promise<void>;
+ abstract resetConnectionSettings() : Promise<BillingSettings>;
abstract startTransaction(transaction: Transaction): Promise<BillingDataTransactionStart>;

MODIFY
src/integration/billing/stripe/StripeBillingIntegration.ts
src/integration/billing/stripe/StripeBillingIntegration.ts
@@ -129,25 +129,22 @@ export default class StripeBillingIntegration extends BillingIntegration {
}
}
- public async resetConnectionSettings(): Promise<void> {
- // reset connection settings
- const { identifier, type } = this.settings;
- const newBillingsSettings: BillingSettings = {
- identifier,
- type,
- billing: {
+ public async resetConnectionSettings(): Promise<BillingSettings> {
+ // Reset connection settings
+ const newBillingsSettings = this.settings;
+ newBillingsSettings.billing = {
isTransactionBillingActivated: false,
immediateBillingAllowed: false,
periodicBillingAllowed: false,
taxID: null
- },
- stripe: {
+ };
+ newBillingsSettings.stripe = {
url: null,
secretKey: null,
publicKey: null
- }
};
await SettingStorage.saveBillingSetting(this.tenant.id, newBillingsSettings);
+ return newBillingsSettings;
}
public async getUsers(): Promise<BillingUser[]> {

MODIFY
src/server/rest/v1/service/BillingService.ts
src/server/rest/v1/service/BillingService.ts
@@ -58,20 +58,28 @@ export default class BillingService {
// Clear the test data
await billingImpl.clearTestData();
// Reset billing settings
- await billingImpl.resetConnectionSettings();
+ const newSettings = await billingImpl.resetConnectionSettings();
// Ok
- res.json(Object.assign({ done: true }, Constants.REST_RESPONSE_SUCCESS));
+ const operationResult: BillingOperationResult = {
+ succeeded: true,
+ internalData: newSettings
+ };
+ res.json(operationResult);
} catch (error) {
// Ko
await Logging.logError({
tenantID: req.user.tenantID,
user: req.user,
module: MODULE_NAME, method: 'handleClearBillingTestData',
- message: 'Billing connection failed',
+ message: 'Failed to clear billing test data',
action: action,
detailedMessages: { error: error.message, stack: error.stack }
});
- res.json(Object.assign({ done: false }, Constants.REST_RESPONSE_SUCCESS));
+ const operationResult: BillingOperationResult = {
+ succeeded: false,
+ error
+ };
+ res.json(operationResult);
}
next();
}

MODIFY
test/api/BillingStripeTestData.ts
test/api/BillingStripeTestData.ts
@@ -367,8 +367,21 @@ export default class StripeIntegrationTestData {
}
public async checkTestDataCleanup(): Promise<void> {
- await this.billingImpl.clearTestData();
+ // await this.billingImpl.clearTestData();
+ const response = await this.adminUserService.billingApi.clearBillingTestData();
+ // Check the response
+ expect(response?.data?.succeeded).to.be.eq(true);
+ expect(response?.data?.internalData).not.to.be.null;
+ // Check the new billing settings
+ const newSettings: BillingSettings = response?.data?.internalData as BillingSettings;
+ expect(newSettings.billing.isTransactionBillingActivated).to.be.false;
+ expect(newSettings.billing.taxID).to.be.null;
+ expect(newSettings.stripe.url).to.be.null;
+ expect(newSettings.stripe.publicKey).to.be.null;
+ expect(newSettings.stripe.secretKey).to.be.null;
+ // Check the invoices
await this.checkNoInvoices();
+ // Check the users
await this.checkNoUsersWithTestData();
}
}

MODIFY
test/api/client/BillingApi.ts
test/api/client/BillingApi.ts
@@ -40,6 +40,10 @@ export default class BillingApi extends CrudApi {
return await super.create(params, super.buildRestEndpointUrl(ServerRoute.REST_BILLING_CHECK, params));
}
+ public async clearBillingTestData(params?) {
+ return await super.create(params, super.buildRestEndpointUrl(ServerRoute.REST_BILLING_CLEAR_TEST_DATA, params));
+ }
+
public async updateBillingSetting(params?) {
return await super.update(params, super.buildRestEndpointUrl(ServerRoute.REST_BILLING_SETTING, params));
}

billing - test clear billing test data endpoint