Updated unit tests with Amps in transaction/ocpp
MODIFY
test/api/OCPPCommonTests.ts
test/api/OCPPCommonTests.ts
@@ -7,6 +7,7 @@ import { InactivityStatus } from '../../src/types/Transaction';
import { PricingSettingsType } from '../../src/types/Setting';
import TenantContext from './context/TenantContext';
import User from '../../src/types/User';
+import Utils from '../../src/utils/Utils';
import chaiSubset from 'chai-subset';
import { fail } from 'assert';
import faker from 'faker';
@@ -522,7 +523,11 @@ export default class OCPPCommonTests {
expect(value).to.include({
'date': transactionCurrentTime.toISOString(),
'instantPower': this.transactionMeterValues[i] * this.transactionMeterValueIntervalSecs,
- 'cumulatedConsumption': transactionCumulatedConsumption
+ 'instantAmps': Utils.convertWattToAmp(this.chargingStationContext.getChargingStation(),
+ null, this.newTransaction.connectorId, this.transactionMeterValues[i] * this.transactionMeterValueIntervalSecs),
+ 'cumulatedConsumption': transactionCumulatedConsumption,
+ 'cumulatedConsumptionAmps': Utils.convertWattToAmp(this.chargingStationContext.getChargingStation(),
+ null, this.newTransaction.connectorId, transactionCumulatedConsumption)
});
if (withSoC) {
// Check

MODIFY
test/api/StatisticsTest.ts
test/api/StatisticsTest.ts
@@ -5,7 +5,8 @@ import ContextDefinition from './context/ContextDefinition';
import ContextProvider from './context/ContextProvider';
import StatisticsApi from './client/StatisticsApi';
import StatisticsContext from './context/StatisticsContext';
-import Utils from './Utils';
+import TestUtils from './TestUtils';
+import Utils from './TestUtils';
import chaiDatetime from 'chai-datetime';
import chaiSubset from 'chai-subset';
import responseHelper from '../helpers/responseHelper';
@@ -303,7 +304,7 @@ describe('Statistics tests', function() {
expect(adminUserListResponse.data,
`Query response for year ${firstYear} on data per charging station should not be empty`
).not.to.be.empty;
- let objectArray = Utils.convertExportFileToObjectArray(adminUserListResponse.data);
+ let objectArray = TestUtils.convertExportFileToObjectArray(adminUserListResponse.data);
expect(objectArray.length,
`Number of exported chargers should be ${numberOfChargers}`
).to.be.eql(numberOfChargers);
@@ -312,7 +313,7 @@ describe('Statistics tests', function() {
expect(adminUserListResponse.data,
`Query response for year ${firstYear} on data per user should not be empty`
).not.to.be.empty;
- objectArray = Utils.convertExportFileToObjectArray(adminUserListResponse.data);
+ objectArray = TestUtils.convertExportFileToObjectArray(adminUserListResponse.data);
expect(objectArray.length,
`Number of exported users should be ${numberOfUsers}`
).to.be.eql(numberOfUsers);
@@ -447,7 +448,7 @@ describe('Statistics tests', function() {
expect(basicUserListResponse.data,
'Query response for all years on data per charging station should not be empty'
).not.to.be.empty;
- let objectArray = Utils.convertExportFileToObjectArray(basicUserListResponse.data);
+ let objectArray = TestUtils.convertExportFileToObjectArray(basicUserListResponse.data);
expect(objectArray.length,
`Number of exported chargers should be ${numberOfChargers}`
).to.be.eql(numberOfChargers);
@@ -456,7 +457,7 @@ describe('Statistics tests', function() {
expect(basicUserListResponse.data,
'Query response for all years on data per user should not be empty'
).not.to.be.empty;
- objectArray = Utils.convertExportFileToObjectArray(basicUserListResponse.data);
+ objectArray = TestUtils.convertExportFileToObjectArray(basicUserListResponse.data);
expect(objectArray.length,
'Number of exported users should be 1'
).to.be.eql(1);
@@ -592,7 +593,7 @@ describe('Statistics tests', function() {
expect(demoUserListResponse.data,
`Query response for year ${firstYear} on data per charging station should not be empty`
).not.to.be.empty;
- let objectArray = Utils.convertExportFileToObjectArray(demoUserListResponse.data);
+ let objectArray = TestUtils.convertExportFileToObjectArray(demoUserListResponse.data);
expect(objectArray.length,
`Number of exported chargers should be ${numberOfChargers}`
).to.be.eql(numberOfChargers);
@@ -601,7 +602,7 @@ describe('Statistics tests', function() {
expect(demoUserListResponse.data,
`Query response for year ${firstYear} on data per user should not be empty`
).not.to.be.empty;
- objectArray = Utils.convertExportFileToObjectArray(demoUserListResponse.data);
+ objectArray = TestUtils.convertExportFileToObjectArray(demoUserListResponse.data);
expect(objectArray.length,
`Number of exported users should be ${numberOfUsers}`
).to.be.eql(numberOfUsers);

MODIFY
test/api/TenantTest.ts
test/api/TenantTest.ts
@@ -2,7 +2,7 @@ import chai, { expect } from 'chai';
import CentralServerService from '../api/client/CentralServerService';
import Factory from '../factories/Factory';
-import Utils from './Utils';
+import TestUtils from './TestUtils';
import chaiSubset from 'chai-subset';
chai.use(chaiSubset);
@@ -58,7 +58,7 @@ describe('Tenant tests', function() {
it('Should delete the created tenant', async () => {
// Temporary workaround to avoid MongoDB issue: Trying to delete a Tenant during index creation leads to an exception like:
// Cannot perform operation: a background operation is currently running for collection...
- await Utils.sleep(1000);
+ await TestUtils.sleep(1000);
// Delete the created entity
await CentralServerService.defaultInstance.deleteEntity(
CentralServerService.defaultInstance.tenantApi, testData.newTenant);

RENAME
test/api/Utils.ts
test/api/TestUtils.ts
-export default class Utils {
+export default class TestUtils {
static async sleep(ms) {
return await new Promise((resolve) => setTimeout(resolve, ms));
}
@@ -12,7 +12,7 @@ export default class Utils {
public static convertExportFileToObjectArray(fileData: string): Array<{ [x: string]: any }> {
let jsonString = '';
const objectArray = [];
- const fileArray = Utils.convertExportFileToRawArray(fileData);
+ const fileArray = TestUtils.convertExportFileToRawArray(fileData);
if (Array.isArray(fileArray) && fileArray.length > 0) {
const columns = fileArray[0].split('\t');
for (let i = 1; i < fileArray.length; i++) {

MODIFY
test/api/TransactionCommonTests.ts
test/api/TransactionCommonTests.ts
@@ -4,8 +4,9 @@ import CentralServerService from './client/CentralServerService';
import ChargingStationContext from './context/ChargingStationContext';
import { InactivityStatus } from '../../src/types/Transaction';
import TenantContext from './context/TenantContext';
+import TestUtils from './TestUtils';
import User from '../../src/types/User';
-import Utils from './Utils';
+import Utils from '../../src/utils/Utils';
import chaiSubset from 'chai-subset';
import faker from 'faker';
import moment from 'moment';
@@ -526,7 +527,11 @@ export default class TransactionCommonTests {
{
date: meterValues[0].timestamp.toISOString(),
instantPower: meterValues[0].value,
- cumulatedConsumption: meterValues[0].value
+ instantAmps: Utils.convertWattToAmp(
+ this.chargingStationContext.getChargingStation(), null, connectorId, meterValues[0].value),
+ cumulatedConsumption: meterValues[0].value,
+ cumulatedConsumptionAmps: Utils.convertWattToAmp(
+ this.chargingStationContext.getChargingStation(), null, connectorId, meterValues[0].value),
},
{
date: meterValues[1].timestamp.toISOString(),
@@ -572,12 +577,20 @@ export default class TransactionCommonTests {
{
date: meterValues[0].timestamp.toISOString(),
instantPower: meterValues[0].value,
- cumulatedConsumption: meterValues[0].value
+ instantAmps: Utils.convertWattToAmp(
+ this.chargingStationContext.getChargingStation(), null, connectorId, meterValues[0].value),
+ cumulatedConsumption: meterValues[0].value,
+ cumulatedConsumptionAmps: Utils.convertWattToAmp(
+ this.chargingStationContext.getChargingStation(), null, connectorId, meterValues[0].value),
},
{
date: meterValues[1].timestamp.toISOString(),
instantPower: meterValues[1].value,
- cumulatedConsumption: cumulated - meterStart
+ instantAmps: Utils.convertWattToAmp(
+ this.chargingStationContext.getChargingStation(), null, connectorId, meterValues[1].value),
+ cumulatedConsumption: cumulated - meterStart,
+ cumulatedConsumptionAmps: Utils.convertWattToAmp(
+ this.chargingStationContext.getChargingStation(), null, connectorId, cumulated - meterStart),
}
]
});
@@ -623,7 +636,11 @@ export default class TransactionCommonTests {
{
date: meterValues[0].timestamp.toISOString(),
instantPower: meterValues[0].value,
- cumulatedConsumption: meterValues[0].value
+ instantAmps: Utils.convertWattToAmp(
+ this.chargingStationContext.getChargingStation(), null, connectorId, meterValues[0].value),
+ cumulatedConsumption: meterValues[0].value,
+ cumulatedConsumptionAmps: Utils.convertWattToAmp(
+ this.chargingStationContext.getChargingStation(), null, connectorId, meterValues[0].value),
}
]
});
@@ -639,7 +656,11 @@ export default class TransactionCommonTests {
{
date: meterValues[0].timestamp.toISOString(),
instantPower: meterValues[0].value,
- cumulatedConsumption: meterValues[0].value
+ instantAmps: Utils.convertWattToAmp(
+ this.chargingStationContext.getChargingStation(), null, connectorId, meterValues[0].value),
+ cumulatedConsumption: meterValues[0].value,
+ cumulatedConsumptionAmps: Utils.convertWattToAmp(
+ this.chargingStationContext.getChargingStation(), null, connectorId, meterValues[0].value),
}
]
});
@@ -655,12 +676,20 @@ export default class TransactionCommonTests {
{
date: meterValues[0].timestamp.toISOString(),
instantPower: meterValues[0].value,
- cumulatedConsumption: meterValues[0].value
+ instantAmps: Utils.convertWattToAmp(
+ this.chargingStationContext.getChargingStation(), null, connectorId, meterValues[0].value),
+ cumulatedConsumption: meterValues[0].value,
+ cumulatedConsumptionAmps: Utils.convertWattToAmp(
+ this.chargingStationContext.getChargingStation(), null, connectorId, meterValues[0].value),
},
{
date: meterValues[1].timestamp.toISOString(),
instantPower: meterValues[1].value,
- cumulatedConsumption: meterValues[1].value + meterValues[0].value
+ instantAmps: Utils.convertWattToAmp(
+ this.chargingStationContext.getChargingStation(), null, connectorId, meterValues[1].value),
+ cumulatedConsumption: meterValues[1].value + meterValues[0].value,
+ cumulatedConsumptionAmps: Utils.convertWattToAmp(
+ this.chargingStationContext.getChargingStation(), null, connectorId, meterValues[1].value + meterValues[0].value),
}
]
});
@@ -676,12 +705,20 @@ export default class TransactionCommonTests {
{
date: meterValues[0].timestamp.toISOString(),
instantPower: meterValues[0].value,
- cumulatedConsumption: meterValues[0].value
+ instantAmps: Utils.convertWattToAmp(
+ this.chargingStationContext.getChargingStation(), null, connectorId, meterValues[0].value),
+ cumulatedConsumption: meterValues[0].value,
+ cumulatedConsumptionAmps: Utils.convertWattToAmp(
+ this.chargingStationContext.getChargingStation(), null, connectorId, meterValues[0].value),
},
{
date: meterValues[1].timestamp.toISOString(),
instantPower: meterValues[1].value,
- cumulatedConsumption: meterValues[1].value + meterValues[0].value
+ instantAmps: Utils.convertWattToAmp(
+ this.chargingStationContext.getChargingStation(), null, connectorId, meterValues[1].value),
+ cumulatedConsumption: meterValues[1].value + meterValues[0].value,
+ cumulatedConsumptionAmps: Utils.convertWattToAmp(
+ this.chargingStationContext.getChargingStation(), null, connectorId, meterValues[1].value + meterValues[0].value),
}
]
});
@@ -697,7 +734,11 @@ export default class TransactionCommonTests {
{
date: meterValues[1].timestamp.toISOString(),
instantPower: meterValues[1].value,
- cumulatedConsumption: meterValues[1].value + meterValues[0].value
+ instantAmps: Utils.convertWattToAmp(
+ this.chargingStationContext.getChargingStation(), null, connectorId, meterValues[1].value),
+ cumulatedConsumption: meterValues[1].value + meterValues[0].value,
+ cumulatedConsumptionAmps: Utils.convertWattToAmp(
+ this.chargingStationContext.getChargingStation(), null, connectorId, meterValues[0].value),
}
]
});
@@ -713,7 +754,11 @@ export default class TransactionCommonTests {
{
date: meterValues[1].timestamp.toISOString(),
instantPower: meterValues[1].value,
- cumulatedConsumption: meterValues[1].value + meterValues[0].value
+ instantAmps: Utils.convertWattToAmp(
+ this.chargingStationContext.getChargingStation(), null, connectorId, meterValues[1].value),
+ cumulatedConsumption: meterValues[1].value + meterValues[0].value,
+ cumulatedConsumptionAmps: Utils.convertWattToAmp(
+ this.chargingStationContext.getChargingStation(), null, connectorId, meterValues[1].value + meterValues[0].value),
}
]
});
@@ -747,7 +792,11 @@ export default class TransactionCommonTests {
{
date: meterValues[0].timestamp.toISOString(),
instantPower: meterValues[0].value,
- cumulatedConsumption: meterValues[0].value
+ instantAmps: Utils.convertWattToAmp(
+ this.chargingStationContext.getChargingStation(), null, connectorId, meterValues[0].value),
+ cumulatedConsumption: meterValues[0].value,
+ cumulatedConsumptionAmps: Utils.convertWattToAmp(
+ this.chargingStationContext.getChargingStation(), null, connectorId, meterValues[0].value),
}
]
});
@@ -762,12 +811,20 @@ export default class TransactionCommonTests {
{
date: meterValues[0].timestamp.toISOString(),
instantPower: meterValues[0].value,
- cumulatedConsumption: meterValues[0].value
+ instantAmps: Utils.convertWattToAmp(
+ this.chargingStationContext.getChargingStation(), null, connectorId, meterValues[0].value),
+ cumulatedConsumption: meterValues[0].value,
+ cumulatedConsumptionAmps: Utils.convertWattToAmp(
+ this.chargingStationContext.getChargingStation(), null, connectorId, meterValues[0].value),
},
{
date: meterValues[1].timestamp.toISOString(),
instantPower: meterValues[1].value,
- cumulatedConsumption: meterValues[1].value + meterValues[0].value
+ instantAmps: Utils.convertWattToAmp(
+ this.chargingStationContext.getChargingStation(), null, connectorId, meterValues[1].value),
+ cumulatedConsumption: meterValues[1].value + meterValues[0].value,
+ cumulatedConsumptionAmps: Utils.convertWattToAmp(
+ this.chargingStationContext.getChargingStation(), null, connectorId, meterValues[1].value + meterValues[0].value),
}
]
});
@@ -782,12 +839,20 @@ export default class TransactionCommonTests {
{
date: meterValues[0].timestamp.toISOString(),
instantPower: meterValues[0].value,
- cumulatedConsumption: meterValues[0].value
+ instantAmps: Utils.convertWattToAmp(
+ this.chargingStationContext.getChargingStation(), null, connectorId, meterValues[0].value),
+ cumulatedConsumption: meterValues[0].value,
+ cumulatedConsumptionAmps: Utils.convertWattToAmp(
+ this.chargingStationContext.getChargingStation(), null, connectorId, meterValues[0].value),
},
{
date: meterValues[1].timestamp.toISOString(),
instantPower: meterValues[1].value,
- cumulatedConsumption: meterValues[1].value + meterValues[0].value
+ instantAmps: Utils.convertWattToAmp(
+ this.chargingStationContext.getChargingStation(), null, connectorId, meterValues[1].value),
+ cumulatedConsumption: meterValues[1].value + meterValues[0].value,
+ cumulatedConsumptionAmps: Utils.convertWattToAmp(
+ this.chargingStationContext.getChargingStation(), null, connectorId, meterValues[1].value + meterValues[0].value),
}
]
});
@@ -813,7 +878,11 @@ export default class TransactionCommonTests {
{
date: stopDate.toISOString(),
instantPower: meterStop - meterStart,
- cumulatedConsumption: meterStop
+ instantAmps: Utils.convertWattToAmp(
+ this.chargingStationContext.getChargingStation(), null, connectorId, meterStop - meterStart),
+ cumulatedConsumption: meterStop,
+ cumulatedConsumptionAmps: Utils.convertWattToAmp(
+ this.chargingStationContext.getChargingStation(), null, connectorId, meterStop),
}
]
});
@@ -1126,7 +1195,7 @@ export default class TransactionCommonTests {
response = await this.chargingStationContext.sendConsumptionMeterValue(connectorId, transactionId, cumulated, meterValue.timestamp);
expect(response.data).to.eql({});
}
- await Utils.sleep(1000);
+ await TestUtils.sleep(1000);
expect(await this.centralUserService.mailApi.isMailReceived(this.transactionUser.email, 'transaction-started')).is.equal(true, 'transaction-started mail');
expect(await this.centralUserService.mailApi.isMailReceived(this.transactionUser.email, 'end-of-charge')).is.equal(true, 'end-of-charge mail');
response = await this.chargingStationContext.stopTransaction(transactionId, tagId, cumulated + 50, currentDate.add(1, 'hour'));
@@ -1171,7 +1240,7 @@ export default class TransactionCommonTests {
public async testExportTransactionsToRefund(params) {
const response = await this.centralUserService.transactionApi.exportTransactionsToRefund(params);
const transactionsToRefund = await this.centralUserService.transactionApi.readAllToRefund(params);
- const responseFileArray = Utils.convertExportFileToObjectArray(response.data);
+ const responseFileArray = TestUtils.convertExportFileToObjectArray(response.data);
expect(response.status).eq(200);
expect(response.data).not.null;

Updated unit tests with Amps in transaction/ocpp