diff --git a/src/server/test/web/readingsBarGroupQuantity.js b/src/server/test/web/readingsBarGroupQuantity.js index 88b88020f..dd8e8f2bb 100644 --- a/src/server/test/web/readingsBarGroupQuantity.js +++ b/src/server/test/web/readingsBarGroupQuantity.js @@ -27,7 +27,7 @@ mocha.describe('readings API', () => { mocha.describe('readings test, test if data returned by API is as expected', () => { mocha.describe('for bar charts', () => { mocha.describe('for quantity groups', () => { - mocha.it('BG1: 1 day bars for 15 + 20 minute reading intervals and quantity units with +-inf start/end time & kWh as kWh', async () =>{ + mocha.it('BG1: 1 day bars for 15 + 20 minute reading intervals and quantity units with +-inf start/end time & kWh as kWh', async () => { //loads data into database await prepareTest(unitDatakWh, conversionDatakWh, meterDatakWhGroups, groupDatakWh) //gets unit ID @@ -36,15 +36,16 @@ mocha.describe('readings API', () => { const expected = await parseExpectedCsv('src/server/test/web/readingsData/expected_bar_group_ri_15-20_mu_kWh_gu_kWh_st_-inf_et_inf_bd_1.csv') const res = await chai.request(app).get(`/api/unitReadings/bar/groups/${GROUP_ID}`) - .query({ - timeInterval: ETERNITY.toString(), + .query({ + timeInterval: ETERNITY.toString(), barWidthDays: '1', - graphicUnitId: unitId }); + graphicUnitId: unitId + }); // Check that the API reading is equal to what it is expected to equal expectReadingToEqualExpected(res, expected, GROUP_ID); }); - mocha.it('BG2: 7 day bars for 15 + 20 minute reading intervals and quantity units with +-inf start/end time & kWh as kWh', async () =>{ + mocha.it('BG2: 7 day bars for 15 + 20 minute reading intervals and quantity units with +-inf start/end time & kWh as kWh', async () => { //loads data into database await prepareTest(unitDatakWh, conversionDatakWh, meterDatakWhGroups, groupDatakWh) //gets unit ID @@ -53,16 +54,17 @@ mocha.describe('readings API', () => { const expected = await parseExpectedCsv('src/server/test/web/readingsData/expected_bar_group_ri_15-20_mu_kWh_gu_kWh_st_-inf_et_inf_bd_7.csv') const res = await chai.request(app).get(`/api/unitReadings/bar/groups/${GROUP_ID}`) - .query({ - timeInterval: ETERNITY.toString(), + .query({ + timeInterval: ETERNITY.toString(), barWidthDays: '7', - graphicUnitId: unitId }); + graphicUnitId: unitId + }); // Check that the API reading is equal to what it is expected to equal expectReadingToEqualExpected(res, expected, GROUP_ID); }); - mocha.it('BG3: 28 day bars for 15 + 20 minute reading intervals and quantity units with +-inf start/end time & kWh as kWh', async () =>{ + mocha.it('BG3: 28 day bars for 15 + 20 minute reading intervals and quantity units with +-inf start/end time & kWh as kWh', async () => { //load data into database await prepareTest(unitDatakWh, conversionDatakWh, meterDatakWhGroups, groupDatakWh); //get unit ID since the DB could use any value. @@ -71,32 +73,34 @@ mocha.describe('readings API', () => { const expected = await parseExpectedCsv('src/server/test/web/readingsData/expected_bar_group_ri_15-20_mu_kWh_gu_kWh_st_-inf_et_inf_bd_28.csv'); // Create a request to the API for unbounded reading times and save the response const res = await chai.request(app).get(`/api/unitReadings/bar/groups/${GROUP_ID}`) - .query({ - timeInterval: ETERNITY.toString(), + .query({ + timeInterval: ETERNITY.toString(), barWidthDays: '28', - graphicUnitId: unitId }); + graphicUnitId: unitId + }); // Check that the API reading is equal to what it is expected to equal expectReadingToEqualExpected(res, expected, GROUP_ID); }); - mocha.it('BG4: 13 day bars for 15 + 20 minute reading intervals and quantity units with +-inf start/end time & kWh as kWh', async () =>{ - //load data into database - await prepareTest(unitDatakWh, conversionDatakWh, meterDatakWhGroups, groupDatakWh); - //get unit ID since the DB could use any value. - const unitId = await getUnitId('kWh'); - // Load the expected response data from the corresponding csv file - const expected = await parseExpectedCsv('src/server/test/web/readingsData/expected_bar_group_ri_15-20_mu_kWh_gu_kWh_st_-inf_et_inf_bd_13.csv'); - // Create a request to the API for unbounded reading times and save the response - const res = await chai.request(app).get(`/api/unitReadings/bar/groups/${GROUP_ID}`) - .query({ - timeInterval: ETERNITY.toString(), - barWidthDays: '13', - graphicUnitId: unitId }); - // Check that the API reading is equal to what it is expected to equal - expectReadingToEqualExpected(res, expected, GROUP_ID); + mocha.it('BG4: 13 day bars for 15 + 20 minute reading intervals and quantity units with +-inf start/end time & kWh as kWh', async () => { + //load data into database + await prepareTest(unitDatakWh, conversionDatakWh, meterDatakWhGroups, groupDatakWh); + //get unit ID since the DB could use any value. + const unitId = await getUnitId('kWh'); + // Load the expected response data from the corresponding csv file + const expected = await parseExpectedCsv('src/server/test/web/readingsData/expected_bar_group_ri_15-20_mu_kWh_gu_kWh_st_-inf_et_inf_bd_13.csv'); + // Create a request to the API for unbounded reading times and save the response + const res = await chai.request(app).get(`/api/unitReadings/bar/groups/${GROUP_ID}`) + .query({ + timeInterval: ETERNITY.toString(), + barWidthDays: '13', + graphicUnitId: unitId + }); + // Check that the API reading is equal to what it is expected to equal + expectReadingToEqualExpected(res, expected, GROUP_ID); }); - mocha.it('BG5: 75 day bars for 15 + 20 minute reading intervals and quantity units with +-inf start/end time & kWh as kWh', async () =>{ + mocha.it('BG5: 75 day bars for 15 + 20 minute reading intervals and quantity units with +-inf start/end time & kWh as kWh', async () => { //load data into database await prepareTest(unitDatakWh, conversionDatakWh, meterDatakWhGroups, groupDatakWh); //get unit ID since the DB could use any value. @@ -105,15 +109,16 @@ mocha.describe('readings API', () => { const expected = await parseExpectedCsv('src/server/test/web/readingsData/expected_bar_group_ri_15-20_mu_kWh_gu_kWh_st_-inf_et_inf_bd_75.csv'); // Create a request to the API for unbounded reading times and save the response const res = await chai.request(app).get(`/api/unitReadings/bar/groups/${GROUP_ID}`) - .query({ - timeInterval: ETERNITY.toString(), + .query({ + timeInterval: ETERNITY.toString(), barWidthDays: '75', - graphicUnitId: unitId }); + graphicUnitId: unitId + }); // Check that the API reading is equal to what it is expected to equal expectReadingToEqualExpected(res, expected, GROUP_ID); }); - mocha.it('BG6: 76 day bars (no values) for 15 + 20 minute reading intervals and quantity units with +-inf start/end time & kWh as kWh', async () =>{ + mocha.it('BG6: 76 day bars (no values) for 15 + 20 minute reading intervals and quantity units with +-inf start/end time & kWh as kWh', async () => { //load data into database await prepareTest(unitDatakWh, conversionDatakWh, meterDatakWhGroups, groupDatakWh); //get unit ID since the DB could use any value. @@ -122,87 +127,108 @@ mocha.describe('readings API', () => { const expected = await parseExpectedCsv('src/server/test/web/readingsData/expected_bar_group_ri_15-20_mu_kWh_gu_kWh_st_-inf_et_inf_bd_76.csv'); // Create a request to the API for unbounded reading times and save the response const res = await chai.request(app).get(`/api/unitReadings/bar/groups/${GROUP_ID}`) - .query({ - timeInterval: ETERNITY.toString(), + .query({ + timeInterval: ETERNITY.toString(), barWidthDays: '76', - graphicUnitId: unitId }); + graphicUnitId: unitId + }); // Check that the API reading is equal to what it is expected to equal expectReadingToEqualExpected(res, expected, GROUP_ID); }); - // Add BG7 here - - mocha.it('BG8: 1 day bars for 15 + 20 minute reading intervals and quantity units with +-inf start/end time & kWh as MJ', async () =>{ - //Define arrays of data for units, conversions and test meter(s)/group - const unitData = unitDatakWh.concat([ - { - //u3 - name: 'MJ', - identifier: 'megaJoules', - unitRepresent: Unit.unitRepresentType.QUANTITY, - secInRate: 3600, - typeOfUnit: Unit.unitType.UNIT, - suffix: '', - displayable: Unit.displayableType.ALL, - preferredDisplay: false, - note: 'MJ' - } - ]); - const conversionData = conversionDatakWh.concat([ - { - //c2 - sourceName: 'kWh', - destinationName: 'MJ', - bidirectional: true, - slope: 3.6, - intercept: 0, - note: 'kWh → MJ' - } - ]); - //load data arrays into database - await prepareTest(unitData, conversionData, meterDatakWhGroups, groupDatakWh); - //get unit ID for API call - const unitId = await getUnitId('MJ'); - //get array of values from csv file - const expected = await parseExpectedCsv('src/server/test/web/readingsData/expected_bar_group_ri_15-20_mu_kWh_gu_MJ_st_-inf_et_inf_bd_1.csv'); - //get data from API call - const res = await chai.request(app).get(`/api/unitReadings/bar/groups/${GROUP_ID}`) - .query({ - timeInterval: ETERNITY.toString(), - barWidthDays: '1', - graphicUnitId: unitId }); - //compare readings data to expected - expectReadingToEqualExpected(res, expected, GROUP_ID); - - }); + + mocha.it("BG7: 13 day bars for 15 + 20 minute reading intervals and quantity units with reduced, partial days & kWh as kWh", async () => { + // Load data into the database + await prepareTest(unitDatakWh, conversionDatakWh, meterDatakWhGroups, groupDatakWh); + // Get unit ID for API call + const unitId = await getUnitId('kWh'); + // Retrieve expected values from CSV file + const expected = await parseExpectedCsv('src/server/test/web/readingsData/expected_bar_group_ri_15-20_mu_kWh_gu_kWh_st_2022-08-20%07#25#35_et_2022-10-28%13#18#28_bd_13.csv'); + // Make API call and retrieve data + const res = await chai.request(app).get(`/api/unitReadings/bar/groups/${GROUP_ID}`) + .query({ + timeInterval: createTimeString('2022-08-20', '07:25:35', '2022-10-28', '13:18:28'), + barWidthDays: '13', + graphicUnitId: unitId + }); + // Compare API returned data with expected values + expectReadingToEqualExpected(res, expected, GROUP_ID); + }); + + + + mocha.it('BG8: 1 day bars for 15 + 20 minute reading intervals and quantity units with +-inf start/end time & kWh as MJ', async () => { + //Define arrays of data for units, conversions and test meter(s)/group + const unitData = unitDatakWh.concat([ + { + //u3 + name: 'MJ', + identifier: 'megaJoules', + unitRepresent: Unit.unitRepresentType.QUANTITY, + secInRate: 3600, + typeOfUnit: Unit.unitType.UNIT, + suffix: '', + displayable: Unit.displayableType.ALL, + preferredDisplay: false, + note: 'MJ' + } + ]); + const conversionData = conversionDatakWh.concat([ + { + //c2 + sourceName: 'kWh', + destinationName: 'MJ', + bidirectional: true, + slope: 3.6, + intercept: 0, + note: 'kWh → MJ' + } + ]); + //load data arrays into database + await prepareTest(unitData, conversionData, meterDatakWhGroups, groupDatakWh); + //get unit ID for API call + const unitId = await getUnitId('MJ'); + //get array of values from csv file + const expected = await parseExpectedCsv('src/server/test/web/readingsData/expected_bar_group_ri_15-20_mu_kWh_gu_MJ_st_-inf_et_inf_bd_1.csv'); + //get data from API call + const res = await chai.request(app).get(`/api/unitReadings/bar/groups/${GROUP_ID}`) + .query({ + timeInterval: ETERNITY.toString(), + barWidthDays: '1', + graphicUnitId: unitId + }); + //compare readings data to expected + expectReadingToEqualExpected(res, expected, GROUP_ID); + + }); // Add BG9 here mocha.it('BG9: 1 day bars for 15 + 20 minute reading intervals and quantity units with +-inf start/end time & kWh as MJ reverse conversion', async () => { - + const unitData = unitDatakWh.concat([ { // u3 - name: 'MJ', - identifier: 'megaJoules', - unitRepresent: Unit.unitRepresentType.QUANTITY, + name: 'MJ', + identifier: 'megaJoules', + unitRepresent: Unit.unitRepresentType.QUANTITY, secInRate: 3600, - typeOfUnit: Unit.unitType.UNIT, - suffix: '', - displayable: Unit.displayableType.ALL, - preferredDisplay: true, - note: 'MJ' + typeOfUnit: Unit.unitType.UNIT, + suffix: '', + displayable: Unit.displayableType.ALL, + preferredDisplay: true, + note: 'MJ' } ]); - + const conversionData = conversionDatakWh.concat([ - - { + + { // c6 sourceName: 'MJ', destinationName: 'kWh', bidirectional: true, slope: 1 / 3.6, intercept: 0, - note: 'MJ → KWh' + note: 'MJ → KWh' } ]); const meterData = [ @@ -219,74 +245,74 @@ mocha.describe('readings API', () => { id: METER_ID } ]; - + // Load data into the database await prepareTest(unitData, conversionData, meterDatakWhGroups, groupDatakWh, meterData); - + // Get unit ID for MJ const unitId = await getUnitId('MJ'); - + // Load expected response data from the corresponding CSV file const expected = await parseExpectedCsv('src/server/test/web/readingsData/expected_bar_group_ri_15-20_mu_kWh_gu_MJ_st_-inf_et_inf_bd_1.csv'); - + // Create a request to the API for unbounded reading times and save the response const result = await chai.request(app).get(`/api/unitReadings/bar/groups/${GROUP_ID}`) - .query({ - timeInterval: ETERNITY.toString(), + .query({ + timeInterval: ETERNITY.toString(), barWidthDays: '1', - graphicUnitId: unitId + graphicUnitId: unitId }); - + // Check that the API reading matches the expected data from the CSV expectReadingToEqualExpected(result, expected, GROUP_ID); }); - mocha.it('BG10: 1 day bars for 15 + 20 minute reading intervals and quantity units with +-inf start/end time & kWh as BTU', async () =>{ + mocha.it('BG10: 1 day bars for 15 + 20 minute reading intervals and quantity units with +-inf start/end time & kWh as BTU', async () => { const unitData = unitDatakWh.concat([ { // u3 - name: 'MJ', - identifier: 'megaJoules', - unitRepresent: Unit.unitRepresentType.QUANTITY, + name: 'MJ', + identifier: 'megaJoules', + unitRepresent: Unit.unitRepresentType.QUANTITY, secInRate: 3600, - typeOfUnit: Unit.unitType.UNIT, - suffix: '', - displayable: Unit.displayableType.ALL, - preferredDisplay: false, - note: 'MJ' + typeOfUnit: Unit.unitType.UNIT, + suffix: '', + displayable: Unit.displayableType.ALL, + preferredDisplay: false, + note: 'MJ' }, - { + { // u16 - name: 'BTU', - identifier: '', - unitRepresent: Unit.unitRepresentType.QUANTITY, - secInRate: 3600, - typeOfUnit: Unit.unitType.UNIT, - suffix: '', - displayable: Unit.displayableType.ALL, - preferredDisplay: true, - note: 'OED created standard unit' + name: 'BTU', + identifier: '', + unitRepresent: Unit.unitRepresentType.QUANTITY, + secInRate: 3600, + typeOfUnit: Unit.unitType.UNIT, + suffix: '', + displayable: Unit.displayableType.ALL, + preferredDisplay: true, + note: 'OED created standard unit' } ]); - + const conversionData = conversionDatakWh.concat([ - { + { // c2 - sourceName: 'kWh', - destinationName: 'MJ', - bidirectional: true, - slope: 3.6, - intercept: 0, - note: 'kWh → MJ' + sourceName: 'kWh', + destinationName: 'MJ', + bidirectional: true, + slope: 3.6, + intercept: 0, + note: 'kWh → MJ' }, - { + { // c3 - sourceName: 'MJ', - destinationName: 'BTU', - bidirectional: true, - slope: 947.8, - intercept: 0, - note: 'MJ → BTU' + sourceName: 'MJ', + destinationName: 'BTU', + bidirectional: true, + slope: 947.8, + intercept: 0, + note: 'MJ → BTU' } ]); @@ -298,10 +324,11 @@ mocha.describe('readings API', () => { const expected = await parseExpectedCsv('src/server/test/web/readingsData/expected_bar_group_ri_15-20_mu_kWh_gu_BTU_st_-inf_et_inf_bd_1.csv'); // Create a request to the API for unbounded reading times and save the response const res = await chai.request(app).get(`/api/unitReadings/bar/groups/${GROUP_ID}`) - .query({ - timeInterval: ETERNITY.toString(), + .query({ + timeInterval: ETERNITY.toString(), barWidthDays: '1', - graphicUnitId: unitId }); + graphicUnitId: unitId + }); // Check that the API reading is equal to what it is expected to equal expectReadingToEqualExpected(res, expected, GROUP_ID); }); @@ -361,14 +388,15 @@ mocha.describe('readings API', () => { const expected = await parseExpectedCsv('src/server/test/web/readingsData/expected_bar_group_ri_15-20_mu_kWh_gu_BTU_st_-inf_et_inf_bd_1.csv'); // Create a request to the API for unbounded reading times and save the response const res = await chai.request(app).get(`/api/unitReadings/bar/groups/${GROUP_ID}`) - .query({ - timeInterval: ETERNITY.toString(), + .query({ + timeInterval: ETERNITY.toString(), barWidthDays: '1', - graphicUnitId: unitId }); + graphicUnitId: unitId + }); // Check that the API reading is equal to what it is expected to equal expectReadingToEqualExpected(res, expected, GROUP_ID); }); - mocha.it('BG12: 1 day bars for 15 + 20 minute reading intervals and quantity units with +-inf start/end time & kWh as kg of CO2', async () =>{ + mocha.it('BG12: 1 day bars for 15 + 20 minute reading intervals and quantity units with +-inf start/end time & kWh as kg of CO2', async () => { const unitData = unitDatakWh.concat([ { // u10 diff --git a/src/server/test/web/readingsData/expected_bar_group_ri_15-20_mu_kWh_gu_kWh_st_2022-08-20%07#25#35_et_2022-10-28%13#18#28_bd_13.csv b/src/server/test/web/readingsData/expected_bar_group_ri_15-20_mu_kWh_gu_kWh_st_2022-08-20%07#25#35_et_2022-10-28%13#18#28_bd_13.csv new file mode 100644 index 000000000..00136eafe --- /dev/null +++ b/src/server/test/web/readingsData/expected_bar_group_ri_15-20_mu_kWh_gu_kWh_st_2022-08-20%07#25#35_et_2022-10-28%13#18#28_bd_13.csv @@ -0,0 +1,6 @@ +reading,start time,end time +107760.512327733,2022-08-24 00:00:00,2022-09-06 00:00:00 +109904.420593228,2022-09-06 00:00:00,2022-09-19 00:00:00 +108695.813086027,2022-09-19 00:00:00,2022-10-02 00:00:00 +108469.275865337,2022-10-02 00:00:00,2022-10-15 00:00:00 +108652.290077713,2022-10-15 00:00:00,2022-10-28 00:00:00 \ No newline at end of file