@bluedot-innovation/models 4.0.0 → 5.0.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (167) hide show
  1. package/.eslintrc.js +42 -0
  2. package/.gitlab-ci.yml +44 -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 +73 -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 +95 -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 +72 -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 +92 -0
  30. package/__tests__/condition/timeActive/timeActive.data.json +5 -0
  31. package/__tests__/condition/timeActive/timeActive.rules.json +14 -0
  32. package/__tests__/condition/timeActive/timeActive.spec.js +103 -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 +141 -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 +87 -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 +132 -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 +71 -0
  52. package/__tests__/monthlyStats/monthlyStats.data.json +29 -0
  53. package/__tests__/monthlyStats/monthlyStats.spec.js +75 -0
  54. package/__tests__/project/project.data.json +18 -0
  55. package/__tests__/project/project.remote.config.json +122 -0
  56. package/__tests__/project/project.rules.json +9 -0
  57. package/__tests__/project/project.spec.js +100 -0
  58. package/__tests__/ruleRequestAggregation/ruleRequestAggregation.data.json +8 -0
  59. package/__tests__/ruleRequestAggregation/ruleRequestAggregation.spec.js +78 -0
  60. package/__tests__/setup.js +7 -0
  61. package/__tests__/user/user.data.js +19 -0
  62. package/__tests__/user/user.rules.js +8 -0
  63. package/__tests__/user/user.spec.js +130 -0
  64. package/__tests__/utils/utils.spec.js +26 -0
  65. package/__tests__/zone/zone.action.spec.js +50 -0
  66. package/__tests__/zone/zone.condition.spec.js +94 -0
  67. package/__tests__/zone/zone.data.json +157 -0
  68. package/__tests__/zone/zone.geofeatures.spec.js +75 -0
  69. package/__tests__/zone/zone.spec.js +140 -0
  70. package/constants/errorMessages.js +2 -0
  71. package/helpers.js +117 -0
  72. package/models/Account.js +50 -0
  73. package/models/AdminPortalUser.js +10 -11
  74. package/models/Beacon.js +84 -32
  75. package/models/Contract.js +37 -38
  76. package/models/CustomerLogin.js +9 -10
  77. package/models/DBEvent.js +13 -14
  78. package/models/DailyStats.js +7 -7
  79. package/models/DeviceRulesRequest.js +27 -28
  80. package/models/MessageAction.js +26 -26
  81. package/models/MonthlyStats.js +35 -19
  82. package/models/NotificationLogEntry.js +7 -8
  83. package/models/POILocation.js +6 -7
  84. package/models/POILookup.js +8 -9
  85. package/models/POIResult.js +7 -8
  86. package/models/PartnerCustomer.js +12 -13
  87. package/models/PartnerPasswordReset.js +8 -9
  88. package/models/PartnerUser.js +10 -11
  89. package/models/Partners.js +11 -12
  90. package/models/Project.js +63 -0
  91. package/models/RuleRequestAggregation.js +33 -17
  92. package/models/SingleUseToken.js +7 -8
  93. package/models/TestDevice.js +11 -12
  94. package/models/TestDeviceCluster.js +9 -10
  95. package/models/TestInstance.js +9 -10
  96. package/models/TestScenario.js +9 -10
  97. package/models/TimeOfDayRange.js +16 -16
  98. package/models/UrlAction.js +37 -0
  99. package/models/User.js +61 -0
  100. package/models/Zone.js +126 -0
  101. package/models/ZoneUIState.js +18 -18
  102. package/models/conditions/DayRange.js +44 -0
  103. package/models/conditions/Speed.js +42 -0
  104. package/models/conditions/TimeActive.js +50 -0
  105. package/models/conditions/TravelDirection.js +59 -0
  106. package/models/conditions/TravelPath.js +36 -0
  107. package/models/geofeatures/BoundingBox.js +44 -0
  108. package/models/geofeatures/Circle.js +39 -0
  109. package/models/geofeatures/Geoline.js +34 -0
  110. package/models/geofeatures/Polygon.js +45 -0
  111. package/models/geofeatures/ZoneBeacon.js +28 -0
  112. package/package.json +30 -6
  113. package/schemas/AccuracySuppression.js +14 -0
  114. package/schemas/AndroidConfig.js +35 -0
  115. package/schemas/IosConfig.js +38 -0
  116. package/schemas/MultiLineStringGeometry.js +14 -0
  117. package/schemas/Point.js +13 -0
  118. package/schemas/PointGeometry.js +14 -0
  119. package/schemas/PolygonGeometry.js +14 -0
  120. package/schemas/ProjectPermission.js +21 -0
  121. package/schemas/StarvationDetection.js +11 -0
  122. package/schemas/Telemetry.js +36 -0
  123. package/schemas/Webhook.js +22 -0
  124. package/utils/index.js +39 -0
  125. package/utils/validators.js +6 -0
  126. package/validators/checkDistanceBetweenVertices.js +21 -0
  127. package/yarn.lock +2796 -0
  128. package/models/AdminUser.js +0 -10
  129. package/models/Application.js +0 -38
  130. package/models/ApplicationNotificationAction.js +0 -30
  131. package/models/ApplicationUsage.js +0 -11
  132. package/models/BeaconFilter.js +0 -23
  133. package/models/BearingFilter.js +0 -19
  134. package/models/BoundingBox.js +0 -17
  135. package/models/Circle.js +0 -21
  136. package/models/ConfigurationParameters.js +0 -20
  137. package/models/Customer.js +0 -38
  138. package/models/DateRangeFilter.js +0 -20
  139. package/models/Fence.js +0 -21
  140. package/models/FormattedBeacon.js +0 -16
  141. package/models/FormattedCircle.js +0 -12
  142. package/models/FormattedConditions.js +0 -11
  143. package/models/FormattedDateRange.js +0 -11
  144. package/models/FormattedPercentageCrossed.js +0 -12
  145. package/models/FormattedPoint.js +0 -10
  146. package/models/FormattedPolygon.js +0 -11
  147. package/models/FormattedPolyline.js +0 -11
  148. package/models/FormattedRectangle.js +0 -12
  149. package/models/FormattedTimeActive.js +0 -17
  150. package/models/FormattedZone.js +0 -28
  151. package/models/GeoFence.js +0 -23
  152. package/models/Geofeature.js +0 -26
  153. package/models/PercentageCrossedFilter.js +0 -19
  154. package/models/Point.js +0 -20
  155. package/models/Polygon.js +0 -18
  156. package/models/Polyline.js +0 -18
  157. package/models/PropertyMapping.js +0 -17
  158. package/models/Reference.js +0 -19
  159. package/models/SequenceFilter.js +0 -18
  160. package/models/SimpleCheckInZone.js +0 -29
  161. package/models/SoundAction.js +0 -28
  162. package/models/SpeedFilter.js +0 -19
  163. package/models/TimeOfDayRangeFilter.js +0 -19
  164. package/models/URLAction.js +0 -31
  165. package/models/VibrationAction.js +0 -28
  166. package/models/property.js +0 -25
  167. 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,95 @@
