@bluedot-innovation/models 5.1.52-zeta.3 → 5.1.52
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 +1 -3
- package/__tests__/condition/dayRange/dayRange.spec.js +1 -1
- package/__tests__/geofeature/geoline/geoline.spec.js +2 -1
- package/__tests__/project/project.spec.js +22 -0
- package/__tests__/zone/zone.geofeatures.spec.js +13 -10
- package/__tests__/zone/zone.spec.js +7 -7
- package/helpers.js +0 -5
- package/models/Zone.js +3 -8
- package/models/conditions/DayRange.js +4 -5
- package/models/geofeatures/Geoline.js +1 -1
- package/package.json +3 -3
- package/schemas/Integration.js +15 -5
- package/schemas/PointGeometry.js +2 -2
package/CHANGELOG.md
CHANGED
|
@@ -23,10 +23,9 @@ 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
26
|
Beacon.validate((err, res) => {
|
|
28
27
|
assert.notExists(res)
|
|
29
|
-
assert
|
|
28
|
+
assert(err === null, 'err should equal null')
|
|
30
29
|
done()
|
|
31
30
|
})
|
|
32
31
|
})
|
|
@@ -41,7 +40,6 @@ describe('Beacon', () => {
|
|
|
41
40
|
assert.isObject(err)
|
|
42
41
|
done()
|
|
43
42
|
})
|
|
44
|
-
|
|
45
43
|
})
|
|
46
44
|
|
|
47
45
|
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, res) => {
|
|
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,7 +66,8 @@ 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) => {
|
|
69
|
+
Geoline.validate((err, res) => {
|
|
70
|
+
assert.notExists(res)
|
|
70
71
|
assert.exists(err, 'err object should exist')
|
|
71
72
|
assert.isObject(err)
|
|
72
73
|
assert.nestedProperty(err, `errors.${i}`, `error should have a ${i} property`)
|
|
@@ -93,6 +93,17 @@ testCase('Project', () => {
|
|
|
93
93
|
done()
|
|
94
94
|
})
|
|
95
95
|
})
|
|
96
|
+
assertions('should throw an error if the mparticle integration misses all keys ', (done) => {
|
|
97
|
+
|
|
98
|
+
project.integrations.mParticle = {}
|
|
99
|
+
|
|
100
|
+
let Project = new ProjectModel(project)
|
|
101
|
+
Project.validate((err, res) => {
|
|
102
|
+
assert.exists(err)
|
|
103
|
+
assert.match(err.message, /either of the two field combinations is mandatory/)
|
|
104
|
+
done()
|
|
105
|
+
})
|
|
106
|
+
})
|
|
96
107
|
assertions('should throw an error if the mparticle integration misses both keys ', (done) => {
|
|
97
108
|
|
|
98
109
|
delete project.integrations.mParticle.iOSApiKey
|
|
@@ -117,6 +128,17 @@ testCase('Project', () => {
|
|
|
117
128
|
done()
|
|
118
129
|
})
|
|
119
130
|
})
|
|
131
|
+
assertions('should throw an error if the mparticle integration has valid android key pair, but no Ios secret ', (done) => {
|
|
132
|
+
|
|
133
|
+
delete project.integrations.mParticle.iOSSecret
|
|
134
|
+
|
|
135
|
+
let Project = new ProjectModel(project)
|
|
136
|
+
Project.validate((err, res) => {
|
|
137
|
+
assert.exists(err)
|
|
138
|
+
assert.match(err.message, /either of the two field combinations is mandatory/)
|
|
139
|
+
done()
|
|
140
|
+
})
|
|
141
|
+
})
|
|
120
142
|
assertions('should validate if the mparticle integration has only Android key ', (done) => {
|
|
121
143
|
|
|
122
144
|
delete project.integrations.mParticle.androidApiKey
|
|
@@ -31,8 +31,10 @@ 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
|
-
|
|
34
|
+
Zone.validate((err, res) => {
|
|
35
|
+
console.log(err)
|
|
36
|
+
assert.notExists(res)
|
|
37
|
+
assert(err === null, 'err should be null')
|
|
36
38
|
done()
|
|
37
39
|
})
|
|
38
40
|
})
|
|
@@ -42,7 +44,7 @@ testCase('Zone - Action', () => {
|
|
|
42
44
|
assertions('should throw an error when an invalid geofeature is instantiated within a zone', (done) => {
|
|
43
45
|
delete zone.geofeatures[0].name
|
|
44
46
|
let Zone = new ZoneModel(zone)
|
|
45
|
-
Zone.validate((err) => {
|
|
47
|
+
Zone.validate((err, res) => {
|
|
46
48
|
assert.exists(err, 'err object should exist')
|
|
47
49
|
assert.isObject(err)
|
|
48
50
|
assert('geofeatures.0.name' in err.errors)
|
|
@@ -52,19 +54,20 @@ testCase('Zone - Action', () => {
|
|
|
52
54
|
assertions('should throw an error when an invalid geofeature (complex validation) is instantiated within a zone', (done) => {
|
|
53
55
|
delete zone.geofeatures[0].minor
|
|
54
56
|
let Zone = new ZoneModel(zone)
|
|
55
|
-
Zone.validate((err) => {
|
|
57
|
+
Zone.validate((err, res) => {
|
|
56
58
|
assert.exists(err, 'err object should exist')
|
|
57
59
|
assert.isObject(err)
|
|
58
60
|
assert('geofeatures.0.minor' in err.errors)
|
|
59
61
|
done()
|
|
60
62
|
})
|
|
61
63
|
})
|
|
62
|
-
assertions('should throw an error when no geofeature is instantiated within a zone', (done) => {
|
|
64
|
+
assertions('should throw an error when an no geofeature is instantiated within a zone', (done) => {
|
|
63
65
|
zone.geofeatures = []
|
|
64
66
|
let Zone = new ZoneModel(zone)
|
|
65
|
-
Zone.validate((err) => {
|
|
67
|
+
Zone.validate((err, res) => {
|
|
66
68
|
assert.exists(err, 'err object should exist')
|
|
67
|
-
assert.
|
|
69
|
+
assert.isObject(err)
|
|
70
|
+
assert('geofeatures' in err.errors)
|
|
68
71
|
done()
|
|
69
72
|
})
|
|
70
73
|
})
|
|
@@ -72,7 +75,7 @@ testCase('Zone - Action', () => {
|
|
|
72
75
|
assertions('should throw an error when a geofeature is missing a type', (done) => {
|
|
73
76
|
delete zone.geofeatures[0].type
|
|
74
77
|
let Zone = new ZoneModel(zone)
|
|
75
|
-
Zone.validate((err) => {
|
|
78
|
+
Zone.validate((err, res) => {
|
|
76
79
|
assert.exists(err, 'err object should exist')
|
|
77
80
|
assert.isObject(err)
|
|
78
81
|
assert.match(err.message, /(Geofeature requires a type of `beacon`, `circle`, `polygon`, `geoline` or `boundingBox`.)/i)
|
|
@@ -83,7 +86,7 @@ testCase('Zone - Action', () => {
|
|
|
83
86
|
assertions('should throw an error when a geofeature type is invalid', (done) => {
|
|
84
87
|
zone.geofeatures[0].type = 'test'
|
|
85
88
|
let Zone = new ZoneModel(zone)
|
|
86
|
-
Zone.validate((err) => {
|
|
89
|
+
Zone.validate((err, res) => {
|
|
87
90
|
assert.exists(err, 'err object should exist')
|
|
88
91
|
assert.isObject(err)
|
|
89
92
|
assert.match(err.message, /(Geofeature requires a type of `beacon`, `circle`, `polygon`, `geoline` or `boundingBox`.)/i)
|
|
@@ -94,7 +97,7 @@ testCase('Zone - Action', () => {
|
|
|
94
97
|
assertions('should throw an error when a geofeature object is empty', (done) => {
|
|
95
98
|
zone.geofeatures = [{}]
|
|
96
99
|
let Zone = new ZoneModel(zone)
|
|
97
|
-
Zone.validate((err) => {
|
|
100
|
+
Zone.validate((err, res) => {
|
|
98
101
|
assert.exists(err, 'err object should exist')
|
|
99
102
|
assert.isObject(err)
|
|
100
103
|
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
|
-
|
|
24
|
+
assert(err === null, 'err equals null')
|
|
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
|
|
43
|
+
assert(err === null, 'err equals null')
|
|
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
|
|
53
|
+
assert(err === null, 'err equals null')
|
|
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
|
|
63
|
+
assert(err === null, 'err equals null')
|
|
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
|
|
73
|
+
assert(err === null, 'err equals null')
|
|
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
|
|
84
|
+
assert(err === null, 'err equals null')
|
|
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
|
|
213
212
|
Zone.validate((err, res) => {
|
|
214
213
|
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,9 +235,4 @@ 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
|
-
|
|
243
238
|
module.exports = helpers
|
package/models/Zone.js
CHANGED
|
@@ -67,12 +67,9 @@ let geofeatureSchema = new Schema({},
|
|
|
67
67
|
{ discriminatorKey: 'type', _id: false })
|
|
68
68
|
|
|
69
69
|
geofeatureSchema.pre('validate', function(next){
|
|
70
|
-
|
|
71
|
-
if([`beacon`,`circle`,`polygon`,`geoline`,`boundingBox`].indexOf(this.type) < 0){
|
|
72
|
-
|
|
70
|
+
if(this.type === undefined){
|
|
73
71
|
return next(new Error('Geofeature requires a type of `beacon`, `circle`, `polygon`, `geoline` or `boundingBox`.'))
|
|
74
72
|
}
|
|
75
|
-
|
|
76
73
|
next()
|
|
77
74
|
})
|
|
78
75
|
|
|
@@ -106,8 +103,7 @@ let zoneSchema = new Schema({
|
|
|
106
103
|
},
|
|
107
104
|
geofeatures: {
|
|
108
105
|
type: [geofeatureSchema],
|
|
109
|
-
required: true
|
|
110
|
-
default: undefined
|
|
106
|
+
required: true
|
|
111
107
|
},
|
|
112
108
|
// To prevent saving `null` we use `required: true`
|
|
113
109
|
// https://github.com/Automattic/mongoose/issues/6034#issuecomment-362112268
|
|
@@ -147,8 +143,7 @@ zoneSchema.pre('validate', function(next) {
|
|
|
147
143
|
new Promise((resolve, reject) => helpers.checkMinimumGeofeaturesValidForZone(this, resolve)),
|
|
148
144
|
new Promise((resolve, reject) => helpers.validateTravelPathConditionCount(this, resolve)),
|
|
149
145
|
new Promise((resolve, reject) => helpers.checkValidLowAccuracyFence(this, resolve)),
|
|
150
|
-
new Promise((resolve, reject) => helpers.checkDuplicateGeofeaturesId(this, resolve))
|
|
151
|
-
new Promise((resolve, reject) => helpers.ensureNonEmptyGeofeatures(this, resolve))
|
|
146
|
+
new Promise((resolve, reject) => helpers.checkDuplicateGeofeaturesId(this, resolve))
|
|
152
147
|
]).then(results => {
|
|
153
148
|
for( let result of results ) {
|
|
154
149
|
if( result )
|
|
@@ -14,16 +14,15 @@ DayRangeConditionSchema.add({
|
|
|
14
14
|
type: {type: String, required: true, validate: validateDateRange}
|
|
15
15
|
})
|
|
16
16
|
|
|
17
|
-
function validateDateRange () {
|
|
17
|
+
function validateDateRange (type, callback) {
|
|
18
18
|
let startDate = this.startDate;
|
|
19
19
|
let endDate = this.endDate;
|
|
20
20
|
|
|
21
|
-
|
|
22
|
-
if (!startDate && !endDate) return Promise.reject(new Error(`Must have a startDate, endDate, or both.`))
|
|
21
|
+
if (!startDate && !endDate) return callback(false, `Must have a startDate, endDate, or both.`)
|
|
23
22
|
|
|
24
|
-
if (startDate && endDate && endDate < startDate) return
|
|
23
|
+
if (startDate && endDate && endDate < startDate) return callback(false, `startDate has to be less than endDate.`)
|
|
25
24
|
|
|
26
|
-
|
|
25
|
+
callback(true)
|
|
27
26
|
}
|
|
28
27
|
|
|
29
28
|
// 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. ']}
|
|
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.52
|
|
3
|
+
"version": "5.1.52",
|
|
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",
|
|
@@ -30,13 +30,13 @@
|
|
|
30
30
|
"dependencies": {
|
|
31
31
|
"@bluedot-innovation/enums": "^2.1.5",
|
|
32
32
|
"@bluedot-innovation/mongoose-json-patch": "0.0.8",
|
|
33
|
-
"@mongoosejs/double": "^0.2
|
|
33
|
+
"@mongoosejs/double": "^0.1.2",
|
|
34
34
|
"@turf/area": "^6.0.1",
|
|
35
35
|
"@turf/helpers": "^6.1.4",
|
|
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": "^4.13.9",
|
|
40
40
|
"uuid": "^3.1.0"
|
|
41
41
|
}
|
|
42
42
|
}
|
package/schemas/Integration.js
CHANGED
|
@@ -31,7 +31,7 @@ const MParticleSchema = new mongoose.Schema({
|
|
|
31
31
|
msg:'iOSSecret should be a non-empty string, found ${VALUE}'
|
|
32
32
|
}
|
|
33
33
|
}
|
|
34
|
-
})
|
|
34
|
+
},{ _id : false })
|
|
35
35
|
|
|
36
36
|
const IntegrationSchema = new mongoose.Schema({
|
|
37
37
|
mParticle: {
|
|
@@ -42,7 +42,7 @@ const IntegrationSchema = new mongoose.Schema({
|
|
|
42
42
|
},
|
|
43
43
|
required: true
|
|
44
44
|
}
|
|
45
|
-
});
|
|
45
|
+
},{ _id : false });
|
|
46
46
|
function apiKeyValidator(value){
|
|
47
47
|
// check if the value is a non-empty string
|
|
48
48
|
return !(typeof value !=='string' || value.trim() === '')
|
|
@@ -50,11 +50,21 @@ function apiKeyValidator(value){
|
|
|
50
50
|
}
|
|
51
51
|
function mParticleValidator(value) {
|
|
52
52
|
const { androidApiKey,androidSecret, iOSApiKey,iOSSecret } = value;
|
|
53
|
+
let isAndroidPairProvided = false
|
|
54
|
+
let isIosPairProvided = false
|
|
55
|
+
if((androidApiKey === undefined) !== (androidSecret ===undefined)){
|
|
56
|
+
return false
|
|
57
|
+
} else if((androidApiKey !== undefined)){
|
|
58
|
+
isAndroidPairProvided=true
|
|
59
|
+
}
|
|
60
|
+
if((iOSApiKey === undefined) !== (iOSSecret ===undefined)){
|
|
61
|
+
return false
|
|
62
|
+
} else if((iOSApiKey !== undefined)){
|
|
63
|
+
isIosPairProvided=true
|
|
64
|
+
}
|
|
53
65
|
|
|
54
|
-
const isAndroidKeyProvided = (typeof androidApiKey !== "undefined" && typeof androidSecret !=="undefined")
|
|
55
|
-
const isIOSKeyProvided = (typeof iOSApiKey !== "undefined" && typeof iOSSecret !== "undefined")
|
|
56
66
|
|
|
57
|
-
return
|
|
67
|
+
return isIosPairProvided || isAndroidPairProvided;
|
|
58
68
|
}
|
|
59
69
|
|
|
60
70
|
module.exports = IntegrationSchema
|
package/schemas/PointGeometry.js
CHANGED
|
@@ -4,8 +4,8 @@ const Double = require('@mongoosejs/double')
|
|
|
4
4
|
let PointGeometrySchema = new mongoose.Schema(
|
|
5
5
|
{
|
|
6
6
|
type: {type: String, match: /Point/},
|
|
7
|
-
coordinates: [{type:
|
|
8
|
-
{type:
|
|
7
|
+
coordinates: [{type: Double, required: [true, 'longitude is required. '], min: -180, max: 180},
|
|
8
|
+
{type: Double, required: [true, 'latitude is required. '], min: -90, max: 90}]
|
|
9
9
|
},
|
|
10
10
|
{
|
|
11
11
|
_id: false,
|