@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,104 @@
|
|
|
1
|
+
let mongoose = require('mongoose')
|
|
2
|
+
|
|
3
|
+
mongoose.Promise = global.Promise
|
|
4
|
+
|
|
5
|
+
let BeaconModel = require('../../Models').Beacon(mongoose)
|
|
6
|
+
let describe = require('mocha').describe
|
|
7
|
+
let it = 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('./beacon.rules.json')
|
|
15
|
+
|
|
16
|
+
let beacon
|
|
17
|
+
|
|
18
|
+
beforeEach(() => {
|
|
19
|
+
beacon = JSON.parse(JSON.stringify(require('./beacon.data.json')))
|
|
20
|
+
})
|
|
21
|
+
|
|
22
|
+
describe('Beacon', () => {
|
|
23
|
+
describe('Valid Beacon', () => {
|
|
24
|
+
it('should validate a valid beacon', (done) => {
|
|
25
|
+
const Beacon = new BeaconModel(beacon)
|
|
26
|
+
Beacon.validate((err, res) => {
|
|
27
|
+
assert.notExists(res)
|
|
28
|
+
assert(err === null, 'err should equal null')
|
|
29
|
+
done()
|
|
30
|
+
})
|
|
31
|
+
})
|
|
32
|
+
})
|
|
33
|
+
|
|
34
|
+
describe('Invalid Beacon', () => {
|
|
35
|
+
it('should not validate a beacon with invalid Beacon', (done) => {
|
|
36
|
+
delete beacon[rules.requiredFields[0]]
|
|
37
|
+
let Beacon = new BeaconModel(beacon)
|
|
38
|
+
Beacon.validate((err, res) => {
|
|
39
|
+
assert.exists(err, 'err object should exist')
|
|
40
|
+
assert.isObject(err)
|
|
41
|
+
done()
|
|
42
|
+
})
|
|
43
|
+
})
|
|
44
|
+
|
|
45
|
+
describe('check each required property of the model and validate that it is present', (done) => {
|
|
46
|
+
let dependentRequiredFields = rules.dependentRequiredFields
|
|
47
|
+
dependentRequiredFields.forEach((parent) => {
|
|
48
|
+
parent.pairings.forEach((i) => {
|
|
49
|
+
i.requiredFields.forEach((field) => {
|
|
50
|
+
it(`should throw an error with property '${parent.property}' if '${i.value}' is selected and '${field}' is invalid`, (done) => {
|
|
51
|
+
// delete beacon[field] i.e. txPower from beacon
|
|
52
|
+
delete beacon[field]
|
|
53
|
+
// set required dependent field property
|
|
54
|
+
beacon[parent.property] = i.value
|
|
55
|
+
let Beacon = new BeaconModel(beacon)
|
|
56
|
+
Beacon.validate((err, res) => {
|
|
57
|
+
assert.notExists(res)
|
|
58
|
+
assert.exists(err, 'err object should exist')
|
|
59
|
+
assert.isObject(err)
|
|
60
|
+
assert.nestedProperty(err, `errors.${parent.property}`, `error should have a ${parent.property} property`)
|
|
61
|
+
done()
|
|
62
|
+
})
|
|
63
|
+
})
|
|
64
|
+
})
|
|
65
|
+
})
|
|
66
|
+
})
|
|
67
|
+
})
|
|
68
|
+
|
|
69
|
+
describe('check each required property of the model and validate that it is present', () => {
|
|
70
|
+
let requiredFields = rules.requiredFields
|
|
71
|
+
requiredFields.forEach((requiredField) => {
|
|
72
|
+
it(`should throw an error with property '${requiredField}' if '${requiredField}' is not present`, (done) => {
|
|
73
|
+
// delete i from geofeatures' beacon child
|
|
74
|
+
delete beacon[requiredField]
|
|
75
|
+
let Beacon = new BeaconModel(beacon)
|
|
76
|
+
Beacon.validate((err, res) => {
|
|
77
|
+
assert.notExists(res)
|
|
78
|
+
assert.exists(err, 'err object should exist')
|
|
79
|
+
assert.isObject(err)
|
|
80
|
+
assert.nestedProperty(err, `errors.${requiredField}`, `error should have a ${requiredField} property`)
|
|
81
|
+
done()
|
|
82
|
+
})
|
|
83
|
+
})
|
|
84
|
+
})
|
|
85
|
+
})
|
|
86
|
+
|
|
87
|
+
describe('should fail validation if the beaconType does not match the enum', () => {
|
|
88
|
+
const failingBeaconTypes = ['ios', 'iOS', 'android', 'ANDROID', 'both', 'BOTH'];
|
|
89
|
+
|
|
90
|
+
failingBeaconTypes.forEach(beaconType => {
|
|
91
|
+
it(beaconType, (done) => {
|
|
92
|
+
let Beacon = new BeaconModel(beacon);
|
|
93
|
+
Beacon.beaconType = beaconType;
|
|
94
|
+
|
|
95
|
+
Beacon.validate((err, res) => {
|
|
96
|
+
assert.exists(err)
|
|
97
|
+
assert.match(err, /(is not a valid enum value)/i)
|
|
98
|
+
done()
|
|
99
|
+
})
|
|
100
|
+
})
|
|
101
|
+
})
|
|
102
|
+
})
|
|
103
|
+
})
|
|
104
|
+
})
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
// not implemented. not sure if required
|
|
@@ -0,0 +1,74 @@
|
|
|
1
|
+
let mongoose = require('mongoose')
|
|
2
|
+
|
|
3
|
+
mongoose.Promise = global.Promise
|
|
4
|
+
|
|
5
|
+
let DayRangeModel = require('../../../Models').DayRange(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('./dayRange.rules.json')
|
|
15
|
+
|
|
16
|
+
let dayRange
|
|
17
|
+
|
|
18
|
+
beforeEach(() => {
|
|
19
|
+
dayRange = JSON.parse(JSON.stringify(require('./dayRange.data.json')))
|
|
20
|
+
})
|
|
21
|
+
|
|
22
|
+
testCase('DayRangeCondition', () => {
|
|
23
|
+
testCase('Valid DayRangeCondition', () => {
|
|
24
|
+
assertions('should validate a valid dayRange', (done) => {
|
|
25
|
+
let DayRangeCondition = new DayRangeModel(dayRange)
|
|
26
|
+
DayRangeCondition.validate((err, res) => {
|
|
27
|
+
assert.notExists(res)
|
|
28
|
+
assert(err === null, 'err should equals null')
|
|
29
|
+
done()
|
|
30
|
+
})
|
|
31
|
+
})
|
|
32
|
+
})
|
|
33
|
+
|
|
34
|
+
testCase('Invalid DayRangeCondition', () => {
|
|
35
|
+
assertions('should not validate a dayRange with invalid DayRangeCondition', (done) => {
|
|
36
|
+
delete dayRange[rules.requiredFields[0]]
|
|
37
|
+
let DayRangeCondition = new DayRangeModel(dayRange)
|
|
38
|
+
DayRangeCondition.validate((err, res) => {
|
|
39
|
+
assert.exists(err, 'err object should exist')
|
|
40
|
+
assert.isObject(err)
|
|
41
|
+
done()
|
|
42
|
+
})
|
|
43
|
+
})
|
|
44
|
+
|
|
45
|
+
assertions('should throw an error if both startDate and endDate are not provided', (done) => {
|
|
46
|
+
delete dayRange.startDate
|
|
47
|
+
delete dayRange.endDate
|
|
48
|
+
let DayRangeCondition = new DayRangeModel(dayRange)
|
|
49
|
+
DayRangeCondition.validate((err, res) => {
|
|
50
|
+
assert.exists(err, 'err object should exist')
|
|
51
|
+
assert.isObject(err)
|
|
52
|
+
done()
|
|
53
|
+
})
|
|
54
|
+
})
|
|
55
|
+
|
|
56
|
+
testCase('check each required property of the model and validate that it is present', () => {
|
|
57
|
+
let requiredFields = rules.requiredFields
|
|
58
|
+
requiredFields.map((i) => {
|
|
59
|
+
assertions(`should throw an error with property '${i}' if '${i}' is not present`, (done) => {
|
|
60
|
+
// delete i from geofeatures' dayRange child
|
|
61
|
+
delete dayRange[i]
|
|
62
|
+
let DayRangeCondition = new DayRangeModel(dayRange)
|
|
63
|
+
DayRangeCondition.validate((err, res) => {
|
|
64
|
+
assert.notExists(res)
|
|
65
|
+
assert.exists(err, 'err object should exist')
|
|
66
|
+
assert.isObject(err)
|
|
67
|
+
assert.nestedProperty(err, `errors.${i}`, `error should have a ${i} property`)
|
|
68
|
+
done()
|
|
69
|
+
})
|
|
70
|
+
})
|
|
71
|
+
})
|
|
72
|
+
})
|
|
73
|
+
})
|
|
74
|
+
})
|
|
@@ -0,0 +1,62 @@
|
|
|
1
|
+
let mongoose = require('mongoose')
|
|
2
|
+
|
|
3
|
+
mongoose.Promise = global.Promise
|
|
4
|
+
|
|
5
|
+
let TravelPathConditionModel = require('../../../Models').TravelPath(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('./travelPath.rules.json')
|
|
15
|
+
|
|
16
|
+
let travelPath
|
|
17
|
+
|
|
18
|
+
beforeEach(() => {
|
|
19
|
+
travelPath = JSON.parse(JSON.stringify(require('./travelPath.data.json')))
|
|
20
|
+
})
|
|
21
|
+
|
|
22
|
+
testCase('PercentageCrossedCondition', () => {
|
|
23
|
+
testCase('Valid PercentageCrossedCondition', () => {
|
|
24
|
+
assertions('should validate a valid travelPath ', (done) => {
|
|
25
|
+
let PercentageCrossedCondition = new TravelPathConditionModel(travelPath)
|
|
26
|
+
PercentageCrossedCondition.validate((err, res) => {
|
|
27
|
+
assert.notExists(res)
|
|
28
|
+
assert(err === null, 'err should equals null')
|
|
29
|
+
done()
|
|
30
|
+
})
|
|
31
|
+
})
|
|
32
|
+
})
|
|
33
|
+
|
|
34
|
+
testCase('Invalid PercentageCrossedCondition', () => {
|
|
35
|
+
assertions('should not validate a travelPath with invalid PercentageCrossedCondition', (done) => {
|
|
36
|
+
delete travelPath[rules.requiredFields[0]]
|
|
37
|
+
let PercentageCrossedCondition = new TravelPathConditionModel(travelPath)
|
|
38
|
+
PercentageCrossedCondition.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' travelPath child
|
|
49
|
+
delete travelPath[i]
|
|
50
|
+
let PercentageCrossedCondition = new TravelPathConditionModel(travelPath)
|
|
51
|
+
PercentageCrossedCondition.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
|
+
})
|
|
@@ -0,0 +1,73 @@
|
|
|
1
|
+
let mongoose = require('mongoose')
|
|
2
|
+
|
|
3
|
+
mongoose.Promise = global.Promise
|
|
4
|
+
|
|
5
|
+
let SpeedConditionModel = require('../../../Models').Speed(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('./speed.rules.json')
|
|
15
|
+
|
|
16
|
+
let speedCondition
|
|
17
|
+
|
|
18
|
+
beforeEach(() => {
|
|
19
|
+
speedCondition = JSON.parse(JSON.stringify(require('./speed.data.json')))
|
|
20
|
+
})
|
|
21
|
+
|
|
22
|
+
testCase('SpeedCondition', () => {
|
|
23
|
+
testCase('Valid SpeedCondition', () => {
|
|
24
|
+
assertions('should validate a valid speedCondition ', (done) => {
|
|
25
|
+
let SpeedCondition = new SpeedConditionModel(speedCondition)
|
|
26
|
+
SpeedCondition.validate((err, res) => {
|
|
27
|
+
assert.notExists(res)
|
|
28
|
+
assert(err === null, 'err should equals null')
|
|
29
|
+
done()
|
|
30
|
+
})
|
|
31
|
+
})
|
|
32
|
+
})
|
|
33
|
+
|
|
34
|
+
testCase('Invalid SpeedCondition', () => {
|
|
35
|
+
assertions('should not validate a speedCondition with invalid SpeedCondition', (done) => {
|
|
36
|
+
delete speedCondition[rules.requiredFields[0]]
|
|
37
|
+
let SpeedCondition = new SpeedConditionModel(speedCondition)
|
|
38
|
+
SpeedCondition.validate((err, res) => {
|
|
39
|
+
assert.exists(err, 'err object should exist')
|
|
40
|
+
assert.isObject(err)
|
|
41
|
+
done()
|
|
42
|
+
})
|
|
43
|
+
})
|
|
44
|
+
assertions('should throw an error when maxSpeed is less than 5 of minSpeed', (done) => {
|
|
45
|
+
speedCondition.minimumSpeed = 10
|
|
46
|
+
speedCondition.maximumSpeed = 11
|
|
47
|
+
let SpeedCondition = new SpeedConditionModel(speedCondition)
|
|
48
|
+
SpeedCondition.validate((err, res) => {
|
|
49
|
+
assert.exists(err, 'err object should exist')
|
|
50
|
+
assert.isObject(err)
|
|
51
|
+
assert.nestedProperty(err, `errors.maximumSpeed`, 'error should have a maximumSpeed property')
|
|
52
|
+
done()
|
|
53
|
+
})
|
|
54
|
+
})
|
|
55
|
+
testCase('check each required property of the model and validate that it is present', () => {
|
|
56
|
+
let requiredFields = rules.requiredFields
|
|
57
|
+
requiredFields.map((i) => {
|
|
58
|
+
assertions(`should throw an error with property '${i}' if '${i}' is not present`, (done) => {
|
|
59
|
+
// delete i from geofeatures' speedCondition child
|
|
60
|
+
delete speedCondition[i]
|
|
61
|
+
let SpeedCondition = new SpeedConditionModel(speedCondition)
|
|
62
|
+
SpeedCondition.validate((err, res) => {
|
|
63
|
+
assert.notExists(res)
|
|
64
|
+
assert.exists(err, 'err object should exist')
|
|
65
|
+
assert.isObject(err)
|
|
66
|
+
assert.nestedProperty(err, `errors.${i}`, `error should have a ${i} property`)
|
|
67
|
+
done()
|
|
68
|
+
})
|
|
69
|
+
})
|
|
70
|
+
})
|
|
71
|
+
})
|
|
72
|
+
})
|
|
73
|
+
})
|
|
@@ -0,0 +1,94 @@
|
|
|
1
|
+
let mongoose = require('mongoose')
|
|
2
|
+
|
|
3
|
+
mongoose.Promise = global.Promise
|
|
4
|
+
|
|
5
|
+
let TimeActiveConditionModel = require('../../../Models').TimeActive(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 rules = require('./timeActive.rules.json')
|
|
14
|
+
|
|
15
|
+
let timeActiveCondition
|
|
16
|
+
|
|
17
|
+
beforeEach(() => {
|
|
18
|
+
timeActiveCondition = JSON.parse(JSON.stringify(require('./timeActive.data.json')))
|
|
19
|
+
})
|
|
20
|
+
|
|
21
|
+
testCase('TimeOfDayRangeCondition', () => {
|
|
22
|
+
testCase('Valid TimeOfDayRangeCondition', () => {
|
|
23
|
+
assertions('should validate a valid timeActiveCondition ', (done) => {
|
|
24
|
+
let TimeOfDayRangeCondition = new TimeActiveConditionModel(timeActiveCondition)
|
|
25
|
+
TimeOfDayRangeCondition.validate((err, res) => {
|
|
26
|
+
assert.notExists(res)
|
|
27
|
+
assert(err === null, 'err should equals null')
|
|
28
|
+
done()
|
|
29
|
+
})
|
|
30
|
+
})
|
|
31
|
+
})
|
|
32
|
+
|
|
33
|
+
testCase('Invalid TimeOfDayRangeCondition', () => {
|
|
34
|
+
assertions('should not validate a timeActiveCondition with invalid TimeOfDayRangeCondition', (done) => {
|
|
35
|
+
delete timeActiveCondition[rules.requiredFields[0]]
|
|
36
|
+
let TimeOfDayRangeCondition = new TimeActiveConditionModel(timeActiveCondition)
|
|
37
|
+
TimeOfDayRangeCondition.validate((err, res) => {
|
|
38
|
+
assert.exists(err, 'err object should exist')
|
|
39
|
+
assert.isObject(err)
|
|
40
|
+
done()
|
|
41
|
+
})
|
|
42
|
+
})
|
|
43
|
+
assertions('should throw an error when toTime === fromTime', (done) => {
|
|
44
|
+
timeActiveCondition.toTime = "00:30:00"
|
|
45
|
+
timeActiveCondition.fromTime = "00:30:00"
|
|
46
|
+
let TimeOfDayRangeCondition = new TimeActiveConditionModel(timeActiveCondition)
|
|
47
|
+
TimeOfDayRangeCondition.validate((err, res) => {
|
|
48
|
+
assert.exists(err, 'err object should exist')
|
|
49
|
+
assert.isObject(err)
|
|
50
|
+
assert.nestedProperty(err, `errors.toTime`, 'error should have a toTime property')
|
|
51
|
+
done()
|
|
52
|
+
})
|
|
53
|
+
})
|
|
54
|
+
|
|
55
|
+
testCase('recursive invalid time inputs check', () => {
|
|
56
|
+
let invalidTimes = rules.customValidators
|
|
57
|
+
|
|
58
|
+
invalidTimes.map(i => {
|
|
59
|
+
i.invalidInput.map(j => {
|
|
60
|
+
assertions(`should throw an error with property '${i.name}' if '${i.name} is invalid => ${i.name} = ${j}'`, done => {
|
|
61
|
+
timeActiveCondition = JSON.parse(JSON.stringify(timeActiveCondition))
|
|
62
|
+
timeActiveCondition[i.name] = j
|
|
63
|
+
let TimeOfDayRangeCondition = new TimeActiveConditionModel(timeActiveCondition)
|
|
64
|
+
TimeOfDayRangeCondition.validate((err, res) => {
|
|
65
|
+
assert.exists(err, 'err object should exits')
|
|
66
|
+
assert.isObject(err)
|
|
67
|
+
assert.nestedProperty(err, `errors.${i.name}`, 'time format must be hh:mm:ss')
|
|
68
|
+
assert.nestedProperty(err, `errors.${i.name}`, 'time format must be hh:mm:ss')
|
|
69
|
+
done()
|
|
70
|
+
})
|
|
71
|
+
})
|
|
72
|
+
})
|
|
73
|
+
})
|
|
74
|
+
})
|
|
75
|
+
|
|
76
|
+
testCase('check each required property of the model and validate that it is present', () => {
|
|
77
|
+
let requiredFields = rules.requiredFields
|
|
78
|
+
requiredFields.map((i) => {
|
|
79
|
+
assertions(`should throw an error with property '${i}' if '${i}' is not present`, (done) => {
|
|
80
|
+
// delete i from geofeatures' timeActiveCondition child
|
|
81
|
+
delete timeActiveCondition[i]
|
|
82
|
+
let TimeOfDayRangeCondition = new TimeActiveConditionModel(timeActiveCondition)
|
|
83
|
+
TimeOfDayRangeCondition.validate((err, res) => {
|
|
84
|
+
assert.notExists(res)
|
|
85
|
+
assert.exists(err, 'err object should exist')
|
|
86
|
+
assert.isObject(err)
|
|
87
|
+
assert.nestedProperty(err, `errors.${i}`, `error should have a ${i} property`)
|
|
88
|
+
done()
|
|
89
|
+
})
|
|
90
|
+
})
|
|
91
|
+
})
|
|
92
|
+
})
|
|
93
|
+
})
|
|
94
|
+
})
|
|
@@ -0,0 +1,132 @@
|
|
|
1
|
+
let mongoose = require('mongoose')
|
|
2
|
+
mongoose.Promise = global.Promise
|
|
3
|
+
|
|
4
|
+
const TravelDirectionModel = require('../../../Models').TravelDirection(mongoose)
|
|
5
|
+
const { isMinimumNinetyApart } = require.main.require('models/conditions/TravelDirection')
|
|
6
|
+
const describe = require('mocha').describe
|
|
7
|
+
const it = require('mocha').it
|
|
8
|
+
const chai = require('chai')
|
|
9
|
+
const assert = chai.assert
|
|
10
|
+
const mocha = require('mocha')
|
|
11
|
+
const beforeEach = mocha.beforeEach
|
|
12
|
+
const rules = require('./travelDirection.rules.json')
|
|
13
|
+
|
|
14
|
+
let travelDirectionCondition
|
|
15
|
+
|
|
16
|
+
beforeEach(() => {
|
|
17
|
+
travelDirectionCondition = JSON.parse(JSON.stringify(require('./travelDirection.data.json')))
|
|
18
|
+
})
|
|
19
|
+
|
|
20
|
+
describe('TravelDirection', () => {
|
|
21
|
+
describe('Valid TravelDirection', () => {
|
|
22
|
+
it('should validate a valid travelDirectionCondition ', (done) => {
|
|
23
|
+
let TravelDirection = new TravelDirectionModel(travelDirectionCondition)
|
|
24
|
+
TravelDirection.validate((err, res) => {
|
|
25
|
+
assert.notExists(res)
|
|
26
|
+
assert(err === null, 'err should equals null')
|
|
27
|
+
done()
|
|
28
|
+
})
|
|
29
|
+
})
|
|
30
|
+
})
|
|
31
|
+
|
|
32
|
+
describe('Invalid TravelDirection', () => {
|
|
33
|
+
it('should not validate a travelDirectionCondition with invalid TravelDirection', (done) => {
|
|
34
|
+
delete travelDirectionCondition[rules.requiredFields[0]]
|
|
35
|
+
let TravelDirection = new TravelDirectionModel(travelDirectionCondition)
|
|
36
|
+
TravelDirection.validate((err, res) => {
|
|
37
|
+
assert.exists(err, 'err object should exist')
|
|
38
|
+
assert.isObject(err)
|
|
39
|
+
done()
|
|
40
|
+
})
|
|
41
|
+
})
|
|
42
|
+
it('should throw an error when toAngle === fromAngle', (done) => {
|
|
43
|
+
travelDirectionCondition.toAngle = 10
|
|
44
|
+
travelDirectionCondition.fromAngle = 10
|
|
45
|
+
let TravelDirection = new TravelDirectionModel(travelDirectionCondition)
|
|
46
|
+
TravelDirection.validate((err, res) => {
|
|
47
|
+
assert.exists(err, 'err object should exist')
|
|
48
|
+
assert.isObject(err)
|
|
49
|
+
assert.nestedProperty(err, `errors.toAngle`, 'error should have a toAngle property')
|
|
50
|
+
done()
|
|
51
|
+
})
|
|
52
|
+
})
|
|
53
|
+
it('should throw an error when toAngle < 90 degrees from fromAngle (and toAngle < fromAngle)', (done) => {
|
|
54
|
+
travelDirectionCondition.toAngle = 5
|
|
55
|
+
travelDirectionCondition.fromAngle = 10
|
|
56
|
+
let TravelDirection = new TravelDirectionModel(travelDirectionCondition)
|
|
57
|
+
TravelDirection.validate((err, res) => {
|
|
58
|
+
assert.exists(err, 'err object should exist')
|
|
59
|
+
assert.isObject(err)
|
|
60
|
+
assert.nestedProperty(err, `errors.toAngle`, 'error should have a toAngle property')
|
|
61
|
+
done()
|
|
62
|
+
})
|
|
63
|
+
})
|
|
64
|
+
it('should throw an error when toAngle < 90 degrees from fromAngle (and toAngle > fromAngle)', (done) => {
|
|
65
|
+
travelDirectionCondition.toAngle = 10
|
|
66
|
+
travelDirectionCondition.fromAngle = 5
|
|
67
|
+
let TravelDirection = new TravelDirectionModel(travelDirectionCondition)
|
|
68
|
+
TravelDirection.validate((err, res) => {
|
|
69
|
+
assert.exists(err, 'err object should exist')
|
|
70
|
+
assert.isObject(err)
|
|
71
|
+
assert.nestedProperty(err, `errors.toAngle`, 'error should have a toAngle property')
|
|
72
|
+
done()
|
|
73
|
+
})
|
|
74
|
+
})
|
|
75
|
+
describe('check each required property of the model and validate that it is present', () => {
|
|
76
|
+
let requiredFields = rules.requiredFields
|
|
77
|
+
requiredFields.map((i) => {
|
|
78
|
+
it(`should throw an error with property '${i}' if '${i}' is not present`, (done) => {
|
|
79
|
+
// delete i from geofeatures' travelDirectionCondition child
|
|
80
|
+
delete travelDirectionCondition[i]
|
|
81
|
+
let TravelDirection = new TravelDirectionModel(travelDirectionCondition)
|
|
82
|
+
TravelDirection.validate((err, res) => {
|
|
83
|
+
assert.notExists(res)
|
|
84
|
+
assert.exists(err, 'err object should exist')
|
|
85
|
+
assert.isObject(err)
|
|
86
|
+
assert.nestedProperty(err, `errors.${i}`, `error should have a ${i} property`)
|
|
87
|
+
done()
|
|
88
|
+
})
|
|
89
|
+
})
|
|
90
|
+
})
|
|
91
|
+
})
|
|
92
|
+
})
|
|
93
|
+
})
|
|
94
|
+
|
|
95
|
+
describe('isMinimumNinetyApart(fromAngle, toAngle)', () => {
|
|
96
|
+
describe('should return true if the angles are at least 90 degrees apart in both directions', () => {
|
|
97
|
+
const angles = [
|
|
98
|
+
[360, 90],
|
|
99
|
+
[0, 90],
|
|
100
|
+
[90, 180],
|
|
101
|
+
[50, 140],
|
|
102
|
+
[315, 50],
|
|
103
|
+
[300, 30],
|
|
104
|
+
[211, 301]
|
|
105
|
+
]
|
|
106
|
+
|
|
107
|
+
angles.forEach(([fromAngle, toAngle]) => {
|
|
108
|
+
it(`fromAngle ${fromAngle} and toAngle ${toAngle} should be true`, () => {
|
|
109
|
+
const result = isMinimumNinetyApart(fromAngle, toAngle)
|
|
110
|
+
assert.isTrue(result)
|
|
111
|
+
})
|
|
112
|
+
})
|
|
113
|
+
})
|
|
114
|
+
|
|
115
|
+
describe('should return false if the angles are NOT at least 90 degrees apart in both directions', () => {
|
|
116
|
+
const angles = [
|
|
117
|
+
[359, 2],
|
|
118
|
+
[50, 90],
|
|
119
|
+
[315, 360],
|
|
120
|
+
[180, 181],
|
|
121
|
+
[0, 89],
|
|
122
|
+
[360, 89]
|
|
123
|
+
]
|
|
124
|
+
|
|
125
|
+
angles.forEach(([fromAngle, toAngle]) => {
|
|
126
|
+
it(`fromAngle ${fromAngle} and toAngle ${toAngle} should be false`, () => {
|
|
127
|
+
const result = isMinimumNinetyApart(fromAngle, toAngle)
|
|
128
|
+
assert.isFalse(result)
|
|
129
|
+
})
|
|
130
|
+
})
|
|
131
|
+
})
|
|
132
|
+
})
|
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
const assert = require('chai').assert
|
|
2
|
+
const DailyStats = require('../../models/DailyStats')
|
|
3
|
+
let testCase = require('mocha').describe
|
|
4
|
+
let assertions = require('mocha').it
|
|
5
|
+
|
|
6
|
+
const dailyStats = {
|
|
7
|
+
totalEndUsers: 4626,
|
|
8
|
+
totalIos: 2196,
|
|
9
|
+
totalAndroid: 2430
|
|
10
|
+
}
|
|
11
|
+
|
|
12
|
+
testCase('Creating new dailyStats document ', () => {
|
|
13
|
+
assertions('validates data types and structure of dailyStats document', (done) => {
|
|
14
|
+
const createDailyStats = new DailyStats(dailyStats)
|
|
15
|
+
assert(createDailyStats._id)
|
|
16
|
+
assert(createDailyStats._id.match(/[a-f0-9]{8}-[a-f0-9]{4}-[a-f0-9]{4}-[a-f0-9]{4}-[a-f0-9]{12}/))
|
|
17
|
+
createDailyStats.validate()
|
|
18
|
+
.then(() => {
|
|
19
|
+
console.log('validate DailyStats')
|
|
20
|
+
assert(true)
|
|
21
|
+
done()
|
|
22
|
+
}).catch(err => {
|
|
23
|
+
console.log('Errors found:')
|
|
24
|
+
for (let key of Object.keys(err.errors)) {
|
|
25
|
+
console.log(err.errors[key].message)
|
|
26
|
+
}
|
|
27
|
+
assert(false)
|
|
28
|
+
done(err)
|
|
29
|
+
})
|
|
30
|
+
})
|
|
31
|
+
})
|