first prototype tests
MODIFY
package.json
package.json
"test:car": "cross-env TS_NODE_FILES=true mocha test/**/CarTest.ts",
"test:locking": "cross-env TS_NODE_FILES=true mocha test/**/LockingTest.ts",
"test:firmwareUpdateStatus": "cross-env TS_NODE_FILES=true mocha test/**/FirmwareUpdateStatusTest.ts",
+ "test:smartCharging": "cross-env TS_NODE_FILES=true mocha test/**/SmartChargingTest.ts",
"clinic:clean": "clinic clean",
"npm-check": "npm-check",
"import-sort": "npx import-sort-cli --write 'src/**/*.ts{,x}' 'test/**/*.ts{,x}' 'build/types/**/*.ts{,x}'"

MODIFY
test/api/SmartChargingTest.ts
test/api/SmartChargingTest.ts
-// Goal : Checks related to settings
-// Note : These unit tests use the tenant utall. This tenant should exist prior running these tests.
-// Run npm run test:createContext to create the needed utall if not present.
-
-import chai, { expect } from 'chai';
+import { BillingSetting, BillingSettingsType, SapSmartChargingSetting, SettingDB, SmartChargingSetting, SmartChargingSettingsType, StripeBillingSetting } from '../../src/types/Setting';
+import chai, { assert, expect } from 'chai';
+import { BillingInvoiceStatus } from '../../src/types/Billing';
import CentralServerService from './client/CentralServerService';
+import ChargingStationContext from './context/ChargingStationContext';
+import { default as ClientConstants } from './client/utils/Constants';
import Constants from '../../src/utils/Constants';
import ContextDefinition from './context/ContextDefinition';
-import TestData from './client/utils/TestData';
+import ContextProvider from './context/ContextProvider';
+import Cypher from '../../src/utils/Cypher';
+import Factory from '../factories/Factory';
+import { HTTPAuthError } from '../../src/types/HTTPError';
+import { ObjectID } from 'mongodb';
+import SapSmartChargingIntegration from '../../src/integration/smart-charging/sap-smart-charging/SapSmartChargingIntegration';
+import SiteContext from './context/SiteContext';
+import SmartChargingIntegration from '../../src/integration/smart-charging/SmartChargingIntegration';
+import TenantContext from './context/TenantContext';
+import User from '../../src/types/User';
+import { UserInErrorType } from '../../src/types/InError';
import chaiSubset from 'chai-subset';
import config from '../config';
+import moment from 'moment';
import responseHelper from '../helpers/responseHelper';
-import SmartChargingIntegration from '../integration/smart-charging/SmartChargingIntegration';
-import { SapSmartChargingSetting, SmartChargingSetting } from '../types/Setting';
-import TenantContext from './context/TenantContext';
-import ChargingStationContext from './context/ChargingStationContext';
chai.use(chaiSubset);
chai.use(responseHelper);
-let smartChargingImpl: SmartChargingIntegration<SmartChargingSetting>;
+let smartChargingIntegration: SmartChargingIntegration<SmartChargingSetting>;
class TestData {
public tenantContext: TenantContext;
public centralUserContext: any;
public centralUserService: CentralServerService;
+ public userContext: User;
public userService: CentralServerService;
+ public siteContext: SiteContext;
public siteAreaContext: any;
public chargingStationContext: ChargingStationContext;
-
+ public createdUsers: User[] = [];
+ public isForcedSynchro: boolean;
+ public pending = false;
public static async setSmartChargingValidCredentials(testData) {
- const stripeSettings = TestData.getSmartChargingSettings();
- await TestData.saveSmartChargingSettings(testData, stripeSettings);
- stripeSettings.secretKey = Cypher.encrypt(stripeSettings.secretKey);
- smartChargingImpl = new StripeBillingIntegration(testData.tenantContext.getTenant().id, stripeSettings);
- expect(smartChargingImpl).to.not.be.null;
+ const sapSmartChargingSettings = TestData.getSmartChargingSettings();
+ await TestData.saveSmartChargingSettings(testData, sapSmartChargingSettings);
+ sapSmartChargingSettings.password = Cypher.encrypt(sapSmartChargingSettings.password);
+ smartChargingIntegration = new SapSmartChargingIntegration(testData.tenantContext.getTenant().id, sapSmartChargingSettings);
+ expect(smartChargingIntegration).to.not.be.null;
}
- public static async setSmartChargingCredentials(testData) {
- const stripeSettings = TestData.getStripeSettings();
- stripeSettings.secretKey = Cypher.encrypt('sk_test_invalid_credentials');
- await TestData.saveBillingSettings(testData, stripeSettings);
- billingImpl = new StripeBillingIntegration(testData.tenantContext.getTenant().id, stripeSettings);
- expect(billingImpl).to.not.be.null;
+
+ public static getSmartChargingSettings(): SapSmartChargingSetting {
+ return {
+ optimizerUrl: config.get('smartCharging.optimizerUrl'),
+ user: config.get('smartCharging.user'),
+ password: config.get('smartCharging.password'),
+ } as SapSmartChargingSetting;
}
- public static async saveSmartChargingSettings(testData, stripeSettings: SapSmartChargingSetting) {
- const tenantBillingSettings = await testData.userService.settingApi.readAll({ 'Identifier': 'billing' });
- expect(tenantBillingSettings.data.count).to.be.eq(1);
- const componentSetting: SettingDB = tenantBillingSettings.data.result[0];
- componentSetting.content.type = BillingSettingsType.STRIPE;
- componentSetting.content.stripe = stripeSettings;
- componentSetting.sensitiveData = ['content.stripe.secretKey'];
+ public static async saveSmartChargingSettings(testData, sapSmartChargingSettings: SapSmartChargingSetting) {
+ const tenantSmartChargingSettings = await testData.userService.settingApi.readAll({ 'Identifier': 'smartCharging' });
+ expect(tenantSmartChargingSettings.data.count).to.be.eq(1);
+ const componentSetting: SettingDB = tenantSmartChargingSettings.data.result[0];
+ componentSetting.content.type = SmartChargingSettingsType.SAP_SMART_CHARGING;
+ componentSetting.content.sapSmartCharging = sapSmartChargingSettings;
+ componentSetting.sensitiveData = ['content.password.secretKey'];
await testData.userService.settingApi.update(componentSetting);
}
+}
- public static getStripeSettings(): StripeBillingSetting {
- return {
- url: config.get('billing.url'),
- publicKey: config.get('billing.publicKey'),
- secretKey: config.get('billing.secretKey'),
- noCardAllowed: config.get('billing.noCardAllowed'),
- advanceBillingAllowed: config.get('billing.advanceBillingAllowed'),
- currency: config.get('billing.currency'),
- immediateBillingAllowed: config.get('billing.immediateBillingAllowed'),
- periodicBillingAllowed: config.get('billing.periodicBillingAllowed')
- } as StripeBillingSetting;
+
+// Async function generateTransaction(user: User, chargingStationContext) {
+// const connectorId = 1;
+// const tagId = user.tags[0].id;
+// const meterStart = 0;
+// const meterStop = 1000;
+// const startDate = moment().toDate();
+// const stopDate = moment(startDate).add(1, 'hour');
+// let response = await chargingStationContext.startTransaction(connectorId, tagId, meterStart, startDate);
+// expect(response).to.be.transactionValid;
+// const transactionId1 = response.data.transactionId;
+// response = await chargingStationContext.stopTransaction(transactionId1, tagId, meterStop, stopDate);
+// expect(response).to.be.transactionStatus('Accepted');
+// }
+
+const testData: TestData = new TestData();
+
+
+describe('Smart Charging Service', function() {
+ this.pending = testData.pending;
+ this.timeout(1000000);
+ describe('With component SmartCharging (tenant utsmartcharg)', () => {
+ before(async () => {
+ testData.tenantContext = await ContextProvider.defaultInstance.getTenantContext(ContextDefinition.TENANT_CONTEXTS.TENANT_SMART_CHARGING);
+ testData.centralUserContext = testData.tenantContext.getUserContext(ContextDefinition.USER_CONTEXTS.DEFAULT_ADMIN);
+ testData.userContext = testData.tenantContext.getUserContext(ContextDefinition.USER_CONTEXTS.DEFAULT_ADMIN);
+ expect(testData.userContext).to.not.be.null;
+ testData.centralUserService = new CentralServerService(
+ testData.tenantContext.getTenant().subdomain,
+ testData.centralUserContext
+ );
+ testData.isForcedSynchro = false;
+ });
+
+ describe('Where admin user', () => {
+ before(async () => {
+ testData.userContext = testData.tenantContext.getUserContext(ContextDefinition.USER_CONTEXTS.DEFAULT_ADMIN);
+ assert(testData.userContext, 'User context cannot be null');
+ if (testData.userContext === testData.centralUserContext) {
+ // Reuse the central user service (to avoid double login)
+ testData.userService = testData.centralUserService;
+ } else {
+ testData.userService = new CentralServerService(
+ testData.tenantContext.getTenant().subdomain,
+ testData.userContext
+ );
}
+ assert(!!testData.userService, 'User service cannot be null');
+ const tenant = testData.tenantContext.getTenant();
+ if (tenant.id) {
+ await TestData.setSmartChargingValidCredentials(testData);
+ } else {
+ throw new Error(`Unable to get Tenant ID for tenant : ${ContextDefinition.TENANT_CONTEXTS.TENANT_SMART_CHARGING}`);
}
-
-describe('Smart Charging Test', function() {
- this.timeout(30000);
-
- before(async function() {
- // Init values
- testData.superCentralService = new CentralServerService(null, { email: config.get('superadmin.username'), password: config.get('superadmin.password') });
- testData.centralService = new CentralServerService('utsmartcharg', { email: config.get('admin.username'), password: config.get('admin.password') });
- testData.credentials.email = config.get('admin.username');
- // Retrieve the tenant id from the name
- const response = await testData.superCentralService.tenantApi.readAll({ 'Search' : ContextDefinition.TENANT_CONTEXTS.TENANT_SMART_CHARGING }, { limit: Constants.UNLIMITED, skip: 0 });
- testData.credentials.tenantId = response ? response.data.result[0].id : '';
});
- after(async function() {
+ it('Should connect to Smart Charging Provider', async () => {
+ const response = await testData.userService.smartChargingApi.testConnection({}, ClientConstants.DEFAULT_PAGING, ClientConstants.DEFAULT_ORDERING);
+ expect(response.data).containSubset(Constants.REST_RESPONSE_SUCCESS);
});
+ it('Trigger smart charging', async () => {
+ const response = await testData.userService.smartChargingApi.triggerSmartCharging({ SiteAreaID: ContextDefinition.TENANT_SITEAREA_LIST.find((element) => element.smartCharging === true).id }, ClientConstants.DEFAULT_PAGING, ClientConstants.DEFAULT_ORDERING);
+ expect(response.data).containSubset(Constants.REST_RESPONSE_SUCCESS);
+ });
- describe('Success cases (tenant utsmartcharg)', () => {
- it('Should connect to Smart Charging Provider', async () => {
- const response = await testData.centralService.smartChargingApi.testConnection();
- expect(response.data.connectionIsValid).to.be.true;
- expect(response.data).containSubset({ status: 'Success' });
+ it('Profile Test of initial smartCharging profiles', async () => {
+ const response = await testData.userService.smartChargingApi.getChargingProfiles({ ChargeBoxID: 'cs-16-ut-site-withSmartCharging' }, ClientConstants.DEFAULT_PAGING, ClientConstants.DEFAULT_ORDERING);
+ console.log(response.data);
+ expect(response.data).containSubset(Constants.REST_RESPONSE_SUCCESS);
});
});
});
+});
+
+
+// It('Should create a user', async () => {
+// const fakeUser = {
+// ...Factory.user.build(),
+// } as User;
+// fakeUser.issuer = true;
+// await testData.userService.createEntity(
+// testData.userService.userApi,
+// fakeUser
+// );
+// testData.createdUsers.push(fakeUser);
+
+// const exists = await billingImpl.userExists(fakeUser);
+// expect(exists).to.be.true;
+// });
+
+// it('Should update a user', async () => {
+// const fakeUser = {
+// ...Factory.user.build(),
+// } as User;
+// fakeUser.issuer = true;
+// await testData.userService.createEntity(
+// testData.userService.userApi,
+// fakeUser
+// );
+// fakeUser.firstName = 'Test';
+// fakeUser.name = 'Name';
+// await testData.userService.updateEntity(
+// testData.userService.userApi,
+// fakeUser,
+// false
+// );
+// testData.createdUsers.push(fakeUser);
+// const billingUser = await billingImpl.getUserByEmail(fakeUser.email);
+// expect(billingUser.name).to.be.eq(fakeUser.firstName + ' ' + fakeUser.name);
+// });
+
+// it('Should delete a user', async () => {
+// await testData.userService.deleteEntity(
+// testData.userService.userApi,
+// { id: testData.createdUsers[0].id }
+// );
+
+// const exists = await billingImpl.userExists(testData.createdUsers[0]);
+// expect(exists).to.be.false;
+// testData.createdUsers.shift();
+// });
+
+// it('Should synchronize a new user', async () => {
+// const fakeUser = {
+// ...Factory.user.build(),
+// } as User;
+// fakeUser.issuer = true;
+// await TestData.setBillingSystemInvalidCredentials(testData);
+// await testData.userService.createEntity(
+// testData.userService.userApi,
+// fakeUser
+// );
+// testData.createdUsers.push(fakeUser);
+// await TestData.setBillingSystemValidCredentials(testData);
+// await testData.userService.billingApi.synchronizeUser({ id: fakeUser.id });
+// const userExists = await billingImpl.userExists(fakeUser);
+// expect(userExists).to.be.true;
+// });
+
+// it('Should set in error users without Billing data', async () => {
+// const fakeUser = {
+// ...Factory.user.build()
+// } as User;
+// fakeUser.issuer = true;
+// await TestData.setBillingSystemInvalidCredentials(testData);
+// // Creates user without billing data
+// await testData.userService.createEntity(
+// testData.userService.userApi,
+// fakeUser
+// );
+// testData.createdUsers.push(fakeUser);
+// // Check if user is in Users In Error
+// const response = await testData.userService.userApi.readAllInError({ ErrorType: UserInErrorType.NO_BILLING_DATA }, {
+// limit: 100,
+// skip: 0
+// });
+// let userFound = false;
+// for (const user of response.data.result) {
+// if (user.id === fakeUser.id) {
+// userFound = true;
+// break;
+// }
+// }
+// assert(userFound, 'User with no billing data not found in Users In Error');
+// });
+
+// it('Should force a user synchronization', async () => {
+// const fakeUser = {
+// ...Factory.user.build(),
+// } as User;
+// fakeUser.issuer = true;
+// await TestData.setBillingSystemValidCredentials(testData);
+// await testData.userService.createEntity(
+// testData.userService.userApi,
+// fakeUser
+// );
+// testData.createdUsers.push(fakeUser);
+// fakeUser.billingData = { customerID: 'cus_test' };
+// await testData.userService.updateEntity(
+// testData.userService.userApi,
+// fakeUser
+// );
+// await testData.userService.billingApi.forceSynchronizeUser({ id: fakeUser.id });
+// const billingUserAfter = await billingImpl.getUserByEmail(fakeUser.email);
+// expect(fakeUser.billingData.customerID).to.not.be.eq(billingUserAfter.billingData.customerID);
+// });
+
+// it('Should list invoices', async () => {
+// const response = await testData.userService.billingApi.readAll({}, ClientConstants.DEFAULT_PAGING, ClientConstants.DEFAULT_ORDERING, '/client/api/BillingUserInvoices');
+// expect(response.status).to.be.eq(200);
+// expect(response.data.result.length).to.be.gt(0);
+// });
+
+// it('Should list filtered invoices', async () => {
+// const response = await testData.userService.billingApi.readAll({ Status: BillingInvoiceStatus.OPEN }, ClientConstants.DEFAULT_PAGING, ClientConstants.DEFAULT_ORDERING, '/client/api/BillingUserInvoices');
+// for (const invoice of response.data.result) {
+// expect(invoice.status).to.be.eq(BillingInvoiceStatus.OPEN);
+// }
+// });
+
+// it('Should synchronize invoices', async () => {
+// const response = await testData.userService.billingApi.synchronizeInvoices({});
+// expect(response.data).containSubset(Constants.REST_RESPONSE_SUCCESS);
+// });
+
+// after(async () => {
+// await TestData.setBillingSystemValidCredentials(testData);
+// for (const user of testData.createdUsers) {
+// await testData.userService.deleteEntity(
+// testData.userService.userApi,
+// user
+// );
+// }
+// });
+// });
+
+// describe('Where basic user', () => {
+// before(async () => {
+// testData.tenantContext = await ContextProvider.defaultInstance.getTenantContext(ContextDefinition.TENANT_CONTEXTS.TENANT_BILLING);
+// testData.centralUserContext = testData.tenantContext.getUserContext(ContextDefinition.USER_CONTEXTS.BASIC_USER);
+// testData.userContext = testData.tenantContext.getUserContext(ContextDefinition.USER_CONTEXTS.BASIC_USER);
+// expect(testData.userContext).to.not.be.null;
+// testData.centralUserService = new CentralServerService(
+// testData.tenantContext.getTenant().subdomain,
+// testData.centralUserContext
+// );
+// if (testData.userContext === testData.centralUserContext) {
+// // Reuse the central user service (to avoid double login)
+// testData.userService = testData.centralUserService;
+// } else {
+// testData.userService = new CentralServerService(
+// testData.tenantContext.getTenant().subdomain,
+// testData.userContext
+// );
+// }
+// expect(testData.userService).to.not.be.null;
+// const tenant = testData.tenantContext.getTenant();
+// if (tenant.id) {
+// await TestData.setBillingSystemValidCredentials(testData);
+// } else {
+// throw new Error(`Unable to get Tenant ID for tenant : ${ContextDefinition.TENANT_CONTEXTS.TENANT_BILLING}`);
+// }
+// });
+
+// it('Should not be able to test connection to Billing Provider', async () => {
+// const response = await testData.userService.billingApi.testConnection({}, ClientConstants.DEFAULT_PAGING, ClientConstants.DEFAULT_ORDERING);
+// expect(response.status).to.be.eq(HTTPAuthError.ERROR);
+// });
+
+// it('Should not create a user', async () => {
+// const fakeUser = {
+// ...Factory.user.build(),
+// } as User;
+
+// const response = await testData.userService.createEntity(
+// testData.userService.userApi,
+// fakeUser,
+// false
+// );
+// testData.createdUsers.push(fakeUser);
+// expect(response.status).to.be.eq(HTTPAuthError.ERROR);
+// });
+
+// it('Should not update a user', async () => {
+// const fakeUser = {
+// id: new ObjectID(),
+// ...Factory.user.build(),
+// } as User;
+// fakeUser.firstName = 'Test';
+// fakeUser.name = 'Name';
+// const response = await testData.userService.updateEntity(
+// testData.userService.userApi,
+// fakeUser,
+// false
+// );
+// expect(response.status).to.be.eq(HTTPAuthError.ERROR);
+// });
+
+// it('Should not delete a user', async () => {
+// const response = await testData.userService.deleteEntity(
+// testData.userService.userApi,
+// { id: 0 },
+// false
+// );
+// expect(response.status).to.be.eq(HTTPAuthError.ERROR);
+// });
+
+// it('Should not synchronize a user', async () => {
+// const fakeUser = {
+// ...Factory.user.build(),
+// } as User;
+// const response = await testData.userService.billingApi.synchronizeUser({ id: fakeUser.id });
+// expect(response.status).to.be.eq(HTTPAuthError.ERROR);
+// });
+
+// it('Should not force synchronization of a user', async () => {
+// const fakeUser = {
+// ...Factory.user.build(),
+// } as User;
+// const response = await testData.userService.billingApi.forceSynchronizeUser({ id: fakeUser.id });
+// expect(response.status).to.be.eq(HTTPAuthError.ERROR);
+// });
+
+// it('Should list invoices', async () => {
+// const basicUser: User = testData.tenantContext.getUserContext(ContextDefinition.USER_CONTEXTS.BASIC_USER);
+
+// // Set back userContext to BASIC to consult invoices
+// testData.userService = new CentralServerService(
+// testData.tenantContext.getTenant().subdomain,
+// basicUser
+// );
+// const response = await testData.userService.billingApi.readAll({}, ClientConstants.DEFAULT_PAGING, ClientConstants.DEFAULT_ORDERING, '/client/api/BillingUserInvoices');
+// for (let i = 0; i < response.data.result.length - 1; i++) {
+// expect(response.data.result[i].userID).to.be.eq(basicUser.id);
+// }
+// });
+
+// it('Should list filtered invoices', async () => {
+// const response = await testData.userService.billingApi.readAll({ Status: BillingInvoiceStatus.OPEN }, ClientConstants.DEFAULT_PAGING, ClientConstants.DEFAULT_ORDERING, '/client/api/BillingUserInvoices');
+// for (const invoice of response.data.result) {
+// expect(invoice.status).to.be.eq(BillingInvoiceStatus.OPEN);
+// }
+// });
+// });
+// });
+
+// describe('With component Billing (tenant utall)', () => {
+// before(async () => {
+// testData.tenantContext = await ContextProvider.defaultInstance.getTenantContext(ContextDefinition.TENANT_CONTEXTS.TENANT_WITH_ALL_COMPONENTS);
+// testData.centralUserContext = testData.tenantContext.getUserContext(ContextDefinition.USER_CONTEXTS.DEFAULT_ADMIN);
+// testData.userContext = testData.tenantContext.getUserContext(ContextDefinition.USER_CONTEXTS.DEFAULT_ADMIN);
+// expect(testData.userContext).to.not.be.null;
+// testData.centralUserService = new CentralServerService(
+// testData.tenantContext.getTenant().subdomain,
+// testData.centralUserContext
+// );
+// testData.isForcedSynchro = false;
+// 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('Where admin user', () => {
+// before(async () => {
+// testData.userContext = testData.tenantContext.getUserContext(ContextDefinition.USER_CONTEXTS.DEFAULT_ADMIN);
+// assert(testData.userContext, 'User context cannot be null');
+// if (testData.userContext === testData.centralUserContext) {
+// // Reuse the central user service (to avoid double login)
+// testData.userService = testData.centralUserService;
+// } else {
+// testData.userService = new CentralServerService(
+// testData.tenantContext.getTenant().subdomain,
+// testData.userContext
+// );
+// }
+// await TestData.setBillingSystemValidCredentials(testData);
+// });
+
+// it('should create an invoice after a transaction', async () => {
+// let response = await testData.userService.billingApi.readAll({}, ClientConstants.DEFAULT_PAGING, ClientConstants.DEFAULT_ORDERING, '/client/api/BillingUserInvoices');
+// const invoicesBefore = response.data.count;
+// await testData.userService.billingApi.forceSynchronizeUser({ id: testData.userContext.id });
+// await generateTransaction(testData.userContext, testData.chargingStationContext);
+// response = await testData.userService.billingApi.readAll({}, ClientConstants.DEFAULT_PAGING, ClientConstants.DEFAULT_ORDERING, '/client/api/BillingUserInvoices');
+// const invoicesAfter = response.data.count;
+// expect(invoicesAfter).to.be.eq(invoicesBefore + 1);
+// });
+
+// it('should synchronize 1 invoice after a transaction', async () => {
+// await testData.userService.billingApi.synchronizeInvoices({});
+// await generateTransaction(testData.userContext, testData.chargingStationContext);
+// const response = await testData.userService.billingApi.synchronizeInvoices({});
+// expect(response.data).containSubset(Constants.REST_RESPONSE_SUCCESS);
+// expect(response.data.inSuccess).to.be.eq(1);
+// });
+// });
+
+// describe('Where basic user', () => {
+// before(async () => {
+// testData.userContext = testData.tenantContext.getUserContext(ContextDefinition.USER_CONTEXTS.BASIC_USER);
+// assert(testData.userContext, 'User context cannot be null');
+// if (testData.userContext === testData.centralUserContext) {
+// // Reuse the central user service (to avoid double login)
+// testData.userService = testData.centralUserService;
+// } else {
+// testData.userService = new CentralServerService(
+// testData.tenantContext.getTenant().subdomain,
+// testData.userContext
+// );
+// }
+// await TestData.setBillingSystemValidCredentials(testData);
+// });
+
+// it('should create an invoice after a transaction', async () => {
+// let response = await testData.userService.billingApi.readAll({}, ClientConstants.DEFAULT_PAGING, ClientConstants.DEFAULT_ORDERING, '/client/api/BillingUserInvoices');
+// const invoicesBefore = response.data.count;
+// const adminUser = testData.tenantContext.getUserContext(ContextDefinition.USER_CONTEXTS.DEFAULT_ADMIN);
+// const basicUser = testData.tenantContext.getUserContext(ContextDefinition.USER_CONTEXTS.BASIC_USER);
+// // Connect as Admin to Force synchronize basic user
+// testData.userContext = adminUser;
+// testData.userService = new CentralServerService(
+// testData.tenantContext.getTenant().subdomain,
+// testData.userContext
+// );
+// await testData.userService.billingApi.forceSynchronizeUser({ id: basicUser.id });
+// // Reconnect as Basic user
+// testData.userContext = basicUser;
+// testData.userService = new CentralServerService(
+// testData.tenantContext.getTenant().subdomain,
+// testData.userContext
+// );
+// await generateTransaction(testData.userContext, testData.chargingStationContext);
+// response = await testData.userService.billingApi.readAll({}, ClientConstants.DEFAULT_PAGING, ClientConstants.DEFAULT_ORDERING, '/client/api/BillingUserInvoices');
+// const invoicesAfter = response.data.count;
+// expect(invoicesAfter).to.be.eq(invoicesBefore + 1);
+// });
+// });
+// });
+// });

MODIFY
test/api/client/SmartChargingApi.ts
test/api/client/SmartChargingApi.ts
@@ -10,19 +10,11 @@ export default class SmartChargingApi extends CrudApi {
return await super.readAll(params, paging, ordering, '/client/api/CheckSmartChargingConnection');
}
- public async synchronizeUsers(params?, paging = Constants.DEFAULT_PAGING, ordering = Constants.DEFAULT_ORDERING) {
- return await super.create(params, '/client/api/BillingSynchronizeUsers');
+ public async getChargingProfiles(params?, paging = Constants.DEFAULT_PAGING, ordering = Constants.DEFAULT_ORDERING) {
+ return await super.readAll(params, paging, ordering, '/client/api/ChargingProfiles');
}
- public async synchronizeUser(params?) {
- return await super.create(params, '/client/api/BillingSynchronizeUser');
- }
-
- public async forceSynchronizeUser(params?) {
- return await super.create(params, '/client/api/BillingForceSynchronizeUser');
- }
-
- public async synchronizeInvoices(params?) {
- return await super.create(params, '/client/api/BillingSynchronizeInvoices');
+ public async triggerSmartCharging(params?, paging = Constants.DEFAULT_PAGING, ordering = Constants.DEFAULT_ORDERING) {
+ return await super.readAll(params, paging, ordering, '/client/api/TriggerSmartCharging');
}
}

MODIFY
test/config-template.json
test/config-template.json
"advanceBillingAllowed": true,
"immediateBillingAllowed": true,
"periodicBillingAllowed": true
+ },
+ "smartCharging": {
+ "optimizerUrl": "",
+ "user": "",
+ "password": ""
}
}

MODIFY
test/config.js
test/config.js
@@ -292,6 +292,22 @@ const config = convict({
format: Boolean,
default: ''
}
+ },
+ smartCharging: {
+ optimizerUrl: {
+ doc: 'smart charging url',
+ format: String,
+ default: ''
+ },
+ user: {
+ doc: 'smart charging user',
+ format: String,
+ default: ''
+ },
+ password: {
+ doc: 'smart charging password',
+ default: ''
+ },
}
});

first prototype tests