From af3a2e6223a82b00e9c63750a7e57c63bb839131 Mon Sep 17 00:00:00 2001 From: alfarj83 Date: Thu, 22 Feb 2024 04:05:58 -0500 Subject: [PATCH 1/9] Max/min parsing function Added function to parse min/max values in the data. --- src/server/util/readingsUtils.js | 23 +++++++++++++++++++++++ 1 file changed, 23 insertions(+) diff --git a/src/server/util/readingsUtils.js b/src/server/util/readingsUtils.js index 936dd56df..b502a909b 100644 --- a/src/server/util/readingsUtils.js +++ b/src/server/util/readingsUtils.js @@ -75,6 +75,29 @@ function expectReadingToEqualExpected(res, expected, id = METER_ID) { } } +/** + * Compares readings from api call against the expected readings csv (now with min/max) + * @param {request.Response} res the response to the HTTP GET request from Chai + * @param {array} expected the returned array from parseExpectedCsv + */ +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); + // 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][1]), DELTA); + // Reading has correct start/end date and time + expect(res.body).to.have.property(`${id}`).to.have.property(`${i}`).to.have.property('startTimestamp').to.equal(Date.parse(expected[i][3])); + expect(res.body).to.have.property(`${id}`).to.have.property(`${i}`).to.have.property('endTimestamp').to.equal(Date.parse(expected[i][4])); + // Reading also has correct max/min + expect(res.body).to.have.property(`${id}`).to.have.property(`${i}`).to.have.property('min').to.equal(Date.parse(expected[i][0])); + expect(res.body).to.have.property(`${id}`).to.have.property(`${i}`).to.have.property('max').to.equal(Date.parse(expected[i][2])); + } +} + /** * Compares readings from api call against the expected readings csv * @param {request.Response} res the response to the HTTP GET request from Chai From 423f394d173c0a9a4e4943d05dd034065aec991e Mon Sep 17 00:00:00 2001 From: alfarj83 Date: Thu, 22 Feb 2024 22:31:14 -0500 Subject: [PATCH 2/9] Add min/max csv file to readingsData --- ...t_2022-08-25000000_et_2022-10-25000000.csv | 62 +++++++++++++++++++ 1 file changed, 62 insertions(+) create mode 100644 src/server/test/web/expected_line_minmax__ri_15_mu_kWh_gu_kWh_st_2022-08-25000000_et_2022-10-25000000.csv diff --git a/src/server/test/web/expected_line_minmax__ri_15_mu_kWh_gu_kWh_st_2022-08-25000000_et_2022-10-25000000.csv b/src/server/test/web/expected_line_minmax__ri_15_mu_kWh_gu_kWh_st_2022-08-25000000_et_2022-10-25000000.csv new file mode 100644 index 000000000..f034cb9ef --- /dev/null +++ b/src/server/test/web/expected_line_minmax__ri_15_mu_kWh_gu_kWh_st_2022-08-25000000_et_2022-10-25000000.csv @@ -0,0 +1,62 @@ +min,reading,max,start time,end time +10.6426891004995,202.88180026332,397.189849395253,2022-08-25 00:00:00,2022-08-26 00:00:00 +16.5997962068877,179.691084704245,395.109107889164,2022-08-26 00:00:00,2022-08-27 00:00:00 +4.5823651802204,199.183807536,398.411679942704,2022-08-27 00:00:00,2022-08-28 00:00:00 +15.3642573360935,192.74995508249,394.643152087121,2022-08-28 00:00:00,2022-08-29 00:00:00 +6.29056060065448,185.412501885932,385.856740151065,2022-08-29 00:00:00,2022-08-30 00:00:00 +6.86420796677648,198.811074839024,395.563823102245,2022-08-30 00:00:00,2022-08-31 00:00:00 +7.43438994317359,193.504608720336,387.965878057152,2022-08-31 00:00:00,2022-09-01 00:00:00 +11.8212615738301,192.030328377401,399.520437427381,2022-09-01 00:00:00,2022-09-02 00:00:00 +8.33718067987179,212.075434543447,398.567045473078,2022-09-02 00:00:00,2022-09-03 00:00:00 +11.4111445542779,202.971610292043,393.389074200625,2022-09-03 00:00:00,2022-09-04 00:00:00 +15.6820576786335,196.141097903804,388.815491970447,2022-09-04 00:00:00,2022-09-05 00:00:00 +6.38333585089936,187.595473624637,397.052005292176,2022-09-05 00:00:00,2022-09-06 00:00:00 +4.96432191677293,199.037216460864,397.035480858967,2022-09-06 00:00:00,2022-09-07 00:00:00 +7.67557143008119,195.285318015471,381.204626945531,2022-09-07 00:00:00,2022-09-08 00:00:00 +6.72960982731486,188.423597655062,394.035396458706,2022-09-08 00:00:00,2022-09-09 00:00:00 +5.08026786370556,206.15342719543,398.133028735512,2022-09-09 00:00:00,2022-09-10 00:00:00 +4.29407258042591,190.350749657986,397.995914276686,2022-09-10 00:00:00,2022-09-11 00:00:00 +7.43874462146493,223.360284254564,399.60078117885,2022-09-11 00:00:00,2022-09-12 00:00:00 +6.74162186785974,197.009006872453,395.97596159838,2022-09-12 00:00:00,2022-09-13 00:00:00 +4.19776432857257,208.140752853939,398.720053843593,2022-09-13 00:00:00,2022-09-14 00:00:00 +7.03930350560177,189.55589714252,398.056285836813,2022-09-14 00:00:00,2022-09-15 00:00:00 +4.55696915516148,203.552587120228,399.432853809808,2022-09-15 00:00:00,2022-09-16 00:00:00 +4.76122698910952,190.556043570215,386.592709772111,2022-09-16 00:00:00,2022-09-17 00:00:00 +4.73481997409481,204.232783877117,398.469854942283,2022-09-17 00:00:00,2022-09-18 00:00:00 +7.45500342512439,214.488485012056,396.534786377705,2022-09-18 00:00:00,2022-09-19 00:00:00 +7.00053262408678,185.094172575785,397.119985055946,2022-09-19 00:00:00,2022-09-20 00:00:00 +7.42313016152277,223.389218077435,398.265853881631,2022-09-20 00:00:00,2022-09-21 00:00:00 +9.67235053788254,187.20328697284,398.374776981315,2022-09-21 00:00:00,2022-09-22 00:00:00 +5.16339174456368,208.275189672324,399.186850998811,2022-09-22 00:00:00,2022-09-23 00:00:00 +17.9386480149719,188.539265544258,395.141115538206,2022-09-23 00:00:00,2022-09-24 00:00:00 +5.8614423320328,190.460396853295,399.516915252127,2022-09-24 00:00:00,2022-09-25 00:00:00 +6.17122260696813,201.820856785749,399.282645580328,2022-09-25 00:00:00,2022-09-26 00:00:00 +8.70731392274497,191.794497445458,394.801202250496,2022-09-26 00:00:00,2022-09-27 00:00:00 +6.34851521671069,192.130376084482,389.992328627658,2022-09-27 00:00:00,2022-09-28 00:00:00 +8.24508983064327,202.533545027477,390.345172000417,2022-09-28 00:00:00,2022-09-29 00:00:00 +6.76368360147995,212.299757197661,391.989085803109,2022-09-29 00:00:00,2022-09-30 00:00:00 +9.10871262767975,199.755451298223,398.972222072231,2022-09-30 00:00:00,2022-10-01 00:00:00 +7.7582582413418,194.301395501046,391.792833080551,2022-10-01 00:00:00,2022-10-02 00:00:00 +8.12940656028438,196.704308757642,392.052627840932,2022-10-02 00:00:00,2022-10-03 00:00:00 +6.52102579118526,185.436973633105,395.797276038057,2022-10-03 00:00:00,2022-10-04 00:00:00 +9.87881993328141,202.952811935456,395.1212023417,2022-10-04 00:00:00,2022-10-05 00:00:00 +6.2135087268549,199.898044281286,393.89547811125,2022-10-05 00:00:00,2022-10-06 00:00:00 +5.07981940271682,193.362702623083,391.978187648988,2022-10-06 00:00:00,2022-10-07 00:00:00 +7.67023150518067,211.543177923329,396.694931535236,2022-10-07 00:00:00,2022-10-08 00:00:00 +7.80832979853782,194.567632110949,390.851636573745,2022-10-08 00:00:00,2022-10-09 00:00:00 +4.96334387737906,176.363865072343,398.367605692982,2022-10-09 00:00:00,2022-10-10 00:00:00 +9.19451095623433,201.989201467621,397.732493942879,2022-10-10 00:00:00,2022-10-11 00:00:00 +4.24986840379062,192.122400198517,396.549993967159,2022-10-11 00:00:00,2022-10-12 00:00:00 +7.74352609726317,209.8374955238,399.270028335499,2022-10-12 00:00:00,2022-10-13 00:00:00 +10.9035712482694,198.688044950915,398.86461625213,2022-10-13 00:00:00,2022-10-14 00:00:00 +8.63879474383298,201.369452146518,389.390695109621,2022-10-14 00:00:00,2022-10-15 00:00:00 +6.65847376258746,192.536837932488,396.806189953665,2022-10-15 00:00:00,2022-10-16 00:00:00 +8.67954780394319,196.416640736523,398.534598443111,2022-10-16 00:00:00,2022-10-17 00:00:00 +4.09507794602362,203.549183294885,395.940654417433,2022-10-17 00:00:00,2022-10-18 00:00:00 +8.97579673030268,193.75716451131,398.955275738124,2022-10-18 00:00:00,2022-10-19 00:00:00 +11.6088771786759,188.061448544929,398.856149589119,2022-10-19 00:00:00,2022-10-20 00:00:00 +6.03539364717974,193.724535703625,397.49600341666,2022-10-20 00:00:00,2022-10-21 00:00:00 +4.31986049410596,207.268466539482,399.340673406538,2022-10-21 00:00:00,2022-10-22 00:00:00 +22.9053626180102,197.886677586795,396.812861365527,2022-10-22 00:00:00,2022-10-23 00:00:00 +4.20468190549354,200.624025945017,392.839138915141,2022-10-23 00:00:00,2022-10-24 00:00:00 +27.7472830952505,203.937945859504,396.731604745749,2022-10-24 00:00:00,2022-10-25 00:00:00 From 0a653f302cff3d57f9a4a92db8f54596a0f42326 Mon Sep 17 00:00:00 2001 From: alfarj83 Date: Thu, 22 Feb 2024 22:32:02 -0500 Subject: [PATCH 3/9] New test file Added readingsLineMinMaxMeterQuantity.js to test file folder --- .../readingsLineMinMaxMeterQuantity.js | 92 +++++++++++++++++++ 1 file changed, 92 insertions(+) create mode 100644 src/server/test/web/readingsData/readingsLineMinMaxMeterQuantity.js diff --git a/src/server/test/web/readingsData/readingsLineMinMaxMeterQuantity.js b/src/server/test/web/readingsData/readingsLineMinMaxMeterQuantity.js new file mode 100644 index 000000000..a592e7307 --- /dev/null +++ b/src/server/test/web/readingsData/readingsLineMinMaxMeterQuantity.js @@ -0,0 +1,92 @@ +/* This Source Code Form is subject to the terms of the Mozilla Public + * License, v. 2.0. If a copy of the MPL was not distributed with this + * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ + +/* + This file tests the readings retrieval API for line chart quantity meters (with added min/max values). + See: https://github.com/OpenEnergyDashboard/DesignDocs/blob/main/testing/testing.md for information. +*/ + +const { chai, mocha, app } = require('../common'); +const Unit = require('../../models/Unit'); +const { prepareTest, + parseExpectedCsv, + expectMaxMinToEqualExpected, + createTimeString, + getUnitId, + ETERNITY, + METER_ID, + unitDatakWh, + conversionDatakWh, + meterDatakWh } = require('../../util/readingsUtils'); + +mocha.describe('readings API', () => { + mocha.describe('readings test, test if data returned by API is as expected', () => { + mocha.describe('for line charts', () => { + mocha.describe('for quantity meters', () => { + // This date range is on the threshold of returning daily point readings, 61 days + mocha.it('L3: should have daily points for middle readings of 15 minute for a 61 day period and quantity units with kWh as kWh', async () => { + // Load the data into the database (u1, u2, c1) + const unitData = unitDatakWh.concat([ + { + // u1 + name: 'kWh', + identifier: '', + unitRepresent: Unit.unitRepresentType.QUANTITY, + secInRate: 3600, + typeOfUnit: Unit.unitType.UNIT, + suffix: '', + displayable: Unit.displayableType.ALL, + preferredDisplay: true, + note: 'OED created standard unit' + }, + { + //u2 + name: 'Electric_Utility', + identifier: '', + unitRepresent: Unit.unitRepresentType.QUANTITY, + secInRate: 3600, + typeOfUnit: Unit.unitType.METER, + suffix: '', + displayable: Unit.displayableType.NONE, + preferredDisplay: false, + note: 'special unit' + } + ]); + const conversionData = conversionDatakWh.concat([ + { + // c6 + sourceName: 'MJ', + destinationName: 'hWh', + bidirectional: true, + slope: 1 / 3.6, + intercept: 0, + note: 'MJ → KWh' + } + ]); + const meterData = [ + { + name: 'Electric Utility MJ', + unit: 'Electric_Utility', + defaultGraphicUnit: '', + displayable: true, + gps: undefined, + note: 'special meter', + file: 'expected_line_minmax__ri_15_mu_kWh_gu_kWh_st_2022-08-25000000_et_2022-10-25000000.csv', + deleteFile: false, + readingFrequency: '15 minutes', + id: METER_ID + } + ]; + await prepareTest(unitDatakWh, conversionDatakWh, meterDatakWh); + // Get the unit ID since the DB could use any value. + const unitId = await getUnitId('kWh'); + const expected = await parseExpectedCsv('src/server/test/web/readingsData/expected_line_minmax__ri_15_mu_kWh_gu_kWh_st_2022-08-25000000_et_2022-10-25000000.csv''); + const res = await chai.request(app).get(`/api/unitReadings/line/meters/${METER_ID}`) + .query({ timeInterval: createTimeString('2022-08-25', '00:00:00', '2022-10-25', '00:00:00'), graphicUnitId: unitId }); + expectMaxMinToEqualExpected(res, expected); + }); + }); + }); + }); +}); \ No newline at end of file From bf15d81a2c76f43896e6bf76f546b8d15d6d7759 Mon Sep 17 00:00:00 2001 From: alfarj83 Date: Thu, 22 Feb 2024 22:32:28 -0500 Subject: [PATCH 4/9] New min/max test (L3) Still being worked on --- .../web/readingsLineMinMaxMeterQuantity.js | 41 +++++++++++++++++++ 1 file changed, 41 insertions(+) create mode 100644 src/server/test/web/readingsLineMinMaxMeterQuantity.js diff --git a/src/server/test/web/readingsLineMinMaxMeterQuantity.js b/src/server/test/web/readingsLineMinMaxMeterQuantity.js new file mode 100644 index 000000000..8c442d029 --- /dev/null +++ b/src/server/test/web/readingsLineMinMaxMeterQuantity.js @@ -0,0 +1,41 @@ +/* This Source Code Form is subject to the terms of the Mozilla Public + * License, v. 2.0. If a copy of the MPL was not distributed with this + * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ + +/* + This file tests the readings retrieval API for line chart quantity meters (with added min/max values). + See: https://github.com/OpenEnergyDashboard/DesignDocs/blob/main/testing/testing.md for information. +*/ + +const { chai, mocha, app } = require('../common'); +const Unit = require('../../models/Unit'); +const { prepareTest, + parseExpectedCsv, + expectMaxMinToEqualExpected, + createTimeString, + getUnitId, + ETERNITY, + METER_ID, + unitDatakWh, + conversionDatakWh, + meterDatakWh } = require('../../util/readingsUtils'); + +mocha.describe('readings API', () => { + mocha.describe('readings test, test if data returned by API is as expected', () => { + mocha.describe('for line charts', () => { + mocha.describe('for quantity meters', () => { + // This date range is on the threshold of returning daily point readings, 61 days + mocha.it('L3: should have daily points for middle readings of 15 minute for a 61 day period and quantity units with kWh as kWh', async () => { + // Load the data into the database (u1, u2, c1) + await prepareTest(unitDatakWh, conversionDatakWh, meterDatakWh); + // Get the unit ID since the DB could use any value. + const unitId = await getUnitId('kWh'); + const expected = await parseExpectedCsv('src/server/test/web/readingsData/expected_line_minmax__ri_15_mu_kWh_gu_kWh_st_2022-08-25000000_et_2022-10-25000000.csv'); + const res = await chai.request(app).get(`/api/unitReadings/line/meters/${METER_ID}`) + .query({ timeInterval: createTimeString('2022-08-25', '00:00:00', '2022-10-25', '00:00:00'), graphicUnitId: unitId }); + expectMaxMinToEqualExpected(res, expected); + }); + }); + }); + }); +}); \ No newline at end of file From 97dd6950febe8807326d8c617854593fcdfc2058 Mon Sep 17 00:00:00 2001 From: alfarj83 Date: Fri, 23 Feb 2024 11:21:14 -0500 Subject: [PATCH 5/9] Delete old version of min/max file --- .../readingsLineMinMaxMeterQuantity.js | 92 ------------------- .../web/readingsLineMinMaxMeterQuantity.js | 2 +- 2 files changed, 1 insertion(+), 93 deletions(-) delete mode 100644 src/server/test/web/readingsData/readingsLineMinMaxMeterQuantity.js diff --git a/src/server/test/web/readingsData/readingsLineMinMaxMeterQuantity.js b/src/server/test/web/readingsData/readingsLineMinMaxMeterQuantity.js deleted file mode 100644 index a592e7307..000000000 --- a/src/server/test/web/readingsData/readingsLineMinMaxMeterQuantity.js +++ /dev/null @@ -1,92 +0,0 @@ -/* This Source Code Form is subject to the terms of the Mozilla Public - * License, v. 2.0. If a copy of the MPL was not distributed with this - * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ - -/* - This file tests the readings retrieval API for line chart quantity meters (with added min/max values). - See: https://github.com/OpenEnergyDashboard/DesignDocs/blob/main/testing/testing.md for information. -*/ - -const { chai, mocha, app } = require('../common'); -const Unit = require('../../models/Unit'); -const { prepareTest, - parseExpectedCsv, - expectMaxMinToEqualExpected, - createTimeString, - getUnitId, - ETERNITY, - METER_ID, - unitDatakWh, - conversionDatakWh, - meterDatakWh } = require('../../util/readingsUtils'); - -mocha.describe('readings API', () => { - mocha.describe('readings test, test if data returned by API is as expected', () => { - mocha.describe('for line charts', () => { - mocha.describe('for quantity meters', () => { - // This date range is on the threshold of returning daily point readings, 61 days - mocha.it('L3: should have daily points for middle readings of 15 minute for a 61 day period and quantity units with kWh as kWh', async () => { - // Load the data into the database (u1, u2, c1) - const unitData = unitDatakWh.concat([ - { - // u1 - name: 'kWh', - identifier: '', - unitRepresent: Unit.unitRepresentType.QUANTITY, - secInRate: 3600, - typeOfUnit: Unit.unitType.UNIT, - suffix: '', - displayable: Unit.displayableType.ALL, - preferredDisplay: true, - note: 'OED created standard unit' - }, - { - //u2 - name: 'Electric_Utility', - identifier: '', - unitRepresent: Unit.unitRepresentType.QUANTITY, - secInRate: 3600, - typeOfUnit: Unit.unitType.METER, - suffix: '', - displayable: Unit.displayableType.NONE, - preferredDisplay: false, - note: 'special unit' - } - ]); - const conversionData = conversionDatakWh.concat([ - { - // c6 - sourceName: 'MJ', - destinationName: 'hWh', - bidirectional: true, - slope: 1 / 3.6, - intercept: 0, - note: 'MJ → KWh' - } - ]); - const meterData = [ - { - name: 'Electric Utility MJ', - unit: 'Electric_Utility', - defaultGraphicUnit: '', - displayable: true, - gps: undefined, - note: 'special meter', - file: 'expected_line_minmax__ri_15_mu_kWh_gu_kWh_st_2022-08-25000000_et_2022-10-25000000.csv', - deleteFile: false, - readingFrequency: '15 minutes', - id: METER_ID - } - ]; - await prepareTest(unitDatakWh, conversionDatakWh, meterDatakWh); - // Get the unit ID since the DB could use any value. - const unitId = await getUnitId('kWh'); - const expected = await parseExpectedCsv('src/server/test/web/readingsData/expected_line_minmax__ri_15_mu_kWh_gu_kWh_st_2022-08-25000000_et_2022-10-25000000.csv''); - const res = await chai.request(app).get(`/api/unitReadings/line/meters/${METER_ID}`) - .query({ timeInterval: createTimeString('2022-08-25', '00:00:00', '2022-10-25', '00:00:00'), graphicUnitId: unitId }); - expectMaxMinToEqualExpected(res, expected); - }); - }); - }); - }); -}); \ No newline at end of file diff --git a/src/server/test/web/readingsLineMinMaxMeterQuantity.js b/src/server/test/web/readingsLineMinMaxMeterQuantity.js index 8c442d029..2ba20ee7b 100644 --- a/src/server/test/web/readingsLineMinMaxMeterQuantity.js +++ b/src/server/test/web/readingsLineMinMaxMeterQuantity.js @@ -25,7 +25,7 @@ mocha.describe('readings API', () => { mocha.describe('for line charts', () => { mocha.describe('for quantity meters', () => { // This date range is on the threshold of returning daily point readings, 61 days - mocha.it('L3: should have daily points for middle readings of 15 minute for a 61 day period and quantity units with kWh as kWh', async () => { + mocha.it('LM3: should have daily points for middle readings of 15 minute for a 61 day period and quantity units with kWh as kWh', async () => { // Load the data into the database (u1, u2, c1) await prepareTest(unitDatakWh, conversionDatakWh, meterDatakWh); // Get the unit ID since the DB could use any value. From df6cc4da0ff65e2766caa664944ca707e2484703 Mon Sep 17 00:00:00 2001 From: alfarj83 Date: Fri, 23 Feb 2024 11:23:40 -0500 Subject: [PATCH 6/9] Move csv file into readingsData --- ...i_15_mu_kWh_gu_kWh_st_2022-08-25000000_et_2022-10-25000000.csv | 0 1 file changed, 0 insertions(+), 0 deletions(-) rename src/server/test/web/{ => readingsData}/expected_line_minmax__ri_15_mu_kWh_gu_kWh_st_2022-08-25000000_et_2022-10-25000000.csv (100%) diff --git a/src/server/test/web/expected_line_minmax__ri_15_mu_kWh_gu_kWh_st_2022-08-25000000_et_2022-10-25000000.csv b/src/server/test/web/readingsData/expected_line_minmax__ri_15_mu_kWh_gu_kWh_st_2022-08-25000000_et_2022-10-25000000.csv similarity index 100% rename from src/server/test/web/expected_line_minmax__ri_15_mu_kWh_gu_kWh_st_2022-08-25000000_et_2022-10-25000000.csv rename to src/server/test/web/readingsData/expected_line_minmax__ri_15_mu_kWh_gu_kWh_st_2022-08-25000000_et_2022-10-25000000.csv From 25b1d469890b36f155fe8b5ab8ad7c89673a7b06 Mon Sep 17 00:00:00 2001 From: alfarj83 Date: Fri, 23 Feb 2024 14:46:10 -0500 Subject: [PATCH 7/9] commented out unused variable --- src/server/test/web/readingsLineMinMaxMeterQuantity.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/server/test/web/readingsLineMinMaxMeterQuantity.js b/src/server/test/web/readingsLineMinMaxMeterQuantity.js index 2ba20ee7b..3ca64a6b7 100644 --- a/src/server/test/web/readingsLineMinMaxMeterQuantity.js +++ b/src/server/test/web/readingsLineMinMaxMeterQuantity.js @@ -14,7 +14,7 @@ const { prepareTest, expectMaxMinToEqualExpected, createTimeString, getUnitId, - ETERNITY, + //ETERNITY, METER_ID, unitDatakWh, conversionDatakWh, From 874c2123d974b72a9eb9377d73917e489423e9eb Mon Sep 17 00:00:00 2001 From: alfarj83 Date: Fri, 23 Feb 2024 16:39:01 -0500 Subject: [PATCH 8/9] Fixed max/min read function --- src/server/util/readingsUtils.js | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/src/server/util/readingsUtils.js b/src/server/util/readingsUtils.js index b502a909b..24ce1c83a 100644 --- a/src/server/util/readingsUtils.js +++ b/src/server/util/readingsUtils.js @@ -89,12 +89,12 @@ function expectMaxMinToEqualExpected(res, expected, id = METER_ID) { 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][1]), DELTA); + // Reading also has correct max/min + expect(res.body).to.have.property(`${id}`).to.have.property(`${i}`).to.have.property('min').to.be.closeTo(Number(expected[i][0]), DELTA); + expect(res.body).to.have.property(`${id}`).to.have.property(`${i}`).to.have.property('max').to.be.closeTo(Number(expected[i][2]), DELTA); // Reading has correct start/end date and time expect(res.body).to.have.property(`${id}`).to.have.property(`${i}`).to.have.property('startTimestamp').to.equal(Date.parse(expected[i][3])); expect(res.body).to.have.property(`${id}`).to.have.property(`${i}`).to.have.property('endTimestamp').to.equal(Date.parse(expected[i][4])); - // Reading also has correct max/min - expect(res.body).to.have.property(`${id}`).to.have.property(`${i}`).to.have.property('min').to.equal(Date.parse(expected[i][0])); - expect(res.body).to.have.property(`${id}`).to.have.property(`${i}`).to.have.property('max').to.equal(Date.parse(expected[i][2])); } } @@ -266,6 +266,7 @@ module.exports = { prepareTest, parseExpectedCsv, expectReadingToEqualExpected, + expectMaxMinToEqualExpected, expectThreeDReadingToEqualExpected, createTimeString, getUnitId, From 6961823de8c25c8b60161f43b0d2da54cc9cec11 Mon Sep 17 00:00:00 2001 From: Steven Huss-Lederman Date: Fri, 23 Feb 2024 16:55:28 -0600 Subject: [PATCH 9/9] small describe change --- src/server/test/web/readingsLineMinMaxMeterQuantity.js | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/server/test/web/readingsLineMinMaxMeterQuantity.js b/src/server/test/web/readingsLineMinMaxMeterQuantity.js index 3ca64a6b7..171fea6da 100644 --- a/src/server/test/web/readingsLineMinMaxMeterQuantity.js +++ b/src/server/test/web/readingsLineMinMaxMeterQuantity.js @@ -22,7 +22,7 @@ const { prepareTest, mocha.describe('readings API', () => { mocha.describe('readings test, test if data returned by API is as expected', () => { - mocha.describe('for line charts', () => { + mocha.describe('for line charts with min/max', () => { mocha.describe('for quantity meters', () => { // This date range is on the threshold of returning daily point readings, 61 days mocha.it('LM3: should have daily points for middle readings of 15 minute for a 61 day period and quantity units with kWh as kWh', async () => { @@ -38,4 +38,4 @@ mocha.describe('readings API', () => { }); }); }); -}); \ No newline at end of file +});