Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Test b15 #1117

Merged
merged 5 commits into from
Feb 18, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
90 changes: 79 additions & 11 deletions src/server/test/web/readingsBarMeterFlow.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,23 +9,91 @@

const { chai, mocha, app } = require('../common');
const Unit = require('../../models/Unit');
// const { prepareTest,
// parseExpectedCsv,
// createTimeString,
// expectReadingToEqualExpected,
// getUnitId,
// ETERNITY,
// METER_ID,
// unitDatakWh,
// conversionDatakWh,
// meterDatakWh } = require('../../util/readingsUtils');
const { prepareTest,
parseExpectedCsv,
//createTimeString,
expectReadingToEqualExpected,
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 bar charts', () => {
mocha.describe('for flow meters', () => {

// Add B15 here
mocha.it('B15: should have daily points for 15 minute reading intervals and flow units with +-inf start/end time & kW as kW', async () => {
const unitData = [
{
// u4
name: 'kW',
identifier: '',
unitRepresent: Unit.unitRepresentType.FLOW,
secInRate: 3600,
typeOfUnit: Unit.unitType.UNIT,
suffix: '',
displayable: Unit.displayableType.ALL,
preferredDisplay: true,
note: 'kilowatts'
},
{
// u5
name: 'Electric',
identifier: '',
unitRepresent: Unit.unitRepresentType.FLOW,
secInRate: 3600,
typeOfUnit: Unit.unitType.METER,
suffix: '',
displayable: Unit.displayableType.NONE,
preferredDisplay: false,
note: 'special unit'
}
];
const conversionData = [
{
// c4
sourceName: 'Electric',
destinationName: 'kW',
bidirectional: false,
slope: 1,
intercept: 0,
note: 'Electric → kW'
}
];
const meterData = [
{
name: 'Electric kW',
unit: 'Electric',
defaultGraphicUnit: 'kW',
displayable: true,
gps: undefined,
note: 'special meter',
file: 'test/web/readingsData/readings_ri_15_days_75.csv',
deleteFile: false,
readingFrequency: '15 minutes',
id: METER_ID
}
];
// Load the data into the database
await prepareTest(unitData, conversionData, meterData);
// Get the unit ID since the DB could use any value.
const unitId = await getUnitId('kW');
// Load the expected response data from the corresponding csv file
const expected = await parseExpectedCsv('src/server/test/web/readingsData/expected_bar_ri_15_mu_kW_gu_kW_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/meters/${METER_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);
});

// Add B16 here

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
reading,start time,end time
15301.1498675756,2022-08-28 00:00:00,2022-09-10 00:00:00
15751.2507459568,2022-09-10 00:00:00,2022-09-23 00:00:00
15351.7660820708,2022-09-23 00:00:00,2022-10-06 00:00:00
15396.6227909537,2022-10-06 00:00:00,2022-10-19 00:00:00
15560.3449027915,2022-10-19 00:00:00,2022-11-01 00:00:00
Loading