@bluedot-innovation/models 5.1.26 → 5.1.27-alpha.2
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 +3 -0
- package/__tests__/beacon/beacon.spec.js +29 -0
- package/helpers.js +1 -1
- package/models/Zone.js +8 -3
- package/package.json +1 -1
package/CHANGELOG.md
CHANGED
|
@@ -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]{
|
|
171
|
+
return /^([0-9a-f]{2}[\:]){5}([0-9a-f]{2})$/i.test(value);
|
|
172
172
|
}
|
|
173
173
|
|
|
174
174
|
const isValidObject = data => {
|
package/models/Zone.js
CHANGED
|
@@ -37,8 +37,9 @@ let customDataValidators = [
|
|
|
37
37
|
{validator: helpers.isValidCustomDataCount, msg: 'Only 5 custom data fields are allowed to be added per zone'}
|
|
38
38
|
];
|
|
39
39
|
|
|
40
|
-
const tagsFormation = (
|
|
41
|
-
|
|
40
|
+
const tagsFormation = (zone, next) => {
|
|
41
|
+
zone.tags = [...new Set(zone.tags.map(tag => tag.toLowerCase()))]
|
|
42
|
+
next()
|
|
42
43
|
}
|
|
43
44
|
|
|
44
45
|
let actionSchema = new Schema({},
|
|
@@ -84,7 +85,7 @@ let zoneSchema = new Schema({
|
|
|
84
85
|
message: '{VALUE} is not a number'
|
|
85
86
|
}
|
|
86
87
|
},
|
|
87
|
-
tags: {type: [String],
|
|
88
|
+
tags: {type: [String], validate: helpers.validateNotNull},
|
|
88
89
|
conditions: {
|
|
89
90
|
type: [conditionSchema],
|
|
90
91
|
validate: {
|
|
@@ -149,6 +150,10 @@ zoneSchema.pre('validate', function(next) {
|
|
|
149
150
|
}).catch((error) => console.log('Validation error ', error));
|
|
150
151
|
})
|
|
151
152
|
|
|
153
|
+
zoneSchema.pre('save', function (next) {
|
|
154
|
+
tagsFormation(this, next)
|
|
155
|
+
})
|
|
156
|
+
|
|
152
157
|
// optional mongoose
|
|
153
158
|
const model = (mongooseInstance) => {
|
|
154
159
|
let Zone
|
package/package.json
CHANGED