@bluedot-innovation/models 3.0.6-alpha.2 → 3.0.6
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 +1 -1
- package/__tests__/beacon/beacon.data.json +0 -1
- package/__tests__/beacon/beacon.rules.json +2 -2
- package/__tests__/beacon/beacon.spec.js +19 -16
- package/__tests__/geofeature/zoneBeacon/zoneBeacon.spec.js +9 -10
- package/__tests__/project/project.data.json +1 -2
- package/__tests__/user/user.data.js +0 -1
- package/__tests__/zone/zone.data.json +0 -1
- package/__tests__/zone/zone.geofeatures.spec.js +10 -10
- package/models/Beacon.js +3 -8
- package/models/Project.js +1 -5
- package/models/User.js +2 -5
- package/models/Zone.js +1 -5
- package/models/ZoneBeacon.js +0 -1
- package/package.json +1 -1
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)
|
|
@@ -3,8 +3,8 @@ let mongoose = require('mongoose')
|
|
|
3
3
|
mongoose.Promise = global.Promise
|
|
4
4
|
|
|
5
5
|
let ZoneBeaconModel = require('../../../Models').ZoneBeacon(mongoose)
|
|
6
|
-
let
|
|
7
|
-
let
|
|
6
|
+
let testCase = require('mocha').describe
|
|
7
|
+
let assertions = require('mocha').it
|
|
8
8
|
let chai = require('chai')
|
|
9
9
|
|
|
10
10
|
let assert = chai.assert
|
|
@@ -19,12 +19,11 @@ beforeEach(() => {
|
|
|
19
19
|
zoneBeacon = JSON.parse(JSON.stringify(require('./zoneBeacon.data.json')))
|
|
20
20
|
})
|
|
21
21
|
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
22
|
+
testCase('ZoneBeacon', () => {
|
|
23
|
+
testCase('Valid ZoneBeacon', () => {
|
|
24
|
+
assertions('should validate a valid zoneBeacon ', (done) => {
|
|
25
25
|
const ZoneBeacon = new ZoneBeaconModel(zoneBeacon)
|
|
26
26
|
ZoneBeacon.validate((err, res) => {
|
|
27
|
-
console.log("err", err)
|
|
28
27
|
assert.notExists(res)
|
|
29
28
|
assert(err === null, 'err should equals null')
|
|
30
29
|
done()
|
|
@@ -32,8 +31,8 @@ describe('ZoneBeacon', () => {
|
|
|
32
31
|
})
|
|
33
32
|
})
|
|
34
33
|
|
|
35
|
-
|
|
36
|
-
|
|
34
|
+
testCase('Invalid ZoneBeacon', () => {
|
|
35
|
+
assertions('should not validate a zoneBeacon with invalid ZoneBeacon', (done) => {
|
|
37
36
|
delete zoneBeacon[rules.requiredFields[0]]
|
|
38
37
|
let ZoneBeacon = new ZoneBeaconModel(zoneBeacon)
|
|
39
38
|
ZoneBeacon.validate((err, res) => {
|
|
@@ -42,10 +41,10 @@ describe('ZoneBeacon', () => {
|
|
|
42
41
|
done()
|
|
43
42
|
})
|
|
44
43
|
})
|
|
45
|
-
|
|
44
|
+
testCase('check each required property of the model and validate that it is present', () => {
|
|
46
45
|
let requiredFields = rules.requiredFields
|
|
47
46
|
requiredFields.map((i) => {
|
|
48
|
-
|
|
47
|
+
assertions(`should throw an error with property '${i}' if '${i}' is not present`, (done) => {
|
|
49
48
|
// delete i from geofeatures' zoneBeacon child
|
|
50
49
|
delete zoneBeacon[i]
|
|
51
50
|
let ZoneBeacon = new ZoneBeaconModel(zoneBeacon)
|
|
@@ -1,5 +1,4 @@
|
|
|
1
1
|
{
|
|
2
|
-
"_id": "11d57188-269a-4028-8034-1c08b76ed6a8",
|
|
3
2
|
"state": "ACTIVE",
|
|
4
3
|
"nextRuleUpdateInterval": 3600,
|
|
5
4
|
"lastUpdateTime": "2018-02-14T04:12:02.103Z",
|
|
@@ -12,4 +11,4 @@
|
|
|
12
11
|
"enabled": true
|
|
13
12
|
},
|
|
14
13
|
"firebaseApiKey": "88888888-4444-4444-4444-121212121212"
|
|
15
|
-
}
|
|
14
|
+
}
|
|
@@ -3,8 +3,8 @@ let mongoose = require('mongoose')
|
|
|
3
3
|
mongoose.Promise = global.Promise
|
|
4
4
|
|
|
5
5
|
let ZoneModel = require('../../Models').Zone(mongoose)
|
|
6
|
-
let
|
|
7
|
-
let
|
|
6
|
+
let testCase = require('mocha').describe
|
|
7
|
+
let assertions = require('mocha').it
|
|
8
8
|
let chai = require('chai')
|
|
9
9
|
let assert = chai.assert
|
|
10
10
|
let mocha = require('mocha')
|
|
@@ -27,12 +27,12 @@ beforeEach(() => {
|
|
|
27
27
|
delete zone.actions
|
|
28
28
|
})
|
|
29
29
|
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
30
|
+
testCase('Zone - Action', () => {
|
|
31
|
+
testCase('Valid Zone - Action', () => {
|
|
32
|
+
assertions('should not throw an error when a valid geofeature is instantiated within a zone', (done) => {
|
|
33
33
|
let Zone = new ZoneModel(zone)
|
|
34
34
|
Zone.validate((err, res) => {
|
|
35
|
-
console.log(
|
|
35
|
+
console.log(err)
|
|
36
36
|
assert.notExists(res)
|
|
37
37
|
assert(err === null, 'err should be null')
|
|
38
38
|
done()
|
|
@@ -40,8 +40,8 @@ describe('Zone - Action', () => {
|
|
|
40
40
|
})
|
|
41
41
|
})
|
|
42
42
|
|
|
43
|
-
|
|
44
|
-
|
|
43
|
+
testCase('Invalid Zone - Action', () => {
|
|
44
|
+
assertions('should throw an error when an invalid geofeature is instantiated within a zone', (done) => {
|
|
45
45
|
delete zone.geofeatures[0].name
|
|
46
46
|
let Zone = new ZoneModel(zone)
|
|
47
47
|
Zone.validate((err, res) => {
|
|
@@ -51,7 +51,7 @@ describe('Zone - Action', () => {
|
|
|
51
51
|
done()
|
|
52
52
|
})
|
|
53
53
|
})
|
|
54
|
-
|
|
54
|
+
assertions('should throw an error when an invalid geofeature (complex validation) is instantiated within a zone', (done) => {
|
|
55
55
|
delete zone.geofeatures[0].minor
|
|
56
56
|
let Zone = new ZoneModel(zone)
|
|
57
57
|
Zone.validate((err, res) => {
|
|
@@ -61,7 +61,7 @@ describe('Zone - Action', () => {
|
|
|
61
61
|
done()
|
|
62
62
|
})
|
|
63
63
|
})
|
|
64
|
-
|
|
64
|
+
assertions('should throw an error when an no geofeature is instantiated within a zone', (done) => {
|
|
65
65
|
zone.geofeatures = []
|
|
66
66
|
let Zone = new ZoneModel(zone)
|
|
67
67
|
Zone.validate((err, res) => {
|
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/models/Project.js
CHANGED
|
@@ -14,11 +14,7 @@ let helpers = require('../helpers')
|
|
|
14
14
|
let WebhookSchema = require('../schemas/Webhook')
|
|
15
15
|
|
|
16
16
|
let ProjectSchema = new mongoose.Schema({
|
|
17
|
-
_id: {
|
|
18
|
-
type: String,
|
|
19
|
-
required: true,
|
|
20
|
-
validator: helpers.validateUUIDv4
|
|
21
|
-
},
|
|
17
|
+
_id: {type: String, default: uuidv4},
|
|
22
18
|
apiKey: {type: String, default: uuidv4}, // Backwards compatability
|
|
23
19
|
state: {type: String, default: StateEnum.active},
|
|
24
20
|
nextRuleUpdateInterval: {
|
package/models/User.js
CHANGED
|
@@ -8,13 +8,10 @@ const mongoose = require('mongoose')
|
|
|
8
8
|
const patcher = require('mongoose-json-patch')
|
|
9
9
|
const helpers = require('../helpers')
|
|
10
10
|
const ProjectPermission = require('../schemas/ProjectPermission')
|
|
11
|
+
const uuidv4 = require('uuid/v4')
|
|
11
12
|
|
|
12
13
|
let UserSchema = new mongoose.Schema({
|
|
13
|
-
_id: {
|
|
14
|
-
type: String,
|
|
15
|
-
required: true,
|
|
16
|
-
validator: helpers.validateUUIDv4
|
|
17
|
-
},
|
|
14
|
+
_id: {type: String, default: uuidv4},
|
|
18
15
|
username: {
|
|
19
16
|
type: String,
|
|
20
17
|
required: true,
|
package/models/Zone.js
CHANGED
|
@@ -45,11 +45,7 @@ let geofeatureSchema = new Schema({},
|
|
|
45
45
|
{ discriminatorKey: 'type', _id: false })
|
|
46
46
|
|
|
47
47
|
let zoneSchema = new Schema({
|
|
48
|
-
_id: {
|
|
49
|
-
type: String,
|
|
50
|
-
required: true,
|
|
51
|
-
validator: helpers.validateUUIDv4
|
|
52
|
-
},
|
|
48
|
+
_id: {type: String, default: uuidv4},
|
|
53
49
|
name: {type: String, required: [true, 'name is required']},
|
|
54
50
|
minimumRetriggerTime: {
|
|
55
51
|
type: Number,
|
package/models/ZoneBeacon.js
CHANGED
package/package.json
CHANGED