@bluedot-innovation/models 10.9.0 → 10.10.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
@@ -1,4 +1,9 @@
1
- ## 10.8.0
1
+ ## 10.10.0
2
+ - Add Dwell Configuration to Zone
3
+ - Support trigger webhook structure 2.2
4
+ - Add a new Scheduled Report type `geo-trigger-v2`
5
+
6
+ ## 10.9.0
2
7
  - Add dashboardIdentityProvider to HelloSSO model
3
8
 
4
9
  ## 10.8.0
@@ -190,6 +190,20 @@ describe('Project', () => {
190
190
  const res = await Project.validate()
191
191
  assert.notExists(res)
192
192
  })
193
+
194
+ it(`should validate a project when trigger webhook has structure is 2.2`, async () => {
195
+ project.webhooks = [
196
+ {
197
+ "type": "trigger",
198
+ "url": "https://webhooklistener.bluedotinnovation.com",
199
+ "retryEnabled": true,
200
+ "structure": "2.2"
201
+ }
202
+ ]
203
+ let Project = new ProjectModel(project)
204
+ const res = await Project.validate()
205
+ assert.notExists(res)
206
+ })
193
207
  })
194
208
  testCase('Valid Project ', () => {
195
209
  assertions('should validate a valid project ', async () => {
@@ -668,7 +682,20 @@ describe('Project', () => {
668
682
  await Project.validate()
669
683
  } catch (err) {
670
684
  assert.exists(err, 'err object should exist')
671
- assert.match(err.message, /Only type "trigger" can have structure 2.0/)
685
+ assert.match(err.message, /Only type "trigger" can have structure 2.0 or 2.2/)
686
+ }
687
+ })
688
+
689
+ it(`should not validate if structure is 2.2 and the type is not trigger`, async () => {
690
+ project.webhooks[0].type = "tempo"
691
+ project.webhooks[0].url = "http://test-url.com"
692
+ project.webhooks[0].structure = "2.2"
693
+ let Project = new ProjectModel(project)
694
+ try {
695
+ await Project.validate()
696
+ } catch (err) {
697
+ assert.exists(err, 'err object should exist')
698
+ assert.match(err.message, /Only type "trigger" can have structure 2.0 or 2.2/)
672
699
  }
673
700
  })
674
701
 
@@ -1010,6 +1037,13 @@ describe('Project', () => {
1010
1037
  "timezone": "Australia/Sydney",
1011
1038
  "recipients": "xyz@example.com"
1012
1039
  })
1040
+ project.reportConfigurations.push({
1041
+ "type": "geo-trigger-v2",
1042
+ "frequency": "monthly",
1043
+ "reportDay": 1,
1044
+ "timezone": "Australia/Sydney",
1045
+ "recipients": "xyz@example.com"
1046
+ })
1013
1047
  let Project = new ProjectModel(project)
1014
1048
  const res = await Project.validate()
1015
1049
  assert.notExists(res)
@@ -91,6 +91,16 @@ describe('Zone', () => {
91
91
  assert.notExists(res)
92
92
  })
93
93
  })
94
+
95
+ it('should set dwell enabled to false by default', async () => {
96
+ zone.dwellConfiguration = {
97
+ threshold: 300
98
+ }
99
+ let Zone = new ZoneModel(zone)
100
+ const res = await Zone.validate()
101
+ assert.isFalse(Zone.dwellConfiguration.enabled)
102
+ assert.notExists(res)
103
+ })
94
104
  })
95
105
 
96
106
  describe('Invalid Zone ', () => {
@@ -415,5 +425,45 @@ describe('Zone', () => {
415
425
  assert.match(err.message, /(destinationId must be less than 129 characters long)/i)
416
426
  }
417
427
  })
428
+
429
+ it('should throw error when dwell threshold is not a number', async () => {
430
+ zone.dwellConfiguration = {
431
+ threshold: 'test'
432
+ }
433
+ let Zone = new ZoneModel(zone)
434
+ try {
435
+ await Zone.validate()
436
+ } catch (err) {
437
+ assert.exists(err, 'err object should exist')
438
+ assert.match(err.message, /dwellConfiguration.threshold: Cast to Number failed/i)
439
+ }
440
+ })
441
+
442
+ it('should throw error when dwell threshold is not an integer number', async () => {
443
+ zone.dwellConfiguration = {
444
+ threshold: 300.5
445
+ }
446
+ let Zone = new ZoneModel(zone)
447
+ try {
448
+ await Zone.validate()
449
+ } catch (err) {
450
+ assert.exists(err, 'err object should exist')
451
+ assert.match(err.message, /dwellConfiguration.threshold: 300.5 is not an integer number/i)
452
+ }
453
+ })
454
+
455
+ it('should throw error when dwell threshold is out of range', async () => {
456
+ zone.dwellConfiguration = {
457
+ threshold: 30
458
+ }
459
+ let Zone = new ZoneModel(zone)
460
+ try {
461
+ await Zone.validate()
462
+ } catch (err) {
463
+ console.log(err)
464
+ assert.exists(err, 'err object should exist')
465
+ assert.match(err.message, /dwellConfiguration.threshold: Path `threshold` \(30\) is less than minimum allowed value \(60\)/i)
466
+ }
467
+ })
418
468
  })
