@bluedot-innovation/models 3.0.15 → 3.0.17
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__/beacon/beacon.spec.js +0 -10
- package/__tests__/project/project.data.json +2 -1
- package/__tests__/user/user.spec.js +23 -0
- package/__tests__/zone/zone.filter.spec.js +26 -0
- package/helpers.js +13 -0
- package/models/Beacon.js +0 -2
- package/models/Project.js +2 -3
- package/models/Zone.js +10 -1
- package/models/filters/TimeActive.js +1 -1
- package/models/filters/TravelPath.js +1 -1
- package/package.json +1 -1
- package/schemas/ProjectPermission.js +1 -0
package/CHANGELOG.md
CHANGED
|
@@ -29,16 +29,6 @@ describe('Beacon', () => {
|
|
|
29
29
|
done()
|
|
30
30
|
})
|
|
31
31
|
})
|
|
32
|
-
it('should accept a valid API Key and customer API Key', (done) => {
|
|
33
|
-
beacon.apiKey = '23a01af0-232a-4518-9c0e-323fb773f5ef'
|
|
34
|
-
beacon.customerApiKey = '23a01af0-232a-4518-9c0e-323fb773ffff'
|
|
35
|
-
let Beacon = new BeaconModel(beacon)
|
|
36
|
-
Beacon.validate((err, res) => {
|
|
37
|
-
assert.notExists(res)
|
|
38
|
-
assert(err === null, 'err should equal null')
|
|
39
|
-
done()
|
|
40
|
-
})
|
|
41
|
-
})
|
|
42
32
|
})
|
|
43
33
|
|
|
44
34
|
describe('Invalid Beacon', () => {
|
|
@@ -94,6 +94,18 @@ describe('User', () => {
|
|
|
94
94
|
})
|
|
95
95
|
})
|
|
96
96
|
|
|
97
|
+
it('should fail if projectId is missing', (done) => {
|
|
98
|
+
user = JSON.parse(JSON.stringify(user))
|
|
99
|
+
user.projectPermissions[0].projectId = undefined
|
|
100
|
+
const User = new UserModel(user)
|
|
101
|
+
|
|
102
|
+
User.validate((err, res) => {
|
|
103
|
+
console.log(err);
|
|
104
|
+
assert.match(err, /(Path `projectId` is required.)/i)
|
|
105
|
+
done()
|
|
106
|
+
})
|
|
107
|
+
})
|
|
108
|
+
|
|
97
109
|
it('should fail if permissionLevel is invalid', (done) => {
|
|
98
110
|
user = JSON.parse(JSON.stringify(user))
|
|
99
111
|
user.projectPermissions[0].permissionLevel = 'INVALID'
|
|
@@ -104,5 +116,16 @@ describe('User', () => {
|
|
|
104
116
|
done()
|
|
105
117
|
})
|
|
106
118
|
})
|
|
119
|
+
|
|
120
|
+
it('should fail if permissionLevel is missing', (done) => {
|
|
121
|
+
user = JSON.parse(JSON.stringify(user))
|
|
122
|
+
user.projectPermissions[0].permissionLevel = undefined
|
|
123
|
+
const User = new UserModel(user)
|
|
124
|
+
|
|
125
|
+
User.validate((err, res) => {
|
|
126
|
+
assert.match(err, /(Path `permissionLevel` is required.)/i)
|
|
127
|
+
done()
|
|
128
|
+
})
|
|
129
|
+
})
|
|
107
130
|
})
|
|
108
131
|
})
|
|
@@ -11,12 +11,14 @@ let mocha = require('mocha')
|
|
|
11
11
|
let beforeEach = mocha.beforeEach
|
|
12
12
|
|
|
13
13
|
let zone
|
|
14
|
+
let geofeatures
|
|
14
15
|
|
|
15
16
|
beforeEach(() => {
|
|
16
17
|
zone = JSON.parse(JSON.stringify(require('./zone.data.json')))
|
|
17
18
|
// remove actions as it's not tested
|
|
18
19
|
delete zone.actions
|
|
19
20
|
// remove all but 1 geofeatures as geofeatures are required
|
|
21
|
+
geofeatures = zone.geofeatures
|
|
20
22
|
zone.geofeatures = zone.geofeatures.filter(x => x.type.match(/circle/i))
|
|
21
23
|
// remove customData
|
|
22
24
|
delete zone.customData
|
|
@@ -46,5 +48,29 @@ testCase('Zone - Filter', () => {
|
|
|
46
48
|
done()
|
|
47
49
|
})
|
|
48
50
|
})
|
|
51
|
+
assertions('should not throw an error when a valid filter is instantiated within a zone', (done) => {
|
|
52
|
+
let Zone = new ZoneModel(zone)
|
|
53
|
+
Zone.validate((err, res) => {
|
|
54
|
+
assert.notExists(res)
|
|
55
|
+
assert(err === null, 'err equals null')
|
|
56
|
+
done()
|
|
57
|
+
})
|
|
58
|
+
})
|
|
59
|
+
assertions('should throw an error when the minimumGeofeaturesCrossed for a travel path filter is greater than the total number of geofeatures', (done) => {
|
|
60
|
+
zone.geofeatures = geofeatures
|
|
61
|
+
zone.filters.push({
|
|
62
|
+
"type" : "travelPath",
|
|
63
|
+
"minimumGeofeaturesCrossed" : zone.geofeatures.length+1,
|
|
64
|
+
"timeOutSeconds": 120,
|
|
65
|
+
"sequential" : false
|
|
66
|
+
})
|
|
67
|
+
let Zone = new ZoneModel(zone)
|
|
68
|
+
Zone.validate((err, res) => {
|
|
69
|
+
assert.exists(err, 'err object should exist')
|
|
70
|
+
assert(err instanceof Error)
|
|
71
|
+
assert(err.message.includes("Zone must not have minimumGeofeaturesCrossed higher than geofeatures count"))
|
|
72
|
+
done()
|
|
73
|
+
})
|
|
74
|
+
})
|
|
49
75
|
})
|
|
50
76
|
})
|
package/helpers.js
CHANGED
|
@@ -86,4 +86,17 @@ helpers.checkFiltersSuitableForBeacon = function(zone, next) {
|
|
|
86
86
|
next();
|
|
87
87
|
}
|
|
88
88
|
|
|
89
|
+
helpers.checkMinimumGeofeaturesValidForZone = function(zone, next) {
|
|
90
|
+
if( !zone.geofeatures )
|
|
91
|
+
return next();
|
|
92
|
+
if( !zone.filters || !zone.filters.length )
|
|
93
|
+
return next(); // No filters.
|
|
94
|
+
for( let filter of zone.filters ) {
|
|
95
|
+
if( filter.type === "travelPath" && filter.minimumGeofeaturesCrossed > zone.geofeatures.length ) {
|
|
96
|
+
return next(new Error("Zone must not have minimumGeofeaturesCrossed higher than geofeatures count"))
|
|
97
|
+
}
|
|
98
|
+
}
|
|
99
|
+
next();
|
|
100
|
+
}
|
|
101
|
+
|
|
89
102
|
module.exports = helpers
|
package/models/Beacon.js
CHANGED
|
@@ -39,8 +39,6 @@ BeaconSchema.index({ macAddress: 1 })
|
|
|
39
39
|
BeaconSchema.index({ proximityUUID: 1, major: 1, minor: 1 })
|
|
40
40
|
BeaconSchema.index({ accountId: 1, geometry: '2dsphere' })
|
|
41
41
|
|
|
42
|
-
// accountId: 1, geometry: "2dsphere"
|
|
43
|
-
|
|
44
42
|
BeaconSchema.plugin(patcher)
|
|
45
43
|
|
|
46
44
|
// mongoose validator helper plugin
|
package/models/Project.js
CHANGED
|
@@ -15,8 +15,6 @@ let WebhookSchema = require('../schemas/Webhook')
|
|
|
15
15
|
|
|
16
16
|
let ProjectSchema = new mongoose.Schema({
|
|
17
17
|
_id: {type: String, default: uuidv4},
|
|
18
|
-
apiKey: {type: String, default: uuidv4}, // Backwards compatability
|
|
19
|
-
state: {type: String, default: StateEnum.active},
|
|
20
18
|
nextRuleUpdateInterval: {
|
|
21
19
|
type: Number,
|
|
22
20
|
required: [true, 'nextRuleUpdateInterval is required'],
|
|
@@ -34,7 +32,8 @@ let ProjectSchema = new mongoose.Schema({
|
|
|
34
32
|
accountId: {type: String, required: true, validate: {isAsync: false, validator: helpers.validateUUIDv4, msg: 'default error message'}},
|
|
35
33
|
webhooks: [WebhookSchema],
|
|
36
34
|
configurationParameters: {type: Schema.Types.Mixed, default: null}, // http://collab.bluedot.io/display/PD/Remote+configuration
|
|
37
|
-
firebaseApiKey: {type: String}
|
|
35
|
+
firebaseApiKey: {type: String},
|
|
36
|
+
apiKey: {type: String}
|
|
38
37
|
},
|
|
39
38
|
{collection: 'project'})
|
|
40
39
|
|
package/models/Zone.js
CHANGED
|
@@ -96,7 +96,16 @@ zoneSchema.path('geofeatures').discriminator('polyline', new Schema(polylineSche
|
|
|
96
96
|
zoneSchema.path('geofeatures').discriminator('boundingBox', new Schema(boundingBoxSchema))
|
|
97
97
|
|
|
98
98
|
zoneSchema.pre('validate', function(next) {
|
|
99
|
-
|
|
99
|
+
Promise.all([
|
|
100
|
+
new Promise((resolve, reject) => helpers.checkFiltersSuitableForBeacon(this, resolve)),
|
|
101
|
+
new Promise((resolve, reject) => helpers.checkMinimumGeofeaturesValidForZone(this, resolve))
|
|
102
|
+
]).then(results => {
|
|
103
|
+
for( let result of results ) {
|
|
104
|
+
if( result )
|
|
105
|
+
return next(result)
|
|
106
|
+
}
|
|
107
|
+
next()
|
|
108
|
+
});
|
|
100
109
|
})
|
|
101
110
|
|
|
102
111
|
// optional mongoose
|
|
@@ -3,7 +3,7 @@ let uuidv4 = require('uuid/v4')
|
|
|
3
3
|
|
|
4
4
|
let schema = {
|
|
5
5
|
fromTime: {type: String, required: [true, 'time is required. '], validate: {isAsync: true, validator: validateTimeHHmmssFormat}},
|
|
6
|
-
toTime: {type: String, required: true, validate: [{isAsync: true, validator:
|
|
6
|
+
toTime: {type: String, required: true, validate: [{isAsync: true, validator: validateTime}, {isAsync: true, validator: validateTimeHHmmssFormat}]}
|
|
7
7
|
}
|
|
8
8
|
let TimeActiveFilterSchema = new mongoose.Schema(schema, {
|
|
9
9
|
_id: false,
|
|
@@ -6,7 +6,7 @@ let schema = {
|
|
|
6
6
|
minimumGeofeaturesCrossed: {
|
|
7
7
|
type: Number,
|
|
8
8
|
required: [true, 'minimumGeofeaturesCrossed is required.'],
|
|
9
|
-
min:
|
|
9
|
+
min: 2
|
|
10
10
|
},
|
|
11
11
|
timeOutSeconds: {type: Number, required: [true, 'timeOutSeconds is required. '], min: 60, max: 86400},
|
|
12
12
|
sequential: {type: Boolean, default: false}
|
package/package.json
CHANGED