@bluedot-innovation/models 3.0.6-alpha.1 → 3.0.6-alpha.3
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
|
@@ -5,8 +5,8 @@
|
|
|
5
5
|
"property": "beaconType",
|
|
6
6
|
"pairings": [
|
|
7
7
|
{"value": "ios", "requiredFields": ["major", "minor"]},
|
|
8
|
-
{"value": "android", "requiredFields": ["
|
|
9
|
-
{"value": "both", "requiredFields": ["major", "minor", "
|
|
8
|
+
{"value": "android", "requiredFields": ["macAddress"]},
|
|
9
|
+
{"value": "both", "requiredFields": ["major", "minor", "macAddress"]}
|
|
10
10
|
]
|
|
11
11
|
}
|
|
12
12
|
]
|
|
@@ -3,8 +3,8 @@ let mongoose = require('mongoose')
|
|
|
3
3
|
mongoose.Promise = global.Promise
|
|
4
4
|
|
|
5
5
|
let BeaconModel = require('../../Models').Beacon(mongoose)
|
|
6
|
-
let
|
|
7
|
-
let
|
|
6
|
+
let describe = require('mocha').describe
|
|
7
|
+
let it = require('mocha').it
|
|
8
8
|
let chai = require('chai')
|
|
9
9
|
|
|
10
10
|
let assert = chai.assert
|
|
@@ -19,9 +19,9 @@ beforeEach(() => {
|
|
|
19
19
|
beacon = JSON.parse(JSON.stringify(require('./beacon.data.json')))
|
|
20
20
|
})
|
|
21
21
|
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
22
|
+
describe('Beacon', () => {
|
|
23
|
+
describe('Valid Beacon', () => {
|
|
24
|
+
it('should validate a valid beacon', (done) => {
|
|
25
25
|
const Beacon = new BeaconModel(beacon)
|
|
26
26
|
Beacon.validate((err, res) => {
|
|
27
27
|
assert.notExists(res)
|
|
@@ -29,7 +29,7 @@ testCase('Beacon', () => {
|
|
|
29
29
|
done()
|
|
30
30
|
})
|
|
31
31
|
})
|
|
32
|
-
|
|
32
|
+
it('should accept a valid API Key and customer API Key', (done) => {
|
|
33
33
|
beacon.apiKey = '23a01af0-232a-4518-9c0e-323fb773f5ef'
|
|
34
34
|
beacon.customerApiKey = '23a01af0-232a-4518-9c0e-323fb773ffff'
|
|
35
35
|
let Beacon = new BeaconModel(beacon)
|
|
@@ -41,8 +41,8 @@ testCase('Beacon', () => {
|
|
|
41
41
|
})
|
|
42
42
|
})
|
|
43
43
|
|
|
44
|
-
|
|
45
|
-
|
|
44
|
+
describe('Invalid Beacon', () => {
|
|
45
|
+
it('should not validate a beacon with invalid Beacon', (done) => {
|
|
46
46
|
delete beacon[rules.requiredFields[0]]
|
|
47
47
|
let Beacon = new BeaconModel(beacon)
|
|
48
48
|
Beacon.validate((err, res) => {
|
|
@@ -51,12 +51,14 @@ testCase('Beacon', () => {
|
|
|
51
51
|
done()
|
|
52
52
|
})
|
|
53
53
|
})
|
|
54
|
-
|
|
54
|
+
|
|
55
|
+
describe('check each required property of the model and validate that it is present', () => {
|
|
55
56
|
let dependentRequiredFields = rules.dependentRequiredFields
|
|
56
|
-
dependentRequiredFields.
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
57
|
+
dependentRequiredFields.forEach((parent) => {
|
|
58
|
+
console.log("parent", parent)
|
|
59
|
+
parent.pairings.forEach((i) => {
|
|
60
|
+
i.requiredFields.forEach((field) => {
|
|
61
|
+
it(`should throw an error with property '${parent.property}' if '${i.value}' is selected and '${field}' is invalid`, (done) => {
|
|
60
62
|
// delete beacon[field] i.e. txPower from beacon
|
|
61
63
|
delete beacon[field]
|
|
62
64
|
// set required dependent field property
|
|
@@ -74,10 +76,11 @@ testCase('Beacon', () => {
|
|
|
74
76
|
})
|
|
75
77
|
})
|
|
76
78
|
})
|
|
77
|
-
|
|
79
|
+
|
|
80
|
+
describe('check each required property of the model and validate that it is present', () => {
|
|
78
81
|
let requiredFields = rules.requiredFields
|
|
79
|
-
requiredFields.
|
|
80
|
-
|
|
82
|
+
requiredFields.forEach((i) => {
|
|
83
|
+
it(`should throw an error with property '${i}' if '${i}' is not present`, (done) => {
|
|
81
84
|
// delete i from geofeatures' beacon child
|
|
82
85
|
delete beacon[i]
|
|
83
86
|
let Beacon = new BeaconModel(beacon)
|
package/models/Beacon.js
CHANGED
|
@@ -4,14 +4,9 @@ let Point = require('../schemas/Point')
|
|
|
4
4
|
let PointGeometry = require('../schemas/PointGeometry')
|
|
5
5
|
let uuidv4 = require('uuid/v4')
|
|
6
6
|
let patcher = require('mongoose-json-patch')
|
|
7
|
-
let helpers = require('../helpers')
|
|
8
7
|
|
|
9
8
|
let schema = {
|
|
10
|
-
_id: {
|
|
11
|
-
type: String,
|
|
12
|
-
required: true,
|
|
13
|
-
validator: helpers.validateUUIDv4
|
|
14
|
-
},
|
|
9
|
+
_id: {type: String, default: uuidv4},
|
|
15
10
|
name: {type: String, required: [true, 'name is required.']},
|
|
16
11
|
description: {type: String, default: ''},
|
|
17
12
|
creationTime: {type: Date, default: Date.now},
|
|
@@ -72,11 +67,11 @@ function validateBeaconType (v, magicCallback) {
|
|
|
72
67
|
let bothRegex = new RegExp(/(both)/ig)
|
|
73
68
|
|
|
74
69
|
if (androidRegex.test(beaconType)) {
|
|
75
|
-
magicCallback((!!macAddress
|
|
70
|
+
magicCallback((!!macAddress), 'Beacon type `Android` must have a mac address')
|
|
76
71
|
} else if (iosRegex.test(beaconType)) {
|
|
77
72
|
magicCallback((!!minor && !!major), 'Beacon type `IOS` must have both minor and major values')
|
|
78
73
|
} else if (bothRegex.test(beaconType)) {
|
|
79
|
-
magicCallback((!!minor && !!major && !!
|
|
74
|
+
magicCallback((!!minor && !!major && !!macAddress), 'Beacon type `Both` must have all of minor, major, and mac address values')
|
|
80
75
|
} else {
|
|
81
76
|
magicCallback(true)
|
|
82
77
|
}
|
package/package.json
CHANGED