@bluedot-innovation/models 5.1.26 → 5.1.27-alpha.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,6 @@
1
+ ## 5.1.27
2
+ - Fixed validations for `macAddress` in Beacon model
3
+
1
4
  ## 5.1.26
2
5
  - Validate txPower for decimals
3
6
 
@@ -138,5 +138,34 @@ describe('Beacon', () => {
138
138
  })
139
139
  })
140
140
  })
141
+
142
+ describe('should fail validation when passed an invalid Mac Address', () => {
143
+ const beaconTypes = ['Android', 'Both'];
144
+ const invalidMacAddresses = [
145
+ 'invalid mac address',
146
+ 1324,
147
+ false,
148
+ undefined,
149
+ 'F:9:0:4:F:2',
150
+ 'F:90:0B:4E:F0:22',
151
+ ]
152
+
153
+ beaconTypes.forEach(beaconType => {
154
+ invalidMacAddresses.forEach(value => {
155
+ it(`should throw an error with a Mac Address with value: ${value} and beaconType: ${beaconType}`, (done) => {
156
+ let Beacon = new BeaconModel(beacon);
157
+ Beacon.beaconType = beaconType;
158
+ Beacon.macAddress = value
159
+ Beacon.validate((err, res) => {
160
+ assert.notExists(res)
161
+ assert.exists(err, 'err object should exist')
162
+ assert.isObject(err)
163
+ assert.nestedProperty(err, 'errors.macAddress' ,`error should have a macAddress property`)
164
+ done()
165
+ })
166
+ })
167
+ })
168
+ })
169
+ })
141
170
  })
142
171
  })
package/helpers.js CHANGED
@@ -168,7 +168,7 @@ helpers.validateNotNull = function(value) {
168
168
  }
169
169
 
170
170
  helpers.isValidMacAddress = function (value){
171
- return /^([0-9a-f]{1,2}[\:]){5}([0-9a-f]{1,2})$/i.test(value);
171
+ return /^([0-9a-f]{2}[\:]){5}([0-9a-f]{2})$/i.test(value);
172
172
  }
173
173
 
174
174
  const isValidObject = data => {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@bluedot-innovation/models",
3
- "version": "5.1.26",
3
+ "version": "5.1.27-alpha.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",