@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.
Files changed (160) hide show
  1. package/.eslintrc.js +42 -0
  2. package/.gitlab-ci.yml +43 -0
  3. package/CHANGELOG.md +156 -0
  4. package/Models.js +55 -10
  5. package/README.MD +36 -0
  6. package/__tests__/account/account.data.json +12 -0
  7. package/__tests__/account/account.rules.js +8 -0
  8. package/__tests__/account/account.spec.js +83 -0
  9. package/__tests__/action/message/messageAction.data.json +5 -0
  10. package/__tests__/action/message/messageAction.rules.json +3 -0
  11. package/__tests__/action/message/messageAction.spec.js +61 -0
  12. package/__tests__/action/url/urlAction.data.json +4 -0
  13. package/__tests__/action/url/urlAction.rules.json +3 -0
  14. package/__tests__/action/url/urlAction.spec.js +74 -0
  15. package/__tests__/beacon/beacon.data.json +15 -0
  16. package/__tests__/beacon/beacon.rules.json +13 -0
  17. package/__tests__/beacon/beacon.spec.js +104 -0
  18. package/__tests__/condition/beacon/beaconFilter.data.json +1 -0
  19. package/__tests__/condition/beacon/beaconFilter.rules.json +3 -0
  20. package/__tests__/condition/beacon/beaconFilter.spec.js +1 -0
  21. package/__tests__/condition/dayRange/dayRange.data.json +5 -0
  22. package/__tests__/condition/dayRange/dayRange.rules.json +3 -0
  23. package/__tests__/condition/dayRange/dayRange.spec.js +74 -0
  24. package/__tests__/condition/percentageCrossed/travelPath.data.json +5 -0
  25. package/__tests__/condition/percentageCrossed/travelPath.rules.json +3 -0
  26. package/__tests__/condition/percentageCrossed/travelPath.spec.js +62 -0
  27. package/__tests__/condition/speed/speed.data.json +5 -0
  28. package/__tests__/condition/speed/speed.rules.json +3 -0
  29. package/__tests__/condition/speed/speed.spec.js +73 -0
  30. package/__tests__/condition/timeActive/timeActive.data.json +5 -0
  31. package/__tests__/condition/timeActive/timeActive.rules.json +7 -0
  32. package/__tests__/condition/timeActive/timeActive.spec.js +94 -0
  33. package/__tests__/condition/travelDirection/travelDirection.data.json +5 -0
  34. package/__tests__/condition/travelDirection/travelDirection.rules.json +3 -0
  35. package/__tests__/condition/travelDirection/travelDirection.spec.js +132 -0
  36. package/__tests__/dailyStats/checkDailyStats.js +31 -0
  37. package/__tests__/geofeature/boundingBox/boundingBox.data.json +12 -0
  38. package/__tests__/geofeature/boundingBox/boundingBox.rules.json +3 -0
  39. package/__tests__/geofeature/boundingBox/boundingBox.spec.js +78 -0
  40. package/__tests__/geofeature/circle/circle.data.json +9 -0
  41. package/__tests__/geofeature/circle/circle.rules.json +3 -0
  42. package/__tests__/geofeature/circle/circle.spec.js +71 -0
  43. package/__tests__/geofeature/geoline/geoline.data.json +46 -0
  44. package/__tests__/geofeature/geoline/geoline.rules.json +3 -0
  45. package/__tests__/geofeature/geoline/geoline.spec.js +70 -0
  46. package/__tests__/geofeature/polygon/polygon.data.json +46 -0
  47. package/__tests__/geofeature/polygon/polygon.rules.json +3 -0
  48. package/__tests__/geofeature/polygon/polygon.spec.js +127 -0
  49. package/__tests__/geofeature/zoneBeacon/zoneBeacon.data.json +16 -0
  50. package/__tests__/geofeature/zoneBeacon/zoneBeacon.rules.json +13 -0
  51. package/__tests__/geofeature/zoneBeacon/zoneBeacon.spec.js +62 -0
  52. package/__tests__/monthlyStats/monthlyStats.data.json +29 -0
  53. package/__tests__/monthlyStats/monthlyStats.spec.js +66 -0
  54. package/__tests__/project/project.data.json +18 -0
  55. package/__tests__/project/project.rules.json +9 -0
  56. package/__tests__/project/project.spec.js +92 -0
  57. package/__tests__/ruleRequestAggregation/ruleRequestAggregation.data.json +8 -0
  58. package/__tests__/ruleRequestAggregation/ruleRequestAggregation.spec.js +69 -0
  59. package/__tests__/setup.js +7 -0
  60. package/__tests__/user/user.data.js +19 -0
  61. package/__tests__/user/user.rules.js +8 -0
  62. package/__tests__/user/user.spec.js +130 -0
  63. package/__tests__/utils/utils.spec.js +24 -0
  64. package/__tests__/zone/zone.action.spec.js +50 -0
  65. package/__tests__/zone/zone.condition.spec.js +94 -0
  66. package/__tests__/zone/zone.data.json +157 -0
  67. package/__tests__/zone/zone.geofeatures.spec.js +75 -0
  68. package/__tests__/zone/zone.spec.js +134 -0
  69. package/constants/errorMessages.js +2 -0
  70. package/helpers.js +117 -0
  71. package/models/Account.js +50 -0
  72. package/models/AdminPortalUser.js +10 -11
  73. package/models/Beacon.js +84 -32
  74. package/models/Contract.js +37 -38
  75. package/models/CustomerLogin.js +9 -10
  76. package/models/DBEvent.js +13 -14
  77. package/models/DailyStats.js +7 -7
  78. package/models/DeviceRulesRequest.js +27 -28
  79. package/models/MessageAction.js +28 -26
  80. package/models/MonthlyStats.js +35 -19
  81. package/models/NotificationLogEntry.js +7 -8
  82. package/models/POILocation.js +6 -7
  83. package/models/POILookup.js +8 -9
  84. package/models/POIResult.js +7 -8
  85. package/models/PartnerCustomer.js +12 -13
  86. package/models/PartnerPasswordReset.js +8 -9
  87. package/models/PartnerUser.js +10 -11
  88. package/models/Partners.js +11 -12
  89. package/models/Project.js +55 -0
  90. package/models/RuleRequestAggregation.js +33 -17
  91. package/models/SingleUseToken.js +7 -8
  92. package/models/TestDevice.js +11 -12
  93. package/models/TestDeviceCluster.js +9 -10
  94. package/models/TestInstance.js +9 -10
  95. package/models/TestScenario.js +9 -10
  96. package/models/TimeOfDayRange.js +16 -16
  97. package/models/UrlAction.js +46 -0
  98. package/models/User.js +61 -0
  99. package/models/Zone.js +126 -0
  100. package/models/ZoneUIState.js +18 -18
  101. package/models/conditions/DayRange.js +52 -0
  102. package/models/conditions/Speed.js +42 -0
  103. package/models/conditions/TimeActive.js +50 -0
  104. package/models/conditions/TravelDirection.js +67 -0
  105. package/models/conditions/TravelPath.js +36 -0
  106. package/models/geofeatures/BoundingBox.js +44 -0
  107. package/models/geofeatures/Circle.js +39 -0
  108. package/models/geofeatures/Geoline.js +34 -0
  109. package/models/geofeatures/Polygon.js +45 -0
  110. package/models/geofeatures/ZoneBeacon.js +28 -0
  111. package/package.json +30 -6
  112. package/schemas/MultiLineStringGeometry.js +14 -0
  113. package/schemas/Point.js +13 -0
  114. package/schemas/PointGeometry.js +14 -0
  115. package/schemas/PolygonGeometry.js +14 -0
  116. package/schemas/ProjectPermission.js +21 -0
  117. package/schemas/Webhook.js +27 -0
  118. package/utils/index.js +39 -0
  119. package/validators/checkDistanceBetweenVertices.js +21 -0
  120. package/yarn.lock +2796 -0
  121. package/models/AdminUser.js +0 -10
  122. package/models/Application.js +0 -38
  123. package/models/ApplicationNotificationAction.js +0 -30
  124. package/models/ApplicationUsage.js +0 -11
  125. package/models/BeaconFilter.js +0 -23
  126. package/models/BearingFilter.js +0 -19
  127. package/models/BoundingBox.js +0 -17
  128. package/models/Circle.js +0 -21
  129. package/models/ConfigurationParameters.js +0 -20
  130. package/models/Customer.js +0 -38
  131. package/models/DateRangeFilter.js +0 -20
  132. package/models/Fence.js +0 -21
  133. package/models/FormattedBeacon.js +0 -16
  134. package/models/FormattedCircle.js +0 -12
  135. package/models/FormattedConditions.js +0 -11
  136. package/models/FormattedDateRange.js +0 -11
  137. package/models/FormattedPercentageCrossed.js +0 -12
  138. package/models/FormattedPoint.js +0 -10
  139. package/models/FormattedPolygon.js +0 -11
  140. package/models/FormattedPolyline.js +0 -11
  141. package/models/FormattedRectangle.js +0 -12
  142. package/models/FormattedTimeActive.js +0 -17
  143. package/models/FormattedZone.js +0 -28
  144. package/models/GeoFence.js +0 -23
  145. package/models/Geofeature.js +0 -26
  146. package/models/PercentageCrossedFilter.js +0 -19
  147. package/models/Point.js +0 -20
  148. package/models/Polygon.js +0 -18
  149. package/models/Polyline.js +0 -18
  150. package/models/PropertyMapping.js +0 -17
  151. package/models/Reference.js +0 -19
  152. package/models/SequenceFilter.js +0 -18
  153. package/models/SimpleCheckInZone.js +0 -29
  154. package/models/SoundAction.js +0 -28
  155. package/models/SpeedFilter.js +0 -19
  156. package/models/TimeOfDayRangeFilter.js +0 -19
  157. package/models/URLAction.js +0 -31
  158. package/models/VibrationAction.js +0 -28
  159. package/models/property.js +0 -25
  160. 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,3 @@
