@bluedot-innovation/models 10.10.0 → 10.10.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +3 -0
- package/__tests__/zone/zone.spec.js +27 -0
- package/helpers.js +8 -0
- package/models/Zone.js +2 -1
- package/package.json +1 -1
package/CHANGELOG.md
CHANGED
|
@@ -101,6 +101,18 @@ describe('Zone', () => {
|
|
|
101
101
|
assert.isFalse(Zone.dwellConfiguration.enabled)
|
|
102
102
|
assert.notExists(res)
|
|
103
103
|
})
|
|
104
|
+
|
|
105
|
+
it('should successfully enable dwell when triggerOnExit is true', async () => {
|
|
106
|
+
zone.dwellConfiguration = {
|
|
107
|
+
threshold: 300,
|
|
108
|
+
enabled: true
|
|
109
|
+
}
|
|
110
|
+
zone.triggerOnExit = true
|
|
111
|
+
let Zone = new ZoneModel(zone)
|
|
112
|
+
const res = await Zone.validate()
|
|
113
|
+
assert.isTrue(Zone.dwellConfiguration.enabled)
|
|
114
|
+
assert.notExists(res)
|
|
115
|
+
})
|
|
104
116
|
})
|
|
105
117
|
|
|
106
118
|
describe('Invalid Zone ', () => {
|
|
@@ -426,6 +438,21 @@ describe('Zone', () => {
|
|
|
426
438
|
}
|
|
427
439
|
})
|
|
428
440
|
|
|
441
|
+
it('should fail to enable dwell when triggerOnExit is false', async () => {
|
|
442
|
+
zone.dwellConfiguration = {
|
|
443
|
+
threshold: 300,
|
|
444
|
+
enabled: true
|
|
445
|
+
}
|
|
446
|
+
zone.triggerOnExit = false
|
|
447
|
+
let Zone = new ZoneModel(zone)
|
|
448
|
+
try {
|
|
449
|
+
await Zone.validate()
|
|
450
|
+
} catch (err) {
|
|
451
|
+
assert.exists(err, 'err object should exist')
|
|
452
|
+
assert.match(err.message, /(triggerOnExit must be true when dwellConfiguration is enabled)/i)
|
|
453
|
+
}
|
|
454
|
+
})
|
|
455
|
+
|
|
429
456
|
it('should throw error when dwell threshold is not a number', async () => {
|
|
430
457
|
zone.dwellConfiguration = {
|
|
431
458
|
threshold: 'test'
|
package/helpers.js
CHANGED
|
@@ -271,4 +271,12 @@ helpers.transformNumbertoDouble = (value) => {
|
|
|
271
271
|
return Number.isInteger(value) ? value + 0.0000001 : value
|
|
272
272
|
}
|
|
273
273
|
|
|
274
|
+
helpers.validateDwellConfigurationTriggerOnExit = function(zone, next) {
|
|
275
|
+
// Validate that if dwellConfiguration.enabled is true, triggerOnExit must also be true
|
|
276
|
+
if (zone.dwellConfiguration && zone.dwellConfiguration.enabled === true && zone.triggerOnExit !== true) {
|
|
277
|
+
return next(new Error('triggerOnExit must be true when dwellConfiguration is enabled'))
|
|
278
|
+
}
|
|
279
|
+
next()
|
|
280
|
+
}
|
|
281
|
+
|
|
274
282
|
module.exports = helpers
|
package/models/Zone.js
CHANGED
|
@@ -127,7 +127,8 @@ zoneSchema.pre('validate', function(next) {
|
|
|
127
127
|
new Promise((resolve, reject) => helpers.validateTravelPathConditionCount(this, resolve)),
|
|
128
128
|
new Promise((resolve, reject) => helpers.checkValidLowAccuracyFence(this, resolve)),
|
|
129
129
|
new Promise((resolve, reject) => helpers.checkDuplicateGeofeaturesId(this, resolve)),
|
|
130
|
-
new Promise((resolve, reject) => helpers.ensureNonEmptyGeofeatures(this, resolve))
|
|
130
|
+
new Promise((resolve, reject) => helpers.ensureNonEmptyGeofeatures(this, resolve)),
|
|
131
|
+
new Promise((resolve, reject) => helpers.validateDwellConfigurationTriggerOnExit(this, resolve))
|
|
131
132
|
]).then(results => {
|
|
132
133
|
for( let result of results ) {
|
|
133
134
|
if( result )
|
package/package.json
CHANGED