From 13a02e4f86a697e016dd93810b36d880fcfcef95 Mon Sep 17 00:00:00 2001 From: alfarj83 Date: Tue, 12 Mar 2024 19:21:07 -0400 Subject: [PATCH] Added CompareToEqualExpected function --- src/server/util/readingsUtils.js | 26 +++++++++++++++++++++++++- 1 file changed, 25 insertions(+), 1 deletion(-) diff --git a/src/server/util/readingsUtils.js b/src/server/util/readingsUtils.js index 24ce1c83a..4173ba61f 100644 --- a/src/server/util/readingsUtils.js +++ b/src/server/util/readingsUtils.js @@ -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). @@ -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 @@ -267,6 +290,7 @@ module.exports = { parseExpectedCsv, expectReadingToEqualExpected, expectMaxMinToEqualExpected, + expectCompareToEqualExpected, expectThreeDReadingToEqualExpected, createTimeString, getUnitId,