utbilling - npm run mochatest:create:utbilling
MODIFY
.vscode/launch.json
.vscode/launch.json
"<node_internals>/**"
],
"stopOnEntry": true
+ },
+ {
+ "name": "Debug mochatest:createContext",
+ "type": "pwa-node",
+ "request": "launch",
+ "cwd": "${workspaceFolder}",
+ "runtimeExecutable": "npm",
+ "runtimeArgs": [
+ "run-script",
+ "mochatest:createContext"
+ ],
+ "sourceMaps": true,
+ "resolveSourceMapLocations": [
+ "${workspaceFolder}/**",
+ "!**/node_modules/**"
+ ],
+ "skipFiles": [
+ "<node_internals>/**"
+ ],
+ "stopOnEntry": true
}
]
}

MODIFY
package.json
package.json
"mochatest:ocpp": "cross-env TS_NODE_FILES=true mocha test/**/OCPP*Test.ts",
"mochatest:authentication": "cross-env TS_NODE_FILES=true mocha test/**/AuthenticationTest.ts",
"mochatest:createContext": "cross-env TS_NODE_FILES=true mocha test/**/ContextBuilderRunner.ts",
- "mochatest:createContext4Billing": "cross-env TS_NODE_FILES=true TENANT_FILTER=utbilling mocha test/**/ContextBuilderRunner.ts",
"mochatest:crypto": "cross-env TS_NODE_FILES=true mocha test/**/EncryptionSettingTest.ts",
"mochatest:filter": "cross-env TS_NODE_FILES=true mocha test/**/FilterTest.ts",
"mochatest:tenantsetting": "cross-env TS_NODE_FILES=true mocha test/**/ComponentActivationTenantTest.ts",
"mochatest:smartCharging": "cross-env TS_NODE_FILES=true mocha test/**/SmartChargingTest.ts",
"mochatest:security": "cross-env TS_NODE_FILES=true mocha test/**/SecurityTest.ts",
"mochatest:registrationToken": "cross-env TS_NODE_FILES=true mocha test/**/RegistrationTokenTest.ts",
+ "mochatest:create:utbilling": "cross-env TS_NODE_FILES=true TENANT_FILTER=utbilling mocha test/**/ContextBuilderRunner.ts",
"coverage": "nyc report --reporter=lcov",
"coverage:html": "nyc report --reporter=html",
"clinic:clean": "clinic clean",

MODIFY
test/api/context/BillingContext.ts
test/api/context/BillingContext.ts
@@ -34,15 +34,10 @@ export default class BillingContext {
}
public async createTestData(): Promise<void> {
- let skip = false;
const settings = BillingContext.getBillingSettings();
- for (const [key, value] of Object.entries(settings)) {
- if (!settings[key] || value === '') {
- skip = true;
- }
- }
- // Skip billing context generation if no settings are provided
+ const skip = (!settings.secretKey);
if (skip) {
+ // Skip billing context generation if no settings are provided
return;
}
await this.saveBillingSettings(BillingContext.getBillingSettings());
@@ -55,28 +50,12 @@ export default class BillingContext {
module: 'BillingContext'
});
}
-
+ // Create Users
const adminUser: User = this.tenantContext.getUserContext(ContextDefinition.USER_CONTEXTS.DEFAULT_ADMIN);
const basicUser: User = this.tenantContext.getUserContext(ContextDefinition.USER_CONTEXTS.BASIC_USER);
-
+ // Synchronize at least these 2 users - this creates a customer on the STRIPE side
await billingImpl.synchronizeUser(this.tenantContext.getTenant().id, adminUser);
await billingImpl.synchronizeUser(this.tenantContext.getTenant().id, basicUser);
-
- // const adminBillingUser = await billingImpl.getUserByEmail(adminUser.email);
- // const basicBillingUser = await billingImpl.getUserByEmail(basicUser.email);
-
- // const adminInvoice = await billingImpl.createInvoice(adminBillingUser, { description: 'TestAdmin 1', amount: 100 });
- // const userInvoice = await billingImpl.createInvoice(basicBillingUser, { description: 'TestBasic 1', amount: 100 });
- // await billingImpl.createInvoiceItem(adminBillingUser, adminInvoice.invoice.invoiceID, { description: 'TestAdmin 2', amount: 100 });
- // await billingImpl.createInvoiceItem(basicBillingUser, userInvoice.invoice.invoiceID, { description: 'TestBasic 2', amount: 100 });
-
- // let invoice = await billingImpl.createInvoice(adminBillingUser, { description: 'TestAdmin3', amount: 100 });
- // await billingImpl.finalizeInvoice(invoice.invoice);
- // await billingImpl.sendInvoiceToUser(invoice.invoice);
- // invoice = await billingImpl.createInvoice(basicBillingUser, { description: 'TestBasic3', amount: 100 });
- // await billingImpl.finalizeInvoice(invoice.invoice);
- // await billingImpl.sendInvoiceToUser(invoice.invoice);
- // Await billingImpl.synchronizeInvoices(this.tenantContext.getTenant().id);
}
private async saveBillingSettings(stripeSettings) {

MODIFY
test/api/context/ContextBuilder.ts
test/api/context/ContextBuilder.ts
@@ -95,7 +95,8 @@ export default class ContextBuilder {
let tenantDefinitions = ContextDefinition.TENANT_CONTEXT_LIST;
if (process.env.TENANT_FILTER) {
- // Just an optimization alowing to only initialize a singe tenant
+ // Just an optimization allowing to only initialize a single tenant
+ // e.g.: npm run mochatest:create:utbilling
tenantDefinitions = ContextDefinition.TENANT_CONTEXT_LIST.filter((def) => def.subdomain === process.env.TENANT_FILTER);
}
for (const tenantContextDef of tenantDefinitions) {

utbilling - npm run mochatest:create:utbilling