billing settings - 1st test for testing REST endpoints
MODIFY
package-lock.json
package-lock.json
}
}
},
+ "safe-url-assembler": {
+ "version": "1.3.5",
+ "resolved": "https://registry.npmjs.org/safe-url-assembler/-/safe-url-assembler-1.3.5.tgz",
+ "integrity": "sha1-vINxZ2wR7KcikQ/XRzIzsIvXwXs=",
+ "dev": true,
+ "requires": {
+ "extend": "~3.0.0",
+ "qs": "~6.3.0"
+ },
+ "dependencies": {
+ "qs": {
+ "version": "6.3.2",
+ "resolved": "https://registry.npmjs.org/qs/-/qs-6.3.2.tgz",
+ "integrity": "sha1-51vV9uJoEioqDgvaYwslUMFmUCw=",
+ "dev": true
+ }
+ }
+ },
"safer-buffer": {
"version": "2.1.2",
"resolved": "https://registry.npmjs.org/safer-buffer/-/safer-buffer-2.1.2.tgz",

MODIFY
package.json
package.json
"querystring": "^0.2.1",
"rimraf": "^3.0.2",
"rosie": "^2.1.0",
+ "safe-url-assembler": "^1.3.5",
"ts-loader": "^8.1.0",
"ts-node": "^9.1.1",
"ts-node-dev": "^1.1.6",

MODIFY
test/api/BillingTest.ts
test/api/BillingTest.ts
@@ -193,6 +193,64 @@ class TestData {
const testData: TestData = new TestData();
+describe('Billing Settings', function() {
+ // Do not run the tests when the settings are not properly set
+ this.pending = !testData.isBillingProperlyConfigured();
+ this.timeout(1000000);
+
+ describe('With component Billing (tenant utbilling)', () => {
+ before(async () => {
+ global.database = new MongoDBStorage(config.get('storage'));
+ await global.database.start();
+ testData.tenantContext = await ContextProvider.defaultInstance.getTenantContext(ContextDefinition.TENANT_CONTEXTS.TENANT_BILLING);
+ testData.adminUserContext = testData.tenantContext.getUserContext(ContextDefinition.USER_CONTEXTS.DEFAULT_ADMIN);
+ testData.adminUserService = new CentralServerService(
+ testData.tenantContext.getTenant().subdomain,
+ testData.adminUserContext
+ );
+ expect(testData.userContext).to.not.be.null;
+ // testData.siteContext = testData.tenantContext.getSiteContext(ContextDefinition.SITE_CONTEXTS.SITE_WITH_OTHER_USER_STOP_AUTHORIZATION);
+ // testData.siteAreaContext = testData.siteContext.getSiteAreaContext(ContextDefinition.SITE_AREA_CONTEXTS.WITH_ACL);
+ // testData.chargingStationContext = testData.siteAreaContext.getChargingStationContext(ContextDefinition.CHARGING_STATION_CONTEXTS.ASSIGNED_OCPP16);
+ });
+
+ describe('As an admin', () => {
+ // 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');
+ // await testData.setBillingSystemValidCredentials();
+ });
+
+ it('should be able to invoke Billing Settings endpoints', async () => {
+ // Get all Billing settings
+ let response = await testData.userService.billingApi.getBillingSettings();
+ assert(response.status === 200, 'Response status should be 200');
+ assert(response.data && response.data.length > 0, 'Response data should not be null');
+ const billingSettings = response.data[0] as BillingSettings ;
+ assert(billingSettings.billing, 'Billing Properties should not be null');
+ assert(billingSettings.type === BillingSettingsType.STRIPE, 'Billing Setting Type should not be set to STRIPE');
+ assert(billingSettings.stripe, 'Stripe Properties should not be null');
+ assert(billingSettings.stripe.secretKey, 'Secret Key should not be null');
+ assert(billingSettings.id, 'ID should not be null');
+ const settingID = billingSettings.id;
+ // Get a single Billing settings
+ response = await testData.userService.billingApi.getBillingSetting(settingID);
+ assert(response.data, 'Response data should not be null');
+ const currentBillingSettings = response.data as BillingSettings ;
+ assert(currentBillingSettings.id === billingSettings.id, 'ID should be the same');
+ // Check a single Billing settings
+ response = await testData.userService.billingApi.checkBillingSetting(settingID);
+ // assert(response.status === 200, 'Response status should be 200');
+ // assert(response.data, 'Response data should not be null');
+ });
+
+ });
+ });
+});
+
describe('Billing Service', function() {
// Do not run the tests when the settings are not properly set
this.pending = !testData.isBillingProperlyConfigured();

MODIFY
test/api/client/BillingApi.ts
test/api/client/BillingApi.ts
import CrudApi from './utils/CrudApi';
+import { ServerRoute } from '../../../src/types/Server';
import TestConstants from './utils/TestConstants';
export default class BillingApi extends CrudApi {
@@ -29,4 +30,26 @@ export default class BillingApi extends CrudApi {
public async downloadInvoiceDocument(params?) {
return await super.read(params, '/client/api/BillingDownloadInvoice');
}
+
+ public async getBillingSettings(params?) {
+ // return await super.read(params, '/v1/api/billing-settings');
+ return await super.read(params, super.buildRestEndpointUrl(ServerRoute.REST_BILLING_SETTINGS, {}));
+ }
+
+ public async getBillingSetting(id, params?) {
+ return await super.read(params, super.buildRestEndpointUrl(ServerRoute.REST_BILLING_SETTING, { id }));
+ }
+
+ public async checkBillingSettingConnection(id, params?) {
+ return await super.create(params, super.buildRestEndpointUrl(ServerRoute.REST_BILLING_SETTING_CHECK_CONNECTION, { id }));
+ }
+
+ public async checkBillingSetting(id, params?) {
+ return await super.create(params, super.buildRestEndpointUrl(ServerRoute.REST_BILLING_SETTING_CHECK, { id }));
+ }
+
+ public async activateBillingSetting(id, params?) {
+ return await super.create(params, super.buildRestEndpointUrl(ServerRoute.REST_BILLING_SETTING_ACTIVATE, { id }));
+ }
+
}

MODIFY
test/api/client/utils/CrudApi.ts
test/api/client/utils/CrudApi.ts
import AuthenticatedBaseApi from './AuthenticatedBaseApi';
+import SafeUrlAssembler from 'safe-url-assembler';
+import { ServerRoute } from '../../../../src/types/Server';
import TestConstants from './TestConstants';
/**
@@ -132,6 +134,17 @@ export default class CrudApi {
});
}
+ // Build URL targeting REST endpoints
+ protected buildRestEndpointUrl(urlPatternAsString: ServerRoute, params: {
+ // Just a flat list of key/value pairs!
+ [name: string]: string | number | null;
+ }): string {
+ const url = SafeUrlAssembler('/v1/api/')
+ .template(urlPatternAsString)
+ .param(params);
+ return url.toString();
+ }
+
// Build the paging in the Queryparam
private _buildPaging(paging, queryString): void {
// Check

billing settings - 1st test for testing REST endpoints