@bluedot-innovation/models 8.5.1 → 9.0.0
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
CHANGED
|
@@ -11,9 +11,12 @@
|
|
|
11
11
|
"longitude": 144.9723565578461
|
|
12
12
|
},
|
|
13
13
|
"address": "48 Pirrama Rd, Pyrmont NSW 2009, Australia",
|
|
14
|
-
"
|
|
15
|
-
"
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
14
|
+
"hello": {
|
|
15
|
+
"waitTime": {
|
|
16
|
+
"goal": 300,
|
|
17
|
+
"alert": 240
|
|
18
|
+
},
|
|
19
|
+
"stateTemplateId": "b0824b76-ce73-4fcf-81f8-1b63edb1114e",
|
|
20
|
+
"consolidationAlert": 600
|
|
21
|
+
}
|
|
19
22
|
}
|
|
@@ -50,7 +50,7 @@ describe('Valid Destination ', () => {
|
|
|
50
50
|
})
|
|
51
51
|
|
|
52
52
|
it('should validate a valid destination without wait time goals', (done) => {
|
|
53
|
-
delete destination.waitTime
|
|
53
|
+
delete destination.hello.waitTime
|
|
54
54
|
let Destination = new DestinationModel(destination)
|
|
55
55
|
Destination.validate((err, res) => {
|
|
56
56
|
assert.notExists(res)
|
|
@@ -60,7 +60,27 @@ describe('Valid Destination ', () => {
|
|
|
60
60
|
})
|
|
61
61
|
|
|
62
62
|
it('should validate a valid destination without stateTemplateId', (done) => {
|
|
63
|
-
delete destination.stateTemplateId
|
|
63
|
+
delete destination.hello.stateTemplateId
|
|
64
|
+
let Destination = new DestinationModel(destination)
|
|
65
|
+
Destination.validate((err, res) => {
|
|
66
|
+
assert.notExists(res)
|
|
67
|
+
assert(err === null, 'err equals null')
|
|
68
|
+
done()
|
|
69
|
+
})
|
|
70
|
+
})
|
|
71
|
+
|
|
72
|
+
it('should validate a valid destination without consolidationAlert', (done) => {
|
|
73
|
+
delete destination.hello.consolidationAlert
|
|
74
|
+
let Destination = new DestinationModel(destination)
|
|
75
|
+
Destination.validate((err, res) => {
|
|
76
|
+
assert.notExists(res)
|
|
77
|
+
assert(err === null, 'err equals null')
|
|
78
|
+
done()
|
|
79
|
+
})
|
|
80
|
+
})
|
|
81
|
+
|
|
82
|
+
it('should validate a valid destination without any hello properties', (done) => {
|
|
83
|
+
delete destination.hello
|
|
64
84
|
let Destination = new DestinationModel(destination)
|
|
65
85
|
Destination.validate((err, res) => {
|
|
66
86
|
assert.notExists(res)
|
|
@@ -176,7 +196,7 @@ describe('Invalid Destination ', () => {
|
|
|
176
196
|
})
|
|
177
197
|
|
|
178
198
|
it("should throw an error if wait time alert is greater than goal", (done) => {
|
|
179
|
-
destination.waitTime.alert = 600
|
|
199
|
+
destination.hello.waitTime.alert = 600
|
|
180
200
|
let Destination = new DestinationModel(destination)
|
|
181
201
|
Destination.validate((err, res) => {
|
|
182
202
|
assert.notExists(res)
|
|
@@ -188,7 +208,7 @@ describe('Invalid Destination ', () => {
|
|
|
188
208
|
})
|
|
189
209
|
|
|
190
210
|
it("should throw an error if alert is not a number", (done) => {
|
|
191
|
-
destination.waitTime.alert = "Twelve"
|
|
211
|
+
destination.hello.waitTime.alert = "Twelve"
|
|
192
212
|
let Destination = new DestinationModel(destination)
|
|
193
213
|
Destination.validate((err, res) => {
|
|
194
214
|
assert.notExists(res)
|
|
@@ -199,8 +219,41 @@ describe('Invalid Destination ', () => {
|
|
|
199
219
|
})
|
|
200
220
|
})
|
|
201
221
|
|
|
222
|
+
it("should throw an error if goal is negative", (done) => {
|
|
223
|
+
destination.hello.waitTime.alert = -1
|
|
224
|
+
let Destination = new DestinationModel(destination)
|
|
225
|
+
Destination.validate((err, res) => {
|
|
226
|
+
assert.notExists(res)
|
|
227
|
+
assert.exists(err)
|
|
228
|
+
assert.match(err.message, /Path `alert` \(-1\) is less than minimum allowed value \(0\)/)
|
|
229
|
+
done()
|
|
230
|
+
})
|
|
231
|
+
})
|
|
232
|
+
|
|
233
|
+
it("should throw an error if consolidationAlert is less than the minimum", (done) => {
|
|
234
|
+
destination.hello.consolidationAlert = 0
|
|
235
|
+
let Destination = new DestinationModel(destination)
|
|
236
|
+
Destination.validate((err, res) => {
|
|
237
|
+
assert.notExists(res)
|
|
238
|
+
assert.exists(err)
|
|
239
|
+
assert.match(err.message, /Path `consolidationAlert` \(0\) is less than minimum allowed value \(1\)/)
|
|
240
|
+
done()
|
|
241
|
+
})
|
|
242
|
+
})
|
|
243
|
+
|
|
244
|
+
it("should throw an error if consolidationAlert is not a number", (done) => {
|
|
245
|
+
destination.hello.consolidationAlert = "Twelve"
|
|
246
|
+
let Destination = new DestinationModel(destination)
|
|
247
|
+
Destination.validate((err, res) => {
|
|
248
|
+
assert.notExists(res)
|
|
249
|
+
assert.exists(err)
|
|
250
|
+
assert.match(err.message, /Cast to Number failed for value "Twelve" \(type string\) at path "consolidationAlert"/)
|
|
251
|
+
done()
|
|
252
|
+
})
|
|
253
|
+
})
|
|
254
|
+
|
|
202
255
|
it("should throw an error if stateTemplateId is not a uuid", (done) => {
|
|
203
|
-
destination.stateTemplateId = "something"
|
|
256
|
+
destination.hello.stateTemplateId = "something"
|
|
204
257
|
let Destination = new DestinationModel(destination)
|
|
205
258
|
Destination.validate((err, res) => {
|
|
206
259
|
assert.notExists(res)
|
package/models/Destination.js
CHANGED
|
@@ -2,9 +2,11 @@ const mongoose = require('mongoose')
|
|
|
2
2
|
const uuidv4 = require('uuid/v4')
|
|
3
3
|
const patcher = require('@bluedot-innovation/mongoose-json-patch')
|
|
4
4
|
const Point = require('../schemas/Point')
|
|
5
|
-
const
|
|
5
|
+
const DestinationHelloSchema = require('../schemas/DestinationHello')
|
|
6
6
|
const helpers = require('../helpers')
|
|
7
7
|
|
|
8
|
+
|
|
9
|
+
|
|
8
10
|
const DestinationSchema = new mongoose.Schema({
|
|
9
11
|
_id: {type: String, default: uuidv4},
|
|
10
12
|
name: {type: String, required: true, maxlength: 128},
|
|
@@ -17,8 +19,7 @@ const DestinationSchema = new mongoose.Schema({
|
|
|
17
19
|
projectId: {type: String, required: true, validate: {validator: helpers.validateUUIDv4, msg: 'Invalid projectId'}},
|
|
18
20
|
creationTime: {type: Date, default: Date.now},
|
|
19
21
|
lastUpdateTime: {type: Date, default: Date.now},
|
|
20
|
-
|
|
21
|
-
stateTemplateId: {type: String, validate: {validator: helpers.validateUUIDv4, msg: 'Invalid state template id'}}
|
|
22
|
+
hello: DestinationHelloSchema
|
|
22
23
|
}, {collection: 'destination'})
|
|
23
24
|
|
|
24
25
|
DestinationSchema.plugin(patcher)
|
package/package.json
CHANGED
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
let mongoose = require('mongoose')
|
|
2
|
+
const helpers = require('../helpers')
|
|
3
|
+
const WaitTime = require("../schemas/WaitTime")
|
|
4
|
+
|
|
5
|
+
let DestinationHelloSchema = new mongoose.Schema({
|
|
6
|
+
waitTime: { type: WaitTime },
|
|
7
|
+
stateTemplateId: {type: String, validate: {validator: helpers.validateUUIDv4, msg: 'Invalid state template id'}},
|
|
8
|
+
consolidationAlert: {type: Number, min: 1}
|
|
9
|
+
}, {
|
|
10
|
+
_id: false
|
|
11
|
+
})
|
|
12
|
+
|
|
13
|
+
module.exports = DestinationHelloSchema
|
package/schemas/WaitTime.js
CHANGED
|
@@ -4,8 +4,8 @@ function validateAlertLessThanGoal(alert){
|
|
|
4
4
|
return alert < this.goal
|
|
5
5
|
}
|
|
6
6
|
const WaitTimeSchema = new mongoose.Schema({
|
|
7
|
-
alert: { type: Number, required: true, validate: { validator: validateAlertLessThanGoal, msg: "alert must be less than the goal value" } },
|
|
8
|
-
goal: { type: Number, required: true }
|
|
7
|
+
alert: { type: Number, min: 0, required: true, validate: { validator: validateAlertLessThanGoal, msg: "alert must be less than the goal value" } },
|
|
8
|
+
goal: { type: Number, min: 0, required: true }
|
|
9
9
|
}, {
|
|
10
10
|
_id: false
|
|
11
11
|
})
|