Skip to content

Commit

Permalink
Added CompareToEqualExpected function
Browse files Browse the repository at this point in the history
  • Loading branch information
alfarj83 committed Mar 12, 2024
1 parent 5e1a2d6 commit 13a02e4
Showing 1 changed file with 25 additions and 1 deletion.
26 changes: 25 additions & 1 deletion src/server/util/readingsUtils.js
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,7 @@ function expectMaxMinToEqualExpected(res, expected, id = METER_ID) {
expect(res).to.be.json;
expect(res).to.have.status(HTTP_CODE.OK);
// Did the response have the correct number of readings.
expect(res.body).to.have.property(`${id}`).to.have.lengthOf(expected.length);
expect(res.body).to.have.property(`${id}`).to.have.lengthOf(2);
// Loop over each reading
for (let i = 0; i < expected.length; i++) {
// Check that the reading's value is within the expected tolerance (DELTA).
Expand All @@ -98,6 +98,29 @@ function expectMaxMinToEqualExpected(res, expected, id = METER_ID) {
}
}

/**
* Compares readings from api call against the expected readings csv
* @param {request.Response} res the response to the HTTP GET request from Chai
* @param {array} expected the returned array from parseExpectedCsv
*/
function expectCompareToEqualExpected(res, expected, id = METER_ID) {
expect(res).to.be.json;
expect(res).to.have.status(HTTP_CODE.OK);
// Did the response have the correct number of readings.
expect(res.body).to.have.property(`${id}`).to.have.lengthOf(expected.length);
console.log(res.body);
console.log(expected.length);
// Loop over each reading
for (let i = 0; i < expected.length; i++) {
// Check that the reading's value is within the expected tolerance (DELTA).
expect(res.body).to.have.property(`${id}`).to.have.property(`${i}`).to.have.property('reading').to.be.closeTo(Number(expected[i][0]), DELTA);
// Reading has correct start/end date and time.
expect(res.body).to.have.property(`${id}`).to.have.property(`${i}`).to.have.property('CurrStart').to.equal(Date.parse(expected[i][1]));
expect(res.body).to.have.property(`${id}`).to.have.property(`${i}`).to.have.property('CurrEnd').to.equal(Date.parse(expected[i][2]));
expect(res.body).to.have.property(`${id}`).to.have.property(`${i}`).to.have.property('Shift').to.equal(Date.parse(expected[i][3]));
}
}

/**
* Compares readings from api call against the expected readings csv
* @param {request.Response} res the response to the HTTP GET request from Chai
Expand Down Expand Up @@ -267,6 +290,7 @@ module.exports = {
parseExpectedCsv,
expectReadingToEqualExpected,
expectMaxMinToEqualExpected,
expectCompareToEqualExpected,
expectThreeDReadingToEqualExpected,
createTimeString,
getUnitId,
Expand Down

0 comments on commit 13a02e4

Please sign in to comment.