@bluedot-innovation/models 4.0.0 → 5.0.0
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 +43 -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 +61 -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 +74 -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 +62 -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 +73 -0
- package/__tests__/condition/timeActive/timeActive.data.json +5 -0
- package/__tests__/condition/timeActive/timeActive.rules.json +7 -0
- package/__tests__/condition/timeActive/timeActive.spec.js +94 -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 +132 -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 +78 -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 +127 -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 +62 -0
- package/__tests__/monthlyStats/monthlyStats.data.json +29 -0
- package/__tests__/monthlyStats/monthlyStats.spec.js +66 -0
- package/__tests__/project/project.data.json +18 -0
- package/__tests__/project/project.rules.json +9 -0
- package/__tests__/project/project.spec.js +92 -0
- package/__tests__/ruleRequestAggregation/ruleRequestAggregation.data.json +8 -0
- package/__tests__/ruleRequestAggregation/ruleRequestAggregation.spec.js +69 -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 +24 -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 +134 -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 +28 -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 +55 -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 +46 -0
- package/models/User.js +61 -0
- package/models/Zone.js +126 -0
- package/models/ZoneUIState.js +18 -18
- package/models/conditions/DayRange.js +52 -0
- package/models/conditions/Speed.js +42 -0
- package/models/conditions/TimeActive.js +50 -0
- package/models/conditions/TravelDirection.js +67 -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/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/Webhook.js +27 -0
- package/utils/index.js +39 -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,9 @@
|
|
|
1
|
+
{
|
|
2
|
+
"requiredFields": ["name", "nextRuleUpdateInterval", "accountId"],
|
|
3
|
+
"customValidators": [
|
|
4
|
+
{"name": "nextRuleUpdateInterval", "invalidInput": [5000.5556]},
|
|
5
|
+
{"name": "lastUpdateTime", "invalidInput": ["21/07/2017", "saturday"]},
|
|
6
|
+
{"name": "creationTime", "invalidInput": ["21/07/2017", "thursday"]},
|
|
7
|
+
{"name": "accountId", "invalidInput": ["21/07/2017", 21072017, "qwe123-21321-ad"]}
|
|
8
|
+
]
|
|
9
|
+
}
|
|
@@ -0,0 +1,92 @@
|
|
|
1
|
+
let mongoose = require('mongoose')
|
|
2
|
+
|
|
3
|
+
mongoose.Promise = global.Promise
|
|
4
|
+
|
|
5
|
+
let ProjectModel = require('../../Models').Project(mongoose)
|
|
6
|
+
let ProjectModelBuiltInMongoose = require('../../Models').Project()
|
|
7
|
+
let testCase = require('mocha').describe
|
|
8
|
+
let assertions = require('mocha').it
|
|
9
|
+
let chai = require('chai')
|
|
10
|
+
let assert = chai.assert
|
|
11
|
+
let mocha = require('mocha')
|
|
12
|
+
let beforeEach = mocha.beforeEach
|
|
13
|
+
let rules = require('./project.rules.json')
|
|
14
|
+
|
|
15
|
+
let project
|
|
16
|
+
|
|
17
|
+
beforeEach(() => {
|
|
18
|
+
project = JSON.parse(JSON.stringify(require('./project.data.json')))
|
|
19
|
+
})
|
|
20
|
+
|
|
21
|
+
testCase('Project', () => {
|
|
22
|
+
testCase('Valid Project ', () => {
|
|
23
|
+
assertions('should validate a valid project ', (done) => {
|
|
24
|
+
let Project = new ProjectModel(project)
|
|
25
|
+
Project.validate((err, res) => {
|
|
26
|
+
assert.notExists(res)
|
|
27
|
+
assert(err === null, 'err equals null')
|
|
28
|
+
done()
|
|
29
|
+
})
|
|
30
|
+
})
|
|
31
|
+
})
|
|
32
|
+
testCase('Valid Project ', () => {
|
|
33
|
+
assertions('should validate a valid project ', (done) => {
|
|
34
|
+
let Project = new ProjectModelBuiltInMongoose(project)
|
|
35
|
+
Project.validate((err, res) => {
|
|
36
|
+
assert.notExists(res)
|
|
37
|
+
assert(err === null, 'err equals null')
|
|
38
|
+
done()
|
|
39
|
+
})
|
|
40
|
+
})
|
|
41
|
+
})
|
|
42
|
+
testCase('Invalid Project ', () => {
|
|
43
|
+
assertions('should not validate if webhook headers have more than 1 key value pair ', (done) => {
|
|
44
|
+
|
|
45
|
+
project.webhooks.headers.anotherKey = 'anotherValue'
|
|
46
|
+
|
|
47
|
+
let Project = new ProjectModel(project)
|
|
48
|
+
Project.validate((err, res) => {
|
|
49
|
+
assert.exists(err)
|
|
50
|
+
assert.match(err.message, /1 key <-> value pair/)
|
|
51
|
+
done()
|
|
52
|
+
})
|
|
53
|
+
})
|
|
54
|
+
testCase('recursive property check', () => {
|
|
55
|
+
let requiredFields = rules.requiredFields
|
|
56
|
+
requiredFields.map((i) => {
|
|
57
|
+
assertions(`should throw an error with property '${i}' if '${i}' is not present`, (done) => {
|
|
58
|
+
project = JSON.parse(JSON.stringify(project))
|
|
59
|
+
delete project[i]
|
|
60
|
+
let Project = new ProjectModel(project)
|
|
61
|
+
Project.validate((err, res) => {
|
|
62
|
+
assert.notExists(res)
|
|
63
|
+
assert.exists(err, 'err object should exist')
|
|
64
|
+
assert.isObject(err)
|
|
65
|
+
assert.nestedProperty(err, `errors.${i}`, 'error should have a radius property')
|
|
66
|
+
done()
|
|
67
|
+
})
|
|
68
|
+
})
|
|
69
|
+
})
|
|
70
|
+
})
|
|
71
|
+
|
|
72
|
+
testCase('recursive invalid entry check', () => {
|
|
73
|
+
let invalidProps = rules.customValidators
|
|
74
|
+
invalidProps.map((i) => {
|
|
75
|
+
i.invalidInput.map((j) => {
|
|
76
|
+
assertions(`should throw an error with property '${i.name}' if '${i.name}' is invalid => ${i.name} = ${j}`, (done) => {
|
|
77
|
+
project = JSON.parse(JSON.stringify(project))
|
|
78
|
+
project[i.name] = j
|
|
79
|
+
let Project = new ProjectModel(project)
|
|
80
|
+
Project.validate((err, res) => {
|
|
81
|
+
assert.notExists(res)
|
|
82
|
+
assert.exists(err, 'err object should exist')
|
|
83
|
+
assert.isObject(err)
|
|
84
|
+
assert.nestedProperty(err, `errors.${i.name}`, `error should have a ${i} property`)
|
|
85
|
+
done()
|
|
86
|
+
})
|
|
87
|
+
})
|
|
88
|
+
})
|
|
89
|
+
})
|
|
90
|
+
})
|
|
91
|
+
})
|
|
92
|
+
})
|
|
@@ -0,0 +1,69 @@
|
|
|
1
|
+
let mongoose = require('mongoose')
|
|
2
|
+
|
|
3
|
+
mongoose.Promise = global.Promise
|
|
4
|
+
|
|
5
|
+
let RuleRequestAggregationModel = require('../../Models').RuleRequestAggregation(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 ruleRequestAggregation
|
|
15
|
+
|
|
16
|
+
beforeEach(() => {
|
|
17
|
+
ruleRequestAggregation = JSON.parse(JSON.stringify(require('./ruleRequestAggregation.data.json')))
|
|
18
|
+
})
|
|
19
|
+
|
|
20
|
+
testCase('RuleRequestAggregation', () => {
|
|
21
|
+
testCase('Valid RuleRequestAggregation document', () => {
|
|
22
|
+
assertions('should validate a valid RuleRequestAggregation document ', (done) => {
|
|
23
|
+
let RuleRequestAggregation = new RuleRequestAggregationModel(ruleRequestAggregation)
|
|
24
|
+
RuleRequestAggregation.validate((err, res) => {
|
|
25
|
+
assert.notExists(res)
|
|
26
|
+
assert(err === null, 'err should equals null')
|
|
27
|
+
done()
|
|
28
|
+
})
|
|
29
|
+
})
|
|
30
|
+
assertions('should not accept a invalid customerId', (done) => {
|
|
31
|
+
ruleRequestAggregation.customerId = 'invalid-customerId'
|
|
32
|
+
let RuleRequestAggregation = new RuleRequestAggregationModel(ruleRequestAggregation)
|
|
33
|
+
RuleRequestAggregation.validate((err, res) => {
|
|
34
|
+
assert.exists(err, 'invalid customerId')
|
|
35
|
+
assert.isObject(err)
|
|
36
|
+
done()
|
|
37
|
+
})
|
|
38
|
+
})
|
|
39
|
+
assertions('should not accept a invalid applicationId', (done) => {
|
|
40
|
+
ruleRequestAggregation.applicationId = 'invalid-applicationId'
|
|
41
|
+
let RuleRequestAggregation = new RuleRequestAggregationModel(ruleRequestAggregation)
|
|
42
|
+
RuleRequestAggregation.validate((err, res) => {
|
|
43
|
+
assert.exists(err, 'invalid applicationId')
|
|
44
|
+
assert.isObject(err)
|
|
45
|
+
done()
|
|
46
|
+
})
|
|
47
|
+
})
|
|
48
|
+
assertions('should not accept a negative iosCount value', (done) => {
|
|
49
|
+
const negativeIosCount = -100
|
|
50
|
+
ruleRequestAggregation.iosCount = negativeIosCount
|
|
51
|
+
let RuleRequestAggregation = new RuleRequestAggregationModel(ruleRequestAggregation)
|
|
52
|
+
RuleRequestAggregation.validate((err, res) => {
|
|
53
|
+
assert.exists(err, 'Path `androidCount` (' + negativeIosCount + ') is less than minimum allowed value (0)')
|
|
54
|
+
assert.isObject(err)
|
|
55
|
+
done()
|
|
56
|
+
})
|
|
57
|
+
})
|
|
58
|
+
assertions('should not accept a negative androidCount value', (done) => {
|
|
59
|
+
const negativeAndroidCount = -100
|
|
60
|
+
ruleRequestAggregation.androidCount = negativeAndroidCount
|
|
61
|
+
let RuleRequestAggregation = new RuleRequestAggregationModel(ruleRequestAggregation)
|
|
62
|
+
RuleRequestAggregation.validate((err, res) => {
|
|
63
|
+
assert.exists(err, 'Path `androidCount` (' + negativeAndroidCount + ') is less than minimum allowed value (0)')
|
|
64
|
+
assert.isObject(err)
|
|
65
|
+
done()
|
|
66
|
+
})
|
|
67
|
+
})
|
|
68
|
+
})
|
|
69
|
+
})
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
module.exports = {
|
|
2
|
+
username: 'test@bluedot.io',
|
|
3
|
+
email: 'test@bluedot.io',
|
|
4
|
+
password: 'jfmamjasond',
|
|
5
|
+
firstName: 'John',
|
|
6
|
+
lastName: 'Citizen',
|
|
7
|
+
phoneNumber: '23429384',
|
|
8
|
+
state: 'ACTIVE',
|
|
9
|
+
lastUpdateTime: '2018-02-14T04:12:02.103Z',
|
|
10
|
+
creationTime: '2018-02-14T04:12:02.103Z',
|
|
11
|
+
isAdmin: true,
|
|
12
|
+
accountId: '37ac5be3-60ec-4fb7-9f88-a4f6e8895f81',
|
|
13
|
+
projectPermissions: [
|
|
14
|
+
{
|
|
15
|
+
permissionLevel: 'READ_WRITE',
|
|
16
|
+
projectId: '1dc621a1-7980-410b-839b-4bed63600139'
|
|
17
|
+
}
|
|
18
|
+
]
|
|
19
|
+
}
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
module.exports = {
|
|
2
|
+
requiredFields: ['username', 'firstName', 'lastName', 'isAdmin', 'accountId'],
|
|
3
|
+
customValidators: [
|
|
4
|
+
{name: 'phoneNumber', invalidInputs: ['409203492039284232034398']},
|
|
5
|
+
{name: 'creationTime', invalidInputs: ['21/07/2017', 'thursday']},
|
|
6
|
+
{name: 'lastUpdateTime', invalidInputs: ['21/07/2017', 'saturday']}
|
|
7
|
+
]
|
|
8
|
+
}
|
|
@@ -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,24 @@
|
|
|
1
|
+
const { trimDecimals } = require('../../utils');
|
|
2
|
+
|
|
3
|
+
describe('trimDecimals(num, n)', () => {
|
|
4
|
+
const tests = [{
|
|
5
|
+
num: -37.8196889692931,
|
|
6
|
+
n: 6,
|
|
7
|
+
expected: -37.819689,
|
|
8
|
+
}, {
|
|
9
|
+
num: 42,
|
|
10
|
+
n: 2,
|
|
11
|
+
expected: 42,
|
|
12
|
+
}, {
|
|
13
|
+
num: 23.39,
|
|
14
|
+
n: 1,
|
|
15
|
+
expected: 23.3,
|
|
16
|
+
}]
|
|
17
|
+
|
|
18
|
+
tests.forEach(({num, n, expected}) => {
|
|
19
|
+
it(`when num is ${num} and n is ${n}, it should return ${expected}`, () => {
|
|
20
|
+
const isCorrect = (trimDecimals(num,n) === expected)
|
|
21
|
+
assert(isCorrect);
|
|
22
|
+
})
|
|
23
|
+
})
|
|
24
|
+
})
|
|
@@ -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
|
+
}
|