@bluedot-innovation/models 2.0.0-alpha1 → 2.0.0-beta.10

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 (130) hide show
  1. package/.eslintrc.js +6 -0
  2. package/.gitlab-ci.yml +43 -0
  3. package/.nyc_output/b3865a46e2cec635045d586cfc79e5c6.json +1 -0
  4. package/.nyc_output/d9020767349457a911ef2b431e357310.json +1 -0
  5. package/Models.js +48 -10
  6. package/README.MD +36 -0
  7. package/__tests__/account/account.data.json +12 -0
  8. package/__tests__/account/account.rules.js +8 -0
  9. package/__tests__/account/account.spec.js +83 -0
  10. package/__tests__/action/message/messageAction.data.json +5 -0
  11. package/__tests__/action/message/messageAction.rules.json +3 -0
  12. package/__tests__/action/message/messageAction.spec.js +61 -0
  13. package/__tests__/action/url/urlAction.data.json +4 -0
  14. package/__tests__/action/url/urlAction.rules.json +3 -0
  15. package/__tests__/action/url/urlAction.spec.js +74 -0
  16. package/__tests__/dailyStats/checkDailyStats.js +31 -0
  17. package/__tests__/filter/beacon/beaconFilter.data.json +1 -0
  18. package/__tests__/filter/beacon/beaconFilter.rules.json +3 -0
  19. package/__tests__/filter/beacon/beaconFilter.spec.js +1 -0
  20. package/__tests__/filter/bearing/bearingFilter.data.json +5 -0
  21. package/__tests__/filter/bearing/bearingFilter.rules.json +3 -0
  22. package/__tests__/filter/bearing/bearingFilter.spec.js +95 -0
  23. package/__tests__/filter/calendarDateRange/calendarDateRangeFilter.data.json +5 -0
  24. package/__tests__/filter/calendarDateRange/calendarDateRangeFilter.rules.json +3 -0
  25. package/__tests__/filter/calendarDateRange/calendarDateRangeFilter.spec.js +62 -0
  26. package/__tests__/filter/percentageCrossed/percentageCrossedFilter.data.json +5 -0
  27. package/__tests__/filter/percentageCrossed/percentageCrossedFilter.rules.json +3 -0
  28. package/__tests__/filter/percentageCrossed/percentageCrossedFilter.spec.js +62 -0
  29. package/__tests__/filter/speed/speedFilter.data.json +5 -0
  30. package/__tests__/filter/speed/speedFilter.rules.json +3 -0
  31. package/__tests__/filter/speed/speedFilter.spec.js +73 -0
  32. package/__tests__/filter/timeOfDayRange/timeOfDayRange.data.json +5 -0
  33. package/__tests__/filter/timeOfDayRange/timeOfDayRange.rules.json +3 -0
  34. package/__tests__/filter/timeOfDayRange/timeOfDayRange.spec.js +73 -0
  35. package/__tests__/geofeature/beacon/beacon.data.json +12 -0
  36. package/__tests__/geofeature/beacon/beacon.rules.json +13 -0
  37. package/__tests__/geofeature/beacon/beacon.spec.js +95 -0
  38. package/__tests__/geofeature/boundingBox/boundingBox.data.json +12 -0
  39. package/__tests__/geofeature/boundingBox/boundingBox.rules.json +3 -0
  40. package/__tests__/geofeature/boundingBox/boundingBox.spec.js +62 -0
  41. package/__tests__/geofeature/circle/circle.data.json +9 -0
  42. package/__tests__/geofeature/circle/circle.rules.json +3 -0
  43. package/__tests__/geofeature/circle/circle.spec.js +71 -0
  44. package/__tests__/geofeature/polygon/polygon.data.json +46 -0
  45. package/__tests__/geofeature/polygon/polygon.rules.json +3 -0
  46. package/__tests__/geofeature/polygon/polygon.spec.js +70 -0
  47. package/__tests__/geofeature/polyline/polyline.data.json +46 -0
  48. package/__tests__/geofeature/polyline/polyline.rules.json +3 -0
  49. package/__tests__/geofeature/polyline/polyline.spec.js +70 -0
  50. package/__tests__/monthlyStats/monthlyStats.data.json +29 -0
  51. package/__tests__/monthlyStats/monthlyStats.spec.js +68 -0
  52. package/__tests__/project/project.data.json +14 -0
  53. package/__tests__/project/project.rules.json +9 -0
  54. package/__tests__/project/project.spec.js +81 -0
  55. package/__tests__/ruleRequestAggregation/ruleRequestAggregation.data.json +8 -0
  56. package/__tests__/ruleRequestAggregation/ruleRequestAggregation.spec.js +69 -0
  57. package/__tests__/user/user.data.js +13 -0
  58. package/__tests__/user/user.rules.js +8 -0
  59. package/__tests__/user/user.spec.js +83 -0
  60. package/__tests__/zone/zone.action.spec.js +50 -0
  61. package/__tests__/zone/zone.data.json +156 -0
  62. package/__tests__/zone/zone.filter.spec.js +50 -0
  63. package/__tests__/zone/zone.geofeatures.spec.js +74 -0
  64. package/__tests__/zone/zone.spec.js +107 -0
  65. package/helpers.js +14 -0
  66. package/models/Account.js +49 -0
  67. package/models/AdminPortalUser.js +10 -11
  68. package/models/Beacon.js +92 -78
  69. package/models/BeaconFilter.js +28 -12
  70. package/models/BearingFilter.js +46 -23
  71. package/models/BoundingBox.js +37 -20
  72. package/models/CalendarDateRangeFilter.js +34 -19
  73. package/models/Circle.js +34 -18
  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 +28 -0
  78. package/models/DeviceRulesRequest.js +27 -28
  79. package/models/Fence.js +12 -13
  80. package/models/GeoFence.js +12 -14
  81. package/models/Geofeature.js +16 -18
  82. package/models/MessageAction.js +31 -16
  83. package/models/MonthlyStats.js +44 -0
  84. package/models/NotificationLogEntry.js +7 -8
  85. package/models/POILocation.js +6 -7
  86. package/models/POILookup.js +8 -9
  87. package/models/POIResult.js +7 -8
  88. package/models/PartnerCustomer.js +12 -13
  89. package/models/PartnerPasswordReset.js +8 -9
  90. package/models/PartnerUser.js +10 -11
  91. package/models/Partners.js +11 -12
  92. package/models/PercentageCrossedFilter.js +30 -15
  93. package/models/Polygon.js +35 -19
  94. package/models/Polyline.js +35 -19
  95. package/models/Project.js +54 -0
  96. package/models/RuleRequestAggregation.js +33 -15
  97. package/models/SimpleCheckInZone.js +21 -21
  98. package/models/SingleUseToken.js +7 -8
  99. package/models/SpeedFilter.js +39 -19
  100. package/models/TestDevice.js +11 -12
  101. package/models/TestDeviceCluster.js +9 -10
  102. package/models/TestInstance.js +9 -10
  103. package/models/TestScenario.js +9 -10
  104. package/models/TimeOfDayRange.js +16 -16
  105. package/models/TimeOfDayRangeFilter.js +36 -18
  106. package/models/UrlAction.js +54 -0
  107. package/models/User.js +59 -0
  108. package/models/Zone.js +85 -273
  109. package/models/ZoneUIState.js +18 -18
  110. package/package.json +20 -8
  111. package/schemas/Point.js +10 -13
  112. package/schemas/Webhook.js +22 -0
  113. package/yarn.lock +2796 -0
  114. package/__tests__/zone/checkActions.js +0 -64
  115. package/__tests__/zone/checkAppId.js +0 -41
  116. package/__tests__/zone/checkBeacon.js +0 -46
  117. package/__tests__/zone/checkBearingFitler.js +0 -48
  118. package/__tests__/zone/checkBoundingBox.js +0 -44
  119. package/__tests__/zone/checkCalendarDateRangeFilterFitler.js +0 -48
  120. package/__tests__/zone/checkCircle.js +0 -41
  121. package/__tests__/zone/checkMRT.js +0 -46
  122. package/__tests__/zone/checkPercentageCrossedFitler.js +0 -48
  123. package/__tests__/zone/checkPolygon.js +0 -78
  124. package/__tests__/zone/checkPolyline.js +0 -78
  125. package/__tests__/zone/checkSpeedFitler.js +0 -48
  126. package/__tests__/zone/checkTimeOfDayRangeFitler.js +0 -48
  127. package/models/AdminUser.js +0 -10
  128. package/models/Application.js +0 -38
  129. package/models/Customer.js +0 -38
  130. package/models/URLAction.js +0 -34
