@bluedot-innovation/models 5.1.15 → 5.1.17-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 +6 -0
- package/__tests__/beacon/beacon.spec.js +22 -0
- package/models/Beacon.js +8 -1
- package/models/User.js +2 -1
- package/models/Zone.js +1 -1
- package/package.json +1 -1
package/CHANGELOG.md
CHANGED
|
@@ -116,5 +116,27 @@ describe('Beacon', () => {
|
|
|
116
116
|
})
|
|
117
117
|
})
|
|
118
118
|
})
|
|
119
|
+
|
|
120
|
+
describe('should fail validation if the txPower is not a number in the range from -100 to 0', () => {
|
|
121
|
+
const beaconTypes = ['Android', 'Both'];
|
|
122
|
+
const invalidTxPowerValues = ['dump_text', 10]
|
|
123
|
+
|
|
124
|
+
beaconTypes.forEach(beaconType => {
|
|
125
|
+
invalidTxPowerValues.forEach(value => {
|
|
126
|
+
it(`should throw an error with txPower with value: ${value} and beaconType: ${beaconType}`, (done) => {
|
|
127
|
+
let Beacon = new BeaconModel(beacon);
|
|
128
|
+
Beacon.beaconType = beaconType;
|
|
129
|
+
Beacon.txPower = value
|
|
130
|
+
Beacon.validate((err, res) => {
|
|
131
|
+
assert.notExists(res)
|
|
132
|
+
assert.exists(err, 'err object should exist')
|
|
133
|
+
assert.isObject(err)
|
|
134
|
+
assert.nestedProperty(err, 'errors.txPower' ,`error should have a txPower property`)
|
|
135
|
+
done()
|
|
136
|
+
})
|
|
137
|
+
})
|
|
138
|
+
})
|
|
139
|
+
})
|
|
140
|
+
})
|
|
119
141
|
})
|
|
120
142
|
})
|
package/models/Beacon.js
CHANGED
|
@@ -30,6 +30,13 @@ function isRequiredForIOS(beaconType){
|
|
|
30
30
|
return beaconType.toLowerCase() === BeaconEnum.IOS.toLowerCase() || beaconType.toLowerCase() === BeaconEnum.BOTH.toLowerCase()
|
|
31
31
|
}
|
|
32
32
|
|
|
33
|
+
function validateTxPower(beaconType, txPower) {
|
|
34
|
+
if(isRequiredForAndroid(beaconType)){
|
|
35
|
+
return txPower >= -100 && txPower <= 0
|
|
36
|
+
}
|
|
37
|
+
return true
|
|
38
|
+
}
|
|
39
|
+
|
|
33
40
|
|
|
34
41
|
let schema = {
|
|
35
42
|
_id: {type: String, default: uuidv4},
|
|
@@ -49,7 +56,7 @@ let schema = {
|
|
|
49
56
|
// These must be unique
|
|
50
57
|
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)']},
|
|
51
58
|
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)']},
|
|
52
|
-
txPower: {type: Number, validate:
|
|
59
|
+
txPower: {type: Number, validate: [function() {return validateTxPower(this.beaconType, this.txPower)}, 'TxPower needs to be within range(-100 to 0)']},
|
|
53
60
|
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']},
|
|
54
61
|
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']}
|
|
55
62
|
}
|
package/models/User.js
CHANGED
package/models/Zone.js
CHANGED
|
@@ -59,7 +59,7 @@ let zoneSchema = new Schema({
|
|
|
59
59
|
message: '{VALUE} is not a number'
|
|
60
60
|
}
|
|
61
61
|
},
|
|
62
|
-
tags: {type: [String], validate: helpers.validateNotNull},
|
|
62
|
+
tags: {type: [String], lowercase: true, validate: helpers.validateNotNull},
|
|
63
63
|
conditions: {
|
|
64
64
|
type: [conditionSchema]
|
|
65
65
|
},
|
package/package.json
CHANGED