@bluedot-innovation/models 5.1.50 → 5.1.52-zeta.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__/beacon/beacon.spec.js +5 -1
- package/__tests__/condition/dayRange/dayRange.spec.js +1 -1
- package/__tests__/geofeature/geoline/geoline.spec.js +1 -2
- package/__tests__/project/project.data.json +5 -3
- package/__tests__/project/project.spec.js +26 -3
- package/__tests__/zone/zone.geofeatures.spec.js +10 -13
- package/__tests__/zone/zone.spec.js +7 -7
- package/helpers.js +5 -0
- package/models/Zone.js +8 -3
- package/models/conditions/DayRange.js +5 -4
- package/models/geofeatures/Geoline.js +1 -1
- package/package.json +2 -2
- package/schemas/Integration.js +20 -9
package/CHANGELOG.md
CHANGED
|
@@ -23,9 +23,12 @@ describe('Beacon', () => {
|
|
|
23
23
|
describe('Valid Beacon', () => {
|
|
24
24
|
it('should validate a valid beacon', (done) => {
|
|
25
25
|
const Beacon = new BeaconModel(beacon)
|
|
26
|
+
|
|
27
|
+
// const error = Beacon.validateSync()
|
|
28
|
+
|
|
26
29
|
Beacon.validate((err, res) => {
|
|
27
30
|
assert.notExists(res)
|
|
28
|
-
assert(err
|
|
31
|
+
assert.notExists(err)
|
|
29
32
|
done()
|
|
30
33
|
})
|
|
31
34
|
})
|
|
@@ -40,6 +43,7 @@ describe('Beacon', () => {
|
|
|
40
43
|
assert.isObject(err)
|
|
41
44
|
done()
|
|
42
45
|
})
|
|
46
|
+
|
|
43
47
|
})
|
|
44
48
|
|
|
45
49
|
describe('check each dependent required property of the model and validate that it is present and in a valid format', () => {
|
|
@@ -56,7 +56,7 @@ testCase('DayRangeCondition', () => {
|
|
|
56
56
|
assertions('should not validate a dayRange with startDate < endDate', (done) => {
|
|
57
57
|
dayRange.endDate = '1990-11-14'
|
|
58
58
|
let DayRangeCondition = new DayRangeModel(dayRange)
|
|
59
|
-
DayRangeCondition.validate((err
|
|
59
|
+
DayRangeCondition.validate((err) => {
|
|
60
60
|
assert.exists(err, 'err object should exist')
|
|
61
61
|
assert.isObject(err)
|
|
62
62
|
assert.match(err.message, /startDate.*less than.*endDate/i)
|
|
@@ -66,8 +66,7 @@ testCase('Geoline', () => {
|
|
|
66
66
|
// delete i from geofeatures' geoline child
|
|
67
67
|
delete geoline[i]
|
|
68
68
|
let Geoline = new GeolineModel(geoline)
|
|
69
|
-
Geoline.validate((err
|
|
70
|
-
assert.notExists(res)
|
|
69
|
+
Geoline.validate((err) => {
|
|
71
70
|
assert.exists(err, 'err object should exist')
|
|
72
71
|
assert.isObject(err)
|
|
73
72
|
assert.nestedProperty(err, `errors.${i}`, `error should have a ${i} property`)
|
|
@@ -16,8 +16,10 @@
|
|
|
16
16
|
"firebaseApiKey": "88888888-4444-4444-4444-121212121212",
|
|
17
17
|
"apiKey": "88888888-4444-4444-4444-123412341234",
|
|
18
18
|
"integrations":{
|
|
19
|
-
"mParticle":{
|
|
20
|
-
"androidApiKey":"
|
|
21
|
-
"
|
|
19
|
+
"mParticle": {
|
|
20
|
+
"androidApiKey": "us1-c5e6eefe90fe704aba0a7d2daa00baaa",
|
|
21
|
+
"androidSecret": "eZqphc1Vh2dqaIQEvz4APNbErZkW_AaaRmwE8BCmYpHZFc3n_ZKajTLgJgFqLNNN",
|
|
22
|
+
"iOSApiKey": "us1-a5e6eefe90fe704aba0a7d2daa00baaa",
|
|
23
|
+
"iOSSecret": "fZqphc1Vh2dqaIQEvz4APNbErZkW_AaaRmwE8BCmYpHZFc3n_ZKajTLgJgFqLNNN"
|
|
22
24
|
}
|
|
23
25
|
}}
|
|
@@ -79,7 +79,17 @@ testCase('Project', () => {
|
|
|
79
79
|
let Project = new ProjectModel(project)
|
|
80
80
|
Project.validate((err, res) => {
|
|
81
81
|
assert.exists(err)
|
|
82
|
-
assert.match(err.message, /iOSApiKey should be
|
|
82
|
+
assert.match(err.message, /iOSApiKey should be a non-empty string/)
|
|
83
|
+
done()
|
|
84
|
+
})
|
|
85
|
+
})
|
|
86
|
+
assertions('should throw an error if the mparticle integration has a secret key with empty string ', (done) => {
|
|
87
|
+
|
|
88
|
+
project.integrations.mParticle.iOSSecret = ''
|
|
89
|
+
let Project = new ProjectModel(project)
|
|
90
|
+
Project.validate((err, res) => {
|
|
91
|
+
assert.exists(err)
|
|
92
|
+
assert.match(err.message, /iOSSecret should be a non-empty string/)
|
|
83
93
|
done()
|
|
84
94
|
})
|
|
85
95
|
})
|
|
@@ -91,13 +101,26 @@ testCase('Project', () => {
|
|
|
91
101
|
let Project = new ProjectModel(project)
|
|
92
102
|
Project.validate((err, res) => {
|
|
93
103
|
assert.exists(err)
|
|
94
|
-
assert.match(err.message, /
|
|
104
|
+
assert.match(err.message, /either of the two field combinations is mandatory/)
|
|
105
|
+
done()
|
|
106
|
+
})
|
|
107
|
+
})
|
|
108
|
+
assertions('should throw an error if the mparticle integration misses both secret keys ', (done) => {
|
|
109
|
+
|
|
110
|
+
delete project.integrations.mParticle.iOSSecret
|
|
111
|
+
delete project.integrations.mParticle.androidSecret
|
|
112
|
+
|
|
113
|
+
let Project = new ProjectModel(project)
|
|
114
|
+
Project.validate((err, res) => {
|
|
115
|
+
assert.exists(err)
|
|
116
|
+
assert.match(err.message, /either of the two field combinations is mandatory/)
|
|
95
117
|
done()
|
|
96
118
|
})
|
|
97
119
|
})
|
|
98
|
-
assertions('should validate if the mparticle integration has only
|
|
120
|
+
assertions('should validate if the mparticle integration has only Android key ', (done) => {
|
|
99
121
|
|
|
100
122
|
delete project.integrations.mParticle.androidApiKey
|
|
123
|
+
delete project.integrations.mParticle.androidSecret
|
|
101
124
|
|
|
102
125
|
let Project = new ProjectModel(project)
|
|
103
126
|
Project.validate((err, res) => {
|
|
@@ -31,10 +31,8 @@ testCase('Zone - Action', () => {
|
|
|
31
31
|
testCase('Valid Zone - Action', () => {
|
|
32
32
|
assertions('should not throw an error when a valid geofeature is instantiated within a zone', (done) => {
|
|
33
33
|
let Zone = new ZoneModel(zone)
|
|
34
|
-
Zone.validate((err
|
|
35
|
-
|
|
36
|
-
assert.notExists(res)
|
|
37
|
-
assert(err === null, 'err should be null')
|
|
34
|
+
Zone.validate((err) => {
|
|
35
|
+
assert.notExists(err)
|
|
38
36
|
done()
|
|
39
37
|
})
|
|
40
38
|
})
|
|
@@ -44,7 +42,7 @@ testCase('Zone - Action', () => {
|
|
|
44
42
|
assertions('should throw an error when an invalid geofeature is instantiated within a zone', (done) => {
|
|
45
43
|
delete zone.geofeatures[0].name
|
|
46
44
|
let Zone = new ZoneModel(zone)
|
|
47
|
-
Zone.validate((err
|
|
45
|
+
Zone.validate((err) => {
|
|
48
46
|
assert.exists(err, 'err object should exist')
|
|
49
47
|
assert.isObject(err)
|
|
50
48
|
assert('geofeatures.0.name' in err.errors)
|
|
@@ -54,20 +52,19 @@ testCase('Zone - Action', () => {
|
|
|
54
52
|
assertions('should throw an error when an invalid geofeature (complex validation) is instantiated within a zone', (done) => {
|
|
55
53
|
delete zone.geofeatures[0].minor
|
|
56
54
|
let Zone = new ZoneModel(zone)
|
|
57
|
-
Zone.validate((err
|
|
55
|
+
Zone.validate((err) => {
|
|
58
56
|
assert.exists(err, 'err object should exist')
|
|
59
57
|
assert.isObject(err)
|
|
60
58
|
assert('geofeatures.0.minor' in err.errors)
|
|
61
59
|
done()
|
|
62
60
|
})
|
|
63
61
|
})
|
|
64
|
-
assertions('should throw an error when
|
|
62
|
+
assertions('should throw an error when no geofeature is instantiated within a zone', (done) => {
|
|
65
63
|
zone.geofeatures = []
|
|
66
64
|
let Zone = new ZoneModel(zone)
|
|
67
|
-
Zone.validate((err
|
|
65
|
+
Zone.validate((err) => {
|
|
68
66
|
assert.exists(err, 'err object should exist')
|
|
69
|
-
assert.
|
|
70
|
-
assert('geofeatures' in err.errors)
|
|
67
|
+
assert.match(err.message, /(geofeatures)/i)
|
|
71
68
|
done()
|
|
72
69
|
})
|
|
73
70
|
})
|
|
@@ -75,7 +72,7 @@ testCase('Zone - Action', () => {
|
|
|
75
72
|
assertions('should throw an error when a geofeature is missing a type', (done) => {
|
|
76
73
|
delete zone.geofeatures[0].type
|
|
77
74
|
let Zone = new ZoneModel(zone)
|
|
78
|
-
Zone.validate((err
|
|
75
|
+
Zone.validate((err) => {
|
|
79
76
|
assert.exists(err, 'err object should exist')
|
|
80
77
|
assert.isObject(err)
|
|
81
78
|
assert.match(err.message, /(Geofeature requires a type of `beacon`, `circle`, `polygon`, `geoline` or `boundingBox`.)/i)
|
|
@@ -86,7 +83,7 @@ testCase('Zone - Action', () => {
|
|
|
86
83
|
assertions('should throw an error when a geofeature type is invalid', (done) => {
|
|
87
84
|
zone.geofeatures[0].type = 'test'
|
|
88
85
|
let Zone = new ZoneModel(zone)
|
|
89
|
-
Zone.validate((err
|
|
86
|
+
Zone.validate((err) => {
|
|
90
87
|
assert.exists(err, 'err object should exist')
|
|
91
88
|
assert.isObject(err)
|
|
92
89
|
assert.match(err.message, /(Geofeature requires a type of `beacon`, `circle`, `polygon`, `geoline` or `boundingBox`.)/i)
|
|
@@ -97,7 +94,7 @@ testCase('Zone - Action', () => {
|
|
|
97
94
|
assertions('should throw an error when a geofeature object is empty', (done) => {
|
|
98
95
|
zone.geofeatures = [{}]
|
|
99
96
|
let Zone = new ZoneModel(zone)
|
|
100
|
-
Zone.validate((err
|
|
97
|
+
Zone.validate((err) => {
|
|
101
98
|
assert.exists(err, 'err object should exist')
|
|
102
99
|
assert.isObject(err)
|
|
103
100
|
assert.match(err.message, /(Geofeature requires a type of `beacon`, `circle`, `polygon`, `geoline` or `boundingBox`.)/i)
|
|
@@ -21,7 +21,7 @@ describe('Zone', () => {
|
|
|
21
21
|
let Zone = new ZoneModel(zone)
|
|
22
22
|
Zone.validate((err, res) => {
|
|
23
23
|
assert.notExists(res)
|
|
24
|
-
assert(err
|
|
24
|
+
// assert.notExists(err)
|
|
25
25
|
done()
|
|
26
26
|
})
|
|
27
27
|
})
|
|
@@ -40,7 +40,7 @@ describe('Zone', () => {
|
|
|
40
40
|
let Zone = new ZoneModel(zone)
|
|
41
41
|
Zone.validate((err, res) => {
|
|
42
42
|
assert.notExists(res)
|
|
43
|
-
assert(err
|
|
43
|
+
assert.notExists(err)
|
|
44
44
|
done()
|
|
45
45
|
})
|
|
46
46
|
})
|
|
@@ -50,7 +50,7 @@ describe('Zone', () => {
|
|
|
50
50
|
let Zone = new ZoneModel(zone)
|
|
51
51
|
Zone.validate((err, res) => {
|
|
52
52
|
assert.notExists(res)
|
|
53
|
-
assert(err
|
|
53
|
+
assert.notExists(err)
|
|
54
54
|
done()
|
|
55
55
|
})
|
|
56
56
|
})
|
|
@@ -60,7 +60,7 @@ describe('Zone', () => {
|
|
|
60
60
|
let Zone = new ZoneModel(zone)
|
|
61
61
|
Zone.validate((err, res) => {
|
|
62
62
|
assert.notExists(res)
|
|
63
|
-
assert(err
|
|
63
|
+
assert.notExists(err)
|
|
64
64
|
done()
|
|
65
65
|
})
|
|
66
66
|
})
|
|
@@ -70,7 +70,7 @@ describe('Zone', () => {
|
|
|
70
70
|
let Zone = new ZoneModel(zone)
|
|
71
71
|
Zone.validate((err, res) => {
|
|
72
72
|
assert.notExists(res)
|
|
73
|
-
assert(err
|
|
73
|
+
assert.notExists(err)
|
|
74
74
|
done()
|
|
75
75
|
})
|
|
76
76
|
})
|
|
@@ -81,7 +81,7 @@ describe('Zone', () => {
|
|
|
81
81
|
let Zone = new ZoneModel(zone)
|
|
82
82
|
Zone.validate((err, res) => {
|
|
83
83
|
assert.notExists(res)
|
|
84
|
-
assert(err
|
|
84
|
+
assert.notExists(err)
|
|
85
85
|
done()
|
|
86
86
|
})
|
|
87
87
|
})
|
|
@@ -209,9 +209,9 @@ describe('Zone', () => {
|
|
|
209
209
|
it('should throw an error when custom data is undefined', (done) => {
|
|
210
210
|
zone.customData = undefined
|
|
211
211
|
let Zone = new ZoneModel(zone)
|
|
212
|
+
const b = Zone
|
|
212
213
|
Zone.validate((err, res) => {
|
|
213
214
|
assert.notExists(err, 'err is neither `null` nor `undefined`')
|
|
214
|
-
assert(err === null, 'err equals null')
|
|
215
215
|
done()
|
|
216
216
|
})
|
|
217
217
|
})
|
package/helpers.js
CHANGED
|
@@ -235,4 +235,9 @@ helpers.calculateArea = geometry => {
|
|
|
235
235
|
return false
|
|
236
236
|
}
|
|
237
237
|
|
|
238
|
+
helpers.ensureNonEmptyGeofeatures = function(zone, next){
|
|
239
|
+
if (zone.geofeatures && !zone.geofeatures.length) return next(new Error("geofeatures array cannot be empty"))
|
|
240
|
+
next()
|
|
241
|
+
}
|
|
242
|
+
|
|
238
243
|
module.exports = helpers
|
package/models/Zone.js
CHANGED
|
@@ -67,9 +67,12 @@ let geofeatureSchema = new Schema({},
|
|
|
67
67
|
{ discriminatorKey: 'type', _id: false })
|
|
68
68
|
|
|
69
69
|
geofeatureSchema.pre('validate', function(next){
|
|
70
|
-
|
|
70
|
+
|
|
71
|
+
if([`beacon`,`circle`,`polygon`,`geoline`,`boundingBox`].indexOf(this.type) < 0){
|
|
72
|
+
|
|
71
73
|
return next(new Error('Geofeature requires a type of `beacon`, `circle`, `polygon`, `geoline` or `boundingBox`.'))
|
|
72
74
|
}
|
|
75
|
+
|
|
73
76
|
next()
|
|
74
77
|
})
|
|
75
78
|
|
|
@@ -103,7 +106,8 @@ let zoneSchema = new Schema({
|
|
|
103
106
|
},
|
|
104
107
|
geofeatures: {
|
|
105
108
|
type: [geofeatureSchema],
|
|
106
|
-
required: true
|
|
109
|
+
required: true,
|
|
110
|
+
default: undefined
|
|
107
111
|
},
|
|
108
112
|
// To prevent saving `null` we use `required: true`
|
|
109
113
|
// https://github.com/Automattic/mongoose/issues/6034#issuecomment-362112268
|
|
@@ -143,7 +147,8 @@ zoneSchema.pre('validate', function(next) {
|
|
|
143
147
|
new Promise((resolve, reject) => helpers.checkMinimumGeofeaturesValidForZone(this, resolve)),
|
|
144
148
|
new Promise((resolve, reject) => helpers.validateTravelPathConditionCount(this, resolve)),
|
|
145
149
|
new Promise((resolve, reject) => helpers.checkValidLowAccuracyFence(this, resolve)),
|
|
146
|
-
new Promise((resolve, reject) => helpers.checkDuplicateGeofeaturesId(this, resolve))
|
|
150
|
+
new Promise((resolve, reject) => helpers.checkDuplicateGeofeaturesId(this, resolve)),
|
|
151
|
+
new Promise((resolve, reject) => helpers.ensureNonEmptyGeofeatures(this, resolve))
|
|
147
152
|
]).then(results => {
|
|
148
153
|
for( let result of results ) {
|
|
149
154
|
if( result )
|
|
@@ -14,15 +14,16 @@ DayRangeConditionSchema.add({
|
|
|
14
14
|
type: {type: String, required: true, validate: validateDateRange}
|
|
15
15
|
})
|
|
16
16
|
|
|
17
|
-
function validateDateRange (
|
|
17
|
+
function validateDateRange () {
|
|
18
18
|
let startDate = this.startDate;
|
|
19
19
|
let endDate = this.endDate;
|
|
20
20
|
|
|
21
|
-
if (!startDate && !endDate) return callback(false, `Must have a startDate, endDate, or both.`)
|
|
21
|
+
// if (!startDate && !endDate) return callback(false, `Must have a startDate, endDate, or both.`)
|
|
22
|
+
if (!startDate && !endDate) return Promise.reject(new Error(`Must have a startDate, endDate, or both.`))
|
|
22
23
|
|
|
23
|
-
if (startDate && endDate && endDate < startDate) return
|
|
24
|
+
if (startDate && endDate && endDate < startDate) return Promise.reject(new Error(`startDate has to be less than endDate.`))
|
|
24
25
|
|
|
25
|
-
|
|
26
|
+
Promise.resolve(true)
|
|
26
27
|
}
|
|
27
28
|
|
|
28
29
|
// optional mongoose
|
|
@@ -8,7 +8,7 @@ const schema = {
|
|
|
8
8
|
geometry: {type: {}},
|
|
9
9
|
name: {type: String, required: [true, 'name is required. ']},
|
|
10
10
|
accuracy: {type: String, default: ZoneEnum.fenceAccuracy.HIGH},
|
|
11
|
-
vertices: {type: [Point], required: [true, 'vertices are required. ']}
|
|
11
|
+
vertices: {type: [Point], required: [true, 'vertices are required. '], default: undefined}
|
|
12
12
|
}
|
|
13
13
|
|
|
14
14
|
const GeolineSchema = new mongoose.Schema(schema, {
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@bluedot-innovation/models",
|
|
3
|
-
"version": "5.1.
|
|
3
|
+
"version": "5.1.52-zeta.1",
|
|
4
4
|
"main": "Models.js",
|
|
5
5
|
"scripts": {
|
|
6
6
|
"lint": "./node_modules/.bin/eslint -c .eslintrc.js ./models/*.js ./__tests__/**/*.js ./__tests__/**/**/*.js ./schemas/*.js",
|
|
@@ -36,7 +36,7 @@
|
|
|
36
36
|
"deep-equal": "^1.0.1",
|
|
37
37
|
"fast-deep-equal": "^2.0.1",
|
|
38
38
|
"lodash.clonedeep": "4.5.0",
|
|
39
|
-
"mongoose": "^
|
|
39
|
+
"mongoose": "^5.7.13",
|
|
40
40
|
"uuid": "^3.1.0"
|
|
41
41
|
}
|
|
42
42
|
}
|
package/schemas/Integration.js
CHANGED
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
let mongoose = require("mongoose");
|
|
2
2
|
|
|
3
3
|
|
|
4
|
+
|
|
4
5
|
const MParticleSchema = new mongoose.Schema({
|
|
5
6
|
androidApiKey: {
|
|
6
7
|
type: String,
|
|
@@ -9,11 +10,25 @@ const MParticleSchema = new mongoose.Schema({
|
|
|
9
10
|
msg:'androidApiKey should be a non-empty string, found ${VALUE}'
|
|
10
11
|
}
|
|
11
12
|
},
|
|
13
|
+
androidSecret: {
|
|
14
|
+
type: String,
|
|
15
|
+
validate:{
|
|
16
|
+
validator:apiKeyValidator,
|
|
17
|
+
msg:'androidSecret should be a non-empty string, found ${VALUE}'
|
|
18
|
+
}
|
|
19
|
+
},
|
|
12
20
|
iOSApiKey:{
|
|
13
21
|
type:String,
|
|
14
22
|
validate:{
|
|
15
23
|
validator:apiKeyValidator,
|
|
16
|
-
msg:'iOSApiKey should be
|
|
24
|
+
msg:'iOSApiKey should be a non-empty string, found ${VALUE}'
|
|
25
|
+
}
|
|
26
|
+
},
|
|
27
|
+
iOSSecret:{
|
|
28
|
+
type:String,
|
|
29
|
+
validate:{
|
|
30
|
+
validator:apiKeyValidator,
|
|
31
|
+
msg:'iOSSecret should be a non-empty string, found ${VALUE}'
|
|
17
32
|
}
|
|
18
33
|
}
|
|
19
34
|
})
|
|
@@ -23,25 +38,21 @@ const IntegrationSchema = new mongoose.Schema({
|
|
|
23
38
|
type: MParticleSchema,
|
|
24
39
|
validate: {
|
|
25
40
|
validator: mParticleValidator,
|
|
26
|
-
msg: '
|
|
41
|
+
msg: 'either of the two field combinations is mandatory: androidApiKey & androidSecret OR iOSApiKey & iOSSecret'
|
|
27
42
|
},
|
|
28
43
|
required: true
|
|
29
44
|
}
|
|
30
45
|
});
|
|
31
46
|
function apiKeyValidator(value){
|
|
32
|
-
// only one of the Api keys is required.
|
|
33
|
-
if(typeof value === 'undefined'){
|
|
34
|
-
return true
|
|
35
|
-
}
|
|
36
47
|
// check if the value is a non-empty string
|
|
37
48
|
return !(typeof value !=='string' || value.trim() === '')
|
|
38
49
|
|
|
39
50
|
}
|
|
40
51
|
function mParticleValidator(value) {
|
|
41
|
-
const { androidApiKey, iOSApiKey } = value;
|
|
52
|
+
const { androidApiKey,androidSecret, iOSApiKey,iOSSecret } = value;
|
|
42
53
|
|
|
43
|
-
const isAndroidKeyProvided = typeof androidApiKey !== "undefined"
|
|
44
|
-
const isIOSKeyProvided = typeof iOSApiKey !== "undefined"
|
|
54
|
+
const isAndroidKeyProvided = (typeof androidApiKey !== "undefined" && typeof androidSecret !=="undefined")
|
|
55
|
+
const isIOSKeyProvided = (typeof iOSApiKey !== "undefined" && typeof iOSSecret !== "undefined")
|
|
45
56
|
|
|
46
57
|
return isAndroidKeyProvided || isIOSKeyProvided;
|
|
47
58
|
}
|