@bluedot-innovation/models 3.1.0 → 4.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/Models.js +10 -55
  2. package/models/AdminPortalUser.js +11 -10
  3. package/models/AdminUser.js +10 -0
  4. package/models/Application.js +38 -0
  5. package/models/ApplicationNotificationAction.js +30 -0
  6. package/models/ApplicationUsage.js +11 -0
  7. package/models/Beacon.js +32 -84
  8. package/models/BeaconFilter.js +23 -0
  9. package/models/BearingFilter.js +19 -0
  10. package/models/BoundingBox.js +17 -0
  11. package/models/Circle.js +21 -0
  12. package/models/ConfigurationParameters.js +20 -0
  13. package/models/Contract.js +38 -37
  14. package/models/Customer.js +38 -0
  15. package/models/CustomerLogin.js +10 -9
  16. package/models/DBEvent.js +14 -13
  17. package/models/DailyStats.js +7 -7
  18. package/models/DateRangeFilter.js +20 -0
  19. package/models/DeviceRulesRequest.js +28 -27
  20. package/models/Fence.js +21 -0
  21. package/models/FormattedBeacon.js +16 -0
  22. package/models/FormattedCircle.js +12 -0
  23. package/models/FormattedConditions.js +11 -0
  24. package/models/FormattedDateRange.js +11 -0
  25. package/models/FormattedPercentageCrossed.js +12 -0
  26. package/models/FormattedPoint.js +10 -0
  27. package/models/FormattedPolygon.js +11 -0
  28. package/models/FormattedPolyline.js +11 -0
  29. package/models/FormattedRectangle.js +12 -0
  30. package/models/FormattedTimeActive.js +17 -0
  31. package/models/FormattedZone.js +28 -0
  32. package/models/GeoFence.js +23 -0
  33. package/models/Geofeature.js +26 -0
  34. package/models/MessageAction.js +26 -28
  35. package/models/MonthlyStats.js +19 -35
  36. package/models/NotificationLogEntry.js +8 -7
  37. package/models/POILocation.js +7 -6
  38. package/models/POILookup.js +9 -8
  39. package/models/POIResult.js +8 -7
  40. package/models/PartnerCustomer.js +13 -12
  41. package/models/PartnerPasswordReset.js +9 -8
  42. package/models/PartnerUser.js +11 -10
  43. package/models/Partners.js +12 -11
  44. package/models/PercentageCrossedFilter.js +19 -0
  45. package/models/Point.js +20 -0
  46. package/models/Polygon.js +18 -0
  47. package/models/Polyline.js +18 -0
  48. package/models/PropertyMapping.js +17 -0
  49. package/models/Reference.js +19 -0
  50. package/models/RuleRequestAggregation.js +17 -33
  51. package/models/SequenceFilter.js +18 -0
  52. package/models/SimpleCheckInZone.js +29 -0
  53. package/models/SingleUseToken.js +8 -7
  54. package/models/SoundAction.js +28 -0
  55. package/models/SpeedFilter.js +19 -0
  56. package/models/TestDevice.js +12 -11
  57. package/models/TestDeviceCluster.js +10 -9
  58. package/models/TestInstance.js +10 -9
  59. package/models/TestScenario.js +10 -9
  60. package/models/TimeOfDayRange.js +16 -16
  61. package/models/TimeOfDayRangeFilter.js +19 -0
  62. package/models/URLAction.js +31 -0
  63. package/models/VibrationAction.js +28 -0
  64. package/models/ZoneUIState.js +18 -18
  65. package/models/property.js +25 -0
  66. package/package-lock.json.bak +170 -0
  67. package/package.json +6 -30
  68. package/.eslintrc.js +0 -42
  69. package/.gitlab-ci.yml +0 -43
  70. package/CHANGELOG.md +0 -148
  71. package/README.MD +0 -36
  72. package/__tests__/account/account.data.json +0 -12
  73. package/__tests__/account/account.rules.js +0 -8
  74. package/__tests__/account/account.spec.js +0 -83
  75. package/__tests__/action/message/messageAction.data.json +0 -5
  76. package/__tests__/action/message/messageAction.rules.json +0 -3
  77. package/__tests__/action/message/messageAction.spec.js +0 -61
  78. package/__tests__/action/url/urlAction.data.json +0 -4
  79. package/__tests__/action/url/urlAction.rules.json +0 -3
  80. package/__tests__/action/url/urlAction.spec.js +0 -74
  81. package/__tests__/beacon/beacon.data.json +0 -15
  82. package/__tests__/beacon/beacon.rules.json +0 -13
  83. package/__tests__/beacon/beacon.spec.js +0 -104
  84. package/__tests__/condition/beacon/beaconFilter.data.json +0 -1
  85. package/__tests__/condition/beacon/beaconFilter.rules.json +0 -3
  86. package/__tests__/condition/beacon/beaconFilter.spec.js +0 -1
  87. package/__tests__/condition/dayRange/dayRange.data.json +0 -5
  88. package/__tests__/condition/dayRange/dayRange.rules.json +0 -3
  89. package/__tests__/condition/dayRange/dayRange.spec.js +0 -74
  90. package/__tests__/condition/percentageCrossed/travelPath.data.json +0 -5
  91. package/__tests__/condition/percentageCrossed/travelPath.rules.json +0 -3
  92. package/__tests__/condition/percentageCrossed/travelPath.spec.js +0 -62
  93. package/__tests__/condition/speed/speed.data.json +0 -5
  94. package/__tests__/condition/speed/speed.rules.json +0 -3
  95. package/__tests__/condition/speed/speed.spec.js +0 -73
  96. package/__tests__/condition/timeActive/timeActive.data.json +0 -5
  97. package/__tests__/condition/timeActive/timeActive.rules.json +0 -7
  98. package/__tests__/condition/timeActive/timeActive.spec.js +0 -94
  99. package/__tests__/condition/travelDirection/travelDirection.data.json +0 -5
  100. package/__tests__/condition/travelDirection/travelDirection.rules.json +0 -3
  101. package/__tests__/condition/travelDirection/travelDirection.spec.js +0 -132
  102. package/__tests__/dailyStats/checkDailyStats.js +0 -31
  103. package/__tests__/geofeature/boundingBox/boundingBox.data.json +0 -12
  104. package/__tests__/geofeature/boundingBox/boundingBox.rules.json +0 -3
  105. package/__tests__/geofeature/boundingBox/boundingBox.spec.js +0 -78
  106. package/__tests__/geofeature/circle/circle.data.json +0 -9
  107. package/__tests__/geofeature/circle/circle.rules.json +0 -3
  108. package/__tests__/geofeature/circle/circle.spec.js +0 -71
  109. package/__tests__/geofeature/polygon/polygon.data.json +0 -46
  110. package/__tests__/geofeature/polygon/polygon.rules.json +0 -3
  111. package/__tests__/geofeature/polygon/polygon.spec.js +0 -127
  112. package/__tests__/geofeature/polyline/polyline.data.json +0 -46
  113. package/__tests__/geofeature/polyline/polyline.rules.json +0 -3
  114. package/__tests__/geofeature/polyline/polyline.spec.js +0 -70
  115. package/__tests__/geofeature/zoneBeacon/zoneBeacon.data.json +0 -16
  116. package/__tests__/geofeature/zoneBeacon/zoneBeacon.rules.json +0 -13
  117. package/__tests__/geofeature/zoneBeacon/zoneBeacon.spec.js +0 -62
  118. package/__tests__/monthlyStats/monthlyStats.data.json +0 -29
  119. package/__tests__/monthlyStats/monthlyStats.spec.js +0 -66
  120. package/__tests__/project/project.data.json +0 -18
  121. package/__tests__/project/project.rules.json +0 -9
  122. package/__tests__/project/project.spec.js +0 -81
  123. package/__tests__/ruleRequestAggregation/ruleRequestAggregation.data.json +0 -8
  124. package/__tests__/ruleRequestAggregation/ruleRequestAggregation.spec.js +0 -69
  125. package/__tests__/setup.js +0 -7
  126. package/__tests__/user/user.data.js +0 -19
  127. package/__tests__/user/user.rules.js +0 -8
  128. package/__tests__/user/user.spec.js +0 -130
  129. package/__tests__/utils/utils.spec.js +0 -24
  130. package/__tests__/zone/zone.action.spec.js +0 -50
  131. package/__tests__/zone/zone.condition.spec.js +0 -76
  132. package/__tests__/zone/zone.data.json +0 -157
  133. package/__tests__/zone/zone.geofeatures.spec.js +0 -75
  134. package/__tests__/zone/zone.spec.js +0 -134
  135. package/constants/errorMessages.js +0 -2
  136. package/helpers.js +0 -102
  137. package/models/Account.js +0 -50
  138. package/models/Project.js +0 -55
  139. package/models/UrlAction.js +0 -46
  140. package/models/User.js +0 -61
  141. package/models/Zone.js +0 -123
  142. package/models/conditions/DayRange.js +0 -52
  143. package/models/conditions/Speed.js +0 -42
  144. package/models/conditions/TimeActive.js +0 -50
  145. package/models/conditions/TravelDirection.js +0 -67
  146. package/models/conditions/TravelPath.js +0 -36
  147. package/models/geofeatures/BoundingBox.js +0 -44
  148. package/models/geofeatures/Circle.js +0 -39
  149. package/models/geofeatures/Polygon.js +0 -45
  150. package/models/geofeatures/Polyline.js +0 -34
  151. package/models/geofeatures/ZoneBeacon.js +0 -28
  152. package/schemas/MultiLineStringGeometry.js +0 -14
  153. package/schemas/Point.js +0 -13
  154. package/schemas/PointGeometry.js +0 -14
  155. package/schemas/PolygonGeometry.js +0 -14
  156. package/schemas/ProjectPermission.js +0 -21
  157. package/schemas/Webhook.js +0 -22
  158. package/utils/index.js +0 -39
  159. package/validators/checkDistanceBetweenVertices.js +0 -21
  160. package/yarn.lock +0 -2796
