Fixed unit tests + deprecated faker data type
MODIFY
package-lock.json
package-lock.json
"node-releases": "^1.1.70"
}
},
- "bson": {
- "version": "1.1.6",
- "resolved": "https://registry.npmjs.org/bson/-/bson-1.1.6.tgz",
- "integrity": "sha512-EvVNVeGo4tHxwi8L6bPj3y3itEvStdwvvlojVxxbyYfoaxJ6keLgrTuKdyfEAszFK+H3olzBuafE0yoh0D1gdg=="
- },
"buffer": {
"version": "5.2.1",
"resolved": "https://registry.npmjs.org/buffer/-/buffer-5.2.1.tgz",

MODIFY
test/api/OCPPCommonTests.ts
test/api/OCPPCommonTests.ts
@@ -152,34 +152,34 @@ export default class OCPPCommonTests {
// eslint-disable-next-line no-useless-escape
this.transactionEndSignedData = '<?xml version=\"1.0\" encoding=\"UTF-8\" ?><signedMeterValue> <publicKey encoding=\"base64\">8Y5UzWD+TZeMKBDkKLpHhwzSfGsnCvo00ndCXv/LVRD5pAVtRZEA49bqpr/DY3KL</publicKey> <meterValueSignature encoding=\"base64\">GChPf/f+0Rw6DDWI0mujec6dOMDqm5cuCLXdEVV6MRua6OVqcHNP85q7K70tRPJKAJ8=</meterValueSignature> <signatureMethod>ECDSA192SHA256</signatureMethod> <encodingMethod>EDL</encodingMethod> <encodedMeterValue encoding=\"base64\">CQFFTUgAAH+eodYDQF0IrEb+ACgAAAABAAERAP8e/8OtYQEAAAAAAJ9sYQoCAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAtVP10AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA=</encodedMeterValue></signedMeterValue>';
// Energy Import Meter Value (14 values)
- this.energyActiveImportMeterValues = Array.from({ length: 12 }, () => faker.random.number({
+ this.energyActiveImportMeterValues = Array.from({ length: 12 }, () => faker.datatype.number({
min: 200, max: 500
})).concat([0, 0]);
// SoC Meter Value (14 values)
- this.socMeterValues = Array.from({ length: 8 }, () => faker.random.number({
+ this.socMeterValues = Array.from({ length: 8 }, () => faker.datatype.number({
min: 10, max: 90
})).concat([8, 8, 98, 99, 100, 100]).sort((a, b) => (a - b));
// Voltage (14 values)
- this.voltageMeterValues = Array.from({ length: 14 }, () => faker.random.number({
+ this.voltageMeterValues = Array.from({ length: 14 }, () => faker.datatype.number({
min: 220, max: 240
}));
- this.voltageL1MeterValues = Array.from({ length: 14 }, () => faker.random.number({
+ this.voltageL1MeterValues = Array.from({ length: 14 }, () => faker.datatype.number({
min: 220, max: 240
}));
- this.voltageL2MeterValues = Array.from({ length: 14 }, () => faker.random.number({
+ this.voltageL2MeterValues = Array.from({ length: 14 }, () => faker.datatype.number({
min: 220, max: 240
}));
- this.voltageL3MeterValues = Array.from({ length: 14 }, () => faker.random.number({
+ this.voltageL3MeterValues = Array.from({ length: 14 }, () => faker.datatype.number({
min: 220, max: 240
}));
// Amperage (14 values)
- this.amperageL1MeterValues = Array.from({ length: 14 }, () => faker.random.number({
+ this.amperageL1MeterValues = Array.from({ length: 14 }, () => faker.datatype.number({
min: 16, max: 32
}));
- this.amperageL2MeterValues = Array.from({ length: 14 }, () => faker.random.number({
+ this.amperageL2MeterValues = Array.from({ length: 14 }, () => faker.datatype.number({
min: 16, max: 32
}));
- this.amperageL3MeterValues = Array.from({ length: 14 }, () => faker.random.number({
+ this.amperageL3MeterValues = Array.from({ length: 14 }, () => faker.datatype.number({
min: 16, max: 32
}));
this.amperageMeterValues = [];
@@ -223,7 +223,7 @@ export default class OCPPCommonTests {
// Tags
this.validTag = faker.random.alphaNumeric(20).toString();
this.invalidTag = faker.random.alphaNumeric(21).toString();
- this.numberTag = faker.random.number(10000);
+ this.numberTag = faker.datatype.number(10000);
if (this.createAnyUser) {
this.anyUser = await this.createUser(Factory.user.build());
if (!this.createdUsers) {
@@ -819,7 +819,7 @@ export default class OCPPCommonTests {
const response = await this.chargingStationContext.startTransaction(
this.chargingStationConnector1.connectorId,
this.numberTag.toString(),
- faker.random.number(100000),
+ faker.datatype.number(100000),
this.transactionStartTime
);
// eslint-disable-next-line @typescript-eslint/unbound-method
@@ -861,7 +861,7 @@ export default class OCPPCommonTests {
expect(startTransactionResponse).to.be.transactionValid;
const transactionId = startTransactionResponse.transactionId;
this.transactionCurrentTime = moment().toDate();
- const stopValue = this.energyActiveImportStartMeterValue + faker.random.number(100000);
+ const stopValue = this.energyActiveImportStartMeterValue + faker.datatype.number(100000);
const stopTransactionResponse = await this.chargingStationContext.stopTransaction(
transactionId, this.numberTag.toString(), stopValue, this.transactionCurrentTime);
expect(stopTransactionResponse).to.have.property('idTagInfo');
@@ -879,7 +879,7 @@ export default class OCPPCommonTests {
expect(startTransactionResponse).to.be.transactionValid;
const transactionId = startTransactionResponse.transactionId;
this.transactionCurrentTime = moment().toDate();
- const stopValue = this.energyActiveImportStartMeterValue + faker.random.number(100000);
+ const stopValue = this.energyActiveImportStartMeterValue + faker.datatype.number(100000);
let transactionData: OCPPMeterValue[] | OCPP15TransactionData;
if (this.chargingStationContext.getChargingStation().ocppVersion === OCPPVersion.VERSION_16) {
transactionData = [
@@ -947,7 +947,7 @@ export default class OCPPCommonTests {
expect(startTransactionResponse).to.be.transactionValid;
const transactionId = startTransactionResponse.transactionId;
this.transactionCurrentTime = moment().toDate();
- const stopValue = this.energyActiveImportStartMeterValue + faker.random.number(100000);
+ const stopValue = this.energyActiveImportStartMeterValue + faker.datatype.number(100000);
let transactionData: OCPPMeterValue[] | OCPP15TransactionData;
// Provide TransactionData for wrong OCPP Version
if (this.chargingStationContext.getChargingStation().ocppVersion === OCPPVersion.VERSION_15) {

MODIFY
test/api/TransactionCommonTests.ts
test/api/TransactionCommonTests.ts
@@ -74,7 +74,7 @@ export default class TransactionCommonTests {
}
public async testReadNonExistingTransaction() {
- const response = await this.transactionUserService.transactionApi.readById(faker.random.number(100000));
+ const response = await this.transactionUserService.transactionApi.readById(faker.datatype.number(100000));
expect(response.status).to.equal(550);
}
@@ -113,7 +113,7 @@ export default class TransactionCommonTests {
public async testReadStartedTransactionWithoutMeterValue() {
const connectorId = 1;
const tagId = this.transactionUser.tags[0].id;
- const meterStart = faker.random.number({ min: 0, max: 1000 });
+ const meterStart = faker.datatype.number({ min: 0, max: 1000 });
const startDate = moment();
const startTransactionResponse = await this.chargingStationContext.startTransaction(
connectorId, tagId, meterStart, startDate.toDate());
@@ -1025,7 +1025,7 @@ export default class TransactionCommonTests {
}
public async testDeleteNotExistingTransaction() {
- const response = await this.transactionUserService.transactionApi.delete(faker.random.number(100000));
+ const response = await this.transactionUserService.transactionApi.delete(faker.datatype.number(100000));
expect(response.status).to.equal(HTTPAuthError.FORBIDDEN);
}
@@ -1090,7 +1090,7 @@ export default class TransactionCommonTests {
}
public async testMultiDeleteNotFoundTransactions() {
- const response = await this.transactionUserService.transactionApi.deleteMany([faker.random.number(100000), faker.random.number(100000)]);
+ const response = await this.transactionUserService.transactionApi.deleteMany([faker.datatype.number(100000), faker.datatype.number(100000)]);
expect(response.status).to.equal(200);
expect(response.data.inSuccess).to.equal(0);
expect(response.data.inError).to.equal(2);
@@ -1109,7 +1109,7 @@ export default class TransactionCommonTests {
const transactionId = startTransactionResponse.transactionId;
const stopTransactionResponse = await this.chargingStationContext.stopTransaction(transactionId, tagId, meterStop, stopDate.toDate());
expect(stopTransactionResponse).to.be.transactionStatus('Accepted');
- const transactionsDeleted = await this.transactionUserService.transactionApi.deleteMany([transactionId, faker.random.number(100000)]);
+ const transactionsDeleted = await this.transactionUserService.transactionApi.deleteMany([transactionId, faker.datatype.number(100000)]);
if (allowed) {
expect(transactionsDeleted.status).to.equal(200);
expect(transactionsDeleted.data.inSuccess).to.equal(1);

MODIFY
test/api/ocpp/soap/OCPPSoapService15.ts
test/api/ocpp/soap/OCPPSoapService15.ts
import { OCPP15MeterValuesRequest, OCPPAuthorizeRequest, OCPPAuthorizeResponse, OCPPBootNotificationRequest, OCPPBootNotificationResponse, OCPPDataTransferRequest, OCPPDataTransferResponse, OCPPDiagnosticsStatusNotificationRequest, OCPPDiagnosticsStatusNotificationResponse, OCPPFirmwareStatusNotificationRequest, OCPPFirmwareStatusNotificationResponse, OCPPHeartbeatRequest, OCPPHeartbeatResponse, OCPPMeterValuesRequest, OCPPMeterValuesResponse, OCPPStartTransactionRequest, OCPPStartTransactionResponse, OCPPStatusNotificationRequest, OCPPStatusNotificationResponse, OCPPStopTransactionRequest, OCPPStopTransactionResponse, OCPPVersion } from '../../../../src/types/ocpp/OCPPServer';
import OCPPService from '../OCPPService';
-import global from '../../../types/GlobalType';
+import global from '../../../../src/types/GlobalType';
import soap from 'strong-soap';
export default class OCPPSoapService15 extends OCPPService {
@@ -101,7 +101,7 @@ export default class OCPPSoapService15 extends OCPPService {
// eslint-disable-next-line no-undef
this.client = await new Promise(function(resolve, reject) {
// Create the client
- soap.soap.createClient(`${global.appRoot}/src/assets/server/ocpp/wsdl/OCPPCentralSystemService15.wsdl`, options, (err, client) => {
+ soap.soap.createClient(`${global.appRoot}/assets/server/ocpp/wsdl/OCPPCentralSystemService15.wsdl`, options, (err, client) => {
if (err) {
reject(err);
} else {

MODIFY
test/factories/AssetFactory.ts
test/factories/AssetFactory.ts
@@ -5,6 +5,6 @@ export default Factory.define('asset')
.attr('name', () => faker.company.companyName())
.attr('siteAreaID', null)
.attr('assetType', null)
- .attr('fluctuationPercent', faker.random.number({ min: 1, max: 100 }))
+ .attr('fluctuationPercent', faker.datatype.number({ min: 1, max: 100 }))
.attr('staticValueWatt', 0)
.attr('excludeFromSmartCharging', false);

MODIFY
test/factories/CarFactory.ts
test/factories/CarFactory.ts
@@ -9,8 +9,8 @@ export default Factory.define('car')
.attr('usersUpserted', [])
.attr('usersRemoved', [])
.attr('converter', {
- 'amperagePerPhase': faker.random.number(64),
- 'numberOfPhases': faker.random.number({ min: 1, max: 4 }),
+ 'amperagePerPhase': faker.datatype.number(64),
+ 'numberOfPhases': faker.datatype.number({ min: 1, max: 4 }),
'type': 'S',
- 'powerWatts': faker.random.number(32)
+ 'powerWatts': faker.datatype.number(32)
});

MODIFY
test/factories/ChargingStationFactory.ts
test/factories/ChargingStationFactory.ts
@@ -6,21 +6,21 @@ const chargingStationThreePhased = Factory.define('chargingStation')
.attr('chargePointModel', () => 'MONOBLOCK')
.attr('chargePointSerialNumber', () => faker.random.alphaNumeric(25))
.attr('chargeBoxSerialNumber', () => 'EV.2S22P44' + faker.random.alphaNumeric(15).toUpperCase())
- .attr('firmwareVersion', () => '3.2.' + faker.random.number(9).toString());
+ .attr('firmwareVersion', () => '3.2.' + faker.datatype.number(9).toString());
const chargingStationSinglePhased = Factory.define('chargingStation')
.attr('chargePointVendor', () => 'Schneider Electric')
.attr('chargePointModel', () => 'MONOBLOCK')
.attr('chargePointSerialNumber', () => faker.random.alphaNumeric(25))
.attr('chargeBoxSerialNumber', () => 'EV.2S7P44' + faker.random.alphaNumeric(15).toUpperCase())
- .attr('firmwareVersion', () => '3.2.' + faker.random.number(9).toString());
+ .attr('firmwareVersion', () => '3.2.' + faker.datatype.number(9).toString());
const chargingStationDC = Factory.define('chargingStation')
.attr('chargePointVendor', () => 'DELTA')
.attr('chargePointModel', () => '10616')
.attr('chargePointSerialNumber', () => faker.random.alphaNumeric(25))
.attr('chargeBoxSerialNumber', () => '20071984' + faker.random.alphaNumeric(15).toUpperCase())
- .attr('firmwareVersion', () => '3.3.' + faker.random.number(9).toString());
+ .attr('firmwareVersion', () => '3.3.' + faker.datatype.number(9).toString());
export default class ChargingStationFactory {
static build(attributes?, options?) {

Fixed unit tests + deprecated faker data type