@bluedot-innovation/models 8.5.1 → 9.0.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 CHANGED
@@ -1,3 +1,9 @@
1
+ ## 9.0.1
2
+ - Add geo-trigger report
3
+
4
+ ## 9.0.0
5
+ - BREAKING CHANGE - Move destination hello properties stateTemplateId, waitTime to hello object and add consolidationAlert
6
+
1
7
  ## 8.5.1
2
8
  - Add min and max limits to activeTtl and finalTtl
3
9
 
@@ -11,9 +11,12 @@
11
11
  "longitude": 144.9723565578461
12
12
  },
13
13
  "address": "48 Pirrama Rd, Pyrmont NSW 2009, Australia",
14
- "waitTime": {
15
- "goal": 300,
16
- "alert": 240
17
- },
18
- "stateTemplateId": "b0824b76-ce73-4fcf-81f8-1b63edb1114e"
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)
@@ -869,7 +869,22 @@ describe('Project', () => {
869
869
  let Project = new ProjectModel(project)
870
870
  Project.validate((err, res) => {
871
871
  assert.exists(err)
872
- assert.match(err.message, /Only one report type per project is allowed/)
872
+ assert.match(err.message, /Multiple reports of the same type are not allowed/)
873
+ done()
874
+ })
875
+ })
876
+
877
+ it('Should be successfull when there are multiple report types per project', (done) => {
878
+ project.reportConfigurations.push({
879
+ "type": "geo-trigger",
880
+ "frequency": "monthly",
881
+ "reportDay": 1,
882
+ "timezone": "Australia/Sydney",
883
+ "recipients": "xyz@example.com"
884
+ })
885
+ let Project = new ProjectModel(project)
886
+ Project.validate((err, res) => {
887
+ assert.notExists(err)
873
888
  done()
874
889
  })
875
890
  })
@@ -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 WaitTime = require('../schemas/WaitTime')
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
- waitTime: { type: WaitTime },
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/models/Project.js CHANGED
@@ -26,7 +26,7 @@ let webhooksValidators = [
26
26
 
27
27
  const reportConfigurationsValidators = [
28
28
  {validator: helpers.validateNotNull},
29
- {validator: helpers.validateNoDuplicateReportConfigurations, msg: "Only one report type per project is allowed"}
29
+ {validator: helpers.validateNoDuplicateReportConfigurations, msg: "Multiple reports of the same type are not allowed"}
30
30
  ]
31
31
 
32
32
  let ProjectSchema = new mongoose.Schema({
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@bluedot-innovation/models",
3
- "version": "8.5.1",
3
+ "version": "9.0.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",
@@ -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
@@ -34,7 +34,7 @@ function validateRecipients(value) {
34
34
  }
35
35
 
36
36
  let ReportConfigurationSchema = new mongoose.Schema({
37
- type: {type: String, enum: ['hello'], required: true},
37
+ type: {type: String, enum: ['hello', 'geo-trigger'], required: true},
38
38
  frequency: {type: String, enum: ['daily', 'weekly', 'monthly'], required: true},
39
39
  reportDay: {type: Number, validate: {validator: validateReportDay}},
40
40
  timezone: {type: String, required: true, validate: { validator: validateTimeZone, msg: 'Invalid timezone'}},
@@ -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
  })