@@ -0,0 +1,62 @@
1
+ let mongoose = require('mongoose')
2
+
3
+ mongoose.Promise = global.Promise
4
+
5
+ let BoundingBoxModel = require('../../../Models').BoundingBox(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('./boundingBox.rules.json')
15
+
16
+ let boundingBox
17
+
18
+ beforeEach(() => {
19
+ boundingBox = JSON.parse(JSON.stringify(require('./boundingBox.data.json')))
20
+ })
21
+
22
+ testCase('BoundingBox', () => {
23
+ testCase('Valid BoundingBox', () => {
24
+ assertions('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
+ testCase('Invalid BoundingBox', () => {
35
+ assertions('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
+ 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' boundingBox child
49
+ delete boundingBox[i]
50
+ let BoundingBox = new BoundingBoxModel(boundingBox)
51
+ BoundingBox.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,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": "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,70 @@
1
+ let mongoose = require('mongoose')
2
+
3
+ mongoose.Promise = global.Promise
4
+
5
+ let PolygonModel = require('../../../Models').Polygon(mongoose)
6
+ let PolygonModelBuiltInMongoose = require('../../../Models').Polygon()
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('./polygon.rules.json')
16
+
17
+ let polygon
18
+
19
+ beforeEach(() => {
20
+ polygon = JSON.parse(JSON.stringify(require('./polygon.data.json')))
21
+ })
22
+ testCase('Polygon', () => {
23
+ testCase('Valid Polygon', () => {
24
+ assertions('should validate a valid polygon ', (done) => {
25
+ let Polygon = new PolygonModel(polygon)
26
+ Polygon.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 polygon (built in mongoose)', (done) => {
33
+ let Polygon = new PolygonModelBuiltInMongoose(polygon)
34
+ Polygon.validate((err, res) => {
35
+ assert.notExists(res)
36
+ assert(err === null, 'err should equals null')
37
+ done()
38
+ })
39
+ })
40
+ })
41
+
42
+ testCase('Invalid Polygon', () => {
43
+ assertions('should not validate a polygon with invalid Polygon', (done) => {
44
+ delete polygon[rules.requiredFields[0]]
45
+ let Polygon = new PolygonModel(polygon)
46
+ Polygon.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' polygon child
57
+ delete polygon[i]
58
+ let Polygon = new PolygonModel(polygon)
59
+ Polygon.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": "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
+ }
@@ -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 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
+ })
@@ -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,68 @@
1
+ let mongoose = require('mongoose')
2
+
3
+ mongoose.Promise = global.Promise
4
+
5
+ let MonthlyStatsModel = require('../../Models').MonthlyStat(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 monthlyStats
15
+
16
+ beforeEach(() => {
17
+ monthlyStats = JSON.parse(JSON.stringify(require('./monthlyStats.data.json')))
18
+ })
19
+
20
+ testCase('MonthlyStat', () => {
21
+ testCase('Valid MonthlyStat document', () => {
22
+ assertions('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
+ assertions('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
+ assertions('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
+ console.log(err)
48
+ assert.exists(err, 'invalid customerId')
49
+ assert.isObject(err)
50
+ done()
51
+ })
52
+ })
53
+ assertions('should not accept a negative monthlyUsers value', (done) => {
54
+ const invalidAppId = {
55
+ applicationId: 'd49fdf10-3744-462c-84f8-abad444d7044',
56
+ monthlyUsers: -100
57
+ }
58
+ monthlyStats.applications.push(invalidAppId)
59
+ let MonthlyStats = new MonthlyStatsModel(monthlyStats)
60
+ MonthlyStats.validate((err, res) => {
61
+ console.log(err)
62
+ assert.exists(err, 'Path `monthlyUsers` (-100) is less than minimum allowed value (0)')
63
+ assert.isObject(err)
64
+ done()
65
+ })
66
+ })
67
+ })
68
+ })
@@ -0,0 +1,14 @@
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
+ },
13
+ "firebaseApiKey": "88888888-4444-4444-4444-121212121212"
14
+ }
@@ -0,0 +1,9 @@
1
+ {
2
+ "requiredFields": ["name", "nextRuleUpdateInterval", "lastUpdateTime", "creationTime", "accountId"],
3
+ "customValidators": [
4
+ {"name": "nextRuleUpdateInterval", "invalidInput": [5000.5556]},
5
+ {"name": "lastUpdateTime", "invalidInput": ["21/07/2017", "saturday"]},
6
+ {"name": "creationTime", "invalidInput": ["21/07/2017", "thursday"]},
7
+ {"name": "accountId", "invalidInput": ["21/07/2017", 21072017, "qwe123-21321-ad"]}
8
+ ]
9
+ }
@@ -0,0 +1,81 @@
1
+ let mongoose = require('mongoose')
2
+
3
+ mongoose.Promise = global.Promise
4
+
5
+ let ProjectModel = require('../../Models').Project(mongoose)
6
+ let ProjectModelBuiltInMongoose = require('../../Models').Project()
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
+ let rules = require('./project.rules.json')
14
+
15
+ let project
16
+
17
+ beforeEach(() => {
18
+ project = JSON.parse(JSON.stringify(require('./project.data.json')))
19
+ })
20
+
21
+ testCase('Project', () => {
22
+ testCase('Valid Project ', () => {
23
+ assertions('should validate a valid project ', (done) => {
24
+ let Project = new ProjectModel(project)
25
+ Project.validate((err, res) => {
26
+ assert.notExists(res)
27
+ assert(err === null, 'err equals null')
28
+ done()
29
+ })
30
+ })
31
+ })
32
+ testCase('Valid Project ', () => {
33
+ assertions('should validate a valid project ', (done) => {
34
+ let Project = new ProjectModelBuiltInMongoose(project)
35
+ Project.validate((err, res) => {
36
+ assert.notExists(res)
37
+ assert(err === null, 'err equals null')
38
+ done()
39
+ })
40
+ })
41
+ })
42
+ testCase('Invalid Zone ', () => {
43
+ testCase('recursive property check', () => {
44
+ let requiredFields = rules.requiredFields
45
+ requiredFields.map((i) => {
46
+ assertions(`should throw an error with property '${i}' if '${i}' is not present`, (done) => {
47
+ project = JSON.parse(JSON.stringify(project))
48
+ delete project[i]
49
+ let Project = new ProjectModel(project)
50
+ Project.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 radius property')
55
+ done()
56
+ })
57
+ })
58
+ })
59
+ })
60
+
61
+ testCase('recursive invalid entry check', () => {
62
+ let invalidProps = rules.customValidators
63
+ invalidProps.map((i) => {
64
+ i.invalidInput.map((j) => {
65
+ assertions(`should throw an error with property '${i.name}' if '${i.name}' is invalid => ${i.name} = ${j}`, (done) => {
66
+ project = JSON.parse(JSON.stringify(project))
67
+ project[i.name] = j
68
+ let Project = new ProjectModel(project)
69
+ Project.validate((err, res) => {
70
+ assert.notExists(res)
71
+ assert.exists(err, 'err object should exist')
72
+ assert.isObject(err)
73
+ assert.nestedProperty(err, `errors.${i.name}`, `error should have a ${i} property`)
74
+ done()
75
+ })
76
+ })
77
+ })
78
+ })
79
+ })
80
+ })
81
+ })
@@ -0,0 +1,8 @@
1
+ {
2
+ "_id" : "bf93ddd2-e7e9-4a89-9bcb-0b2164c17e45",
3
+ "appplicationId" : "fd150b63-08dc-4114-aaf9-359cef30def6",
4
+ "customerId" : "f944c7e9-63cc-4c0a-8ad3-acf3c30415fc",
5
+ "iosCount" : 9,
6
+ "androidCount" : 0,
7
+ "creationDate" : "2018-02-22T05:54:21.327+0000"
8
+ }
@@ -0,0 +1,69 @@
1
+ let mongoose = require('mongoose')
2
+
3
+ mongoose.Promise = global.Promise
4
+
5
+ let RuleRequestAggregationModel = require('../../Models').RuleRequestAggregation(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 ruleRequestAggregation
15
+
16
+ beforeEach(() => {
17
+ ruleRequestAggregation = JSON.parse(JSON.stringify(require('./ruleRequestAggregation.data.json')))
18
+ })
19
+
20
+ testCase('RuleRequestAggregation', () => {
21
+ testCase('Valid RuleRequestAggregation document', () => {
22
+ assertions('should validate a valid RuleRequestAggregation document ', (done) => {
23
+ let RuleRequestAggregation = new RuleRequestAggregationModel(ruleRequestAggregation)
24
+ RuleRequestAggregation.validate((err, res) => {
25
+ assert.notExists(res)
26
+ assert(err === null, 'err should equals null')
27
+ done()
28
+ })
29
+ })
30
+ assertions('should not accept a invalid customerId', (done) => {
31
+ ruleRequestAggregation.customerId = 'invalid-customerId'
32
+ let RuleRequestAggregation = new RuleRequestAggregationModel(ruleRequestAggregation)
33
+ RuleRequestAggregation.validate((err, res) => {
34
+ assert.exists(err, 'invalid customerId')
35
+ assert.isObject(err)
36
+ done()
37
+ })
38
+ })
39
+ assertions('should not accept a invalid appplicationId', (done) => {
40
+ ruleRequestAggregation.appplicationId = 'invalid-applicationId'
41
+ let RuleRequestAggregation = new RuleRequestAggregationModel(ruleRequestAggregation)
42
+ RuleRequestAggregation.validate((err, res) => {
43
+ assert.exists(err, 'invalid aplicationId')
44
+ assert.isObject(err)
45
+ done()
46
+ })
47
+ })
48
+ assertions('should not accept a negative iosCount value', (done) => {
49
+ const negativeIosCount = -100
50
+ ruleRequestAggregation.iosCount = negativeIosCount
51
+ let RuleRequestAggregation = new RuleRequestAggregationModel(ruleRequestAggregation)
52
+ RuleRequestAggregation.validate((err, res) => {
53
+ assert.exists(err, 'Path `androidCount` (' + negativeIosCount + ') is less than minimum allowed value (0)')
54
+ assert.isObject(err)
55
+ done()
56
+ })
57
+ })
58
+ assertions('should not accept a negative androidCount value', (done) => {
59
+ const negativeAndroidCount = -100
60
+ ruleRequestAggregation.androidCount = negativeAndroidCount
61
+ let RuleRequestAggregation = new RuleRequestAggregationModel(ruleRequestAggregation)
62
+ RuleRequestAggregation.validate((err, res) => {
63
+ assert.exists(err, 'Path `androidCount` (' + negativeAndroidCount + ') is less than minimum allowed value (0)')
64
+ assert.isObject(err)
65
+ done()
66
+ })
67
+ })
68
+ })
69
+ })