Issue 1439 Fix#1588
Conversation
…match mocha tests
…when passed with null
…t values when Meter.convertUnitValue is called within them
…rted expectMetersToBeEquivalent from meters.js
huss
left a comment
There was a problem hiding this comment.
@tazmeenahhmed Thank you for another contribution and addressing this issue. Overall, the changes look good. I've made a few comments to consider. Please let me know if anything is not clear, you have thoughts or would like my help.
| const sqlFile = database.sqlFile; | ||
|
|
||
| class Meter { | ||
| class Meter { |
There was a problem hiding this comment.
There is a space added to the end of this line. OED prefers not to do that and this is the only change in the file. Could you undo this so no changes are shown in the file.
| expect(meter).to.have.property('previousEnd', null); | ||
| expect(meter).to.have.property('areaUnit', Unit.areaUnitType.METERS); | ||
| expect(meter).to.have.property('readingFrequency', null); | ||
|
|
| expect(meter).to.have.property('previousEnd', '2020-03-05T13:15:13.000Z'); | ||
| expect(meter).to.have.property('areaUnit', Unit.areaUnitType.METERS); | ||
| expect(meter).to.have.property('readingFrequency', 'PT13H57M19S'); | ||
| } else { |
There was a problem hiding this comment.
src/server/models/Meter.js has these params that I don't see being checked:
* @param minVal inclusive minimum acceptable reading value (won't be rejected)
* @param maxVal inclusive maximum acceptable reading value (won't be rejected)
* @param minDate inclusive earliest acceptable date (won't be rejected)
* @param maxDate inclusive latest acceptable date (won't be rejected)
* @param maxError maximum number of errors to be reported, ignore the rest
* @param disableChecks disable checks on meter for conditionSet
I think they are all admin only so null for non-admins.
| }); | ||
|
|
||
| mocha.describe('Meter model', () => { | ||
| let unitId; |
There was a problem hiding this comment.
It seems only the last test uses the unitId set in the beforeEach. Given this, I'm wondering about moving this code to that test.
| } | ||
| }); | ||
|
|
||
| mocha.it('can get meter by identifier', async () => { |
There was a problem hiding this comment.
I like this and the next new tests. Two thoughts about these and they may apply to other tests:
- A few values are null/undefined. I wonder if some tests should use other values to verify that works.
- The other values discussed in another comment that are part of a Meter do not have explicit values for the meter being created. That should be done for the tests.
| Unit.areaUnitType.METERS, undefined); | ||
|
|
||
| await Promise.all([meterA, meterB, meterC].map(meter => meter.insert(conn))); | ||
| const allExpectedMeters = await Meter.getAll(conn); |
There was a problem hiding this comment.
I think Expected and Actual should be the other way around. Normally expected is what the test knows is correct and actual is what you get back. Maybe this is based on another test but I would still like them flipped (if you agree).
| 'MeterB', 'notes 2', 35.0, true, true, '01:01:25', '00:00:00', 5, 0, 1, 'increasing', false, | ||
| 1.5, '0001-01-01 23:59:59', '2020-07-02 01:00:10', '2020-03-05 02:12:00', unitB.id, unitB.id, | ||
| Unit.areaUnitType.METERS, undefined); | ||
| const meterC = new Meter(undefined, 'Meter C', null, true, true, Meter.type.MAMAC, null); |
There was a problem hiding this comment.
This is a good test for the default value of -99 for the unit. It might be good to add another meter that explicitly sets the unit to -99 to verify that is the same.
| expectMetersToBeEquivalent(allExpectedMeters[i], allActualMeters[i]); | ||
| } | ||
| }); | ||
| }); |
There was a problem hiding this comment.
Overall, the test coverage is good for all functions in Meter. I noticed two that are not tested and it would be good to do those so this is complete:
- existsByName
- makeMeterDataValid (do other one of this type)
Also, the pipeline tests do check about admin vs not (I think) but I think that having a test in this file that adds the info and gets as a non-admin to be sure the correct values are nulled out would be a good idea since it is directly related to the Meter interface.
Description
Implemented changes described in issue #1439 which are the following:
Fixes #1439
Type of change
(Check the ones that apply by placing an "x" instead of the space in the [ ] so it becomes [x])
Checklist
(Note what you have done by placing an "x" instead of the space in the [ ] so it becomes [x]. It is hoped you do all of them.)