@bluedot-innovation/models 5.1.24 → 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 +9 -0
- package/__tests__/beacon/beacon.spec.js +30 -1
- package/__tests__/zone/zone.spec.js +22 -0
- package/helpers.js +1 -1
- package/models/Beacon.js +5 -1
- package/models/Zone.js +10 -2
- package/package.json +1 -1
package/CHANGELOG.md
CHANGED
|
@@ -1,3 +1,12 @@
|
|
|
1
|
+
## 5.1.27
|
|
2
|
+
- Fixed validations for `macAddress` in Beacon model
|
|
3
|
+
|
|
4
|
+
## 5.1.26
|
|
5
|
+
- Validate txPower for decimals
|
|
6
|
+
|
|
7
|
+
## 5.1.25
|
|
8
|
+
- Null validation for array fields: conditions, actions
|
|
9
|
+
|
|
1
10
|
## 5.1.24
|
|
2
11
|
- Using Double type for floating-point numbers instead of the type Number
|
|
3
12
|
|
|
@@ -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 => {
|
|
@@ -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
|
})
|
|
@@ -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/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/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