@bluedot-innovation/models 10.10.0 → 10.11.0
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 +6 -0
- package/__tests__/account/account.data.json +3 -0
- package/__tests__/account/account.spec.js +12 -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/schemas/AccountFeatures.js +2 -0
- package/schemas/HelloStackFeature.js +13 -0
package/CHANGELOG.md
CHANGED
|
@@ -102,6 +102,18 @@ testCase('Account', () => {
|
|
|
102
102
|
assert.match(err.message, /`Invalid` is not a valid enum value for path `type`/)
|
|
103
103
|
}
|
|
104
104
|
})
|
|
105
|
+
|
|
106
|
+
assertions('should throw an error when Account has invalid Hello stack', async () => {
|
|
107
|
+
let Account = new AccountModel(account)
|
|
108
|
+
Account.features.helloStack.name = "Invalid"
|
|
109
|
+
try {
|
|
110
|
+
await Account.validate()
|
|
111
|
+
} catch (err) {
|
|
112
|
+
assert.exists(err, 'err object should exist')
|
|
113
|
+
assert.isObject(err.errors)
|
|
114
|
+
assert.match(err.message, /`Invalid` is not a valid enum value for path `name`/)
|
|
115
|
+
}
|
|
116
|
+
})
|
|
105
117
|
})
|
|
106
118
|
|
|
107
119
|
testCase('recursive invalid entry check', () => {
|
|
@@ -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
|
@@ -5,6 +5,7 @@ let AccountScreensSchema = require('./AccountScreens')
|
|
|
5
5
|
let AccountCemdPersistenceSchema = require('./AccountCemdPersistence')
|
|
6
6
|
let HelloSsoSchema = require('./HelloSso')
|
|
7
7
|
const CanvasSsoSchema = require('./CanvasSsoFeature')
|
|
8
|
+
const HelloStackSchema = require('./HelloStackFeature')
|
|
8
9
|
|
|
9
10
|
function helloSsoValidator (value) {
|
|
10
11
|
const { enabled, identityProvider, dashboardIdentityProvider } = value
|
|
@@ -26,6 +27,7 @@ let AccountFeaturesSchema = new mongoose.Schema({
|
|
|
26
27
|
helloSso: { type: HelloSsoSchema, validate: { validator: helloSsoValidator, msg: 'When the feature is enbaled, at leat one of provider need to be provided.' } },
|
|
27
28
|
canvasSso: CanvasSsoSchema,
|
|
28
29
|
helloStateTemplates: AccountBasicFeatureSchema,
|
|
30
|
+
helloStack: HelloStackSchema
|
|
29
31
|
}, {
|
|
30
32
|
_id: false
|
|
31
33
|
})
|