@bluedot-innovation/models 7.0.3 → 7.0.4

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,11 +1,5 @@
1
- ## 7.0.3
2
- - Reverted changes on 7.0.2 for renaming of doorbell premigration
3
- - Renamed doorbell trigger type to wave
4
-
5
- ## 7.0.2
6
- - Removed tempo webhooks array for post doorbell migration deployment
7
- - Removed tempo destinationId for post doorbell migration deployment
8
- - Removed geoTrigger type from webhooks
1
+ ## 7.0.4
2
+ - Re-added Circle radius to be > 5m
9
3
 
10
4
  ## 7.0.1
11
5
  - Added tempo webhooks array back for migration
@@ -17,6 +11,9 @@
17
11
  - BREAKING CHANGE - Moved zone destinationId to object root and removed tempo object from zone
18
12
  - Added 'doorbell' type to project webhooks
19
13
 
14
+ ## 6.2.12
15
+ - Re-added Circle radius to be > 5m
16
+
20
17
  ## 6.2.11
21
18
  - Replace `isAsync` validators with Mongoose 5.x validators
22
19
 
@@ -51,6 +51,18 @@ testCase('Circle', () => {
51
51
  })
52
52
 
53
53
  testCase('Invalid Circle', () => {
54
+ // BD2571
55
+ assertions('should not validate a Circle with radius <5 meters', (done) => {
56
+ circle.radius = 3
57
+ let Circle = new CircleModelBuiltInMongoose(circle)
58
+ Circle.validate((err, res) => {
59
+ assert.exists(err)
60
+ assert.isObject(err.errors)
61
+ assert.strictEqual(err.errors.radius.message, `radius [3m] must be greater than 5m`)
62
+ done()
63
+ })
64
+ })
65
+
54
66
  assertions('should not validate a Circle with no radius', (done) => {
55
67
  delete circle.radius
56
68
  let Circle = new CircleModel(circle)
@@ -7,7 +7,7 @@
7
7
  "accountId":"b0824b76-ce73-4fcf-81f8-1b63edb1114e",
8
8
  "webhooks": [
9
9
  {
10
- "type": "trigger",
10
+ "type": "geoTrigger",
11
11
  "url": "https://webhooklistener.bluedotinnovation.com",
12
12
  "headers" : {
13
13
  "securityToken" : "value"
@@ -21,7 +21,14 @@
21
21
  }
22
22
  },
23
23
  {
24
- "type": "wave",
24
+ "type": "doorbell",
25
+ "url": "https://webhooklistener.bluedotinnovation.com",
26
+ "headers" : {
27
+ "securityToken" : "value"
28
+ }
29
+ },
30
+ {
31
+ "type": "trigger",
25
32
  "url": "https://webhooklistener.bluedotinnovation.com",
26
33
  "headers" : {
27
34
  "securityToken" : "value"
@@ -6,7 +6,7 @@
6
6
  "name": "A New Project",
7
7
  "accountId":"b0824b76-ce73-4fcf-81f8-1b63edb1114e",
8
8
  "webhooks": {
9
- "type": "trigger",
9
+ "type": "geoTrigger",
10
10
  "url": "https://webhooklistener.bluedotinnovation.com",
11
11
  "headers" : {
12
12
  "securityToken" : "value"
@@ -92,7 +92,7 @@ testCase('Project', () => {
92
92
  })
93
93
 
94
94
  // TODO: Remove trigger type after migration
95
- assertions(`should not validate if one of webhooks have a type other than 'tempo', 'wave' or 'trigger'`, (done) => {
95
+ assertions(`should not validate if one of webhooks have a type other than 'geoTrigger', 'tempo', 'doorbell' or 'trigger'`, (done) => {
96
96
  project.webhooks.push({
97
97
  "type": "sandwich",
98
98
  "url": "https://webhooklistener.bluedotinnovation.com",
@@ -280,7 +280,8 @@ testCase('Project', () => {
280
280
  })
281
281
 
282
282
  testCase('should not validate if webhooks contains two webhooks of the same type', () => {
283
- const webhookTypes = ['tempo', 'wave', 'trigger']
283
+ // TODO: Remove trigger type after migration
284
+ const webhookTypes = ['geoTrigger', 'tempo', 'doorbell', 'trigger']
284
285
 
285
286
  webhookTypes.map(webhookType => {
286
287
  assertions(`should not validate if there are duplicate ${webhookType} webhooks`, (done) => {
package/helpers.js CHANGED
@@ -267,12 +267,12 @@ helpers.validateDestinationIdGeofeatureType = function(destinationId) {
267
267
  }
268
268
 
269
269
  helpers.validateNoDuplicateWebhookTypes = function(webhookArray) {
270
- const webhookCounts = {}
270
+ // TODO: Remove trigger type after migration
271
+ const webhookTypes = ['geoTrigger', 'tempo', 'doorbell', 'trigger']
272
+ const webhookCounts = {};
273
+ webhookTypes.forEach(webhookType => webhookCounts[webhookType] = 0);
271
274
  let duplicateFound = false
272
275
  webhookArray.forEach(webhook => {
273
- if(webhookCounts[webhook.type] === undefined){
274
- webhookCounts[webhook.type] = 0
275
- }
276
276
  if(webhookCounts[webhook.type] > 0){
277
277
  duplicateFound = true
278
278
  }
@@ -10,7 +10,17 @@ let schema = {
10
10
  name: {type: String, required: [true, 'name is required. ']},
11
11
  color: String,
12
12
  accuracy: {type: String, enum: Object.values(ZoneEnum.fenceAccuracy)},
13
- radius: {type: Double, required: [true, 'radius is required. '], min: 5},
13
+ radius: {
14
+ type: Double,
15
+ required: [true, 'radius is required. '],
16
+ validate: {
17
+ validator: function(v) {
18
+ return (v >= 5) ;
19
+ },
20
+ message: props => `radius [${props.value}m] must be greater than 5m`
21
+ },
22
+
23
+ },
14
24
  center: {type: Point, required: [true, 'center is required. ']}
15
25
  }
16
26
 
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@bluedot-innovation/models",
3
- "version": "7.0.3",
3
+ "version": "7.0.4",
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",
@@ -2,7 +2,8 @@ let mongoose = require('mongoose')
2
2
  let validators = require('../utils/validators')
3
3
 
4
4
  let WebhookSchema = new mongoose.Schema({
5
- type: {type: String, enum: ['tempo', 'wave', 'trigger'], required: [true, 'webhook type is required']},
5
+ // TODO: Remove trigger type after migration
6
+ type: {type: String, enum: ['geoTrigger', 'tempo', 'doorbell', 'trigger'], required: [true, 'webhook type is required']},
6
7
  url: {type: String, required: [true, 'URL is required'], validate: {validator: validators.validateUrl, msg: 'Please enter a valid URL'}},
7
8
  headers: {type: mongoose.Schema.Types.Mixed, validate: { validator: validateHeaderlength, msg: 'Header object can only have 1 key <-> value pair' }}
8
9
  }, {