1
+ {
2
+ "requiredFields":[]
3
+ }
@@ -0,0 +1 @@
1
+ // not implemented. not sure if required
@@ -0,0 +1,5 @@
1
+ {
2
+ "type" : "dayRange",
3
+ "startDate" : "2017-11-14",
4
+ "endDate" : "2030-11-15"
5
+ }
@@ -0,0 +1,3 @@
1
+ {
2
+ "requiredFields": ["type"]
3
+ }
@@ -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,5 @@
1
+ {
2
+ "type": "travelPath",
3
+ "minimumGeofeaturesCrossed": 20,
4
+ "timeOutSeconds": 300
5
+ }
@@ -0,0 +1,3 @@
1
+ {
2
+ "requiredFields":["timeOutSeconds", "minimumGeofeaturesCrossed"]
3
+ }
@@ -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,5 @@
1
+ {
2
+ "type" : "speed",
3
+ "minimumSpeed" : 20,
4
+ "maximumSpeed" : 26
5
+ }
@@ -0,0 +1,3 @@
1
+ {
2
+ "requiredFields":["minimumSpeed", "maximumSpeed"]
3
+ }
@@ -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,5 @@
1
+ {
2
+ "type": "timeActiveCondition",
3
+ "fromTime": "00:30:00",
4
+ "toTime": "20:30:00"
5
+ }
@@ -0,0 +1,7 @@
1
+ {
2
+ "requiredFields":["fromTime", "toTime"],
3
+ "customValidators":[
4
+ {"name": "fromTime", "invalidInput": [6800, "24:00:00", "invalid-input"]},
5
+ {"name": "toTime", "invalidInput": [6800, "24:00:00", "invalid-input"]}
6
+ ]
7
+ }
@@ -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,5 @@
1
+ {
2
+ "type" : "travelDirection",
3
+ "fromAngle" : 0,
4
+ "toAngle" : 90
5
+ }
@@ -0,0 +1,3 @@
1
+ {
2
+ "requiredFields":["type", "fromAngle", "toAngle"]
3
+ }
@@ -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
+ })
@@ -0,0 +1,12 @@
1
+ {
2
+ "type": "boundingBox",
3
+ "name": "Test BoundingBox",
4
+ "northEast": {
5
+ "latitude": -37.81794619852986,
6
+ "longitude": 144.97999548912048
7
+ },
8
+ "southWest": {
9
+ "latitude": -37.81846319511329,
10
+ "longitude": 144.97921228408813
11
+ }
12
+ }
@@ -0,0 +1,3 @@
1
+ {
2
+ "requiredFields":["name", "northEast", "southWest"]
3
+ }