@bluedot-innovation/models 5.1.21 → 5.1.23-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 +9 -0
- package/__tests__/zone/zone.geofeatures.spec.js +33 -0
- package/__tests__/zone/zone.spec.js +45 -0
- package/models/Zone.js +21 -0
- package/package.json +3 -2
- package/schemas/Point.js +3 -2
package/CHANGELOG.md
CHANGED
|
@@ -71,5 +71,38 @@ testCase('Zone - Action', () => {
|
|
|
71
71
|
done()
|
|
72
72
|
})
|
|
73
73
|
})
|
|
74
|
+
|
|
75
|
+
assertions('should throw an error when a geofeature is missing a type', (done) => {
|
|
76
|
+
delete zone.geofeatures[0].type
|
|
77
|
+
let Zone = new ZoneModel(zone)
|
|
78
|
+
Zone.validate((err, res) => {
|
|
79
|
+
assert.exists(err, 'err object should exist')
|
|
80
|
+
assert.isObject(err)
|
|
81
|
+
assert.match(err.message, /(Geofeature requires a type of `beacon`, `circle`, `polygon`, `geoline` or `boundingBox`.)/i)
|
|
82
|
+
done()
|
|
83
|
+
})
|
|
84
|
+
})
|
|
85
|
+
|
|
86
|
+
assertions('should throw an error when a geofeature type is invalid', (done) => {
|
|
87
|
+
zone.geofeatures[0].type = 'test'
|
|
88
|
+
let Zone = new ZoneModel(zone)
|
|
89
|
+
Zone.validate((err, res) => {
|
|
90
|
+
assert.exists(err, 'err object should exist')
|
|
91
|
+
assert.isObject(err)
|
|
92
|
+
assert.match(err.message, /(Geofeature requires a type of `beacon`, `circle`, `polygon`, `geoline` or `boundingBox`.)/i)
|
|
93
|
+
done()
|
|
94
|
+
})
|
|
95
|
+
})
|
|
96
|
+
|
|
97
|
+
assertions('should throw an error when a geofeature object is empty', (done) => {
|
|
98
|
+
zone.geofeatures = [{}]
|
|
99
|
+
let Zone = new ZoneModel(zone)
|
|
100
|
+
Zone.validate((err, res) => {
|
|
101
|
+
assert.exists(err, 'err object should exist')
|
|
102
|
+
assert.isObject(err)
|
|
103
|
+
assert.match(err.message, /(Geofeature requires a type of `beacon`, `circle`, `polygon`, `geoline` or `boundingBox`.)/i)
|
|
104
|
+
done()
|
|
105
|
+
})
|
|
106
|
+
})
|
|
74
107
|
})
|
|
75
108
|
})
|
|
@@ -121,6 +121,29 @@ describe('Zone', () => {
|
|
|
121
121
|
})
|
|
122
122
|
})
|
|
123
123
|
|
|
124
|
+
it('should throw an error when action type is missing', (done) => {
|
|
125
|
+
delete zone.actions[0].type
|
|
126
|
+
delete zone.actions[1].type
|
|
127
|
+
let Zone = new ZoneModel(zone)
|
|
128
|
+
Zone.validate((err, res) => {
|
|
129
|
+
assert.exists(err, 'err object should exist')
|
|
130
|
+
assert.isObject(err)
|
|
131
|
+
assert.match(err.message, /(Action requires a type of `url` or `message`.)/i)
|
|
132
|
+
done()
|
|
133
|
+
})
|
|
134
|
+
})
|
|
135
|
+
|
|
136
|
+
it('should throw an error when action object is empty', (done) => {
|
|
137
|
+
zone.actions = [{}]
|
|
138
|
+
let Zone = new ZoneModel(zone)
|
|
139
|
+
Zone.validate((err, res) => {
|
|
140
|
+
assert.exists(err, 'err object should exist')
|
|
141
|
+
assert.isObject(err)
|
|
142
|
+
assert.match(err.message, /(Action requires a type of `url` or `message`.)/i)
|
|
143
|
+
done()
|
|
144
|
+
})
|
|
145
|
+
})
|
|
146
|
+
|
|
124
147
|
it('should throw an error when a condition is invalid', (done) => {
|
|
125
148
|
zone.conditions[0].startDate = 'abc'
|
|
126
149
|
let Zone = new ZoneModel(zone)
|
|
@@ -132,6 +155,28 @@ describe('Zone', () => {
|
|
|
132
155
|
})
|
|
133
156
|
})
|
|
134
157
|
|
|
158
|
+
it('should throw an error when a condition type is missing', (done) => {
|
|
159
|
+
delete zone.conditions[0].type
|
|
160
|
+
let Zone = new ZoneModel(zone)
|
|
161
|
+
Zone.validate((err, res) => {
|
|
162
|
+
assert.exists(err, 'err object should exist')
|
|
163
|
+
assert.isObject(err)
|
|
164
|
+
assert.match(err.message, /(Condition requires a type of `dayRange`, `speed`, `timeActive`, `travelDirection` or `travelPath`.)/i)
|
|
165
|
+
done()
|
|
166
|
+
})
|
|
167
|
+
})
|
|
168
|
+
|
|
169
|
+
it('should throw an error when a condition object is empty', (done) => {
|
|
170
|
+
zone.conditions = [{}]
|
|
171
|
+
let Zone = new ZoneModel(zone)
|
|
172
|
+
Zone.validate((err, res) => {
|
|
173
|
+
assert.exists(err, 'err object should exist')
|
|
174
|
+
assert.isObject(err)
|
|
175
|
+
assert.match(err.message, /(Condition requires a type of `dayRange`, `speed`, `timeActive`, `travelDirection` or `travelPath`.)/i)
|
|
176
|
+
done()
|
|
177
|
+
})
|
|
178
|
+
})
|
|
179
|
+
|
|
135
180
|
it('should throw an error when custom data is null', (done) => {
|
|
136
181
|
zone.customData = null
|
|
137
182
|
let Zone = new ZoneModel(zone)
|
package/models/Zone.js
CHANGED
|
@@ -44,12 +44,33 @@ const tagsFormation = (tags) => {
|
|
|
44
44
|
let actionSchema = new Schema({},
|
|
45
45
|
{ discriminatorKey: 'type', _id: false })
|
|
46
46
|
|
|
47
|
+
actionSchema.pre('validate', function(next){
|
|
48
|
+
if(this.type === undefined){
|
|
49
|
+
return next(new Error('Action requires a type of `url` or `message`.'))
|
|
50
|
+
}
|
|
51
|
+
next()
|
|
52
|
+
})
|
|
53
|
+
|
|
47
54
|
let conditionSchema = new Schema({},
|
|
48
55
|
{ discriminatorKey: 'type', _id: false })
|
|
49
56
|
|
|
57
|
+
conditionSchema.pre('validate', function(next){
|
|
58
|
+
if(this.type === undefined){
|
|
59
|
+
return next(new Error('Condition requires a type of `dayRange`, `speed`, `timeActive`, `travelDirection` or `travelPath`.'))
|
|
60
|
+
}
|
|
61
|
+
next()
|
|
62
|
+
})
|
|
63
|
+
|
|
50
64
|
let geofeatureSchema = new Schema({},
|
|
51
65
|
{ discriminatorKey: 'type', _id: false })
|
|
52
66
|
|
|
67
|
+
geofeatureSchema.pre('validate', function(next){
|
|
68
|
+
if(this.type === undefined){
|
|
69
|
+
return next(new Error('Geofeature requires a type of `beacon`, `circle`, `polygon`, `geoline` or `boundingBox`.'))
|
|
70
|
+
}
|
|
71
|
+
next()
|
|
72
|
+
})
|
|
73
|
+
|
|
53
74
|
let zoneSchema = new Schema({
|
|
54
75
|
_id: {type: String, default: uuidv4},
|
|
55
76
|
name: {type: String, required: true},
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@bluedot-innovation/models",
|
|
3
|
-
"version": "5.1.
|
|
3
|
+
"version": "5.1.23-alpha.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",
|
|
@@ -28,12 +28,13 @@
|
|
|
28
28
|
"sinon": "^4.1.2"
|
|
29
29
|
},
|
|
30
30
|
"dependencies": {
|
|
31
|
-
"@bluedot-innovation/enums": "2.1.5",
|
|
31
|
+
"@bluedot-innovation/enums": "^2.1.5",
|
|
32
32
|
"@bluedot-innovation/mongoose-json-patch": "0.0.6",
|
|
33
33
|
"deep-equal": "^1.0.1",
|
|
34
34
|
"fast-deep-equal": "^2.0.1",
|
|
35
35
|
"lodash.clonedeep": "4.5.0",
|
|
36
36
|
"mongoose": "^4.13.9",
|
|
37
|
+
"mongoose-double": "0.0.1",
|
|
37
38
|
"uuid": "^3.1.0"
|
|
38
39
|
}
|
|
39
40
|
}
|
package/schemas/Point.js
CHANGED
|
@@ -1,9 +1,10 @@
|
|
|
1
1
|
let mongoose = require('mongoose')
|
|
2
|
+
require('mongoose-double')(mongoose)
|
|
2
3
|
|
|
3
4
|
let PointSchema = new mongoose.Schema({
|
|
4
5
|
type: {type: String},
|
|
5
|
-
latitude: {type:
|
|
6
|
-
longitude: {type:
|
|
6
|
+
latitude: {type: mongoose.Schema.Types.Double, required: [true, 'latitude is required. '], min: -90, max: 90},
|
|
7
|
+
longitude: {type: mongoose.Schema.Types.Double, required: [true, 'longitude is required. '], min: -180, max: 180}
|
|
7
8
|
},
|
|
8
9
|
{
|
|
9
10
|
_id: false,
|