@bluedot-innovation/models 2.0.5-alpha.4 → 2.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/Models.js +7 -7
- package/__tests__/beacon/beacon.data.json +4 -2
- package/__tests__/beacon/beacon.rules.json +2 -2
- package/__tests__/beacon/beacon.spec.js +5 -5
- package/__tests__/geofeature/zoneBeacon/zoneBeacon.data.json +16 -0
- package/__tests__/geofeature/zoneBeacon/zoneBeacon.rules.json +13 -0
- package/__tests__/geofeature/zoneBeacon/zoneBeacon.spec.js +62 -0
- package/__tests__/zone/zone.data.json +4 -2
- package/__tests__/zone/zone.geofeatures.spec.js +2 -1
- package/models/Beacon.js +2 -0
- package/models/BoundingBox.js +2 -0
- package/models/Circle.js +2 -0
- package/models/Polygon.js +1 -0
- package/models/Polyline.js +2 -0
- package/package.json +1 -1
- package/schemas/MultiLineStringGeometry.js +14 -0
- package/schemas/PointGeometry.js +14 -0
- package/schemas/PolygonGeometry.js +14 -0
package/Models.js
CHANGED
|
@@ -12,18 +12,18 @@ Models.BoundingBox = require('./models/BoundingBox').Model
|
|
|
12
12
|
Models.CalendarDateRangeFilter = require('./models/CalendarDateRangeFilter').Model
|
|
13
13
|
Models.Circle = require('./models/Circle').Model
|
|
14
14
|
Models.MessageAction = require('./models/MessageAction').Model
|
|
15
|
+
Models.MonthlyStat = require('./models/MonthlyStats').Model
|
|
15
16
|
Models.PercentageCrossedFilter = require('./models/PercentageCrossedFilter').Model
|
|
16
17
|
Models.Polygon = require('./models/Polygon').Model
|
|
17
18
|
Models.Polyline = require('./models/Polyline').Model
|
|
19
|
+
Models.Project = require('./models/Project').Model
|
|
20
|
+
Models.RuleRequestAggregation = require('./models/RuleRequestAggregation').Model
|
|
18
21
|
Models.SpeedFilter = require('./models/SpeedFilter').Model
|
|
19
22
|
Models.TimeOfDayRangeFilter = require('./models/TimeOfDayRangeFilter').Model
|
|
20
23
|
Models.UrlAction = require('./models/UrlAction').Model
|
|
21
24
|
Models.User = require('./models/User').Model
|
|
22
25
|
Models.Zone = require('./models/Zone').Model
|
|
23
|
-
Models.
|
|
24
|
-
Models.Project = require('./models/Project').Model
|
|
25
|
-
Models.MonthlyStat = require('./models/MonthlyStats').Model
|
|
26
|
-
Models.RuleRequestAggregation = require('./models/RuleRequestAggregation').Model
|
|
26
|
+
Models.ZoneBeacon = require('./models/ZoneBeacon').Model
|
|
27
27
|
|
|
28
28
|
let Schemas = {}
|
|
29
29
|
|
|
@@ -35,17 +35,17 @@ Schemas.BoundingBox = require('./models/BoundingBox').Schema
|
|
|
35
35
|
Schemas.CalendarDateRangeFilter = require('./models/CalendarDateRangeFilter').Schema
|
|
36
36
|
Schemas.Circle = require('./models/Circle').Schema
|
|
37
37
|
Schemas.MessageAction = require('./models/MessageAction').Schema
|
|
38
|
+
Schemas.MonthlyStat = require('./models/MonthlyStats').Schema
|
|
38
39
|
Schemas.PercentageCrossedFilter = require('./models/PercentageCrossedFilter').Schema
|
|
39
40
|
Schemas.Polygon = require('./models/Polygon').Schema
|
|
40
41
|
Schemas.Polyline = require('./models/Polyline').Schema
|
|
42
|
+
Schemas.Project = require('./models/Project').Schema
|
|
43
|
+
Schemas.RuleRequestAggregation = require('./models/RuleRequestAggregation').Schema
|
|
41
44
|
Schemas.SpeedFilter = require('./models/SpeedFilter').Schema
|
|
42
45
|
Schemas.TimeOfDayRangeFilter = require('./models/TimeOfDayRangeFilter').Schema
|
|
43
46
|
Schemas.UrlAction = require('./models/UrlAction').Schema
|
|
44
47
|
Schemas.User = require('./models/User').Schema
|
|
45
48
|
Schemas.Zone = require('./models/Zone').Schema
|
|
46
|
-
Schemas.Project = require('./models/Project').Schema
|
|
47
|
-
Schemas.MonthlyStat = require('./models/MonthlyStats').Schema
|
|
48
|
-
Schemas.RuleRequestAggregation = require('./models/RuleRequestAggregation').Schema
|
|
49
49
|
|
|
50
50
|
Models.Schemas = Schemas
|
|
51
51
|
|
|
@@ -2,8 +2,10 @@
|
|
|
2
2
|
"type": "beacon",
|
|
3
3
|
"name": "create beacon",
|
|
4
4
|
"proximityUUID": "23a01af0-232a-4518-9c0e-323fb773f5ef",
|
|
5
|
-
"
|
|
6
|
-
|
|
5
|
+
"location": {
|
|
6
|
+
"latitude": -37.8159544565362,
|
|
7
|
+
"longitude": 144.9723565578461
|
|
8
|
+
},
|
|
7
9
|
"beaconType": "Both",
|
|
8
10
|
"major": 10000,
|
|
9
11
|
"minor": 56466,
|
|
@@ -21,21 +21,21 @@ beforeEach(() => {
|
|
|
21
21
|
|
|
22
22
|
testCase('Beacon', () => {
|
|
23
23
|
testCase('Valid Beacon', () => {
|
|
24
|
-
assertions('should validate a valid beacon
|
|
25
|
-
|
|
24
|
+
assertions('should validate a valid beacon', (done) => {
|
|
25
|
+
const Beacon = new BeaconModel(beacon)
|
|
26
26
|
Beacon.validate((err, res) => {
|
|
27
27
|
assert.notExists(res)
|
|
28
|
-
assert(err === null, 'err should
|
|
28
|
+
assert(err === null, 'err should equal null')
|
|
29
29
|
done()
|
|
30
30
|
})
|
|
31
31
|
})
|
|
32
|
-
assertions('should accept a valid API Key and customer API Key
|
|
32
|
+
assertions('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)
|
|
36
36
|
Beacon.validate((err, res) => {
|
|
37
37
|
assert.notExists(res)
|
|
38
|
-
assert(err === null, 'err should
|
|
38
|
+
assert(err === null, 'err should equal null')
|
|
39
39
|
done()
|
|
40
40
|
})
|
|
41
41
|
})
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
{
|
|
2
|
+
"type": "beacon",
|
|
3
|
+
"name": "create beacon",
|
|
4
|
+
"proximityUUID": "23a01af0-232a-4518-9c0e-323fb773f5ef",
|
|
5
|
+
"location": {
|
|
6
|
+
"latitude": -37.8159544565362,
|
|
7
|
+
"longitude": 144.9723565578461
|
|
8
|
+
},
|
|
9
|
+
"beaconType": "Both",
|
|
10
|
+
"major": 10000,
|
|
11
|
+
"minor": 56466,
|
|
12
|
+
"txPower": -77,
|
|
13
|
+
"proximity": "Near",
|
|
14
|
+
"macAddress": "01:17:c5:31:84:19",
|
|
15
|
+
"accountId": "90a2ed18-86be-48e7-948b-393b8b679ef6"
|
|
16
|
+
}
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
{
|
|
2
|
+
"requiredFields":["name", "location", "beaconType"],
|
|
3
|
+
"dependentRequiredFields": [
|
|
4
|
+
{
|
|
5
|
+
"property": "beaconType",
|
|
6
|
+
"pairings": [
|
|
7
|
+
{"value": "ios", "requiredFields": ["major", "minor"]},
|
|
8
|
+
{"value": "android", "requiredFields": ["txPower", "macAddress"]},
|
|
9
|
+
{"value": "both", "requiredFields": ["major", "minor", "txPower", "macAddress"]}
|
|
10
|
+
]
|
|
11
|
+
}
|
|
12
|
+
]
|
|
13
|
+
}
|
|
@@ -0,0 +1,62 @@
|
|
|
1
|
+
let mongoose = require('mongoose')
|
|
2
|
+
|
|
3
|
+
mongoose.Promise = global.Promise
|
|
4
|
+
|
|
5
|
+
let ZoneBeaconModel = require('../../../Models').ZoneBeacon(mongoose)
|
|
6
|
+
let testCase = require('mocha').describe
|
|
7
|
+
let assertions = require('mocha').it
|
|
8
|
+
let chai = require('chai')
|
|
9
|
+
|
|
10
|
+
let assert = chai.assert
|
|
11
|
+
let mocha = require('mocha')
|
|
12
|
+
let beforeEach = mocha.beforeEach
|
|
13
|
+
|
|
14
|
+
let rules = require('./zoneBeacon.rules.json')
|
|
15
|
+
|
|
16
|
+
let zoneBeacon
|
|
17
|
+
|
|
18
|
+
beforeEach(() => {
|
|
19
|
+
zoneBeacon = JSON.parse(JSON.stringify(require('./zoneBeacon.data.json')))
|
|
20
|
+
})
|
|
21
|
+
|
|
22
|
+
testCase('ZoneBeacon', () => {
|
|
23
|
+
testCase('Valid ZoneBeacon', () => {
|
|
24
|
+
assertions('should validate a valid zoneBeacon ', (done) => {
|
|
25
|
+
const ZoneBeacon = new ZoneBeaconModel(zoneBeacon)
|
|
26
|
+
ZoneBeacon.validate((err, res) => {
|
|
27
|
+
assert.notExists(res)
|
|
28
|
+
assert(err === null, 'err should equals null')
|
|
29
|
+
done()
|
|
30
|
+
})
|
|
31
|
+
})
|
|
32
|
+
})
|
|
33
|
+
|
|
34
|
+
testCase('Invalid ZoneBeacon', () => {
|
|
35
|
+
assertions('should not validate a zoneBeacon with invalid ZoneBeacon', (done) => {
|
|
36
|
+
delete zoneBeacon[rules.requiredFields[0]]
|
|
37
|
+
let ZoneBeacon = new ZoneBeaconModel(zoneBeacon)
|
|
38
|
+
ZoneBeacon.validate((err, res) => {
|
|
39
|
+
assert.exists(err, 'err object should exist')
|
|
40
|
+
assert.isObject(err)
|
|
41
|
+
done()
|
|
42
|
+
})
|
|
43
|
+
})
|
|
44
|
+
testCase('check each required property of the model and validate that it is present', () => {
|
|
45
|
+
let requiredFields = rules.requiredFields
|
|
46
|
+
requiredFields.map((i) => {
|
|
47
|
+
assertions(`should throw an error with property '${i}' if '${i}' is not present`, (done) => {
|
|
48
|
+
// delete i from geofeatures' zoneBeacon child
|
|
49
|
+
delete zoneBeacon[i]
|
|
50
|
+
let ZoneBeacon = new ZoneBeaconModel(zoneBeacon)
|
|
51
|
+
ZoneBeacon.validate((err, res) => {
|
|
52
|
+
assert.notExists(res)
|
|
53
|
+
assert.exists(err, 'err object should exist')
|
|
54
|
+
assert.isObject(err)
|
|
55
|
+
assert.nestedProperty(err, `errors.${i}`, `error should have a ${i} property`)
|
|
56
|
+
done()
|
|
57
|
+
})
|
|
58
|
+
})
|
|
59
|
+
})
|
|
60
|
+
})
|
|
61
|
+
})
|
|
62
|
+
})
|
|
@@ -33,8 +33,10 @@
|
|
|
33
33
|
"type": "beacon",
|
|
34
34
|
"name": "create beacon",
|
|
35
35
|
"proximityUUID": "23a01af0-232a-4518-9c0e-323fb773f5ef",
|
|
36
|
-
"
|
|
37
|
-
|
|
36
|
+
"location": {
|
|
37
|
+
"latitude": -37.8159544565362,
|
|
38
|
+
"longitude": 144.9723565578461
|
|
39
|
+
},
|
|
38
40
|
"beaconType": "Both",
|
|
39
41
|
"major": 10000,
|
|
40
42
|
"phone": 123123123123,
|
|
@@ -32,8 +32,9 @@ testCase('Zone - Action', () => {
|
|
|
32
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(err)
|
|
35
36
|
assert.notExists(res)
|
|
36
|
-
assert(err === null, 'err
|
|
37
|
+
assert(err === null, 'err should be null')
|
|
37
38
|
done()
|
|
38
39
|
})
|
|
39
40
|
})
|
package/models/Beacon.js
CHANGED
|
@@ -1,11 +1,13 @@
|
|
|
1
1
|
let mongoose = require('mongoose')
|
|
2
2
|
let StateEnum = require('@bluedot-innovation/enums').StateEnum
|
|
3
3
|
let Point = require('../schemas/Point')
|
|
4
|
+
let PointGeometry = require('../schemas/PointGeometry')
|
|
4
5
|
let uuidv4 = require('uuid/v4')
|
|
5
6
|
let patcher = require('mongoose-json-patch')
|
|
6
7
|
|
|
7
8
|
let schema = {
|
|
8
9
|
_id: {type: String, default: uuidv4},
|
|
10
|
+
geometry: {type: PointGeometry},
|
|
9
11
|
name: {type: String, required: [true, 'name is required.']},
|
|
10
12
|
description: {type: String, default: ''},
|
|
11
13
|
creationTime: {type: Date, default: Date.now},
|
package/models/BoundingBox.js
CHANGED
|
@@ -2,9 +2,11 @@ let mongoose = require('mongoose')
|
|
|
2
2
|
let StateEnum = require('@bluedot-innovation/enums').StateEnum
|
|
3
3
|
let uuidv4 = require('uuid/v4')
|
|
4
4
|
let Point = require('../schemas/Point')
|
|
5
|
+
let PolygonGeometry = require('../schemas/PolygonGeometry')
|
|
5
6
|
|
|
6
7
|
const schema = {
|
|
7
8
|
_id: {type: String, default: uuidv4},
|
|
9
|
+
geometry: {type: PolygonGeometry},
|
|
8
10
|
name: {type: String, required: [true, 'name is required. ']},
|
|
9
11
|
color: String,
|
|
10
12
|
northEast: {type: Point, required: [true, 'northEast is required. ']},
|
package/models/Circle.js
CHANGED
|
@@ -2,9 +2,11 @@ let mongoose = require('mongoose')
|
|
|
2
2
|
let StateEnum = require('@bluedot-innovation/enums').StateEnum
|
|
3
3
|
let Point = require('../schemas/Point')
|
|
4
4
|
let uuidv4 = require('uuid/v4')
|
|
5
|
+
let PolygonGeometry = require('../schemas/PolygonGeometry')
|
|
5
6
|
|
|
6
7
|
let schema = {
|
|
7
8
|
_id: {type: String, default: uuidv4},
|
|
9
|
+
geometry: {type: PolygonGeometry},
|
|
8
10
|
name: {type: String, required: [true, 'name is required. ']},
|
|
9
11
|
color: String,
|
|
10
12
|
radius: {type: Number, required: [true, 'radius is required. '], min: 5},
|
package/models/Polygon.js
CHANGED
|
@@ -5,6 +5,7 @@ let uuidv4 = require('uuid/v4')
|
|
|
5
5
|
|
|
6
6
|
const schema = {
|
|
7
7
|
_id: {type: String, default: uuidv4},
|
|
8
|
+
geometry: {type: mongoose.Schema.Types.Mixed},
|
|
8
9
|
name: {type: String, required: [true, 'name is required. ']},
|
|
9
10
|
color: String,
|
|
10
11
|
vertices: {type: [Point], required: [true, 'vertices is required. ']},
|
package/models/Polyline.js
CHANGED
|
@@ -2,9 +2,11 @@ let mongoose = require('mongoose')
|
|
|
2
2
|
let StateEnum = require('@bluedot-innovation/enums').StateEnum
|
|
3
3
|
let Point = require('../schemas/Point')
|
|
4
4
|
let uuidv4 = require('uuid/v4')
|
|
5
|
+
let MultiLineStringGeometry = require('../schemas/MultiLineStringGeometry')
|
|
5
6
|
|
|
6
7
|
const schema = {
|
|
7
8
|
_id: {type: String, default: uuidv4},
|
|
9
|
+
geometry: {type: MultiLineStringGeometry},
|
|
8
10
|
name: {type: String, required: [true, 'name is required. ']},
|
|
9
11
|
vertices: {type: [Point], required: [true, 'vertices is required. ']},
|
|
10
12
|
creationTime: {type: Date, default: Date.now},
|
package/package.json
CHANGED
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
let mongoose = require('mongoose')
|
|
2
|
+
|
|
3
|
+
let MultiLineStringSchema = new mongoose.Schema(
|
|
4
|
+
{
|
|
5
|
+
type: {type: String, match: /MultiLineString/},
|
|
6
|
+
coordinates: [[[{type: Number, required: [true, 'longitude is required. '], min: -180, max: 180},
|
|
7
|
+
{type: Number, required: [true, 'latitude is required. '], min: -90, max: 90}]]]
|
|
8
|
+
},
|
|
9
|
+
{
|
|
10
|
+
_id: false,
|
|
11
|
+
__v: false
|
|
12
|
+
})
|
|
13
|
+
|
|
14
|
+
module.exports = MultiLineStringSchema
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
let mongoose = require('mongoose')
|
|
2
|
+
|
|
3
|
+
let PointGeometrySchema = new mongoose.Schema(
|
|
4
|
+
{
|
|
5
|
+
type: {type: String, match: /Point/},
|
|
6
|
+
coordinates: [{type: Number, required: [true, 'longitude is required. '], min: -180, max: 180},
|
|
7
|
+
{type: Number, required: [true, 'latitude is required. '], min: -90, max: 90}]
|
|
8
|
+
},
|
|
9
|
+
{
|
|
10
|
+
_id: false,
|
|
11
|
+
__v: false
|
|
12
|
+
})
|
|
13
|
+
|
|
14
|
+
module.exports = PointGeometrySchema
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
let mongoose = require('mongoose')
|
|
2
|
+
|
|
3
|
+
let PolygonGeometrySchema = new mongoose.Schema(
|
|
4
|
+
{
|
|
5
|
+
type: {type: String, match: /Polygon/},
|
|
6
|
+
coordinates: [[[{type: Number, required: [true, 'longitude is required. '], min: -180, max: 180},
|
|
7
|
+
{type: Number, required: [true, 'latitude is required. '], min: -90, max: 90}]]]
|
|
8
|
+
},
|
|
9
|
+
{
|
|
10
|
+
_id: false,
|
|
11
|
+
__v: false
|
|
12
|
+
})
|
|
13
|
+
|
|
14
|
+
module.exports = PolygonGeometrySchema
|