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

Completed test case CG15 #1369

Merged
merged 3 commits into from
Oct 28, 2024
Merged
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
105 changes: 101 additions & 4 deletions src/server/test/web/readingsCompareGroupFlow.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,19 +7,116 @@
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,
expectCompareToEqualExpected,
getUnitId,
GROUP_ID,
METER_ID,
unitDatakWh,
conversionDatakWh,
meterDatakWh } = require('../../util/readingsUtils');
unitDatakWh,
conversionDatakWh
} = require('../../util/readingsUtils');

mocha.describe('readings API', () => {
mocha.describe('readings test, test if data returned by API is as expected', () => {
mocha.describe('for compare charts', () => {
mocha.describe('for groups', () => {
// Add CG15 here
// Test CG15
mocha.it('CG15: 7 day shift end 2022-10-31 17:00:00 for 15 minute reading intervals and flow units & kW as kW ', async () => {

// unit data
const unitDatakW = [
{
// 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'
},
];
// conversion data
const conversionDatakW = [
{
// c4
sourceName: 'Electric',
destinationName: 'kW',
bidirectional: false,
slope: 1,
intercept: 0,
note: 'Electric → kW'
}
];
// meter groups
const meterDatakWGroups = [
{
name: 'meterDatakW',
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
},
{
name: 'meterDatakWOther',
unit: 'Electric',
defaultGraphicUnit: 'kW',
displayable: true,
gps: undefined,
note: 'special meter',
file: 'test/web/readingsData/readings_ri_20_days_75.csv',
deleteFile: false,
readingFrequency: '20 minutes',
id: (METER_ID + 1)
}
];
// group data
const groupDatakW = [
{
id: GROUP_ID,
name: 'meterDatakW + meterDatakWOther',
displayable: true,
note: 'special group',
defaultGraphicUnit: 'kW',
childMeters: ['meterDatakW', 'meterDatakWOther'],
childGroups: [],
}
]
//load data into database
await prepareTest(unitDatakW, conversionDatakW, meterDatakWGroups, groupDatakW);
//get unit ID since the DB could use any value.
const unitId = await getUnitId('kW');
const expected = [14017.4841100155, 14605.4957015091];
//for compare, need the unitID, currentStart, currentEnd, shift
const res = await chai.request(app).get(`/api/compareReadings/groups/${GROUP_ID}`)
.query({
curr_start: '2022-10-30 00:00:00',
curr_end: '2022-10-31 17:00:00',
shift: 'P7D',
graphicUnitId: unitId,
});
expectCompareToEqualExpected(res, expected, GROUP_ID);
});

// Add CG16 here
});
Expand Down
Loading