@@ -1,132 +0,0 @@
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
- })
@@ -1,31 +0,0 @@
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
- })
@@ -1,12 +0,0 @@
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
- }
@@ -1,3 +0,0 @@
1
- {
2
- "requiredFields":["name", "northEast", "southWest"]
3
- }
@@ -1,78 +0,0 @@
1
- let mongoose = require('mongoose')
2
-
3
- mongoose.Promise = global.Promise
4
-
5
- let BoundingBoxModel = require('../../../Models').BoundingBox(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('./boundingBox.rules.json')
15
-
16
- let boundingBox
17
-
18
- beforeEach(() => {
19
- boundingBox = JSON.parse(JSON.stringify(require('./boundingBox.data.json')))
20
- })
21
-
22
- describe('BoundingBox', () => {
23
- describe('Valid BoundingBox', () => {
24
- it('should validate a valid boundingBox ', (done) => {
25
- let BoundingBox = new BoundingBoxModel(boundingBox)
26
- BoundingBox.validate((err, res) => {
27
- assert.notExists(res)
28
- assert(err === null, 'err should equals null')
29
- done()
30
- })
31
- })
32
- })
33
-
34
- describe('Invalid BoundingBox', () => {
35
- it('should not validate a boundingBox with invalid BoundingBox', (done) => {
36
- delete boundingBox[rules.requiredFields[0]]
37
- let BoundingBox = new BoundingBoxModel(boundingBox)
38
- BoundingBox.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', () => {
46
- let requiredFields = rules.requiredFields
47
- requiredFields.map((i) => {
48
- it(`should throw an error with property '${i}' if '${i}' is not present`, (done) => {
49
- // delete i from geofeatures' boundingBox child
50
- delete boundingBox[i]
51
- let BoundingBox = new BoundingBoxModel(boundingBox)
52
- BoundingBox.validate((err, res) => {
53
- assert.notExists(res)
54
- assert.exists(err, 'err object should exist')
55
- assert.isObject(err)
56
- assert.nestedProperty(err, `errors.${i}`, `error should have a ${i} property`)
57
- done()
58
- })
59
- })
60
- })
61
- })
62
-
63
- it('should be invalid when southWest and NorthEast are the same', (done) => {
64
- boundingBox.southWest = {
65
- latitude: -37.81794619852986,
66
- longitude: 144.97999548912048
67
- }
68
-
69
- const BoundingBox = new BoundingBoxModel(boundingBox)
70
-
71
- BoundingBox.validate((err, res) => {
72
- assert.exists(err, 'err object should exist')
73
- assert.isObject(err)
74
- done()
75
- })
76
- })
77
- })
78
- })
@@ -1,9 +0,0 @@
1
- {
2
- "type": "circle",
3
- "name": "Test Circle",
4
- "radius": 10,
5
- "center": {
6
- "latitude": -37.8159544565362,
7
- "longitude": 144.9723565578461
8
- }
9
- }
@@ -1,3 +0,0 @@
1
- {
2
- "requiredFields":["name", "radius", "center"]
3
- }
@@ -1,71 +0,0 @@
1
- let mongoose = require('mongoose')
2
-
3
- mongoose.Promise = global.Promise
4
-
5
- let CircleModel = require('../../../Models').Circle(mongoose)
6
- let CircleModelBuiltInMongoose = require('../../../Models').Circle()
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 beforeEach = require('mocha').beforeEach
13
-
14
- let rules = require('./circle.rules.json')
15
-
16
- let circle
17
-
18
- beforeEach(() => {
19
- circle = JSON.parse(JSON.stringify(require('./circle.data.json')))
20
- })
21
-
22
- testCase('Circle', () => {
23
- testCase('Valid Circle', () => {
24
- assertions('should validate zone with Circle ', (done) => {
25
- let Circle = new CircleModel(circle)
26
- Circle.validate((err, res) => {
27
- assert.notExists(res)
28
- assert(err === null, 'err should equals null')
29
- done()
30
- })
31
- })
32
- assertions('should validate zone with Circle (built in mongoose)', (done) => {
33
- let Circle = new CircleModelBuiltInMongoose(circle)
34
- Circle.validate((err, res) => {
35
- assert.notExists(res)
36
- assert(err === null, 'err should equals null')
37
- done()
38
- })
39
- })
40
- })
41
-
42
- testCase('Invalid Circle', () => {
43
- assertions('should not validate a Circle with no radius', (done) => {
44
- delete circle.radius
45
- let Circle = new CircleModel(circle)
46
- Circle.validate((err, res) => {
47
- assert.exists(err, 'err object should exist')
48
- assert.isObject(err)
49
- done()
50
- })
51
- })
52
-
53
- testCase('recursive property check', () => {
54
- let requiredFields = rules.requiredFields
55
- requiredFields.map((i) => {
56
- assertions(`should throw an error with property '${i}' if '${i}' is not present`, (done) => {
57
- // delete i from geofeatures' circle child
58
- delete circle[i]
59
- let Circle = new CircleModel(circle)
60
- Circle.validate((err, res) => {
61
- assert.notExists(res)
62
- assert.exists(err, 'err object should exist')
63
- assert.isObject(err)
64
- assert.nestedProperty(err, `errors.${i}`, `error should have a ${i} property`)
65
- done()
66
- })
67
- })
68
- })
69
- })
70
- })
71
- })
@@ -1,46 +0,0 @@
1
- {
2
- "type": "polygon",
3
- "name": "Test Polygon",
4
- "vertices": [
5
- {
6
- "latitude": -37.81902680201739,
7
- "longitude": 144.9821037054062
8
- },
9
- {
10
- "latitude": -37.8196878692931,
11
- "longitude": 144.98161554336548
12
- },
13
- {
14
- "latitude": -37.82052267015026,
15
- "longitude": 144.9816906452179
16
- },
17
- {
18
- "latitude": -37.82128118660006,
19
- "longitude": 144.98312830924988
20
- },
21
- {
22
- "latitude": -37.82102693614463,
23
- "longitude": 144.98458743095398
24
- },
25
- {
26
- "latitude": -37.820196378553405,
27
- "longitude": 144.98524725437164
28
- },
29
- {
30
- "latitude": -37.81895899991077,
31
- "longitude": 144.9847161769867
32
- },
33
- {
34
- "latitude": -37.81865812731128,
35
- "longitude": 144.9839222431183
36
- },
37
- {
38
- "latitude": -37.81866660261256,
39
- "longitude": 144.98308539390564
40
- },
41
- {
42
- "latitude": -37.81902680201739,
43
- "longitude": 144.9821037054062
44
- }
45
- ]
46
- }
@@ -1,3 +0,0 @@
1
- {
2
- "requiredFields":["type", "name", "vertices"]
3
- }
@@ -1,127 +0,0 @@
1
- let PolygonModel = require('../../../Models').Polygon(mongoose)
2
- let PolygonModelBuiltInMongoose = require('../../../Models').Polygon()
3
- const { VERTICES_TOO_CLOSE, CANT_HAVE_THREE_OR_MORE_VERTICES } = require('../../../constants/errorMessages')
4
- let rules = require('./polygon.rules.json')
5
-
6
- let polygon
7
-
8
- beforeEach(() => {
9
- polygon = JSON.parse(JSON.stringify(require('./polygon.data.json')))
10
- })
11
-
12
- describe('Polygon', () => {
13
- describe('Valid Polygon', () => {
14
- it('should validate a valid polygon ', (done) => {
15
- let Polygon = new PolygonModel(polygon)
16
- Polygon.validate((err, res) => {
17
- assert.notExists(res)
18
- assert(err === null, 'err should equals null')
19
- done()
20
- })
21
- })
22
- it('should validate a valid polygon (built in mongoose)', (done) => {
23
- let Polygon = new PolygonModelBuiltInMongoose(polygon)
24
- Polygon.validate((err, res) => {
25
- assert.notExists(res)
26
- assert(err === null, 'err should equals null')
27
- done()
28
- })
29
- })
30
- })
31
-
32
- describe('Invalid Polygon', () => {
33
- it('should not validate a polygon with invalid Polygon', (done) => {
34
- delete polygon[rules.requiredFields[0]]
35
- let Polygon = new PolygonModel(polygon)
36
- Polygon.validate((err, res) => {
37
- assert.exists(err, 'err object should exist')
38
- assert.isObject(err)
39
- done()
40
- })
41
- })
42
-
43
- describe('check each required property of the model and validate that it is present', () => {
44
- let requiredFields = rules.requiredFields
45
- requiredFields.map((i) => {
46
- it(`should throw an error with property '${i}' if '${i}' is not present`, (done) => {
47
- // delete i from geofeatures' polygon child
48
- delete polygon[i]
49
- let Polygon = new PolygonModel(polygon)
50
- Polygon.validate((err, res) => {
51
- assert.notExists(res)
52
- assert.exists(err, 'err object should exist')
53
- assert.isObject(err)
54
- assert.nestedProperty(err, `errors.${i}`, `error should have a ${i} property`)
55
- done()
56
- })
57
- })
58
- })
59
- })
60
-
61
- it('when it has less than 3 vertices, it should error', (done) => {
62
- polygon.vertices = [{
63
- "latitude": -37.81902680201739,
64
- "longitude": 144.9821037054062
65
- },
66
- {
67
- "latitude": -37.8196878692931,
68
- "longitude": 144.98161554336548
69
- }]
70
-
71
- let Polygon = new PolygonModel(polygon)
72
- Polygon.validate((err, res) => {
73
- const regex = new RegExp(CANT_HAVE_THREE_OR_MORE_VERTICES)
74
- assert.match(err, regex)
75
- done()
76
- })
77
- })
78
-
79
- describe('For any given vertex, if any of the next 2 vertices (accurate to 6 decimal points) are the same, it should error', (done) => {
80
- it('next vertice is the same', (done) => {
81
- polygon.vertices = [{
82
- "latitude": -37.81902680201733,
83
- "longitude": 144.9821037054044
84
- }, {
85
- "latitude": -37.81902680201731,
86
- "longitude": 144.9821037054062
87
- }, {
88
- "latitude": -36.81902680201745,
89
- "longitude": 143.9821037054032
90
- }, {
91
- "latitude": -37.23968786929315,
92
- "longitude": 144.1216155433654
93
- }]
94
-
95
- let Polygon = new PolygonModel(polygon)
96
- Polygon.validate((err, res) => {
97
- const regex = new RegExp(VERTICES_TOO_CLOSE)
98
- assert.match(err, regex)
99
- done()
100
- })
101
- })
102
-
103
- it('the one after next is the same', (done) => {
104
- polygon.vertices = [{
105
- "latitude": -37.81902680201739,
106
- "longitude": 144.9821037054062
107
- }, {
108
- "latitude": -36.81902680201745,
109
- "longitude": 143.9821037054033
110
- }, {
111
- "latitude": -37.81902680201739,
112
- "longitude": 144.9821037054062
113
- }, {
114
- "latitude": -37.23968786929314,
115
- "longitude": 144.1216155433654
116
- }]
117
-
118
- let Polygon = new PolygonModel(polygon)
119
- Polygon.validate((err, res) => {
120
- const regex = new RegExp(VERTICES_TOO_CLOSE)
121
- assert.match(err, regex)
122
- done()
123
- })
124
- })
125
- })
126
- })
127
- })
@@ -1,46 +0,0 @@
1
- {
2
- "type": "polyline",
3
- "name": "Test Polygon",
4
- "vertices": [
5
- {
6
- "latitude": -37.81902680201739,
7
- "longitude": 144.9821037054062
8
- },
9
- {
10
- "latitude": -37.8196878692931,
11
- "longitude": 144.98161554336548
12
- },
13
- {
14
- "latitude": -37.82052267015026,
15
- "longitude": 144.9816906452179
16
- },
17
- {
18
- "latitude": -37.82128118660006,
19
- "longitude": 144.98312830924988
20
- },
21
- {
22
- "latitude": -37.82102693614463,
23
- "longitude": 144.98458743095398
24
- },
25
- {
26
- "latitude": -37.820196378553405,
27
- "longitude": 144.98524725437164
28
- },
29
- {
30
- "latitude": -37.81895899991077,
31
- "longitude": 144.9847161769867
32
- },
33
- {
34
- "latitude": -37.81865812731128,
35
- "longitude": 144.9839222431183
36
- },
37
- {
38
- "latitude": -37.81866660261256,
39
- "longitude": 144.98308539390564
40
- },
41
- {
42
- "latitude": -37.81902680201739,
43
- "longitude": 144.9821037054062
44
- }
45
- ]
46
- }
@@ -1,3 +0,0 @@
1
- {
2
- "requiredFields":["type", "name", "vertices"]
3
- }
@@ -1,70 +0,0 @@
1
- let mongoose = require('mongoose')
2
-
3
- mongoose.Promise = global.Promise
4
-
5
- let PolylineModel = require('../../../Models').Polyline(mongoose)
6
- let PolylineModelBuiltInMongoose = require('../../../Models').Polyline()
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('./polyline.rules.json')
16
-
17
- let polyline
18
-
19
- beforeEach(() => {
20
- polyline = JSON.parse(JSON.stringify(require('./polyline.data.json')))
21
- })
22
- testCase('Polyline', () => {
23
- testCase('Valid Polyline', () => {
24
- assertions('should validate a valid polyline ', (done) => {
25
- let Polyline = new PolylineModel(polyline)
26
- Polyline.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 polyline (built in mongoose)', (done) => {
33
- let Polyline = new PolylineModelBuiltInMongoose(polyline)
34
- Polyline.validate((err, res) => {
35
- assert.notExists(res)
36
- assert(err === null, 'err should equals null')
37
- done()
38
- })
39
- })
40
- })
41
-
42
- testCase('Invalid Polyline', () => {
43
- assertions('should not validate a polyline with invalid polyline', (done) => {
44
- delete polyline[rules.requiredFields[0]]
45
- let Polyline = new PolylineModel(polyline)
46
- Polyline.validate((err, res) => {
47
- assert.exists(err, 'err object should exist')
48
- assert.isObject(err)
49
- done()
50
- })
51
- })
52
- testCase('check each required property of the model and validate that it is present', () => {
53
- let requiredFields = rules.requiredFields
54
- requiredFields.map((i) => {
55
- assertions(`should throw an error with property '${i}' if '${i}' is not present`, (done) => {
56
- // delete i from geofeatures' polyline child
57
- delete polyline[i]
58
- let Polyline = new PolylineModel(polyline)
59
- Polyline.validate((err, res) => {
60
- assert.notExists(res)
61
- assert.exists(err, 'err object should exist')
62
- assert.isObject(err)
63
- assert.nestedProperty(err, `errors.${i}`, `error should have a ${i} property`)
64
- done()
65
- })
66
- })
67
- })
68
- })
69
- })
70
- })
@@ -1,16 +0,0 @@
1
- {
2
- "type": "beacon",
3
- "name": "create beacon",
4
- "proximityUUID": "23a01af0-232a-4518-9c0e-323fb773f5ef",
5
- "location": {
6
- "latitude": -37.8159544565362,
7
- "longitude": 144.9723565578461
8
- },
9
- "beaconType": "Both",
10
- "major": 10000,
11
- "minor": 56466,
12
- "txPower": -77,
13
- "proximity": "Near",
14
- "macAddress": "01:17:c5:31:84:19",
15
- "accountId": "90a2ed18-86be-48e7-948b-393b8b679ef6"
16
- }
@@ -1,13 +0,0 @@
1
- {
2
- "requiredFields":["name", "location", "beaconType"],
3
- "dependentRequiredFields": [
4
- {
5
- "property": "beaconType",
6
- "pairings": [
7
- {"value": "ios", "requiredFields": ["major", "minor"]},
8
- {"value": "android", "requiredFields": ["txPower", "macAddress"]},
9
- {"value": "both", "requiredFields": ["major", "minor", "txPower", "macAddress"]}
10
- ]
11
- }
12
- ]
13
- }