1
+ let mongoose = require('mongoose')
2
+
3
+ mongoose.Promise = global.Promise
4
+
5
+ let DayRangeModel = require('../../../Models').DayRange(mongoose)
6
+ let DayRangeModelBuiltInSchema = require('../../../Models').DayRange()
7
+ let testCase = require('mocha').describe
8
+ let assertions = require('mocha').it
9
+ let chai = require('chai')
10
+
11
+ let assert = chai.assert
12
+ let mocha = require('mocha')
13
+ let beforeEach = mocha.beforeEach
14
+
15
+ let rules = require('./dayRange.rules.json')
16
+
17
+ let dayRange
18
+
19
+ beforeEach(() => {
20
+ dayRange = JSON.parse(JSON.stringify(require('./dayRange.data.json')))
21
+ })
22
+
23
+ testCase('DayRangeCondition', () => {
24
+ testCase('Valid DayRangeCondition', () => {
25
+ assertions('should validate a valid dayRange', (done) => {
26
+ let DayRangeCondition = new DayRangeModel(dayRange)
27
+ DayRangeCondition.validate((err, res) => {
28
+ assert.notExists(res)
29
+ assert(err === null, 'err should equals null')
30
+ done()
31
+ })
32
+ })
33
+ })
34
+ testCase('Valid DayRangeCondition', () => {
35
+ assertions('should validate a valid dayRange', (done) => {
36
+ let DayRangeCondition = new DayRangeModelBuiltInSchema(dayRange)
37
+ DayRangeCondition.validate((err, res) => {
38
+ assert.notExists(res)
39
+ assert(err === null, 'err should equals null')
40
+ done()
41
+ })
42
+ })
43
+ })
44
+
45
+ testCase('Invalid DayRangeCondition', () => {
46
+ assertions('should not validate a dayRange with invalid DayRangeCondition', (done) => {
47
+ delete dayRange[rules.requiredFields[0]]
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
+ assertions('should not validate a dayRange with startDate < endDate', (done) => {
57
+ dayRange.endDate = '1990-11-14'
58
+ let DayRangeCondition = new DayRangeModel(dayRange)
59
+ DayRangeCondition.validate((err, res) => {
60
+ assert.exists(err, 'err object should exist')
61
+ assert.isObject(err)
62
+ assert.match(err.message, /startDate.*less than.*endDate/i)
63
+ done()
64
+ })
65
+ })
66
+ assertions('should throw an error if both startDate and endDate are not provided', (done) => {
67
+ delete dayRange.startDate
68
+ delete dayRange.endDate
69
+ let DayRangeCondition = new DayRangeModel(dayRange)
70
+ DayRangeCondition.validate((err, res) => {
71
+ assert.exists(err, 'err object should exist')
72
+ assert.isObject(err)
73
+ done()
74
+ })
75
+ })
76
+
77
+ testCase('check each required property of the model and validate that it is present', () => {
78
+ let requiredFields = rules.requiredFields
79
+ requiredFields.map((i) => {
80
+ assertions(`should throw an error with property '${i}' if '${i}' is not present`, (done) => {
81
+ // delete i from geofeatures' dayRange child
82
+ delete dayRange[i]
83
+ let DayRangeCondition = new DayRangeModel(dayRange)
84
+ DayRangeCondition.validate((err, res) => {
85
+ assert.notExists(res)
86
+ assert.exists(err, 'err object should exist')
87
+ assert.isObject(err)
88
+ assert.nestedProperty(err, `errors.${i}`, `error should have a ${i} property`)
89
+ done()
90
+ })
91
+ })
92
+ })
93
+ })
94
+ })
95
+ })
@@ -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,72 @@
1
+ let mongoose = require('mongoose')
2
+
3
+ mongoose.Promise = global.Promise
4
+
5
+ let TravelPathConditionModel = require('../../../Models').TravelPath(mongoose)
6
+ let TravelPathConditionModelBuiltInMongoose = require('../../../Models').TravelPath()
7
+ let testCase = require('mocha').describe
8
+ let assertions = require('mocha').it
9
+ let chai = require('chai')
10
+
11
+ let assert = chai.assert
12
+ let mocha = require('mocha')
13
+ let beforeEach = mocha.beforeEach
14
+
15
+ let rules = require('./travelPath.rules.json')
16
+
17
+ let travelPath
18
+
19
+ beforeEach(() => {
20
+ travelPath = JSON.parse(JSON.stringify(require('./travelPath.data.json')))
21
+ })
22
+
23
+ testCase('PercentageCrossedCondition', () => {
24
+ testCase('Valid PercentageCrossedCondition', () => {
25
+ assertions('should validate a valid travelPath ', (done) => {
26
+ let PercentageCrossedCondition = new TravelPathConditionModel(travelPath)
27
+ PercentageCrossedCondition.validate((err, res) => {
28
+ assert.notExists(res)
29
+ assert(err === null, 'err should equals null')
30
+ done()
31
+ })
32
+ })
33
+ })
34
+ testCase('Valid PercentageCrossedCondition', () => {
35
+ assertions('should validate a valid travelPath ', (done) => {
36
+ let PercentageCrossedCondition = new TravelPathConditionModelBuiltInMongoose(travelPath)
37
+ PercentageCrossedCondition.validate((err, res) => {
38
+ assert.notExists(res)
39
+ assert(err === null, 'err should equals null')
40
+ done()
41
+ })
42
+ })
43
+ })
44
+ testCase('Invalid PercentageCrossedCondition', () => {
45
+ assertions('should not validate a travelPath with invalid PercentageCrossedCondition', (done) => {
46
+ delete travelPath[rules.requiredFields[0]]
47
+ let PercentageCrossedCondition = new TravelPathConditionModel(travelPath)
48
+ PercentageCrossedCondition.validate((err, res) => {
49
+ assert.exists(err, 'err object should exist')
50
+ assert.isObject(err)
51
+ done()
52
+ })
53
+ })
54
+ testCase('check each required property of the model and validate that it is present', () => {
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
+ // delete i from geofeatures' travelPath child
59
+ delete travelPath[i]
60
+ let PercentageCrossedCondition = new TravelPathConditionModel(travelPath)
61
+ PercentageCrossedCondition.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 ${i} property`)
66
+ done()
67
+ })
68
+ })
69
+ })
70
+ })
71
+ })
72
+ })
@@ -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,92 @@
1
+ let mongoose = require('mongoose')
2
+
3
+ mongoose.Promise = global.Promise
4
+
5
+ let SpeedConditionModel = require('../../../Models').Speed(mongoose)
6
+ let SpeedConditionModelBuiltInMongoose = require('../../../Models').Speed()
7
+ let testCase = require('mocha').describe
8
+ let assertions = require('mocha').it
9
+ let chai = require('chai')
10
+
11
+ let assert = chai.assert
12
+ let mocha = require('mocha')
13
+ let beforeEach = mocha.beforeEach
14
+
15
+ let rules = require('./speed.rules.json')
16
+
17
+ let speedCondition
18
+
19
+ beforeEach(() => {
20
+ speedCondition = JSON.parse(JSON.stringify(require('./speed.data.json')))
21
+ })
22
+
23
+ testCase('SpeedCondition', () => {
24
+ testCase('Valid SpeedCondition', () => {
25
+ assertions('should validate a valid speedCondition ', (done) => {
26
+ let SpeedCondition = new SpeedConditionModel(speedCondition)
27
+ SpeedCondition.validate((err, res) => {
28
+ assert.notExists(res)
29
+ assert(err === null, 'err should equals null')
30
+ done()
31
+ })
32
+ })
33
+ assertions('should validate a valid speedCondition ', (done) => {
34
+ let SpeedCondition = new SpeedConditionModelBuiltInMongoose(speedCondition)
35
+ SpeedCondition.validate((err, res) => {
36
+ assert.notExists(res)
37
+ assert(err === null, 'err should equals null')
38
+ done()
39
+ })
40
+ })
41
+ })
42
+
43
+ testCase('Invalid SpeedCondition', () => {
44
+ assertions('should not validate a speedCondition with invalid SpeedCondition', (done) => {
45
+ delete speedCondition[rules.requiredFields[0]]
46
+ let SpeedCondition = new SpeedConditionModel(speedCondition)
47
+ SpeedCondition.validate((err, res) => {
48
+ assert.exists(err, 'err object should exist')
49
+ assert.isObject(err)
50
+ done()
51
+ })
52
+ })
53
+ assertions('should throw an error when maxSpeed is less than 5 greater than minSpeed', (done) => {
54
+ speedCondition.minimumSpeed = 10
55
+ speedCondition.maximumSpeed = 11
56
+ let SpeedCondition = new SpeedConditionModel(speedCondition)
57
+ SpeedCondition.validate((err, res) => {
58
+ assert.exists(err, 'err object should exist')
59
+ assert.isObject(err)
60
+ assert.nestedProperty(err, `errors.maximumSpeed`, 'error should have a maximumSpeed property')
61
+ done()
62
+ })
63
+ })
64
+ assertions('should throw an error when maxSpeed is less than 5 m/s', (done) => {
65
+ speedCondition.maximumSpeed = 4
66
+ let SpeedCondition = new SpeedConditionModel(speedCondition)
67
+ SpeedCondition.validate((err, res) => {
68
+ assert.exists(err, 'err object should exist')
69
+ assert.isObject(err)
70
+ assert.nestedProperty(err, `errors.maximumSpeed`, 'error should have a maximumSpeed property')
71
+ done()
72
+ })
73
+ })
74
+ testCase('check each required property of the model and validate that it is present', () => {
75
+ let requiredFields = rules.requiredFields
76
+ requiredFields.map((i) => {
77
+ assertions(`should throw an error with property '${i}' if '${i}' is not present`, (done) => {
78
+ // delete i from geofeatures' speedCondition child
79
+ delete speedCondition[i]
80
+ let SpeedCondition = new SpeedConditionModel(speedCondition)
81
+ SpeedCondition.validate((err, res) => {
82
+ assert.notExists(res)
83
+ assert.exists(err, 'err object should exist')
84
+ assert.isObject(err)
85
+ assert.nestedProperty(err, `errors.${i}`, `error should have a ${i} property`)
86
+ done()
87
+ })
88
+ })
89
+ })
90
+ })
91
+ })
92
+ })
@@ -0,0 +1,5 @@
1
+ {
2
+ "type": "timeActiveCondition",
3
+ "fromTime": "00:30:00",
4
+ "toTime": "20:30:00"
5
+ }
@@ -0,0 +1,14 @@
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
+ {"name": "fromTime", "invalidInput": [6800, "0:00:01", "invalid-input"]},
7
+ {"name": "toTime", "invalidInput": [6800, "00:0:01", "invalid-input"]},
8
+ {"name": "toTime", "invalidInput": [6800, "00:00:1", "invalid-input"]},
9
+ {"name": "toTime", "invalidInput": [6800, "00:60:60", "invalid-input"]},
10
+ {"name": "toTime", "invalidInput": [6800, "00:590:00", "invalid-input"]},
11
+ {"name": "toTime", "invalidInput": [6800, "00:59:100", "invalid-input"]},
12
+ {"name": "toTime", "invalidInput": [6800, "000:000:060", "invalid-input"]}
13
+ ]
14
+ }
@@ -0,0 +1,103 @@
1
+ let mongoose = require('mongoose')
2
+
3
+ mongoose.Promise = global.Promise
4
+
5
+ let TimeActiveConditionModel = require('../../../Models').TimeActive(mongoose)
6
+ let TimeActiveConditionModelBuiltInMongoose = require('../../../Models').TimeActive()
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
+
14
+ let rules = require('./timeActive.rules.json')
15
+
16
+ let timeActiveCondition
17
+
18
+ beforeEach(() => {
19
+ timeActiveCondition = JSON.parse(JSON.stringify(require('./timeActive.data.json')))
20
+ })
21
+
22
+ testCase('TimeOfDayRangeCondition', () => {
23
+ testCase('Valid TimeOfDayRangeCondition', () => {
24
+ assertions('should validate a valid timeActiveCondition ', (done) => {
25
+ let TimeOfDayRangeCondition = new TimeActiveConditionModel(timeActiveCondition)
26
+ TimeOfDayRangeCondition.validate((err, res) => {
27
+ assert.notExists(res)
28
+ assert(err === null, 'err should equals null')
29
+ done()
30
+ })
31
+ })
32
+ assertions('should validate a valid timeActiveCondition ', (done) => {
33
+ let TimeOfDayRangeCondition = new TimeActiveConditionModelBuiltInMongoose(timeActiveCondition)
34
+ TimeOfDayRangeCondition.validate((err, res) => {
35
+ assert.notExists(res)
36
+ assert(err === null, 'err should equals null')
37
+ done()
38
+ })
39
+ })
40
+ })
41
+
42
+ testCase('Invalid TimeOfDayRangeCondition', () => {
43
+ assertions('should not validate a timeActiveCondition with invalid TimeOfDayRangeCondition', (done) => {
44
+ delete timeActiveCondition[rules.requiredFields[0]]
45
+ let TimeOfDayRangeCondition = new TimeActiveConditionModel(timeActiveCondition)
46
+ TimeOfDayRangeCondition.validate((err, res) => {
47
+ assert.exists(err, 'err object should exist')
48
+ assert.isObject(err)
49
+ done()
50
+ })
51
+ })
52
+ assertions('should throw an error when toTime === fromTime', (done) => {
53
+ timeActiveCondition.toTime = "00:30:00"
54
+ timeActiveCondition.fromTime = "00:30:00"
55
+ let TimeOfDayRangeCondition = new TimeActiveConditionModel(timeActiveCondition)
56
+ TimeOfDayRangeCondition.validate((err, res) => {
57
+ assert.exists(err, 'err object should exist')
58
+ assert.isObject(err)
59
+ assert.nestedProperty(err, `errors.toTime`, 'error should have a toTime property')
60
+ done()
61
+ })
62
+ })
63
+
64
+ testCase('recursive invalid time inputs check', () => {
65
+ let invalidTimes = rules.customValidators
66
+
67
+ invalidTimes.map(i => {
68
+ i.invalidInput.map(j => {
69
+ assertions(`should throw an error with property '${i.name}' if '${i.name} is invalid => ${i.name} = ${j}'`, done => {
70
+ timeActiveCondition = JSON.parse(JSON.stringify(timeActiveCondition))
71
+ timeActiveCondition[i.name] = j
72
+ let TimeOfDayRangeCondition = new TimeActiveConditionModel(timeActiveCondition)
73
+ TimeOfDayRangeCondition.validate((err, res) => {
74
+ assert.exists(err, 'err object should exits')
75
+ assert.isObject(err)
76
+ assert.nestedProperty(err, `errors.${i.name}`, 'time format must be hh:mm:ss')
77
+ assert.nestedProperty(err, `errors.${i.name}`, 'time format must be hh:mm:ss')
78
+ done()
79
+ })
80
+ })
81
+ })
82
+ })
83
+ })
84
+
85
+ testCase('check each required property of the model and validate that it is present', () => {
86
+ let requiredFields = rules.requiredFields
87
+ requiredFields.map((i) => {
88
+ assertions(`should throw an error with property '${i}' if '${i}' is not present`, (done) => {
89
+ // delete i from geofeatures' timeActiveCondition child
90
+ delete timeActiveCondition[i]
91
+ let TimeOfDayRangeCondition = new TimeActiveConditionModel(timeActiveCondition)
92
+ TimeOfDayRangeCondition.validate((err, res) => {
93
+ assert.notExists(res)
94
+ assert.exists(err, 'err object should exist')
95
+ assert.isObject(err)
96
+ assert.nestedProperty(err, `errors.${i}`, `error should have a ${i} property`)
97
+ done()
98
+ })
99
+ })
100
+ })
101
+ })
102
+ })
103
+ })
@@ -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
+ }