@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,78 @@
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
+ })
@@ -0,0 +1,9 @@
1
+ {
2
+ "type": "circle",
3
+ "name": "Test Circle",
4
+ "radius": 10,
5
+ "center": {
6
+ "latitude": -37.8159544565362,
7
+ "longitude": 144.9723565578461
8
+ }
9
+ }
@@ -0,0 +1,3 @@
1
+ {
2
+ "requiredFields":["name", "radius", "center"]
3
+ }
@@ -0,0 +1,71 @@
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
+ })
@@ -0,0 +1,46 @@
1
+ {
2
+ "type": "geoline",
3
+ "name": "Test geoline",
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
+ }
@@ -0,0 +1,3 @@
1
+ {
2
+ "requiredFields":["type", "name", "vertices"]
3
+ }
@@ -0,0 +1,70 @@
1
+ let mongoose = require('mongoose')
2
+
3
+ mongoose.Promise = global.Promise
4
+
5
+ let GeolineModel = require('../../../Models').Geoline(mongoose)
6
+ let GeolineModelBuiltInMongoose = require('../../../Models').Geoline()
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('./geoline.rules.json')
16
+
17
+ let geoline
18
+
19
+ beforeEach(() => {
20
+ geoline = JSON.parse(JSON.stringify(require('./geoline.data.json')))
21
+ })
22
+ testCase('Geoline', () => {
23
+ testCase('Valid Geoline', () => {
24
+ assertions('should validate a valid geoline ', (done) => {
25
+ let Geoline = new GeolineModel(geoline)
26
+ Geoline.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 geoline (built in mongoose)', (done) => {
33
+ let Geoline = new GeolineModelBuiltInMongoose(geoline)
34
+ Geoline.validate((err, res) => {
35
+ assert.notExists(res)
36
+ assert(err === null, 'err should equals null')
37
+ done()
38
+ })
39
+ })
40
+ })
41
+
42
+ testCase('Invalid Geoline', () => {
43
+ assertions('should not validate a geoline with invalid geoline', (done) => {
44
+ delete geoline[rules.requiredFields[0]]
45
+ let Geoline = new GeolineModel(geoline)
46
+ Geoline.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' geoline child
57
+ delete geoline[i]
58
+ let Geoline = new GeolineModel(geoline)
59
+ Geoline.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
+ })
@@ -0,0 +1,46 @@
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
+ }
@@ -0,0 +1,3 @@
1
+ {
2
+ "requiredFields":["type", "name", "vertices"]
3
+ }
@@ -0,0 +1,127 @@
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
+ })
@@ -0,0 +1,16 @@
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
+ }
@@ -0,0 +1,13 @@
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
+ }
@@ -0,0 +1,62 @@
1
+ let mongoose = require('mongoose')
2
+
3
+ mongoose.Promise = global.Promise
4
+
5
+ let ZoneBeaconModel = require('../../../Models').ZoneBeacon(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('./zoneBeacon.rules.json')
15
+
16
+ let zoneBeacon
17
+
18
+ beforeEach(() => {
19
+ zoneBeacon = JSON.parse(JSON.stringify(require('./zoneBeacon.data.json')))
20
+ })
21
+
22
+ describe('ZoneBeacon', () => {
23
+ describe('Valid ZoneBeacon', () => {
24
+ it('should validate a valid zoneBeacon ', (done) => {
25
+ const ZoneBeacon = new ZoneBeaconModel(zoneBeacon)
26
+ ZoneBeacon.validate((err, res) => {
27
+ assert.notExists(res)
28
+ assert(err === null, 'err should equals null')
29
+ done()
30
+ })
31
+ })
32
+ })
33
+
34
+ describe('Invalid ZoneBeacon', () => {
35
+ it('should not validate a zoneBeacon with invalid ZoneBeacon', (done) => {
36
+ delete zoneBeacon[rules.requiredFields[0]]
37
+ let ZoneBeacon = new ZoneBeaconModel(zoneBeacon)
38
+ ZoneBeacon.validate((err, res) => {
39
+ assert.exists(err, 'err object should exist')
40
+ assert.isObject(err)
41
+ done()
42
+ })
43
+ })
44
+ describe('check each required property of the model and validate that it is present', () => {
45
+ let requiredFields = rules.requiredFields
46
+ requiredFields.map((i) => {
47
+ it(`should throw an error with property '${i}' if '${i}' is not present`, (done) => {
48
+ // delete i from geofeatures' zoneBeacon child
49
+ delete zoneBeacon[i]
50
+ let ZoneBeacon = new ZoneBeaconModel(zoneBeacon)
51
+ ZoneBeacon.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,29 @@
1
+ {
2
+ "_id": "709aa8f4-3c53-496d-8824-73cb73ce6963",
3
+ "creationTime": "2017-12-31T23:17:30.658Z",
4
+ "monthOfCount": "2017-12-31T23:17:30.658Z",
5
+ "customerId": "313ff409-0bb7-4af5-8cc9-9d0ff3631b9f",
6
+ "totalMonthlyUsers": 23,
7
+ "applications": [
8
+ {
9
+ "applicationId": "d49fdf10-3744-462c-84f8-abad444d7044",
10
+ "monthlyUsers": 3
11
+ },
12
+ {
13
+ "applicationId": "d26b75ad-42ca-401c-b526-d745105886cd",
14
+ "monthlyUsers": 12
15
+ },
16
+ {
17
+ "applicationId": "6a2d898f-6894-41b8-8e7b-3445872f27d3",
18
+ "monthlyUsers": 3
19
+ },
20
+ {
21
+ "applicationId": "df9dd8a9-e6f1-417b-88c4-6d314a64ab80",
22
+ "monthlyUsers": 4
23
+ },
24
+ {
25
+ "applicationId": "ab45514e-0d66-47dd-9508-b19c8cad1c4e",
26
+ "monthlyUsers": 1
27
+ }
28
+ ]
29
+ }
@@ -0,0 +1,66 @@
1
+ let mongoose = require('mongoose')
2
+
3
+ mongoose.Promise = global.Promise
4
+
5
+ let MonthlyStatsModel = require('../../Models').MonthlyStat(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 monthlyStats
15
+
16
+ beforeEach(() => {
17
+ monthlyStats = JSON.parse(JSON.stringify(require('./monthlyStats.data.json')))
18
+ })
19
+
20
+ describe('MonthlyStat', () => {
21
+ describe('Valid MonthlyStat document', () => {
22
+ it('should validate a valid MonthlyStat document ', (done) => {
23
+ let MonthlyStats = new MonthlyStatsModel(monthlyStats)
24
+ MonthlyStats.validate((err, res) => {
25
+ assert.notExists(res)
26
+ assert(err === null, 'err should equals null')
27
+ done()
28
+ })
29
+ })
30
+ it('should not accept a invalid customerId', (done) => {
31
+ monthlyStats.customerId = 'invalid-customerId'
32
+ let MonthlyStats = new MonthlyStatsModel(monthlyStats)
33
+ MonthlyStats.validate((err, res) => {
34
+ assert.exists(err, 'invalid customerId')
35
+ assert.isObject(err)
36
+ done()
37
+ })
38
+ })
39
+ it('should not accept a invalid applicationId', (done) => {
40
+ const invalidAppId = {
41
+ applicationId: 'invalid-applicationId',
42
+ monthlyUsers: 0
43
+ }
44
+ monthlyStats.applications.push(invalidAppId)
45
+ let MonthlyStats = new MonthlyStatsModel(monthlyStats)
46
+ MonthlyStats.validate((err, res) => {
47
+ assert.exists(err, 'invalid customerId')
48
+ assert.isObject(err)
49
+ done()
50
+ })
51
+ })
52
+ it('should not accept a negative monthlyUsers value', (done) => {
53
+ const invalidAppId = {
54
+ applicationId: 'd49fdf10-3744-462c-84f8-abad444d7044',
55
+ monthlyUsers: -100
56
+ }
57
+ monthlyStats.applications.push(invalidAppId)
58
+ let MonthlyStats = new MonthlyStatsModel(monthlyStats)
59
+ MonthlyStats.validate((err, res) => {
60
+ assert.exists(err, 'Path `monthlyUsers` (-100) is less than minimum allowed value (0)')
61
+ assert.isObject(err)
62
+ done()
63
+ })
64
+ })
65
+ })
66
+ })
@@ -0,0 +1,18 @@
1
+ {
2
+ "state": "ACTIVE",
3
+ "nextRuleUpdateInterval": 3600,
4
+ "lastUpdateTime": "2018-02-14T04:12:02.103Z",
5
+ "creationTime": "2018-02-14T04:12:02.103Z",
6
+ "name": "A New Project",
7
+ "accountId":"b0824b76-ce73-4fcf-81f8-1b63edb1114e",
8
+ "webhooks": {
9
+ "type": "trigger",
10
+ "url": "https://webhooklistener.bluedotinnovation.com",
11
+ "enabled": true,
12
+ "headers" : {
13
+ "securityToken" : "value"
14
+ }
15
+ },
16
+ "firebaseApiKey": "88888888-4444-4444-4444-121212121212",
17
+ "apiKey": "88888888-4444-4444-4444-123412341234"
18
+ }