@bluedot-innovation/models 6.1.0 → 6.1.2-alpha.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 +8 -0
- package/__tests__/user/user.spec.js +0 -11
- package/__tests__/zone/zone.spec.js +101 -0
- package/helpers.js +26 -0
- package/models/Project.js +1 -1
- package/models/Zone.js +4 -1
- package/package.json +1 -1
- package/schemas/AccountEta.js +9 -0
- package/schemas/AccountFeatures.js +2 -1
- package/schemas/ZoneEta.js +14 -0
package/CHANGELOG.md
CHANGED
|
@@ -1,3 +1,11 @@
|
|
|
1
|
+
## 6.1.2
|
|
2
|
+
- Updated zone destinationId to accept null values
|
|
3
|
+
- Added zone destinationId validation on zone geofeatures
|
|
4
|
+
|
|
5
|
+
## 6.1.1
|
|
6
|
+
- Add destinationId to Zone model
|
|
7
|
+
- Edit features.eta.enabled to Account model
|
|
8
|
+
|
|
1
9
|
## 6.1.0
|
|
2
10
|
- Remove unused fields in remote config
|
|
3
11
|
|
|
@@ -40,17 +40,6 @@ describe('User', () => {
|
|
|
40
40
|
done()
|
|
41
41
|
})
|
|
42
42
|
})
|
|
43
|
-
|
|
44
|
-
it('should validate a user without a phone number', (done) => {
|
|
45
|
-
delete user.phoneNumber;
|
|
46
|
-
let User = new UserModelBuiltInMongoose(user)
|
|
47
|
-
|
|
48
|
-
User.validate((err, res) => {
|
|
49
|
-
assert.notExists(res)
|
|
50
|
-
assert(err === null, 'err equals null')
|
|
51
|
-
done()
|
|
52
|
-
})
|
|
53
|
-
})
|
|
54
43
|
})
|
|
55
44
|
|
|
56
45
|
describe('Invalid User', () => {
|
|
@@ -93,6 +93,57 @@ describe('Zone', () => {
|
|
|
93
93
|
assert.strictEqual(zone.tags[0], "tag")
|
|
94
94
|
assert.strictEqual(zone.tags[1], "1")
|
|
95
95
|
})
|
|
96
|
+
|
|
97
|
+
it('should save without errors when eta.destinationId is null', (done) => {
|
|
98
|
+
zone.eta = {
|
|
99
|
+
"destinationId": null
|
|
100
|
+
}
|
|
101
|
+
let Zone = new ZoneModel(zone)
|
|
102
|
+
Zone.validate((err, res) => {
|
|
103
|
+
assert.notExists(res)
|
|
104
|
+
assert.notExists(err)
|
|
105
|
+
done()
|
|
106
|
+
})
|
|
107
|
+
})
|
|
108
|
+
|
|
109
|
+
it('should save without errors when eta.destinationId is set and there is a single polygon geofeature', (done) => {
|
|
110
|
+
zone.eta = {
|
|
111
|
+
"destinationId": "test-destination-id"
|
|
112
|
+
}
|
|
113
|
+
zone.geofeatures = zone.geofeatures.filter(gf => gf.type.match(/^polygon$/))
|
|
114
|
+
let Zone = new ZoneModel(zone)
|
|
115
|
+
Zone.validate((err, res) => {
|
|
116
|
+
assert.notExists(res)
|
|
117
|
+
assert.notExists(err)
|
|
118
|
+
done()
|
|
119
|
+
})
|
|
120
|
+
})
|
|
121
|
+
|
|
122
|
+
it('should save without errors when eta.destinationId is set and there is a single boundingBox geofeature', (done) => {
|
|
123
|
+
zone.eta = {
|
|
124
|
+
"destinationId": "test-destination-id"
|
|
125
|
+
}
|
|
126
|
+
zone.geofeatures = zone.geofeatures.filter(gf => gf.type.match(/^boundingBox$/))
|
|
127
|
+
let Zone = new ZoneModel(zone)
|
|
128
|
+
Zone.validate((err, res) => {
|
|
129
|
+
assert.notExists(res)
|
|
130
|
+
assert.notExists(err)
|
|
131
|
+
done()
|
|
132
|
+
})
|
|
133
|
+
})
|
|
134
|
+
it('should save without errors when eta.destinationId is set and there is a single circle geofeature', (done) => {
|
|
135
|
+
|
|
136
|
+
zone.eta = {
|
|
137
|
+
"destinationId": "test-destination-id"
|
|
138
|
+
}
|
|
139
|
+
zone.geofeatures = zone.geofeatures.filter(gf => gf.type.match(/^circle$/))
|
|
140
|
+
let Zone = new ZoneModel(zone)
|
|
141
|
+
Zone.validate((err, res) => {
|
|
142
|
+
assert.notExists(res)
|
|
143
|
+
assert.notExists(err)
|
|
144
|
+
done()
|
|
145
|
+
})
|
|
146
|
+
})
|
|
96
147
|
})
|
|
97
148
|
|
|
98
149
|
describe('Invalid Zone ', () => {
|
|
@@ -389,5 +440,55 @@ describe('Zone', () => {
|
|
|
389
440
|
done()
|
|
390
441
|
})
|
|
391
442
|
})
|
|
443
|
+
|
|
444
|
+
it('should throw an error when eta.destinationId is longer than 128 characters', (done) => {
|
|
445
|
+
zone.eta = {
|
|
446
|
+
"destinationId": 'Lorem Ipsum is simply dummy text of the printing and typesetting industry. Lorem Ipsum has been the industry standard dummy text ever since the 1500s'
|
|
447
|
+
}
|
|
448
|
+
let Zone = new ZoneModel(zone)
|
|
449
|
+
Zone.validate((err, res) => {
|
|
450
|
+
assert.exists(err, 'err object should exist')
|
|
451
|
+
assert.match(err.message, /(destinationId must be no more than 128 characters long)/i)
|
|
452
|
+
done()
|
|
453
|
+
})
|
|
454
|
+
})
|
|
455
|
+
|
|
456
|
+
it('should not throw an error when eta.destinationId is set and there is a single geoline geofeature', (done) => {
|
|
457
|
+
zone.eta = {
|
|
458
|
+
"destinationId": "test-destination-id"
|
|
459
|
+
}
|
|
460
|
+
zone.geofeatures = zone.geofeatures.filter(gf => gf.type.match(/^geoline$/))
|
|
461
|
+
let Zone = new ZoneModel(zone)
|
|
462
|
+
Zone.validate((err, res) => {
|
|
463
|
+
assert.exists(err, 'err object should exist')
|
|
464
|
+
assert.match(err.message, /(destinationId cannot be set on zones with a geoline or beacon)/i)
|
|
465
|
+
done()
|
|
466
|
+
})
|
|
467
|
+
})
|
|
468
|
+
|
|
469
|
+
it('should not throw an error when eta.destinationId is set and there is a single beacon geofeature', (done) => {
|
|
470
|
+
zone.eta = {
|
|
471
|
+
"destinationId": "test-destination-id"
|
|
472
|
+
}
|
|
473
|
+
zone.geofeatures = zone.geofeatures.filter(gf => gf.type.match(/^beacon$/))
|
|
474
|
+
let Zone = new ZoneModel(zone)
|
|
475
|
+
Zone.validate((err, res) => {
|
|
476
|
+
assert.exists(err, 'err object should exist')
|
|
477
|
+
assert.match(err.message, /(destinationId cannot be set on zones with a geoline or beacon)/i)
|
|
478
|
+
done()
|
|
479
|
+
})
|
|
480
|
+
})
|
|
481
|
+
|
|
482
|
+
it('should not throw an error when eta.destinationId is set and there is more than one geofeatue', (done) => {
|
|
483
|
+
zone.eta = {
|
|
484
|
+
"destinationId": "test-destination-id"
|
|
485
|
+
}
|
|
486
|
+
let Zone = new ZoneModel(zone)
|
|
487
|
+
Zone.validate((err, res) => {
|
|
488
|
+
assert.exists(err, 'err object should exist')
|
|
489
|
+
assert.match(err.message, /(destinationId can only be set on zones with a single geofeature)/i)
|
|
490
|
+
done()
|
|
491
|
+
})
|
|
492
|
+
})
|
|
392
493
|
})
|
|
393
494
|
})
|
package/helpers.js
CHANGED
|
@@ -240,6 +240,32 @@ helpers.ensureNonEmptyGeofeatures = function(zone, next){
|
|
|
240
240
|
next()
|
|
241
241
|
}
|
|
242
242
|
|
|
243
|
+
helpers.validateEtaDestinationIdLength = function(etaDestinationId) {
|
|
244
|
+
if(etaDestinationId){
|
|
245
|
+
return !(etaDestinationId.length > 128)
|
|
246
|
+
}
|
|
247
|
+
return true
|
|
248
|
+
}
|
|
249
|
+
|
|
250
|
+
helpers.validateEtaDestinationSingleGeofeature = function(etaDestinationId) {
|
|
251
|
+
if(etaDestinationId){
|
|
252
|
+
const geofeatures = this.ownerDocument().geofeatures
|
|
253
|
+
if(!geofeatures.length){
|
|
254
|
+
return false
|
|
255
|
+
}
|
|
256
|
+
return geofeatures.length === 1
|
|
257
|
+
}
|
|
258
|
+
return true
|
|
259
|
+
}
|
|
260
|
+
|
|
261
|
+
helpers.validateEtaDestinationIdGeofeatureType = function(etaDestinationId) {
|
|
262
|
+
const geofeatures = this.ownerDocument().geofeatures
|
|
263
|
+
if(etaDestinationId && geofeatures.length){
|
|
264
|
+
return !(geofeatures[0].type === 'geoline' || geofeatures[0].type === 'beacon')
|
|
265
|
+
}
|
|
266
|
+
return true
|
|
267
|
+
}
|
|
268
|
+
|
|
243
269
|
helpers.validateTriggerWebhooks = function(webhooks) {
|
|
244
270
|
const notTrigger = webhooks.some(webhook => {
|
|
245
271
|
return webhook.type && webhook.type != 'trigger'
|
package/models/Project.js
CHANGED
|
@@ -47,7 +47,7 @@ let ProjectSchema = new mongoose.Schema({
|
|
|
47
47
|
firebaseApiKey: {type: String, validate: helpers.validateNotNull},
|
|
48
48
|
apiKey: {type: String},
|
|
49
49
|
integrations: IntegrationSchema,
|
|
50
|
-
eta:
|
|
50
|
+
eta: projectEtaSchema
|
|
51
51
|
},
|
|
52
52
|
{collection: 'project'})
|
|
53
53
|
|
package/models/Zone.js
CHANGED
|
@@ -22,6 +22,8 @@ let travelDirectionRawSchema = require('./conditions/TravelDirection').rawSchema
|
|
|
22
22
|
let travelPathRawSchema = require('./conditions/TravelPath').rawSchema
|
|
23
23
|
let timeActiveRawSchema = require('./conditions/TimeActive').rawSchema
|
|
24
24
|
|
|
25
|
+
let zoneEtaSchema = require('../schemas/ZoneEta')
|
|
26
|
+
|
|
25
27
|
let uuidv4 = require('uuid/v4')
|
|
26
28
|
let patcher = require('@bluedot-innovation/mongoose-json-patch')
|
|
27
29
|
let helpers = require('../helpers')
|
|
@@ -117,7 +119,8 @@ let zoneSchema = new Schema({
|
|
|
117
119
|
lastUpdateTime: {type: Date, default: Date.now},
|
|
118
120
|
projectId: {type: String, required: true, validate: {validator: helpers.validateUUIDv4, message: 'Invalid Project Id.'}},
|
|
119
121
|
state: {type: String, default: StateEnum.ACTIVE, select: false},
|
|
120
|
-
accountId: {type: String, required: true, validate: {isAsync: false, validator: helpers.validateUUIDv4, msg: 'default error message'}}
|
|
122
|
+
accountId: {type: String, required: true, validate: {isAsync: false, validator: helpers.validateUUIDv4, msg: 'default error message'}},
|
|
123
|
+
eta: zoneEtaSchema
|
|
121
124
|
}, {collection: 'zone'})
|
|
122
125
|
|
|
123
126
|
// Mongoose-json-patch
|
package/package.json
CHANGED
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
let mongoose = require('mongoose')
|
|
2
|
+
let helpers = require('../helpers')
|
|
3
|
+
|
|
4
|
+
let ZoneEtaSchema = new mongoose.Schema({
|
|
5
|
+
destinationId: {type: String, validate: [
|
|
6
|
+
{ validator: helpers.validateEtaDestinationIdLength, msg: 'destinationId must be no more than 128 characters long' },
|
|
7
|
+
{ validator: helpers.validateEtaDestinationSingleGeofeature, msg: 'destinationId can only be set on zones with a single geofeature' },
|
|
8
|
+
{ validator: helpers.validateEtaDestinationIdGeofeatureType, msg: 'destinationId cannot be set on zones with a geoline or beacon' }
|
|
9
|
+
]}
|
|
10
|
+
}, {
|
|
11
|
+
_id: false
|
|
12
|
+
})
|
|
13
|
+
|
|
14
|
+
module.exports = ZoneEtaSchema
|