First Site Area tests
MODIFY
test/api/SmartChargingTest.ts
test/api/SmartChargingTest.ts
-import { BillingSetting, BillingSettingsType, SapSmartChargingSetting, SettingDB, SmartChargingSetting, SmartChargingSettingsType, StripeBillingSetting } from '../../src/types/Setting';
+import { SapSmartChargingSetting, SettingDB, SmartChargingSetting, SmartChargingSettingsType } from '../../src/types/Setting';
import chai, { assert, expect } from 'chai';
-import { BillingInvoiceStatus } from '../../src/types/Billing';
import CentralServerService from './client/CentralServerService';
+import { ChargePointStatus } from '../../src/types/ocpp/OCPPServer';
import ChargingStationContext from './context/ChargingStationContext';
import { default as ClientConstants } from './client/utils/Constants';
+import { Connector } from '../types/ChargingStation';
import Constants from '../../src/utils/Constants';
import ContextDefinition from './context/ContextDefinition';
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 MongoDBStorage from '../../src/storage/mongodb/MongoDBStorage';
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 global from '../../src/types/GlobalType';
import moment from 'moment';
import responseHelper from '../helpers/responseHelper';
@@ -69,21 +68,6 @@ class TestData {
}
}
-
-// 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();
@@ -92,6 +76,8 @@ describe('Smart Charging Service', function() {
this.timeout(1000000);
describe('With component SmartCharging (tenant utsmartcharg)', () => {
before(async () => {
+ global.database = new MongoDBStorage(config.get('storage'));
+ await global.database.start();
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);
@@ -103,7 +89,7 @@ describe('Smart Charging Service', function() {
testData.isForcedSynchro = false;
});
- describe('Where admin user', () => {
+ describe('Test for three phased site area', () => {
before(async () => {
testData.userContext = testData.tenantContext.getUserContext(ContextDefinition.USER_CONTEXTS.DEFAULT_ADMIN);
assert(testData.userContext, 'User context cannot be null');
@@ -123,6 +109,11 @@ describe('Smart Charging Service', function() {
} else {
throw new Error(`Unable to get Tenant ID for tenant : ${ContextDefinition.TENANT_CONTEXTS.TENANT_SMART_CHARGING}`);
}
+ testData.siteContext = testData.tenantContext.getSiteContext(ContextDefinition.SITE_CONTEXTS.SITE_BASIC);
+ testData.siteAreaContext = testData.siteContext.getSiteAreaContext(ContextDefinition.SITE_AREA_CONTEXTS.WITH_SMART_CHARGING_THREE_PHASED);
+ testData.chargingStationContext = testData.siteAreaContext.getChargingStationContext(ContextDefinition.CHARGING_STATION_CONTEXTS.ASSIGNED_OCPP16);
+ testData.siteAreaContext.siteArea.voltage = 230;
+ testData.siteAreaContext.siteArea.numberOfPhases = 3;
});
it('Should connect to Smart Charging Provider', async () => {
@@ -130,362 +121,181 @@ describe('Smart Charging Service', function() {
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);
+ it('Test for one car charging', async () => {
+ const connectorId = 1;
+ const tagId = testData.userContext.tags[0].id;
+ const meterStart = 180;
+ const startDate = moment();
+ const transactionResponse = await testData.chargingStationContext.startTransaction(connectorId, tagId, meterStart, startDate);
+ const connector = testData.chargingStationContext.getChargingStation().connectors[0];
+ connector.currentTransactionID = transactionResponse.data.transactionId;
+ connector.status = ChargePointStatus.CHARGING;
+ await testData.chargingStationContext.setConnectorStatus(connector);
+ const chargingProfiles = await smartChargingIntegration.buildChargingProfiles(testData.siteAreaContext.siteArea);
+ expect(chargingProfiles).containSubset([{
+ 'chargingStationID': 'cs-16-ut-site-withSmartChargingThreePhased',
+ 'connectorID': 1,
+ 'chargePointID': 1,
+ 'profile': {
+ 'chargingProfileId': 1,
+ 'chargingProfileKind': 'Absolute',
+ 'chargingProfilePurpose': 'TxProfile',
+ 'stackLevel': 2,
+ 'chargingSchedule': {
+ 'chargingRateUnit': 'A',
+ 'chargingSchedulePeriod': [
+ {
+ 'startPeriod': 0,
+ 'limit': 96
+ },
+ {
+ 'startPeriod': 900,
+ 'limit': 96
+ },
+ {
+ 'startPeriod': 1800,
+ 'limit': 96
+ }
+ ],
+ 'duration': 2700
+ }
+ }
+ }]);
});
- 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('Test for two cars charging', async () => {
+ const connectorId = 2;
+ const tagId = testData.userContext.tags[0].id;
+ const meterStart = 180;
+ const startDate = moment();
+ const transactionResponse = await testData.chargingStationContext.startTransaction(connectorId, tagId, meterStart, startDate);
+ const connector = testData.chargingStationContext.getChargingStation().connectors[1];
+ connector.currentTransactionID = transactionResponse.data.transactionId;
+ connector.status = ChargePointStatus.CHARGING;
+ await testData.chargingStationContext.setConnectorStatus(connector);
+ const chargingProfiles = await smartChargingIntegration.buildChargingProfiles(testData.siteAreaContext.siteArea);
+ expect(chargingProfiles[0]).containSubset({
+ 'chargingStationID': 'cs-16-ut-site-withSmartChargingThreePhased',
+ 'connectorID': 1,
+ 'chargePointID': 1,
+ 'profile': {
+ 'chargingProfileId': 1,
+ 'chargingProfileKind': 'Absolute',
+ 'chargingProfilePurpose': 'TxProfile',
+ 'stackLevel': 2,
+ 'chargingSchedule': {
+ 'chargingRateUnit': 'A',
+ 'chargingSchedulePeriod': [
+ {
+ 'startPeriod': 0,
+ 'limit': 96
+ },
+ {
+ 'startPeriod': 900,
+ 'limit': 96
+ },
+ {
+ 'startPeriod': 1800,
+ 'limit': 96
+ }
+ ],
+ 'duration': 2700
+ }
+ }
+ });
+ expect(chargingProfiles[1]).containSubset({
+ 'chargingStationID': 'cs-16-ut-site-withSmartChargingThreePhased',
+ 'connectorID': 2,
+ 'chargePointID': 1,
+ 'profile': {
+ 'chargingProfileId': 2,
+ 'chargingProfileKind': 'Absolute',
+ 'chargingProfilePurpose': 'TxProfile',
+ 'stackLevel': 2,
+ 'chargingSchedule': {
+ 'chargingRateUnit': 'A',
+ 'chargingSchedulePeriod': [
+ {
+ 'startPeriod': 0,
+ 'limit': 96
+ },
+ {
+ 'startPeriod': 900,
+ 'limit': 96
+ },
+ {
+ 'startPeriod': 1800,
+ 'limit': 96
+ }
+ ],
+ 'duration': 2700
+ }
+ }
+ });
+ });
+ it('Test for two cars charging with lower site area limit', async () => {
+ testData.siteAreaContext.siteArea.maximumPower = 30000;
+ const chargingProfiles = await smartChargingIntegration.buildChargingProfiles(testData.siteAreaContext.siteArea);
+ console.log(JSON.stringify(chargingProfiles, null, ' '));
+ expect(chargingProfiles[0]).containSubset({
+ 'chargingStationID': 'cs-16-ut-site-withSmartChargingThreePhased',
+ 'connectorID': 1,
+ 'chargePointID': 1,
+ 'profile': {
+ 'chargingProfileId': 1,
+ 'chargingProfileKind': 'Absolute',
+ 'chargingProfilePurpose': 'TxProfile',
+ 'stackLevel': 2,
+ 'chargingSchedule': {
+ 'chargingRateUnit': 'A',
+ 'chargingSchedulePeriod': [
+ {
+ 'startPeriod': 0,
+ 'limit': 34
+ },
+ {
+ 'startPeriod': 900,
+ 'limit': 34
+ },
+ {
+ 'startPeriod': 1800,
+ 'limit': 34
+ }
+ ],
+ 'duration': 2700
+ }
+ }
+ });
+ expect(chargingProfiles[1]).containSubset({
+ 'chargingStationID': 'cs-16-ut-site-withSmartChargingThreePhased',
+ 'connectorID': 2,
+ 'chargePointID': 1,
+ 'profile': {
+ 'chargingProfileId': 2,
+ 'chargingProfileKind': 'Absolute',
+ 'chargingProfilePurpose': 'TxProfile',
+ 'stackLevel': 2,
+ 'chargingSchedule': {
+ 'chargingRateUnit': 'A',
+ 'chargingSchedulePeriod': [
+ {
+ 'startPeriod': 0,
+ 'limit': 96
+ },
+ {
+ 'startPeriod': 900,
+ 'limit': 96
+ },
+ {
+ 'startPeriod': 1800,
+ 'limit': 96
+ }
+ ],
+ 'duration': 2700
+ }
+ }
+ });
});
});
});
});
-
-
-// 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/context/ContextBuilder.ts
test/api/context/ContextBuilder.ts
@@ -292,6 +292,7 @@ export default class ContextBuilder {
siteAreaTemplate.smartCharging = siteAreaDef.smartCharging;
siteAreaTemplate.maximumPower = siteAreaDef.maximumPower;
siteAreaTemplate.numberOfPhases = siteAreaDef.numberOfPhases;
+ siteAreaTemplate.voltage = siteAreaDef.voltage;
console.log(siteAreaTemplate.name);
const sireAreaID = await SiteAreaStorage.saveSiteArea(buildTenant.id, siteAreaTemplate);
const siteAreaModel = await SiteAreaStorage.getSiteArea(buildTenant.id, sireAreaID);
@@ -300,19 +301,17 @@ export default class ContextBuilder {
(chargingStation) => chargingStation.siteAreaNames && chargingStation.siteAreaNames.includes(siteAreaModel.name) === true);
// Create Charging Station for site area
for (const chargingStationDef of relevantCS) {
- if (siteAreaModel.smartCharging) {
+ if (siteAreaModel.smartCharging && siteAreaModel.numberOfPhases === 1) {
const chargingStationTemplate = Factory.chargingStation.build();
chargingStationTemplate.id = chargingStationDef.baseName + '-' + siteAreaModel.name;
console.log(chargingStationTemplate.id);
- const connectorsDef: any = [{
- numberOfConnectedPhase: siteAreaModel.numberOfPhases,
- status: 'Charging'
- },
- {
- numberOfConnectedPhase: siteAreaModel.numberOfPhases,
- status: 'Charging'
- }];
- const newChargingStationContext = await newTenantContext.createChargingStation(chargingStationDef.ocppVersion, chargingStationTemplate, connectorsDef, siteAreaModel);
+ const newChargingStationContext = await newTenantContext.createChargingStation(chargingStationDef.ocppVersion, chargingStationTemplate, null, siteAreaModel);
+ await siteAreaContext.addChargingStation(newChargingStationContext.getChargingStation());
+ } else if (siteAreaModel.smartCharging && siteAreaModel.numberOfPhases === 3) {
+ const chargingStationTemplate = Factory.chargingStation.build();
+ chargingStationTemplate.id = chargingStationDef.baseName + '-' + siteAreaModel.name;
+ console.log(chargingStationTemplate.id);
+ const newChargingStationContext = await newTenantContext.createChargingStation(chargingStationDef.ocppVersion, chargingStationTemplate, null, siteAreaModel);
await siteAreaContext.addChargingStation(newChargingStationContext.getChargingStation());
} else {
const chargingStationTemplate = Factory.chargingStation.build();

MODIFY
test/api/context/ContextDefinition.ts
test/api/context/ContextDefinition.ts
@@ -46,7 +46,8 @@ export default class ContextDefinition {
NO_SITE: 'No site', // Used for unassigned Charging Station or CS in tenant with no organizations
WITH_ACL: 'withACL', // ACL is active
WITHOUT_ACL: 'withoutACL', // ACL is inactive
- WITH_SMART_CHARGING: 'withSmartCharging' // Smart Charging is active
+ WITH_SMART_CHARGING_THREE_PHASED: 'withSmartChargingThreePhased', // Smart Charging is active three phased
+ WITH_SMART_CHARGING_SINGLE_PHASED: 'withSmartChargingSinglePhased', // Smart Charging is active single phased
};
static readonly CHARGING_STATION_CONTEXTS: any = {
@@ -562,14 +563,25 @@ export default class ContextDefinition {
},
{ // With smart charging three phased
id: '5ce249a2372f0b1c8caf5442',
- name: `${ContextDefinition.SITE_CONTEXTS.SITE_BASIC}-${ContextDefinition.SITE_AREA_CONTEXTS.WITH_SMART_CHARGING}`,
+ name: `${ContextDefinition.SITE_CONTEXTS.SITE_BASIC}-${ContextDefinition.SITE_AREA_CONTEXTS.WITH_SMART_CHARGING_THREE_PHASED}`,
smartCharging: true,
numberOfPhases: 3,
maximumPower: 100000,
+ voltage: 230,
siteName: ContextDefinition.SITE_CONTEXTS.SITE_BASIC
},
+ { // With smart charging single phased
+ id: '5ce249a2372f0b1c8caf5443',
+ name: `${ContextDefinition.SITE_CONTEXTS.SITE_BASIC}-${ContextDefinition.SITE_AREA_CONTEXTS.WITH_SMART_CHARGING_SINGLE_PHASED}`,
+ smartCharging: true,
+ numberOfPhases: 1,
+ maximumPower: 100000,
+ voltage: 230,
+ siteName: ContextDefinition.SITE_CONTEXTS.SITE_BASIC
+ }
];
+
// List of Charging Station created in a tenant
// siteAreaNames must refer the site Areas where teh charging station will be created
// if siteAreaNames is null then the CS will not be assigned or created in tenant with no porganization, so the baseName MUST be unique
@@ -584,7 +596,9 @@ export default class ContextDefinition {
`${ContextDefinition.SITE_CONTEXTS.SITE_WITH_AUTO_USER_ASSIGNMENT}-${ContextDefinition.SITE_AREA_CONTEXTS.WITHOUT_ACL}`,
`${ContextDefinition.SITE_CONTEXTS.SITE_WITH_OTHER_USER_STOP_AUTHORIZATION}-${ContextDefinition.SITE_AREA_CONTEXTS.WITH_ACL}`,
`${ContextDefinition.SITE_CONTEXTS.SITE_WITH_OTHER_USER_STOP_AUTHORIZATION}-${ContextDefinition.SITE_AREA_CONTEXTS.WITHOUT_ACL}`,
- `${ContextDefinition.SITE_CONTEXTS.SITE_BASIC}-${ContextDefinition.SITE_AREA_CONTEXTS.WITH_SMART_CHARGING}`]
+ `${ContextDefinition.SITE_CONTEXTS.SITE_BASIC}-${ContextDefinition.SITE_AREA_CONTEXTS.WITH_SMART_CHARGING}`,
+ `${ContextDefinition.SITE_CONTEXTS.SITE_BASIC}-${ContextDefinition.SITE_AREA_CONTEXTS.WITH_SMART_CHARGING_SINGLE_PHASED}`,
+ `${ContextDefinition.SITE_CONTEXTS.SITE_BASIC}-${ContextDefinition.SITE_AREA_CONTEXTS.WITH_SMART_CHARGING_THREE_PHASED}`]
},
{
baseName: ContextDefinition.CHARGING_STATION_CONTEXTS.ASSIGNED_OCPP15, // Concatenated with siteAreaName
@@ -595,8 +609,7 @@ export default class ContextDefinition {
`${ContextDefinition.SITE_CONTEXTS.SITE_WITH_AUTO_USER_ASSIGNMENT}-${ContextDefinition.SITE_AREA_CONTEXTS.WITH_ACL}`,
`${ContextDefinition.SITE_CONTEXTS.SITE_WITH_AUTO_USER_ASSIGNMENT}-${ContextDefinition.SITE_AREA_CONTEXTS.WITHOUT_ACL}`,
`${ContextDefinition.SITE_CONTEXTS.SITE_WITH_OTHER_USER_STOP_AUTHORIZATION}-${ContextDefinition.SITE_AREA_CONTEXTS.WITH_ACL}`,
- `${ContextDefinition.SITE_CONTEXTS.SITE_WITH_OTHER_USER_STOP_AUTHORIZATION}-${ContextDefinition.SITE_AREA_CONTEXTS.WITHOUT_ACL}`,
- `${ContextDefinition.SITE_CONTEXTS.SITE_BASIC}-${ContextDefinition.SITE_AREA_CONTEXTS.WITH_SMART_CHARGING}`]
+ `${ContextDefinition.SITE_CONTEXTS.SITE_WITH_OTHER_USER_STOP_AUTHORIZATION}-${ContextDefinition.SITE_AREA_CONTEXTS.WITHOUT_ACL}`]
},
{
baseName: ContextDefinition.CHARGING_STATION_CONTEXTS.UNASSIGNED_OCPP16,

First Site Area tests