419
469
  })
package/models/Zone.js CHANGED
@@ -19,6 +19,8 @@ let travelDirectionRawSchema = require('./conditions/TravelDirection').rawSchema
19
19
  let travelPathRawSchema = require('./conditions/TravelPath').rawSchema
20
20
  let timeActiveRawSchema = require('./conditions/TimeActive').rawSchema
21
21
 
22
+ let dwellConfigurationSchema = require('../schemas/DwellConfiguration')
23
+
22
24
  let uuidv4 = require('uuid/v4')
23
25
  let patcher = require('@bluedot-innovation/mongoose-json-patch')
24
26
  let helpers = require('../helpers')
@@ -99,6 +101,7 @@ let zoneSchema = new Schema({
99
101
  state: {type: String, default: StateEnum.ACTIVE, select: false},
100
102
  accountId: {type: String, required: true, validate: {validator: helpers.validateUUIDv4, msg: 'default error message'}},
101
103
  destinationId: {type: String, validate: { validator: helpers.validateDestinationIdLength, msg: 'destinationId must be less than 129 characters long' }},
104
+ dwellConfiguration: dwellConfigurationSchema
102
105
  }, {collection: 'zone', autoIndex: false})
103
106
 
104
107
  // Mongoose-json-patch
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@bluedot-innovation/models",
3
- "version": "10.9.0",
3
+ "version": "10.10.0",
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,19 @@
1
+ let mongoose = require('mongoose')
2
+
3
+ let DwellConfigurationSchema = new mongoose.Schema({
4
+ enabled: {type: Boolean, default: false},
5
+ threshold: {
6
+ type: Number,
7
+ required: true,
8
+ min: 60,
9
+ max: 86400,
10
+ validate: {
11
+ validator: Number.isInteger,
12
+ message: '{VALUE} is not an integer number'
13
+ }
14
+ }
15
+ }, {
16
+ _id: false
17
+ })
18
+
19
+ module.exports = DwellConfigurationSchema
@@ -34,7 +34,7 @@ function validateRecipients(value) {
34
34
  }
35
35
 
36
36
  let ReportConfigurationSchema = new mongoose.Schema({
37
- type: {type: String, enum: ['hello', 'geo-trigger'], required: true},
37
+ type: {type: String, enum: ['hello', 'geo-trigger', 'geo-trigger-v2'], 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'}},
@@ -34,8 +34,8 @@ function validateTypeAndStructure(type) {
34
34
  } else if ((type === "helloOrder" && !['default', '2.1'].includes(this.structure))
35
35
  || (type !== "helloOrder" && this.structure === 'default')) {
36
36
  throw new Error('type "helloOrder" can only have structure "default" or "2.1"')
37
- } else if (type !== 'trigger' && this.structure === '2.0') {
38
- throw new Error('Only type "trigger" can have structure 2.0')
37
+ } else if (type !== 'trigger' && ['2.0', '2.2'].includes(this.structure)) {
38
+ throw new Error('Only type "trigger" can have structure 2.0 or 2.2')
39
39
  }
40
40
  }
41
41
 
@@ -46,7 +46,7 @@ let WebhookSchema = new mongoose.Schema({
46
46
  body: {type: mongoose.Schema.Types.Mixed, validate: [{ validator: validators.validateNonEmptyStringKeyValuePairsOnly, msg: 'webhook body keys and values must be strings' }, { validator: validators.validateNoSpacesInObjectKeys, msg: 'webhook body keys cannot contain spaces' }]},
47
47
  structure: {
48
48
  type: String,
49
- enum: ['standard', 'tealium', 'mobivity', 'default', '2.0', '2.1'],
49
+ enum: ['standard', 'tealium', 'mobivity', 'default', '2.0', '2.1', '2.2'],
50
50
  default: function () {
51
51
  return this.type === 'trigger' ? '2.0' : 'standard'
52
52
  },