@bluedot-innovation/models 4.0.0 → 5.0.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/.eslintrc.js +42 -0
- package/.gitlab-ci.yml +44 -0
- package/CHANGELOG.md +156 -0
- package/Models.js +55 -10
- package/README.MD +36 -0
- package/__tests__/account/account.data.json +12 -0
- package/__tests__/account/account.rules.js +8 -0
- package/__tests__/account/account.spec.js +83 -0
- package/__tests__/action/message/messageAction.data.json +5 -0
- package/__tests__/action/message/messageAction.rules.json +3 -0
- package/__tests__/action/message/messageAction.spec.js +73 -0
- package/__tests__/action/url/urlAction.data.json +4 -0
- package/__tests__/action/url/urlAction.rules.json +3 -0
- package/__tests__/action/url/urlAction.spec.js +74 -0
- package/__tests__/beacon/beacon.data.json +15 -0
- package/__tests__/beacon/beacon.rules.json +13 -0
- package/__tests__/beacon/beacon.spec.js +104 -0
- package/__tests__/condition/beacon/beaconFilter.data.json +1 -0
- package/__tests__/condition/beacon/beaconFilter.rules.json +3 -0
- package/__tests__/condition/beacon/beaconFilter.spec.js +1 -0
- package/__tests__/condition/dayRange/dayRange.data.json +5 -0
- package/__tests__/condition/dayRange/dayRange.rules.json +3 -0
- package/__tests__/condition/dayRange/dayRange.spec.js +95 -0
- package/__tests__/condition/percentageCrossed/travelPath.data.json +5 -0
- package/__tests__/condition/percentageCrossed/travelPath.rules.json +3 -0
- package/__tests__/condition/percentageCrossed/travelPath.spec.js +72 -0
- package/__tests__/condition/speed/speed.data.json +5 -0
- package/__tests__/condition/speed/speed.rules.json +3 -0
- package/__tests__/condition/speed/speed.spec.js +92 -0
- package/__tests__/condition/timeActive/timeActive.data.json +5 -0
- package/__tests__/condition/timeActive/timeActive.rules.json +14 -0
- package/__tests__/condition/timeActive/timeActive.spec.js +103 -0
- package/__tests__/condition/travelDirection/travelDirection.data.json +5 -0
- package/__tests__/condition/travelDirection/travelDirection.rules.json +3 -0
- package/__tests__/condition/travelDirection/travelDirection.spec.js +141 -0
- package/__tests__/dailyStats/checkDailyStats.js +31 -0
- package/__tests__/geofeature/boundingBox/boundingBox.data.json +12 -0
- package/__tests__/geofeature/boundingBox/boundingBox.rules.json +3 -0
- package/__tests__/geofeature/boundingBox/boundingBox.spec.js +87 -0
- package/__tests__/geofeature/circle/circle.data.json +9 -0
- package/__tests__/geofeature/circle/circle.rules.json +3 -0
- package/__tests__/geofeature/circle/circle.spec.js +71 -0
- package/__tests__/geofeature/geoline/geoline.data.json +46 -0
- package/__tests__/geofeature/geoline/geoline.rules.json +3 -0
- package/__tests__/geofeature/geoline/geoline.spec.js +70 -0
- package/__tests__/geofeature/polygon/polygon.data.json +46 -0
- package/__tests__/geofeature/polygon/polygon.rules.json +3 -0
- package/__tests__/geofeature/polygon/polygon.spec.js +132 -0
- 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 +71 -0
- package/__tests__/monthlyStats/monthlyStats.data.json +29 -0
- package/__tests__/monthlyStats/monthlyStats.spec.js +75 -0
- package/__tests__/project/project.data.json +18 -0
- package/__tests__/project/project.remote.config.json +122 -0
- package/__tests__/project/project.rules.json +9 -0
- package/__tests__/project/project.spec.js +100 -0
- package/__tests__/ruleRequestAggregation/ruleRequestAggregation.data.json +8 -0
- package/__tests__/ruleRequestAggregation/ruleRequestAggregation.spec.js +78 -0
- package/__tests__/setup.js +7 -0
- package/__tests__/user/user.data.js +19 -0
- package/__tests__/user/user.rules.js +8 -0
- package/__tests__/user/user.spec.js +130 -0
- package/__tests__/utils/utils.spec.js +26 -0
- package/__tests__/zone/zone.action.spec.js +50 -0
- package/__tests__/zone/zone.condition.spec.js +94 -0
- package/__tests__/zone/zone.data.json +157 -0
- package/__tests__/zone/zone.geofeatures.spec.js +75 -0
- package/__tests__/zone/zone.spec.js +140 -0
- package/constants/errorMessages.js +2 -0
- package/helpers.js +117 -0
- package/models/Account.js +50 -0
- package/models/AdminPortalUser.js +10 -11
- package/models/Beacon.js +84 -32
- package/models/Contract.js +37 -38
- package/models/CustomerLogin.js +9 -10
- package/models/DBEvent.js +13 -14
- package/models/DailyStats.js +7 -7
- package/models/DeviceRulesRequest.js +27 -28
- package/models/MessageAction.js +26 -26
- package/models/MonthlyStats.js +35 -19
- package/models/NotificationLogEntry.js +7 -8
- package/models/POILocation.js +6 -7
- package/models/POILookup.js +8 -9
- package/models/POIResult.js +7 -8
- package/models/PartnerCustomer.js +12 -13
- package/models/PartnerPasswordReset.js +8 -9
- package/models/PartnerUser.js +10 -11
- package/models/Partners.js +11 -12
- package/models/Project.js +63 -0
- package/models/RuleRequestAggregation.js +33 -17
- package/models/SingleUseToken.js +7 -8
- package/models/TestDevice.js +11 -12
- package/models/TestDeviceCluster.js +9 -10
- package/models/TestInstance.js +9 -10
- package/models/TestScenario.js +9 -10
- package/models/TimeOfDayRange.js +16 -16
- package/models/UrlAction.js +37 -0
- package/models/User.js +61 -0
- package/models/Zone.js +126 -0
- package/models/ZoneUIState.js +18 -18
- package/models/conditions/DayRange.js +44 -0
- package/models/conditions/Speed.js +42 -0
- package/models/conditions/TimeActive.js +50 -0
- package/models/conditions/TravelDirection.js +59 -0
- package/models/conditions/TravelPath.js +36 -0
- package/models/geofeatures/BoundingBox.js +44 -0
- package/models/geofeatures/Circle.js +39 -0
- package/models/geofeatures/Geoline.js +34 -0
- package/models/geofeatures/Polygon.js +45 -0
- package/models/geofeatures/ZoneBeacon.js +28 -0
- package/package.json +30 -6
- package/schemas/AccuracySuppression.js +14 -0
- package/schemas/AndroidConfig.js +35 -0
- package/schemas/IosConfig.js +38 -0
- package/schemas/MultiLineStringGeometry.js +14 -0
- package/schemas/Point.js +13 -0
- package/schemas/PointGeometry.js +14 -0
- package/schemas/PolygonGeometry.js +14 -0
- package/schemas/ProjectPermission.js +21 -0
- package/schemas/StarvationDetection.js +11 -0
- package/schemas/Telemetry.js +36 -0
- package/schemas/Webhook.js +22 -0
- package/utils/index.js +39 -0
- package/utils/validators.js +6 -0
- package/validators/checkDistanceBetweenVertices.js +21 -0
- package/yarn.lock +2796 -0
- package/models/AdminUser.js +0 -10
- package/models/Application.js +0 -38
- package/models/ApplicationNotificationAction.js +0 -30
- package/models/ApplicationUsage.js +0 -11
- package/models/BeaconFilter.js +0 -23
- package/models/BearingFilter.js +0 -19
- package/models/BoundingBox.js +0 -17
- package/models/Circle.js +0 -21
- package/models/ConfigurationParameters.js +0 -20
- package/models/Customer.js +0 -38
- package/models/DateRangeFilter.js +0 -20
- package/models/Fence.js +0 -21
- package/models/FormattedBeacon.js +0 -16
- package/models/FormattedCircle.js +0 -12
- package/models/FormattedConditions.js +0 -11
- package/models/FormattedDateRange.js +0 -11
- package/models/FormattedPercentageCrossed.js +0 -12
- package/models/FormattedPoint.js +0 -10
- package/models/FormattedPolygon.js +0 -11
- package/models/FormattedPolyline.js +0 -11
- package/models/FormattedRectangle.js +0 -12
- package/models/FormattedTimeActive.js +0 -17
- package/models/FormattedZone.js +0 -28
- package/models/GeoFence.js +0 -23
- package/models/Geofeature.js +0 -26
- package/models/PercentageCrossedFilter.js +0 -19
- package/models/Point.js +0 -20
- package/models/Polygon.js +0 -18
- package/models/Polyline.js +0 -18
- package/models/PropertyMapping.js +0 -17
- package/models/Reference.js +0 -19
- package/models/SequenceFilter.js +0 -18
- package/models/SimpleCheckInZone.js +0 -29
- package/models/SoundAction.js +0 -28
- package/models/SpeedFilter.js +0 -19
- package/models/TimeOfDayRangeFilter.js +0 -19
- package/models/URLAction.js +0 -31
- package/models/VibrationAction.js +0 -28
- package/models/property.js +0 -25
- package/package-lock.json.bak +0 -170
|
@@ -0,0 +1,130 @@
|
|
|
1
|
+
let mongoose = require('mongoose')
|
|
2
|
+
|
|
3
|
+
let UserModel = require('../../Models').User(mongoose)
|
|
4
|
+
let UserModelBuiltInMongoose = require('../../Models').User()
|
|
5
|
+
let describe = require('mocha').describe
|
|
6
|
+
let it = require('mocha').it
|
|
7
|
+
let rules = require('./user.rules.js')
|
|
8
|
+
let chai = require('chai')
|
|
9
|
+
let assert = chai.assert
|
|
10
|
+
let mocha = require('mocha')
|
|
11
|
+
let beforeEach = mocha.beforeEach
|
|
12
|
+
|
|
13
|
+
let user
|
|
14
|
+
|
|
15
|
+
beforeEach(() => {
|
|
16
|
+
user = require('./user.data.js')
|
|
17
|
+
})
|
|
18
|
+
|
|
19
|
+
describe('User', () => {
|
|
20
|
+
describe('Valid User ', () => {
|
|
21
|
+
it('should validate a valid user when initializing the model with an external mongoose instance', (done) => {
|
|
22
|
+
let User = new UserModel(user)
|
|
23
|
+
|
|
24
|
+
User.validate((err, res) => {
|
|
25
|
+
assert.notExists(res)
|
|
26
|
+
assert(err === null, 'err equals null')
|
|
27
|
+
|
|
28
|
+
done()
|
|
29
|
+
})
|
|
30
|
+
})
|
|
31
|
+
|
|
32
|
+
it('should validate a valid user', (done) => {
|
|
33
|
+
let User = new UserModelBuiltInMongoose(user)
|
|
34
|
+
|
|
35
|
+
User.validate((err, res) => {
|
|
36
|
+
assert.notExists(res)
|
|
37
|
+
assert(err === null, 'err equals null')
|
|
38
|
+
done()
|
|
39
|
+
})
|
|
40
|
+
})
|
|
41
|
+
})
|
|
42
|
+
|
|
43
|
+
describe('Invalid User', () => {
|
|
44
|
+
describe('recursive property check', () => {
|
|
45
|
+
let requiredFields = rules.requiredFields
|
|
46
|
+
requiredFields.forEach((requiredField) => {
|
|
47
|
+
it(`should throw an error with property '${requiredField}' if '${requiredField}' is not present`, (done) => {
|
|
48
|
+
user = JSON.parse(JSON.stringify(user))
|
|
49
|
+
delete user[requiredField]
|
|
50
|
+
let User = new UserModel(user)
|
|
51
|
+
User.validate((err, res) => {
|
|
52
|
+
assert.notExists(res)
|
|
53
|
+
assert.exists(err, 'err object should exist')
|
|
54
|
+
assert.isObject(err)
|
|
55
|
+
assert.nestedProperty(err, `errors.${requiredField}`, `error should have a ${requiredField} property`)
|
|
56
|
+
done()
|
|
57
|
+
})
|
|
58
|
+
})
|
|
59
|
+
})
|
|
60
|
+
})
|
|
61
|
+
})
|
|
62
|
+
|
|
63
|
+
describe('recursive invalid entry check', () => {
|
|
64
|
+
const { customValidators } = rules
|
|
65
|
+
|
|
66
|
+
customValidators.forEach((customValidator) => {
|
|
67
|
+
customValidator.invalidInputs.forEach((invalidInput) => {
|
|
68
|
+
it(`should throw an error with property '${customValidator.name}' if '${customValidator.name}' is invalid => ${customValidator.name} = ${invalidInput}`, (done) => {
|
|
69
|
+
user = JSON.parse(JSON.stringify(user))
|
|
70
|
+
user[customValidator.name] = invalidInput
|
|
71
|
+
let User = new UserModel(user)
|
|
72
|
+
|
|
73
|
+
User.validate((err, res) => {
|
|
74
|
+
assert.notExists(res)
|
|
75
|
+
assert.exists(err, 'err object should exist')
|
|
76
|
+
assert.isObject(err)
|
|
77
|
+
assert.nestedProperty(err, `errors.${customValidator.name}`, `error should have a ${customValidator.name} property`)
|
|
78
|
+
done()
|
|
79
|
+
})
|
|
80
|
+
})
|
|
81
|
+
})
|
|
82
|
+
})
|
|
83
|
+
})
|
|
84
|
+
|
|
85
|
+
describe('projectPermissions:', () => {
|
|
86
|
+
it('should fail if projectId is invalid', (done) => {
|
|
87
|
+
user = JSON.parse(JSON.stringify(user))
|
|
88
|
+
user.projectPermissions[0].projectId = '8b1b5cb5-3c7b-452a-b9a7-'
|
|
89
|
+
const User = new UserModel(user)
|
|
90
|
+
|
|
91
|
+
User.validate((err, res) => {
|
|
92
|
+
assert.match(err, /(projectId not in UUID v4 format)/i)
|
|
93
|
+
done()
|
|
94
|
+
})
|
|
95
|
+
})
|
|
96
|
+
|
|
97
|
+
it('should fail if projectId is missing', (done) => {
|
|
98
|
+
user = JSON.parse(JSON.stringify(user))
|
|
99
|
+
user.projectPermissions[0].projectId = undefined
|
|
100
|
+
const User = new UserModel(user)
|
|
101
|
+
|
|
102
|
+
User.validate((err, res) => {
|
|
103
|
+
assert.match(err, /(Path `projectId` is required.)/i)
|
|
104
|
+
done()
|
|
105
|
+
})
|
|
106
|
+
})
|
|
107
|
+
|
|
108
|
+
it('should fail if permissionLevel is invalid', (done) => {
|
|
109
|
+
user = JSON.parse(JSON.stringify(user))
|
|
110
|
+
user.projectPermissions[0].permissionLevel = 'INVALID'
|
|
111
|
+
const User = new UserModel(user)
|
|
112
|
+
|
|
113
|
+
User.validate((err, res) => {
|
|
114
|
+
assert.match(err, /(not a valid enum value)/i)
|
|
115
|
+
done()
|
|
116
|
+
})
|
|
117
|
+
})
|
|
118
|
+
|
|
119
|
+
it('should fail if permissionLevel is missing', (done) => {
|
|
120
|
+
user = JSON.parse(JSON.stringify(user))
|
|
121
|
+
user.projectPermissions[0].permissionLevel = undefined
|
|
122
|
+
const User = new UserModel(user)
|
|
123
|
+
|
|
124
|
+
User.validate((err, res) => {
|
|
125
|
+
assert.match(err, /(Path `permissionLevel` is required.)/i)
|
|
126
|
+
done()
|
|
127
|
+
})
|
|
128
|
+
})
|
|
129
|
+
})
|
|
130
|
+
})
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
const { trimDecimals } = require('../../utils')
|
|
2
|
+
let chai = require('chai')
|
|
3
|
+
let assert = chai.assert
|
|
4
|
+
|
|
5
|
+
describe('trimDecimals(num, n)', () => {
|
|
6
|
+
const tests = [{
|
|
7
|
+
num: -37.8196889692931,
|
|
8
|
+
n: 6,
|
|
9
|
+
expected: -37.819689,
|
|
10
|
+
}, {
|
|
11
|
+
num: 42,
|
|
12
|
+
n: 2,
|
|
13
|
+
expected: 42,
|
|
14
|
+
}, {
|
|
15
|
+
num: 23.39,
|
|
16
|
+
n: 1,
|
|
17
|
+
expected: 23.3,
|
|
18
|
+
}]
|
|
19
|
+
|
|
20
|
+
tests.forEach(({num, n, expected}) => {
|
|
21
|
+
it(`when num is ${num} and n is ${n}, it should return ${expected}`, () => {
|
|
22
|
+
const isCorrect = (trimDecimals(num,n) === expected)
|
|
23
|
+
assert(isCorrect);
|
|
24
|
+
})
|
|
25
|
+
})
|
|
26
|
+
})
|
|
@@ -0,0 +1,50 @@
|
|
|
1
|
+
let mongoose = require('mongoose')
|
|
2
|
+
|
|
3
|
+
mongoose.Promise = global.Promise
|
|
4
|
+
|
|
5
|
+
let ZoneModel = require('../../Models').Zone(mongoose)
|
|
6
|
+
let testCase = require('mocha').describe
|
|
7
|
+
let assertions = require('mocha').it
|
|
8
|
+
let chai = require('chai')
|
|
9
|
+
let assert = chai.assert
|
|
10
|
+
let mocha = require('mocha')
|
|
11
|
+
let beforeEach = mocha.beforeEach
|
|
12
|
+
|
|
13
|
+
let zone
|
|
14
|
+
|
|
15
|
+
beforeEach(() => {
|
|
16
|
+
zone = JSON.parse(JSON.stringify(require('./zone.data.json')))
|
|
17
|
+
// remove conditions as it's not tested
|
|
18
|
+
delete zone.conditions
|
|
19
|
+
// remove all but 1 geofeatures as geofeatures are required
|
|
20
|
+
zone.geofeatures = zone.geofeatures.filter(x => x.type.match(/circle/i))
|
|
21
|
+
// remove customData
|
|
22
|
+
delete zone.customData
|
|
23
|
+
})
|
|
24
|
+
|
|
25
|
+
testCase('Zone - Action', () => {
|
|
26
|
+
testCase('Valid Zone - Action', () => {
|
|
27
|
+
assertions('should not throw an error when a valid action is instantiated within a zone', (done) => {
|
|
28
|
+
let Zone = new ZoneModel(zone)
|
|
29
|
+
Zone.validate((err, res) => {
|
|
30
|
+
assert.notExists(res)
|
|
31
|
+
assert(err === null, 'err equals null')
|
|
32
|
+
done()
|
|
33
|
+
})
|
|
34
|
+
})
|
|
35
|
+
})
|
|
36
|
+
|
|
37
|
+
testCase('Invalid Zone - Action', () => {
|
|
38
|
+
assertions('should throw an error when an invalid action is instantiated within a zone', (done) => {
|
|
39
|
+
delete zone.actions[1].url
|
|
40
|
+
let Zone = new ZoneModel(zone)
|
|
41
|
+
Zone.validate((err, res) => {
|
|
42
|
+
assert.exists(err, 'err object should exist')
|
|
43
|
+
assert.isObject(err)
|
|
44
|
+
assert('actions.1.url' in err.errors)
|
|
45
|
+
assert.notNestedProperty(err, `errors.geofeatures`, 'error should have a url property')
|
|
46
|
+
done()
|
|
47
|
+
})
|
|
48
|
+
})
|
|
49
|
+
})
|
|
50
|
+
})
|
|
@@ -0,0 +1,94 @@
|
|
|
1
|
+
let mongoose = require('mongoose')
|
|
2
|
+
|
|
3
|
+
mongoose.Promise = global.Promise
|
|
4
|
+
|
|
5
|
+
let ZoneModel = require('../../models/Zone').Model(mongoose)
|
|
6
|
+
let testCase = require('mocha').describe
|
|
7
|
+
let assertions = require('mocha').it
|
|
8
|
+
let chai = require('chai')
|
|
9
|
+
let assert = chai.assert
|
|
10
|
+
let mocha = require('mocha')
|
|
11
|
+
let beforeEach = mocha.beforeEach
|
|
12
|
+
|
|
13
|
+
let zone
|
|
14
|
+
let geofeatures
|
|
15
|
+
|
|
16
|
+
beforeEach(() => {
|
|
17
|
+
zone = JSON.parse(JSON.stringify(require('./zone.data.json')))
|
|
18
|
+
// remove actions as it's not tested
|
|
19
|
+
delete zone.actions
|
|
20
|
+
// remove all but 2 geofeatures as geofeatures are required
|
|
21
|
+
geofeatures = zone.geofeatures
|
|
22
|
+
zone.geofeatures = zone.geofeatures.filter(x => (x.type.match(/circle/i) || x.type.match(/boundingBox/i)) )
|
|
23
|
+
// remove customData
|
|
24
|
+
delete zone.customData
|
|
25
|
+
})
|
|
26
|
+
|
|
27
|
+
testCase('Zone - Condition', () => {
|
|
28
|
+
testCase('Valid Zone - Condition', () => {
|
|
29
|
+
assertions('should not throw an error when a valid condition is instantiated within a zone', (done) => {
|
|
30
|
+
let Zone = new ZoneModel(zone)
|
|
31
|
+
Zone.validate((err, res) => {
|
|
32
|
+
assert.notExists(res)
|
|
33
|
+
assert(err === null, 'err equals null')
|
|
34
|
+
done()
|
|
35
|
+
})
|
|
36
|
+
})
|
|
37
|
+
})
|
|
38
|
+
|
|
39
|
+
testCase('Invalid Zone - Condition', () => {
|
|
40
|
+
assertions('should throw an error when an invalid condition is instantiated within a zone', (done) => {
|
|
41
|
+
zone.conditions[0].startDate = 'abc'
|
|
42
|
+
let Zone = new ZoneModel(zone)
|
|
43
|
+
Zone.validate((err, res) => {
|
|
44
|
+
assert.exists(err, 'err object should exist')
|
|
45
|
+
assert.isObject(err)
|
|
46
|
+
assert('conditions.0.startDate' in err.errors)
|
|
47
|
+
assert.notNestedProperty(err, `errors.geofeatures`, 'error should have a url property')
|
|
48
|
+
done()
|
|
49
|
+
})
|
|
50
|
+
})
|
|
51
|
+
assertions('should not throw an error when a valid condition is instantiated within a zone', (done) => {
|
|
52
|
+
let Zone = new ZoneModel(zone)
|
|
53
|
+
Zone.validate((err, res) => {
|
|
54
|
+
assert.notExists(res)
|
|
55
|
+
assert(err === null, 'err equals null')
|
|
56
|
+
done()
|
|
57
|
+
})
|
|
58
|
+
})
|
|
59
|
+
assertions('should throw an error when the minimumGeofeaturesCrossed for a travel path condition is greater than the total number of geofeatures', (done) => {
|
|
60
|
+
zone.geofeatures = geofeatures
|
|
61
|
+
zone.conditions.push({
|
|
62
|
+
"type" : "travelPath",
|
|
63
|
+
"minimumGeofeaturesCrossed" : zone.geofeatures.length+1,
|
|
64
|
+
"timeOutSeconds": 120,
|
|
65
|
+
"sequential" : false
|
|
66
|
+
})
|
|
67
|
+
let Zone = new ZoneModel(zone)
|
|
68
|
+
Zone.validate((err, res) => {
|
|
69
|
+
assert.exists(err, 'err object should exist')
|
|
70
|
+
assert(err instanceof Error)
|
|
71
|
+
assert(err.message.includes("Zone must not have minimumGeofeaturesCrossed higher than geofeatures count"))
|
|
72
|
+
done()
|
|
73
|
+
})
|
|
74
|
+
})
|
|
75
|
+
assertions('should throw an error when more than 1 travelpath condition is specified', (done) => {
|
|
76
|
+
const travelPath = {
|
|
77
|
+
type: "travelPath",
|
|
78
|
+
minimumGeofeaturesCrossed: 2,
|
|
79
|
+
timeOutSeconds: 60,
|
|
80
|
+
sequential: true
|
|
81
|
+
}
|
|
82
|
+
// push 2 travelpaths into the zone's conditions array
|
|
83
|
+
zone.conditions.push(travelPath)
|
|
84
|
+
zone.conditions.push(travelPath)
|
|
85
|
+
|
|
86
|
+
let Zone = new ZoneModel(zone)
|
|
87
|
+
Zone.validate((err, res) => {
|
|
88
|
+
assert(err instanceof Error, "It should throw an error when more htan 1 travelpath condition is specified")
|
|
89
|
+
assert(err.message.includes("Zone must not have more than 1 travel path condition"), "It should throw a descriptive error when more than 1 travel path condition is specified")
|
|
90
|
+
done()
|
|
91
|
+
})
|
|
92
|
+
})
|
|
93
|
+
})
|
|
94
|
+
})
|
|
@@ -0,0 +1,157 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "TDD zone",
|
|
3
|
+
"minimumRetriggerTime": "60",
|
|
4
|
+
"checkout": true,
|
|
5
|
+
"lastUpdateTime": "2018-02-14T04:12:02.103Z",
|
|
6
|
+
"creationTime": "2018-02-14T04:12:02.103Z",
|
|
7
|
+
"projectId": "c7058934-f1e6-4176-8730-a0bd28e8e0a9",
|
|
8
|
+
"accountId": "23a01af0-232a-4518-9c0e-323fb773f5ef",
|
|
9
|
+
"customData": {
|
|
10
|
+
"name1": "A Custom action1",
|
|
11
|
+
"name2": "A Custom action2"
|
|
12
|
+
},
|
|
13
|
+
"actions": [
|
|
14
|
+
{
|
|
15
|
+
"type": "message",
|
|
16
|
+
"message": "hello",
|
|
17
|
+
"title": "hello"
|
|
18
|
+
},
|
|
19
|
+
{
|
|
20
|
+
"type": "url",
|
|
21
|
+
"url": "https://www.google.com"
|
|
22
|
+
}
|
|
23
|
+
],
|
|
24
|
+
"beacons": [],
|
|
25
|
+
"conditions": [
|
|
26
|
+
{
|
|
27
|
+
"type" : "dayRange",
|
|
28
|
+
"startDate" : "2017-11-14",
|
|
29
|
+
"endDate" : "2030-11-15"
|
|
30
|
+
}
|
|
31
|
+
],
|
|
32
|
+
"geofeatures": [{
|
|
33
|
+
"type": "beacon",
|
|
34
|
+
"name": "create beacon",
|
|
35
|
+
"proximityUUID": "23a01af0-232a-4518-9c0e-323fb773f5ef",
|
|
36
|
+
"location": {
|
|
37
|
+
"latitude": -37.8159544565362,
|
|
38
|
+
"longitude": 144.9723565578461
|
|
39
|
+
},
|
|
40
|
+
"beaconType": "Both",
|
|
41
|
+
"major": 10000,
|
|
42
|
+
"phone": 123123123123,
|
|
43
|
+
"minor": 56466,
|
|
44
|
+
"txPower": -77,
|
|
45
|
+
"macAddress": "01:17:c5:31:84:19",
|
|
46
|
+
"accountId": "90a2ed18-86be-48e7-948b-393b8b679ef6"
|
|
47
|
+
},{
|
|
48
|
+
"type": "circle",
|
|
49
|
+
"name": "Test Circle",
|
|
50
|
+
"radius": 10,
|
|
51
|
+
"center": {
|
|
52
|
+
"latitude": -37.8159544565362,
|
|
53
|
+
"longitude": 144.9723565578461
|
|
54
|
+
}
|
|
55
|
+
},{
|
|
56
|
+
"type": "boundingBox",
|
|
57
|
+
"name": "Test BoundingBox",
|
|
58
|
+
"northEast": {
|
|
59
|
+
"latitude": -37.81794619852986,
|
|
60
|
+
"longitude": 144.97999548912048
|
|
61
|
+
},
|
|
62
|
+
"southWest": {
|
|
63
|
+
"latitude": -37.81846319511329,
|
|
64
|
+
"longitude": 144.97921228408813
|
|
65
|
+
}
|
|
66
|
+
},{
|
|
67
|
+
"type": "polygon",
|
|
68
|
+
"name": "Test Polygon",
|
|
69
|
+
"vertices": [
|
|
70
|
+
{
|
|
71
|
+
"latitude": -37.81902680201739,
|
|
72
|
+
"longitude": 144.9821037054062
|
|
73
|
+
},
|
|
74
|
+
{
|
|
75
|
+
"latitude": -37.8196878692931,
|
|
76
|
+
"longitude": 144.98161554336548
|
|
77
|
+
},
|
|
78
|
+
{
|
|
79
|
+
"latitude": -37.82052267015026,
|
|
80
|
+
"longitude": 144.9816906452179
|
|
81
|
+
},
|
|
82
|
+
{
|
|
83
|
+
"latitude": -37.82128118660006,
|
|
84
|
+
"longitude": 144.98312830924988
|
|
85
|
+
},
|
|
86
|
+
{
|
|
87
|
+
"latitude": -37.82102693614463,
|
|
88
|
+
"longitude": 144.98458743095398
|
|
89
|
+
},
|
|
90
|
+
{
|
|
91
|
+
"latitude": -37.820196378553405,
|
|
92
|
+
"longitude": 144.98524725437164
|
|
93
|
+
},
|
|
94
|
+
{
|
|
95
|
+
"latitude": -37.81895899991077,
|
|
96
|
+
"longitude": 144.9847161769867
|
|
97
|
+
},
|
|
98
|
+
{
|
|
99
|
+
"latitude": -37.81865812731128,
|
|
100
|
+
"longitude": 144.9839222431183
|
|
101
|
+
},
|
|
102
|
+
{
|
|
103
|
+
"latitude": -37.81866660261256,
|
|
104
|
+
"longitude": 144.98308539390564
|
|
105
|
+
},
|
|
106
|
+
{
|
|
107
|
+
"latitude": -37.81902680201739,
|
|
108
|
+
"longitude": 144.9821037054062
|
|
109
|
+
}
|
|
110
|
+
]
|
|
111
|
+
},{
|
|
112
|
+
"type": "geoline",
|
|
113
|
+
"name": "Test Geoline",
|
|
114
|
+
"vertices": [
|
|
115
|
+
{
|
|
116
|
+
"latitude": -37.81902680201739,
|
|
117
|
+
"longitude": 144.9821037054062
|
|
118
|
+
},
|
|
119
|
+
{
|
|
120
|
+
"latitude": -37.8196878692931,
|
|
121
|
+
"longitude": 144.98161554336548
|
|
122
|
+
},
|
|
123
|
+
{
|
|
124
|
+
"latitude": -37.82052267015026,
|
|
125
|
+
"longitude": 144.9816906452179
|
|
126
|
+
},
|
|
127
|
+
{
|
|
128
|
+
"latitude": -37.82128118660006,
|
|
129
|
+
"longitude": 144.98312830924988
|
|
130
|
+
},
|
|
131
|
+
{
|
|
132
|
+
"latitude": -37.82102693614463,
|
|
133
|
+
"longitude": 144.98458743095398
|
|
134
|
+
},
|
|
135
|
+
{
|
|
136
|
+
"latitude": -37.820196378553405,
|
|
137
|
+
"longitude": 144.98524725437164
|
|
138
|
+
},
|
|
139
|
+
{
|
|
140
|
+
"latitude": -37.81895899991077,
|
|
141
|
+
"longitude": 144.9847161769867
|
|
142
|
+
},
|
|
143
|
+
{
|
|
144
|
+
"latitude": -37.81865812731128,
|
|
145
|
+
"longitude": 144.9839222431183
|
|
146
|
+
},
|
|
147
|
+
{
|
|
148
|
+
"latitude": -37.81866660261256,
|
|
149
|
+
"longitude": 144.98308539390564
|
|
150
|
+
},
|
|
151
|
+
{
|
|
152
|
+
"latitude": -37.81902680201739,
|
|
153
|
+
"longitude": 144.9821037054062
|
|
154
|
+
}
|
|
155
|
+
]
|
|
156
|
+
}]
|
|
157
|
+
}
|
|
@@ -0,0 +1,75 @@
|
|
|
1
|
+
let mongoose = require('mongoose')
|
|
2
|
+
|
|
3
|
+
mongoose.Promise = global.Promise
|
|
4
|
+
|
|
5
|
+
let ZoneModel = require('../../Models').Zone(mongoose)
|
|
6
|
+
let testCase = require('mocha').describe
|
|
7
|
+
let assertions = require('mocha').it
|
|
8
|
+
let chai = require('chai')
|
|
9
|
+
let assert = chai.assert
|
|
10
|
+
let mocha = require('mocha')
|
|
11
|
+
let beforeEach = mocha.beforeEach
|
|
12
|
+
|
|
13
|
+
let zone
|
|
14
|
+
|
|
15
|
+
beforeEach(() => {
|
|
16
|
+
zone = JSON.parse(JSON.stringify(require('./zone.data.json')))
|
|
17
|
+
// remove conditions as it's not tested
|
|
18
|
+
delete zone.conditions
|
|
19
|
+
|
|
20
|
+
// geofeatures are tested individually so we only need to try one in Zones' test
|
|
21
|
+
zone.geofeatures = zone.geofeatures.filter(x => x.type.match(/beacon/i))
|
|
22
|
+
|
|
23
|
+
// remove customData
|
|
24
|
+
delete zone.customData
|
|
25
|
+
|
|
26
|
+
// remove actions
|
|
27
|
+
delete zone.actions
|
|
28
|
+
})
|
|
29
|
+
|
|
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
|
+
let Zone = new ZoneModel(zone)
|
|
34
|
+
Zone.validate((err, res) => {
|
|
35
|
+
console.log(err)
|
|
36
|
+
assert.notExists(res)
|
|
37
|
+
assert(err === null, 'err should be null')
|
|
38
|
+
done()
|
|
39
|
+
})
|
|
40
|
+
})
|
|
41
|
+
})
|
|
42
|
+
|
|
43
|
+
testCase('Invalid Zone - Action', () => {
|
|
44
|
+
assertions('should throw an error when an invalid geofeature is instantiated within a zone', (done) => {
|
|
45
|
+
delete zone.geofeatures[0].name
|
|
46
|
+
let Zone = new ZoneModel(zone)
|
|
47
|
+
Zone.validate((err, res) => {
|
|
48
|
+
assert.exists(err, 'err object should exist')
|
|
49
|
+
assert.isObject(err)
|
|
50
|
+
assert('geofeatures.0.name' in err.errors)
|
|
51
|
+
done()
|
|
52
|
+
})
|
|
53
|
+
})
|
|
54
|
+
assertions('should throw an error when an invalid geofeature (complex validation) is instantiated within a zone', (done) => {
|
|
55
|
+
delete zone.geofeatures[0].minor
|
|
56
|
+
let Zone = new ZoneModel(zone)
|
|
57
|
+
Zone.validate((err, res) => {
|
|
58
|
+
assert.exists(err, 'err object should exist')
|
|
59
|
+
assert.isObject(err)
|
|
60
|
+
assert('geofeatures.0.beaconType' in err.errors)
|
|
61
|
+
done()
|
|
62
|
+
})
|
|
63
|
+
})
|
|
64
|
+
assertions('should throw an error when an no geofeature is instantiated within a zone', (done) => {
|
|
65
|
+
zone.geofeatures = []
|
|
66
|
+
let Zone = new ZoneModel(zone)
|
|
67
|
+
Zone.validate((err, res) => {
|
|
68
|
+
assert.exists(err, 'err object should exist')
|
|
69
|
+
assert.isObject(err)
|
|
70
|
+
assert('geofeatures' in err.errors)
|
|
71
|
+
done()
|
|
72
|
+
})
|
|
73
|
+
})
|
|
74
|
+
})
|
|
75
|
+
})
|
|
@@ -0,0 +1,140 @@
|
|
|
1
|
+
let mongoose = require('mongoose')
|
|
2
|
+
mongoose.Promise = global.Promise
|
|
3
|
+
let chai = require('chai')
|
|
4
|
+
let assert = chai.assert
|
|
5
|
+
|
|
6
|
+
|
|
7
|
+
let ZoneModel = require('../../Models').Zone(mongoose)
|
|
8
|
+
let ZoneModelBuiltInMongoose = require('../../Models').Zone()
|
|
9
|
+
|
|
10
|
+
let zone
|
|
11
|
+
|
|
12
|
+
beforeEach(() => {
|
|
13
|
+
zone = JSON.parse(JSON.stringify(require('./zone.data.json')))
|
|
14
|
+
})
|
|
15
|
+
|
|
16
|
+
describe('Zone', () => {
|
|
17
|
+
describe('Valid Zone ', () => {
|
|
18
|
+
it('should validate a valid zone ', (done) => {
|
|
19
|
+
let Zone = new ZoneModel(zone)
|
|
20
|
+
Zone.validate((err, res) => {
|
|
21
|
+
assert.notExists(res)
|
|
22
|
+
assert(err === null, 'err equals null')
|
|
23
|
+
done()
|
|
24
|
+
})
|
|
25
|
+
})
|
|
26
|
+
|
|
27
|
+
it('should validate a valid zone ', (done) => {
|
|
28
|
+
let Zone = new ZoneModelBuiltInMongoose(zone)
|
|
29
|
+
Zone.validate((err, res) => {
|
|
30
|
+
assert.notExists(res)
|
|
31
|
+
assert(err === null, 'err equals null')
|
|
32
|
+
done()
|
|
33
|
+
})
|
|
34
|
+
})
|
|
35
|
+
|
|
36
|
+
it('should instantiate a circle', (done) => {
|
|
37
|
+
zone.geofeatures = zone.geofeatures.filter(gf => gf.type.match(/^circle$/))
|
|
38
|
+
let Zone = new ZoneModel(zone)
|
|
39
|
+
Zone.validate((err, res) => {
|
|
40
|
+
assert.notExists(res)
|
|
41
|
+
assert(err === null, 'err equals null')
|
|
42
|
+
done()
|
|
43
|
+
})
|
|
44
|
+
})
|
|
45
|
+
|
|
46
|
+
it('should instantiate a bounding box', (done) => {
|
|
47
|
+
zone.geofeatures = zone.geofeatures.filter(gf => gf.type.match(/^boundingBox$/))
|
|
48
|
+
let Zone = new ZoneModel(zone)
|
|
49
|
+
Zone.validate((err, res) => {
|
|
50
|
+
assert.notExists(res)
|
|
51
|
+
assert(err === null, 'err equals null')
|
|
52
|
+
done()
|
|
53
|
+
})
|
|
54
|
+
})
|
|
55
|
+
|
|
56
|
+
it('should instantiate a polygon', (done) => {
|
|
57
|
+
zone.geofeatures = zone.geofeatures.filter(gf => gf.type.match(/^polygon$/))
|
|
58
|
+
let Zone = new ZoneModel(zone)
|
|
59
|
+
Zone.validate((err, res) => {
|
|
60
|
+
assert.notExists(res)
|
|
61
|
+
assert(err === null, 'err equals null')
|
|
62
|
+
done()
|
|
63
|
+
})
|
|
64
|
+
})
|
|
65
|
+
|
|
66
|
+
it('should instantiate a geoline', (done) => {
|
|
67
|
+
zone.geofeatures = zone.geofeatures.filter(gf => gf.type.match(/^geoline$/))
|
|
68
|
+
let Zone = new ZoneModel(zone)
|
|
69
|
+
Zone.validate((err, res) => {
|
|
70
|
+
assert.notExists(res)
|
|
71
|
+
assert(err === null, 'err equals null')
|
|
72
|
+
done()
|
|
73
|
+
})
|
|
74
|
+
})
|
|
75
|
+
})
|
|
76
|
+
|
|
77
|
+
describe('Invalid Zone ', () => {
|
|
78
|
+
it('should throw an error when validating an invalid zone ', (done) => {
|
|
79
|
+
delete zone.name
|
|
80
|
+
let Zone = new ZoneModel(zone)
|
|
81
|
+
Zone.validate((err, res) => {
|
|
82
|
+
assert.exists(err, 'err object should exist')
|
|
83
|
+
assert.isObject(err)
|
|
84
|
+
done()
|
|
85
|
+
})
|
|
86
|
+
})
|
|
87
|
+
|
|
88
|
+
it('should throw an error when action is invalid', (done) => {
|
|
89
|
+
delete zone.actions[1].url
|
|
90
|
+
let Zone = new ZoneModel(zone)
|
|
91
|
+
Zone.validate((err, res) => {
|
|
92
|
+
assert.exists(err, 'err object should exist')
|
|
93
|
+
assert.isObject(err)
|
|
94
|
+
assert('actions.1.url' in err.errors, `errors should have a 'actions.1.url' property`)
|
|
95
|
+
done()
|
|
96
|
+
})
|
|
97
|
+
})
|
|
98
|
+
|
|
99
|
+
it('should throw an error when a condition is invalid', (done) => {
|
|
100
|
+
zone.conditions[0].startDate = 'abc'
|
|
101
|
+
let Zone = new ZoneModel(zone)
|
|
102
|
+
Zone.validate((err, res) => {
|
|
103
|
+
assert.exists(err, 'err object should exist')
|
|
104
|
+
assert.isObject(err)
|
|
105
|
+
assert('conditions.0.startDate' in err.errors, `errors should have a 'conditions.0.startDate' property`)
|
|
106
|
+
done()
|
|
107
|
+
})
|
|
108
|
+
})
|
|
109
|
+
|
|
110
|
+
it('should throw an error when validating an invalid customData key ', (done) => {
|
|
111
|
+
zone.customData["name#3"] = "A Custom action3"
|
|
112
|
+
let Zone = new ZoneModel(zone)
|
|
113
|
+
Zone.validate((err, res) => {
|
|
114
|
+
assert.exists(err, 'err object should exist')
|
|
115
|
+
assert.isObject(err)
|
|
116
|
+
done()
|
|
117
|
+
})
|
|
118
|
+
})
|
|
119
|
+
|
|
120
|
+
it('should throw an error when it contains both a beacon and a travelDirection condition', (done) => {
|
|
121
|
+
zone.conditions.push(require('../condition/travelDirection/travelDirection.data.json'));
|
|
122
|
+
let Zone = new ZoneModel(zone)
|
|
123
|
+
Zone.validate((err, res) => {
|
|
124
|
+
assert.exists(err, 'err object should exist')
|
|
125
|
+
assert(err instanceof Error, "Should throw error.")
|
|
126
|
+
done()
|
|
127
|
+
})
|
|
128
|
+
})
|
|
129
|
+
|
|
130
|
+
it('should throw an error when it contains both a beacon and a speed condition', (done) => {
|
|
131
|
+
zone.conditions.push(require('../condition/speed/speed.data.json'));
|
|
132
|
+
let Zone = new ZoneModel(zone)
|
|
133
|
+
Zone.validate((err, res) => {
|
|
134
|
+
assert.exists(err, 'err object should exist')
|
|
135
|
+
assert(err instanceof Error, "Should throw error.")
|
|
136
|
+
done()
|
|
137
|
+
})
|
|
138
|
+
})
|
|
139
|
+
})
|
|
140
|
+
})
|