Billing - Test that transaction cannot be started
MODIFY
src/integration/billing/stripe/StripeBillingIntegration.ts
src/integration/billing/stripe/StripeBillingIntegration.ts
@@ -820,7 +820,7 @@ export default class StripeBillingIntegration extends BillingIntegration {
public async stopTransaction(transaction: Transaction): Promise<BillingDataTransactionStop> {
// Check whether the billing was activated on start transaction
- if (!transaction.billingData.withBillingActive) {
+ if (!transaction.billingData?.withBillingActive) {
return {
status: BillingStatus.UNBILLED
};

MODIFY
src/server/ocpp/utils/OCPPUtils.ts
src/server/ocpp/utils/OCPPUtils.ts
@@ -340,6 +340,7 @@ export default class OCPPUtils {
module: MODULE_NAME, method: 'billTransaction',
message, detailedMessages: { error: error.message, stack: error.stack }
});
+ // Prevent from starting a transaction when Billing prerequisites are not met
throw new BackendError({
user: transaction.user,
action: ServerAction.BILLING_TRANSACTION,
@@ -367,12 +368,6 @@ export default class OCPPUtils {
module: MODULE_NAME, method: 'billTransaction',
message, detailedMessages: { error: error.message, stack: error.stack }
});
- throw new BackendError({
- user: transaction.user,
- action: ServerAction.BILLING_TRANSACTION,
- module: MODULE_NAME, method: 'billTransaction',
- message, detailedMessages: { error: error.message, stack: error.stack }
- });
}
break;
// Stop Transaction
@@ -395,12 +390,6 @@ export default class OCPPUtils {
module: MODULE_NAME, method: 'billTransaction',
message, detailedMessages: { error: error.message, stack: error.stack }
});
- throw new BackendError({
- user: transaction.user,
- action: ServerAction.BILLING_TRANSACTION,
- module: MODULE_NAME, method: 'billTransaction',
- message, detailedMessages: { error: error.message, stack: error.stack }
- });
}
break;
}

MODIFY
test/api/BillingTest.ts
test/api/BillingTest.ts
@@ -131,7 +131,7 @@ class TestData {
await this.adminUserService.settingApi.update(componentSetting);
}
- public async generateTransaction(user: any): Promise<number> {
+ public async generateTransaction(user: any, expectedStatus = 'Accepted'): Promise<number> {
// const user:any = this.userContext;
const connectorId = 1;
assert((user.tags && user.tags.length), 'User must have a valid tag');
@@ -141,11 +141,12 @@ class TestData {
const startDate = moment().toDate();
const stopDate = moment(startDate).add(1, 'hour').toDate();
const startTransactionResponse = await this.chargingStationContext.startTransaction(connectorId, tagId, meterStart, startDate);
- // eslint-disable-next-line @typescript-eslint/unbound-method
- expect(startTransactionResponse).to.be.transactionValid;
+ expect(startTransactionResponse).to.be.transactionStatus(expectedStatus);
const transactionId = startTransactionResponse.transactionId;
+ if (expectedStatus === 'Accepted') {
const stopTransactionResponse = await this.chargingStationContext.stopTransaction(transactionId, tagId, meterStop, stopDate);
expect(stopTransactionResponse).to.be.transactionStatus('Accepted');
+ }
return transactionId;
}
@@ -692,7 +693,7 @@ describe('Billing Service', function() {
});
});
- describe('Negative tests - Invalid Credentials', () => {
+ describe('Negative tests - Wrong Billing Settings', () => {
// eslint-disable-next-line @typescript-eslint/require-await
before(async () => {
testData.userContext = testData.adminUserContext;
@@ -709,11 +710,9 @@ describe('Billing Service', function() {
testData.billingImpl = await testData.setBillingSystemValidCredentials();
});
- it('Should set a transaction in error', async () => {
- const transactionID = await testData.generateTransaction(testData.userContext);
- expect(transactionID).to.not.be.null;
- const transactions = await testData.userService.transactionApi.readAllInError({});
- expect(transactions.data.result.find((transaction) => transaction.id === transactionID)).to.not.be.null;
+ it('Should not be able to start a transaction', async () => {
+ const transactionID = await testData.generateTransaction(testData.userContext, 'Invalid');
+ assert(!transactionID, 'Transaction ID should not be set');
});
it('Should set in error users without Billing data', async () => {
@@ -741,6 +740,29 @@ describe('Billing Service', function() {
}
assert(userFound, 'User with no billing data not found in Users In Error');
});
+
+ });
+
+ describe('Negative tests', () => {
+ // eslint-disable-next-line @typescript-eslint/require-await
+ before(async () => {
+ testData.userContext = testData.adminUserContext;
+ assert(testData.userContext, 'User context cannot be null');
+ testData.userService = testData.adminUserService;
+ assert(!!testData.userService, 'User service cannot be null');
+ // Set STRIPE credentials
+ testData.billingImpl = await testData.setBillingSystemInvalidCredentials();
+ });
+
+ after(async () => {
+ });
+
+ xit('Should set a transaction in error', async () => {
+ const transactionID = await testData.generateTransaction(testData.userContext);
+ const transactions = await testData.userService.transactionApi.readAllInError({});
+ expect(transactions.data.result.find((transaction) => transaction.id === transactionID)).to.not.be.null;
+ });
+
});
});

Billing - Test that transaction cannot be started