@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,62 +0,0 @@
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
- })
@@ -1,29 +0,0 @@
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
- }
@@ -1,66 +0,0 @@
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
- })
@@ -1,18 +0,0 @@
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
- }
@@ -1,9 +0,0 @@
1
- {
2
- "requiredFields": ["name", "nextRuleUpdateInterval", "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
- }
@@ -1,81 +0,0 @@
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 Project ', () => {
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
- })
@@ -1,8 +0,0 @@
1
- {
2
- "_id" : "bf93ddd2-e7e9-4a89-9bcb-0b2164c17e45",
3
- "applicationId" : "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
- }
@@ -1,69 +0,0 @@
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 applicationId', (done) => {
40
- ruleRequestAggregation.applicationId = 'invalid-applicationId'
41
- let RuleRequestAggregation = new RuleRequestAggregationModel(ruleRequestAggregation)
42
- RuleRequestAggregation.validate((err, res) => {
43
- assert.exists(err, 'invalid applicationId')
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
- })
@@ -1,7 +0,0 @@
1
- const mocha = require('mocha')
2
- global.mongoose = require('mongoose')
3
- global.mongoose.Promise = global.Promise
4
- global.describe = mocha.describe
5
- global.it = mocha.it
6
- global.assert = require('chai').assert
7
- global.beforeEach = mocha.beforeEach
@@ -1,19 +0,0 @@
1
- module.exports = {
2
- username: 'test@bluedot.io',
3
- email: 'test@bluedot.io',
4
- password: 'jfmamjasond',
5
- firstName: 'John',
6
- lastName: 'Citizen',
7
- phoneNumber: '23429384',
8
- state: 'ACTIVE',
9
- lastUpdateTime: '2018-02-14T04:12:02.103Z',
10
- creationTime: '2018-02-14T04:12:02.103Z',
11
- isAdmin: true,
12
- accountId: '37ac5be3-60ec-4fb7-9f88-a4f6e8895f81',
13
- projectPermissions: [
14
- {
15
- permissionLevel: 'READ_WRITE',
16
- projectId: '1dc621a1-7980-410b-839b-4bed63600139'
17
- }
18
- ]
19
- }
@@ -1,8 +0,0 @@
1
- module.exports = {
2
- requiredFields: ['username', 'firstName', 'lastName', 'isAdmin', 'accountId'],
3
- customValidators: [
4
- {name: 'phoneNumber', invalidInputs: ['409203492039284232034398']},
5
- {name: 'creationTime', invalidInputs: ['21/07/2017', 'thursday']},
6
- {name: 'lastUpdateTime', invalidInputs: ['21/07/2017', 'saturday']}
7
- ]
8
- }
@@ -1,130 +0,0 @@
1
- let mongoose = require('mongoose')
2
-
3
- let UserModel = require('../../Models').User(mongoose)
4
- let UserModelBuiltInMongoose = require('../../Models').User()
5
- let describe = require('mocha').describe
6
- let it = require('mocha').it
7
- let rules = require('./user.rules.js')
8
- let chai = require('chai')
9
- let assert = chai.assert
10
- let mocha = require('mocha')
11
- let beforeEach = mocha.beforeEach
12
-
13
- let user
14
-
15
- beforeEach(() => {
16
- user = require('./user.data.js')
17
- })
18
-
19
- describe('User', () => {
20
- describe('Valid User ', () => {
21
- it('should validate a valid user when initializing the model with an external mongoose instance', (done) => {
22
- let User = new UserModel(user)
23
-
24
- User.validate((err, res) => {
25
- assert.notExists(res)
26
- assert(err === null, 'err equals null')
27
-
28
- done()
29
- })
30
- })
31
-
32
- it('should validate a valid user', (done) => {
33
- let User = new UserModelBuiltInMongoose(user)
34
-
35
- User.validate((err, res) => {
36
- assert.notExists(res)
37
- assert(err === null, 'err equals null')
38
- done()
39
- })
40
- })
41
- })
42
-
43
- describe('Invalid User', () => {
44
- describe('recursive property check', () => {
45
- let requiredFields = rules.requiredFields
46
- requiredFields.forEach((requiredField) => {
47
- it(`should throw an error with property '${requiredField}' if '${requiredField}' is not present`, (done) => {
48
- user = JSON.parse(JSON.stringify(user))
49
- delete user[requiredField]
50
- let User = new UserModel(user)
51
- User.validate((err, res) => {
52
- assert.notExists(res)
53
- assert.exists(err, 'err object should exist')
54
- assert.isObject(err)
55
- assert.nestedProperty(err, `errors.${requiredField}`, `error should have a ${requiredField} property`)
56
- done()
57
- })
58
- })
59
- })
60
- })
61
- })
62
-
63
- describe('recursive invalid entry check', () => {
64
- const { customValidators } = rules
65
-
66
- customValidators.forEach((customValidator) => {
67
- customValidator.invalidInputs.forEach((invalidInput) => {
68
- it(`should throw an error with property '${customValidator.name}' if '${customValidator.name}' is invalid => ${customValidator.name} = ${invalidInput}`, (done) => {
69
- user = JSON.parse(JSON.stringify(user))
70
- user[customValidator.name] = invalidInput
71
- let User = new UserModel(user)
72
-
73
- User.validate((err, res) => {
74
- assert.notExists(res)
75
- assert.exists(err, 'err object should exist')
76
- assert.isObject(err)
77
- assert.nestedProperty(err, `errors.${customValidator.name}`, `error should have a ${customValidator.name} property`)
78
- done()
79
- })
80
- })
81
- })
82
- })
83
- })
84
-
85
- describe('projectPermissions:', () => {
86
- it('should fail if projectId is invalid', (done) => {
87
- user = JSON.parse(JSON.stringify(user))
88
- user.projectPermissions[0].projectId = '8b1b5cb5-3c7b-452a-b9a7-'
89
- const User = new UserModel(user)
90
-
91
- User.validate((err, res) => {
92
- assert.match(err, /(projectId not in UUID v4 format)/i)
93
- done()
94
- })
95
- })
96
-
97
- it('should fail if projectId is missing', (done) => {
98
- user = JSON.parse(JSON.stringify(user))
99
- user.projectPermissions[0].projectId = undefined
100
- const User = new UserModel(user)
101
-
102
- User.validate((err, res) => {
103
- assert.match(err, /(Path `projectId` is required.)/i)
104
- done()
105
- })
106
- })
107
-
108
- it('should fail if permissionLevel is invalid', (done) => {
109
- user = JSON.parse(JSON.stringify(user))
110
- user.projectPermissions[0].permissionLevel = 'INVALID'
111
- const User = new UserModel(user)
112
-
113
- User.validate((err, res) => {
114
- assert.match(err, /(not a valid enum value)/i)
115
- done()
116
- })
117
- })
118
-
119
- it('should fail if permissionLevel is missing', (done) => {
120
- user = JSON.parse(JSON.stringify(user))
121
- user.projectPermissions[0].permissionLevel = undefined
122
- const User = new UserModel(user)
123
-
124
- User.validate((err, res) => {
125
- assert.match(err, /(Path `permissionLevel` is required.)/i)
126
- done()
127
- })
128
- })
129
- })
130
- })
@@ -1,24 +0,0 @@
1
- const { trimDecimals } = require('../../utils');
2
-
3
- describe('trimDecimals(num, n)', () => {
4
- const tests = [{
5
- num: -37.8196889692931,
6
- n: 6,
7
- expected: -37.819689,
8
- }, {
9
- num: 42,
10
- n: 2,
11
- expected: 42,
12
- }, {
13
- num: 23.39,
14
- n: 1,
15
- expected: 23.3,
16
- }]
17
-
18
- tests.forEach(({num, n, expected}) => {
19
- it(`when num is ${num} and n is ${n}, it should return ${expected}`, () => {
20
- const isCorrect = (trimDecimals(num,n) === expected)
21
- assert(isCorrect);
22
- })
23
- })
24
- })
@@ -1,50 +0,0 @@
1
- let mongoose = require('mongoose')
2
-
3
- mongoose.Promise = global.Promise
4
-
5
- let ZoneModel = require('../../Models').Zone(mongoose)
6
- let testCase = require('mocha').describe
7
- let assertions = require('mocha').it
8
- let chai = require('chai')
9
- let assert = chai.assert
10
- let mocha = require('mocha')
11
- let beforeEach = mocha.beforeEach
12
-
13
- let zone
14
-
15
- beforeEach(() => {
16
- zone = JSON.parse(JSON.stringify(require('./zone.data.json')))
17
- // remove conditions as it's not tested
18
- delete zone.conditions
19
- // remove all but 1 geofeatures as geofeatures are required
20
- zone.geofeatures = zone.geofeatures.filter(x => x.type.match(/circle/i))
21
- // remove customData
22
- delete zone.customData
23
- })
24
-
25
- testCase('Zone - Action', () => {
26
- testCase('Valid Zone - Action', () => {
27
- assertions('should not throw an error when a valid action is instantiated within a zone', (done) => {
28
- let Zone = new ZoneModel(zone)
29
- Zone.validate((err, res) => {
30
- assert.notExists(res)
31
- assert(err === null, 'err equals null')
32
- done()
33
- })
34
- })
35
- })
36
-
37
- testCase('Invalid Zone - Action', () => {
38
- assertions('should throw an error when an invalid action is instantiated within a zone', (done) => {
39
- delete zone.actions[1].url
40
- let Zone = new ZoneModel(zone)
41
- Zone.validate((err, res) => {
42
- assert.exists(err, 'err object should exist')
43
- assert.isObject(err)
44
- assert('actions.1.url' in err.errors)
45
- assert.notNestedProperty(err, `errors.geofeatures`, 'error should have a url property')
46
- done()
47
- })
48
- })
49
- })
50
- })
@@ -1,76 +0,0 @@
1
- let mongoose = require('mongoose')
2
-
3
- mongoose.Promise = global.Promise
4
-
5
- let ZoneModel = require('../../models/Zone').Model(mongoose)
6
- let testCase = require('mocha').describe
7
- let assertions = require('mocha').it
8
- let chai = require('chai')
9
- let assert = chai.assert
10
- let mocha = require('mocha')
11
- let beforeEach = mocha.beforeEach
12
-
13
- let zone
14
- let geofeatures
15
-
16
- beforeEach(() => {
17
- zone = JSON.parse(JSON.stringify(require('./zone.data.json')))
18
- // remove actions as it's not tested
19
- delete zone.actions
20
- // remove all but 1 geofeatures as geofeatures are required
21
- geofeatures = zone.geofeatures
22
- zone.geofeatures = zone.geofeatures.filter(x => x.type.match(/circle/i))
23
- // remove customData
24
- delete zone.customData
25
- })
26
-
27
- testCase('Zone - Condition', () => {
28
- testCase('Valid Zone - Condition', () => {
29
- assertions('should not throw an error when a valid condition is instantiated within a zone', (done) => {
30
- let Zone = new ZoneModel(zone)
31
- Zone.validate((err, res) => {
32
- assert.notExists(res)
33
- assert(err === null, 'err equals null')
34
- done()
35
- })
36
- })
37
- })
38
-
39
- testCase('Invalid Zone - Condition', () => {
40
- assertions('should throw an error when an invalid condition is instantiated within a zone', (done) => {
41
- zone.conditions[0].startDate = 'abc'
42
- let Zone = new ZoneModel(zone)
43
- Zone.validate((err, res) => {
44
- assert.exists(err, 'err object should exist')
45
- assert.isObject(err)
46
- assert('conditions.0.startDate' in err.errors)
47
- assert.notNestedProperty(err, `errors.geofeatures`, 'error should have a url property')
48
- done()
49
- })
50
- })
51
- assertions('should not throw an error when a valid condition is instantiated within a zone', (done) => {
52
- let Zone = new ZoneModel(zone)
53
- Zone.validate((err, res) => {
54
- assert.notExists(res)
55
- assert(err === null, 'err equals null')
56
- done()
57
- })
58
- })
59
- assertions('should throw an error when the minimumGeofeaturesCrossed for a travel path condition is greater than the total number of geofeatures', (done) => {
60
- zone.geofeatures = geofeatures
61
- zone.conditions.push({
62
- "type" : "travelPath",
63
- "minimumGeofeaturesCrossed" : zone.geofeatures.length+1,
64
- "timeOutSeconds": 120,
65
- "sequential" : false
66
- })
67
- let Zone = new ZoneModel(zone)
68
- Zone.validate((err, res) => {
69
- assert.exists(err, 'err object should exist')
70
- assert(err instanceof Error)
71
- assert(err.message.includes("Zone must not have minimumGeofeaturesCrossed higher than geofeatures count"))
72
- done()
73
- })
74
- })
75
- })
76
- })