Skip to content

Commit

Permalink
address requested changes
Browse files Browse the repository at this point in the history
  • Loading branch information
BrendenHaskins committed Dec 6, 2024
1 parent acbc079 commit 7ec61e6
Showing 1 changed file with 31 additions and 21 deletions.
52 changes: 31 additions & 21 deletions src/server/test/web/obviusTest.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,19 @@ const bcrypt = require('bcryptjs');
const { insertUnits } = require('../../util/insertData');
const Unit = require('../../models/Unit');
const Meter = require('../../models/Meter.js');
const { Console } = require('console');

//expected names and ids for obvius meters.
const expMeterNames = [
'mb-001.0', 'mb-001.1', 'mb-001.2', 'mb-001.3', 'mb-001.4', 'mb-001.5', 'mb-001.6', 'mb-001.7',
'mb-001.8', 'mb-001.9', 'mb-001.10', 'mb-001.11', 'mb-001.12', 'mb-001.13', 'mb-001.14', 'mb-001.15',
'mb-001.16', 'mb-001.17', 'mb-001.18', 'mb-001.19', 'mb-001.20', 'mb-001.21', 'mb-001.22', 'mb-001.23',
'mb-001.24', 'mb-001.25', 'mb-001.26', 'mb-001.27'
];

const expMeterIDs = [
1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23, 24, 25, 26, 27, 28
];

mocha.describe('Obvius API', () => {
mocha.describe('upload: ', () => {
Expand Down Expand Up @@ -176,15 +189,15 @@ mocha.describe('Obvius API', () => {
.field('modbusdevice', '1234')
.attach('files', configFilePath);

//logfile upload should respond with 200, success
expect(upload).to.have.status(200);

const res = await chai.request(app)
.post('/api/obvius')
.field('username', obviusUser.username)
.field('password', obviusUser.password)
.field('mode', manifestRequestMode);

//logfile upload should respond with 200, success
expect(upload).to.have.status(200);

//logfile request should respond with 200, success
expect(res).to.have.status(200);

Expand All @@ -201,8 +214,8 @@ mocha.describe('Obvius API', () => {
//config file uploads should create accurate meter objects
const allMeters = await Meter.getAll(conn);

//mb-001.ini should make 28 meters
expect(allMeters.length).to.equal(28);
//mb-001.ini should make meters equal to expMeterNames.length
expect(allMeters.length).to.equal(expMeterNames.length);

//these arrays should vary for different submeters
const meterNames = [];
Expand All @@ -213,20 +226,9 @@ mocha.describe('Obvius API', () => {
const allMetersAreNotDisplayable = true;
const allMetersAreNotEnabled = true;

//expected names and ids
const expMeterNames = [
'mb-001.0', 'mb-001.1', 'mb-001.2', 'mb-001.3', 'mb-001.4', 'mb-001.5', 'mb-001.6', 'mb-001.7',
'mb-001.8', 'mb-001.9', 'mb-001.10', 'mb-001.11', 'mb-001.12', 'mb-001.13', 'mb-001.14', 'mb-001.15',
'mb-001.16', 'mb-001.17', 'mb-001.18', 'mb-001.19', 'mb-001.20', 'mb-001.21', 'mb-001.22', 'mb-001.23',
'mb-001.24', 'mb-001.25', 'mb-001.26', 'mb-001.27'
];

const expMeterIDs = [
1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23, 24, 25, 26, 27, 28
];
for (const meter of allMeters) {
//populate arrays with varying values in ascending order
let currentName = meter.name + "";
let currentName = meter.name;
let idx = currentName.split('.')[1];
meterNames[parseInt(idx)] = meter.name;
meterIDs[meter.id - 1] = meter.id;
Expand All @@ -243,17 +245,25 @@ mocha.describe('Obvius API', () => {
}

//flags for comparison between expected arrays and actual arrays
const expectedNamesAreEqual = true;
const expectedIDsAreEqual = true;
let expectedNamesAreEqual = true;
let expectedIDsAreEqual = true;

//error message for more descriptive failures
let allErrorMessagesNames = "";
let allErrorMessagesIDs = "";


//both arrays should be contain the same sequence of values
for (let i = 0; i < 28; i++) {
if (expMeterNames[i] != meterNames[i]) {
expectedNamesAreEqual = false;
allErrorMessagesNames += "Meter failed name comparison, Expeceted: " + expMeterNames[i] + " Actual: " + meterNames[i] + "\n";
}

if (expMeterIDs[i] != meterIDs[i]) {
expectedIDsAreEqual = false;
allErrorMessagesIDs += "Meter failed ID comparison. Expected: " + expMeterIDs[i] + " Actual: " + meterIDs[i] + "\n";

}
}

Expand All @@ -263,8 +273,8 @@ mocha.describe('Obvius API', () => {
expect(allMetersAreNotEnabled).to.equal(true);

//expected arrays should equal actual arrays
expect(expectedNamesAreEqual).to.equal(true);
expect(expectedIDsAreEqual).to.equal(true);
expect(expectedNamesAreEqual).to.equal(true, allErrorMessagesNames);
expect(expectedIDsAreEqual).to.equal(true, allErrorMessagesIDs);
});
});
});
Expand Down

0 comments on commit 7ec61e6

Please sign in to comment.