@bluedot-innovation/models 8.5.0 → 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 +6 -0
- package/__tests__/destination/destination.data.json +8 -5
- package/__tests__/destination/destination.spec.js +58 -5
- package/__tests__/project/project.spec.js +41 -0
- package/models/Destination.js +4 -3
- package/package.json +1 -1
- package/schemas/DestinationHello.js +13 -0
- package/schemas/ProjectHello.js +2 -2
- package/schemas/WaitTime.js +2 -2
package/CHANGELOG.md
CHANGED
|
@@ -1,3 +1,9 @@
|
|
|
1
|
+
## 9.0.0
|
|
2
|
+
- BREAKING CHANGE - Move destination hello properties stateTemplateId, waitTime to hello object and add consolidationAlert
|
|
3
|
+
|
|
4
|
+
## 8.5.1
|
|
5
|
+
- Add min and max limits to activeTtl and finalTtl
|
|
6
|
+
|
|
1
7
|
## 8.5.0
|
|
2
8
|
- Add activeTtl and finalTtl to project.hello and remove registrationTtl
|
|
3
9
|
|
|
@@ -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)
|
|
@@ -293,6 +293,47 @@ describe('Project', () => {
|
|
|
293
293
|
})
|
|
294
294
|
})
|
|
295
295
|
|
|
296
|
+
it('should not validate if hello.finalTtl is a negative', (done) => {
|
|
297
|
+
project.hello.finalTtl = -2
|
|
298
|
+
let Project = new ProjectModel(project)
|
|
299
|
+
Project.validate((err, res) => {
|
|
300
|
+
assert.exists(err)
|
|
301
|
+
assert.match(err.message, /finalTtl` \(-2\) is less than minimum allowed value \(0\)/)
|
|
302
|
+
done()
|
|
303
|
+
})
|
|
304
|
+
})
|
|
305
|
+
|
|
306
|
+
it('should not validate if hello.activeTtl is a negative', (done) => {
|
|
307
|
+
project.hello.activeTtl = -2
|
|
308
|
+
let Project = new ProjectModel(project)
|
|
309
|
+
Project.validate((err, res) => {
|
|
310
|
+
assert.exists(err)
|
|
311
|
+
assert.match(err.message, /activeTtl` \(-2\) is less than minimum allowed value \(0\)/)
|
|
312
|
+
done()
|
|
313
|
+
})
|
|
314
|
+
})
|
|
315
|
+
|
|
316
|
+
it('should not validate if hello.finalTtl is a greater than the maximum', (done) => {
|
|
317
|
+
project.hello.finalTtl = 1209601
|
|
318
|
+
let Project = new ProjectModel(project)
|
|
319
|
+
Project.validate((err, res) => {
|
|
320
|
+
console.log(err)
|
|
321
|
+
assert.exists(err)
|
|
322
|
+
assert.match(err.message, /finalTtl` \(1209601\) is more than maximum allowed value/)
|
|
323
|
+
done()
|
|
324
|
+
})
|
|
325
|
+
})
|
|
326
|
+
|
|
327
|
+
it('should not validate if hello.activeTtl is a greater than the maximum', (done) => {
|
|
328
|
+
project.hello.activeTtl = 1209601
|
|
329
|
+
let Project = new ProjectModel(project)
|
|
330
|
+
Project.validate((err, res) => {
|
|
331
|
+
assert.exists(err)
|
|
332
|
+
assert.match(err.message, /activeTtl` \(1209601\) is more than maximum allowed value/)
|
|
333
|
+
done()
|
|
334
|
+
})
|
|
335
|
+
})
|
|
336
|
+
|
|
296
337
|
describe("webhook validation", () => {
|
|
297
338
|
assertions(`should not validate if webhook protocol is not valid `, (done) => {
|
|
298
339
|
project.webhooks[0].url = 'htt://test.com'
|
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/ProjectHello.js
CHANGED
|
@@ -2,8 +2,8 @@ let mongoose = require('mongoose')
|
|
|
2
2
|
const helpers = require('../helpers')
|
|
3
3
|
|
|
4
4
|
let ProjectHelloSchema = new mongoose.Schema({
|
|
5
|
-
activeTtl: {type: Number, validate: { validator: Number.isInteger, msg: 'hello.activeTtl should be an integer number' }},
|
|
6
|
-
finalTtl: {type: Number, validate: { validator: Number.isInteger, msg: 'hello.finalTtl should be an integer number' }},
|
|
5
|
+
activeTtl: {type: Number, min: 0, max: 1209600, validate: { validator: Number.isInteger, msg: 'hello.activeTtl should be an integer number' }},
|
|
6
|
+
finalTtl: {type: Number, min: 0, max: 1209600, validate: { validator: Number.isInteger, msg: 'hello.finalTtl should be an integer number' }},
|
|
7
7
|
ssoLinkingCode: {type: String, validate: {validator: helpers.validateSsoLinkingCode, msg: 'SSO linking code must be a 12 character capital alphanumeric text'}}
|
|
8
8
|
}, {
|
|
9
9
|
_id: false
|
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
|
})
|