@bluedot-innovation/models 5.1.24 → 5.1.26

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
+ ## 5.1.26
2
+ - Validate txPower for decimals
3
+
4
+ ## 5.1.25
5
+ - Null validation for array fields: conditions, actions
6
+
1
7
  ## 5.1.24
2
8
  - Using Double type for floating-point numbers instead of the type Number
3
9
 
@@ -119,7 +119,7 @@ describe('Beacon', () => {
119
119
 
120
120
  describe('should fail validation if the txPower is not a number in the range from -100 to 0', () => {
121
121
  const beaconTypes = ['Android', 'Both'];
122
- const invalidTxPowerValues = ['dump_text', 10]
122
+ const invalidTxPowerValues = ['dump_text', 10, -77.77]
123
123
 
124
124
  beaconTypes.forEach(beaconType => {
125
125
  invalidTxPowerValues.forEach(value => {
@@ -144,6 +144,17 @@ describe('Zone', () => {
144
144
  })
145
145
  })
146
146
 
147
+ it('should throw an error when actions is null', (done) => {
148
+ zone.actions = null
149
+ let Zone = new ZoneModel(zone)
150
+ Zone.validate((err, res) => {
151
+ assert.exists(err, 'err object should exist')
152
+ assert.isObject(err)
153
+ assert.match(err.message, /(actions must have a value)/i)
154
+ done()
155
+ })
156
+ })
157
+
147
158
  it('should throw an error when a condition is invalid', (done) => {
148
159
  zone.conditions[0].startDate = 'abc'
149
160
  let Zone = new ZoneModel(zone)
@@ -177,6 +188,17 @@ describe('Zone', () => {
177
188
  })
178
189
  })
179
190
 
191
+ it('should throw an error when a conditions is null', (done) => {
192
+ zone.conditions = null
193
+ let Zone = new ZoneModel(zone)
194
+ Zone.validate((err, res) => {
195
+ assert.exists(err, 'err object should exist')
196
+ assert.isObject(err)
197
+ assert.match(err.message, /(conditions must have a value)/i)
198
+ done()
199
+ })
200
+ })
201
+
180
202
  it('should throw an error when custom data is null', (done) => {
181
203
  zone.customData = null
182
204
  let Zone = new ZoneModel(zone)
package/models/Beacon.js CHANGED
@@ -32,6 +32,10 @@ function isRequiredForIOS(beaconType){
32
32
 
33
33
  function validateTxPower(beaconType, txPower) {
34
34
  if(isRequiredForAndroid(beaconType)){
35
+ if(txPower % 1 != 0) {
36
+ return false;
37
+ }
38
+
35
39
  return txPower >= -100 && txPower <= 0
36
40
  }
37
41
  return true
@@ -56,7 +60,7 @@ let schema = {
56
60
  // These must be unique
57
61
  major: {type: Number, required: [function() {return isRequiredForIOS(this.beaconType)}, 'Please enter a major'], validate: [function() {return validateMajorMinor(this.beaconType, this.major)}, 'Major needs to be within range(0-65535)']},
58
62
  minor: {type: Number, required: [function() {return isRequiredForIOS(this.beaconType)}, 'Please enter a minor'], validate: [function() {return validateMajorMinor(this.beaconType, this.minor)}, 'Minor needs to be within range(0-65535)']},
59
- txPower: {type: Number, validate: [function() {return validateTxPower(this.beaconType, this.txPower)}, 'TxPower needs to be within range(-100 to 0)']},
63
+ txPower: {type: Number, validate: [function() {return validateTxPower(this.beaconType, this.txPower)}, 'TxPower needs to be within range(-100 to 0) without decimals']},
60
64
  macAddress: {type: String, required: [function() {return isRequiredForAndroid(this.beaconType)}, 'Please enter a Mac Address'], validate: [function () {return validateMacAddress(this.beaconType, this.macAddress)}, 'Please enter a valid Mac Address']},
61
65
  proximityUUID: {type: String, required: [function() {return isRequiredForIOS(this.beaconType)}, 'Please enter a Proximity UUID'], validate: [function () {return validateProximityUUID(this.beaconType, this.proximityUUID)}, 'Please enter a valid Proximity UUID']}
62
66
  }
package/models/Zone.js CHANGED
@@ -86,10 +86,18 @@ let zoneSchema = new Schema({
86
86
  },
87
87
  tags: {type: [String], set : tagsFormation, validate: helpers.validateNotNull},
88
88
  conditions: {
89
- type: [conditionSchema]
89
+ type: [conditionSchema],
90
+ validate: {
91
+ validator: helpers.validateNotNull,
92
+ message: 'conditions must have a value'
93
+ }
90
94
  },
91
95
  actions: {
92
- type: [actionSchema]
96
+ type: [actionSchema],
97
+ validate: {
98
+ validator: helpers.validateNotNull,
99
+ message: 'actions must have a value'
100
+ }
93
101
  },
94
102
  geofeatures: {
95
103
  type: [geofeatureSchema],
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@bluedot-innovation/models",
3
- "version": "5.1.24",
3
+ "version": "5.1.26",
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",