@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
package/.eslintrc.js ADDED
@@ -0,0 +1,42 @@
1
+ module.exports = {
2
+ "extends" : [
3
+ "prettier"
4
+ ],
5
+ "plugins": [
6
+ "prettier"
7
+ ],
8
+ "parser": "babel-eslint",
9
+ "parserOptions": {
10
+ "ecmaVersion": 2015,
11
+ "sourceType": "module",
12
+ "ecmaFeatures": {
13
+ "jsx": true
14
+ }
15
+ },
16
+ "rules": {
17
+ "indent": [
18
+ 2,
19
+ 4,
20
+ {"SwitchCase": 1}
21
+ ],
22
+ "no-underscore-dangle": 0,
23
+ "import/prefer-default-export": false,
24
+ "arrow-body-style": 0
25
+ },
26
+ "env": {
27
+ "es6": true,
28
+ "browser": true,
29
+ "node": true,
30
+ "jest": true
31
+ },
32
+ "settings": {
33
+ "import/resolver": {
34
+ "webpack": {
35
+ "config": "./webpack.config.js"
36
+ }
37
+ }
38
+ },
39
+ "globals": {
40
+ "google": true
41
+ }
42
+ }
package/.gitlab-ci.yml ADDED
@@ -0,0 +1,43 @@
1
+ # Official framework image. Look for the different tagged releases at:
2
+ # https://hub.docker.com/r/library/node/tags/
3
+ image: node:8
4
+
5
+ before_script:
6
+ - npm install
7
+
8
+ # This folder is cached between builds
9
+ # http://docs.gitlab.com/ce/ci/yaml/README.html#cache
10
+ cache:
11
+ paths:
12
+ - node_modules/
13
+
14
+ test:lint:
15
+ tags:
16
+ - infrastructure
17
+ script:
18
+ - npm run lint
19
+
20
+ # Supported node versions can be found here:
21
+ # https://github.com/nodejs/LTS#lts_schedule
22
+ # jest does not support node < 4
23
+ # https://facebook.github.io/jest/docs/troubleshooting.html#compatibility-issues
24
+ test:node:8:
25
+ tags:
26
+ - infrastructure
27
+ script:
28
+ - npm run test:coverage
29
+
30
+ # Publish tagged versions to npm
31
+ publish:
32
+ stage: deploy
33
+ tags:
34
+ - xcode9
35
+ only:
36
+ - tags
37
+ - triggers
38
+ #gitlab open issue: https://gitlab.com/gitlab-org/gitlab-ce/issues/27818
39
+ except:
40
+ - /^(?!.*(master)$).*$/
41
+ script:
42
+ - echo '//registry.npmjs.org/:_authToken=${NPM_TOKEN}'>.npmrc
43
+ - npm publish
package/CHANGELOG.md ADDED
@@ -0,0 +1,156 @@
1
+
2
+ ## 4.0.0
3
+ - Webhooks schema no longer allow headers of more than 1 key- value pair
4
+ - Webhooks no longer require enabled field
5
+
6
+ ## 3.1.1
7
+ - Rename `Polyline` to `Geoline`
8
+
9
+ ## 3.1.0
10
+ - Rename `filters` to `conditions`
11
+
12
+ ## 3.0.16
13
+ - `timeActive` - Changed validations order
14
+
15
+ ## 3.0.15
16
+ - `webhooks` - Fixed webhooks validations
17
+
18
+ ## 3.0.13
19
+ - `Polygon` and `Polyline` "same vertices" check measures accurate to 6 decimal places only.
20
+
21
+ ## 3.0.12
22
+ - Enforce `beaconType` capitalization on `Beacon` model
23
+
24
+ ## 3.0.11
25
+ - Added `lastSyncTime` to the `project` model
26
+
27
+ ## 3.0.10
28
+ - Remove validations on `geometry`'s
29
+ - Geofeatures moved to own separate folder
30
+
31
+ ## 3.0.9
32
+ - `dayRange` fixed validation issue
33
+
34
+ ## 3.0.7
35
+ - `proximityUUID` is now mandatory
36
+
37
+ ## 3.0.6
38
+ - `txPower` no longer mandatory
39
+
40
+ ## 3.0.5
41
+ - `User` - Remove password field
42
+
43
+ ## 3.0.4
44
+ - `Polygon` - disallow a vertices next 2 being the same
45
+
46
+ ## 3.0.3
47
+ - `BoundingBox` - disallow same values for `northEast` and `southWest`
48
+ - `Polygon` - disallow a vertices next vertice being the same
49
+
50
+ ## 3.0.2
51
+ - Remove `_id`'s on the actions and filters (for real this time)
52
+
53
+ ## 3.0.1
54
+ - `DayRange` must have at least startTime or endTime or both
55
+
56
+ ## 3.0.0
57
+
58
+ - Breaking changes:
59
+ - `bearing` -> `travelDirection`
60
+ - `percentageCrossed` -> `travelPath`
61
+ - `percentage.percentage` -> `travelPath.minimumGeofeaturesCrossed`
62
+ - `timeOfDayRange` -> `timeActive`
63
+ - `calendarDateRange` -> `dayRange`
64
+ - Remove `state` from all subdocuments
65
+ - Remove `creationTime` from all subdocuments
66
+ - Remove `lastUpdateTime` from all subdocuments
67
+ - Remove `_id` from all subdocuments EXCEPT geofeatures
68
+ - Remove `description` from all subdocuments
69
+ - Remove `__v` from all subdocuments
70
+
71
+ ## 2.0.22
72
+
73
+ - Allow 0 Major and Minor
74
+
75
+ ## 2.0.21
76
+
77
+ - Validation: Polygon needs 3 or more vertices
78
+
79
+ ## 2.0.20
80
+ - Added customData validation in helpers so that it can be imported in the UI
81
+
82
+ ## 2.0.19
83
+ - Added validations for keys in customData
84
+
85
+ ## 2.0.18
86
+ - `password` on `user` model no longer required. We will rely on cognito to throw an error
87
+
88
+ ## 2.0.17
89
+ - Tag model added
90
+
91
+ ## 2.0.16
92
+ - Don't enforce in `CalendarDateRangeFilter` that `endDate` is later than current date.
93
+
94
+ ## 2.0.15
95
+ - Update `bearingFilter` with new business logic.
96
+
97
+ ## 2.0.14
98
+ - Remove `password` from user model
99
+
100
+ ## 2.0.13
101
+ - Republish to bring changes from 2.0.11
102
+
103
+ ## 2.0.12
104
+ - Update `bearingFilter` to allow wrap around angles (e.g. 315deg & 45deg)
105
+
106
+ ## 2.0.11
107
+ - Added uuid as `_id` for user
108
+
109
+ ## 2.0.10
110
+ - Added indexes on beacons model
111
+ - Added `apiKey` to project model (for backwards compatibility)
112
+ - Added `customerApiKey` to account model (for backwards compatibility)
113
+
114
+ ## 2.0.9
115
+ - Validation on `projectPermissions` in user model
116
+
117
+ ## 2.0.8
118
+ - Removed `description` from `zone` model.
119
+ - Added `triggerOnExit` to `zone` model.
120
+
121
+ ## 2.0.7
122
+ - All `guid`'s changed to `_id`'s
123
+
124
+ ## 2.0.6
125
+ - Added `geometry` to geofeature models
126
+
127
+ ## 2.0.5
128
+ - Beacon using a `location` property instead of `latitude` and `longitude` on the root
129
+ - ZoneBeacon model inheriting from Beacon, adds `proximity` and `type`
130
+ - Zone will use ZoneBeacon instead of Beacon model
131
+ - Removed `proximity` from Beacon
132
+
133
+ ## 2.0.4
134
+ - customData no longer an array
135
+ - add accountId to zones
136
+
137
+ ## 2.0.3-alpha.1
138
+ - Moved beacon back into geofeatures
139
+ - Changed all geofeatures guids to id's
140
+ - Updated creationTime/lastUpdateTime code on all models
141
+
142
+ ## 2.0.2
143
+ - Added patcher to beacon model
144
+
145
+ ## 2.0.1
146
+ - Beacon model: guid -> id
147
+
148
+ ## 2.0.0-beta.14
149
+ - Beacon model: Removed console.debug breaking lambda execution
150
+
151
+ ## 2.0.0-beta.13
152
+ - Beacon model: Added accountId
153
+ - Zone model: Added beacons
154
+
155
+ ## 2.0.0-beta.12
156
+ - User model: `emailAddress` changed to `email`
package/Models.js CHANGED
@@ -2,13 +2,58 @@
2
2
  * Created by andrewstirling on 22/12/16.
3
3
  */
4
4
 
5
- var Models = {};
6
- var normalizedPath = require("path").join(__dirname, "models");
7
- var fs = require("fs");
8
- fs.readdirSync(normalizedPath).forEach(function(file) {
9
- if( !fs.lstatSync(normalizedPath+'/'+file).isDirectory() ) {
10
- Models[file.substring(0, file.length - 3)] = require("./models/" + file);
11
- }
12
- });
13
-
14
- module.exports = Models;
5
+ let Models = {}
6
+
7
+ Models.Account = require('./models/Account').Model
8
+ Models.Beacon = require('./models/Beacon').Model
9
+
10
+ Models.MessageAction = require('./models/MessageAction').Model
11
+ Models.MonthlyStat = require('./models/MonthlyStats').Model
12
+ Models.Project = require('./models/Project').Model
13
+ Models.RuleRequestAggregation = require('./models/RuleRequestAggregation').Model
14
+ Models.UrlAction = require('./models/UrlAction').Model
15
+ Models.User = require('./models/User').Model
16
+ Models.Zone = require('./models/Zone').Model
17
+
18
+ // Geofeatures
19
+ Models.BoundingBox = require('./models/geofeatures/BoundingBox').Model
20
+ Models.Circle = require('./models/geofeatures/Circle').Model
21
+ Models.Polygon = require('./models/geofeatures/Polygon').Model
22
+ Models.Geoline = require('./models/geofeatures/Geoline').Model
23
+ Models.ZoneBeacon = require('./models/geofeatures/ZoneBeacon').Model
24
+
25
+ // Conditions
26
+ Models.DayRange = require('./models/conditions/DayRange').Model
27
+ Models.TimeActive = require('./models/conditions/TimeActive').Model
28
+ Models.TravelPath = require('./models/conditions/TravelPath').Model
29
+ Models.Speed = require('./models/conditions/Speed').Model
30
+ Models.TravelDirection = require('./models/conditions/TravelDirection').Model
31
+
32
+ let Schemas = {}
33
+
34
+ Schemas.Account = require('./models/Account').Schema
35
+ Schemas.Beacon = require('./models/Beacon').Schema
36
+ Schemas.MessageAction = require('./models/MessageAction').Schema
37
+ Schemas.MonthlyStat = require('./models/MonthlyStats').Schema
38
+ Schemas.Project = require('./models/Project').Schema
39
+ Schemas.RuleRequestAggregation = require('./models/RuleRequestAggregation').Schema
40
+ Schemas.UrlAction = require('./models/UrlAction').Schema
41
+ Schemas.User = require('./models/User').Schema
42
+ Schemas.Zone = require('./models/Zone').Schema
43
+
44
+ // Geofeatures
45
+ Schemas.BoundingBox = require('./models/geofeatures/BoundingBox').Schema
46
+ Schemas.Circle = require('./models/geofeatures/Circle').Schema
47
+ Schemas.Polygon = require('./models/geofeatures/Polygon').Schema
48
+ Schemas.Geoline = require('./models/geofeatures/Geoline').Schema
49
+ Schemas.ZoneBeacon = require('./models/geofeatures/ZoneBeacon').Schema
50
+
51
+ // Conditions
52
+ Schemas.DayRange = require('./models/conditions/DayRange').Schema
53
+ Schemas.Speed = require('./models/conditions/Speed').Schema
54
+ Schemas.TimeActive = require('./models/conditions/TimeActive').Schema
55
+ Schemas.TravelPath = require('./models/conditions/TravelPath').Schema
56
+ Schemas.TravelDirection = require('./models/conditions/TravelDirection').Schema
57
+
58
+ Models.Schemas = Schemas
59
+ module.exports = Models
package/README.MD ADDED
@@ -0,0 +1,36 @@
1
+ #### Bluedot Innovation Public API
2
+ ```
3
+ Created by: Andrew Stirling
4
+ Last update by: Ryan Kan / 0421772600 / ryan@bluedotinnovation.com
5
+ Last updated: 4th December 2017
6
+ ```
7
+
8
+ Styleguide link [JSS Standard Javascript](https://standardjs.com/),
9
+ implemented with [ESLint](https://github.com/standard/eslint-config-standard)
10
+
11
+
12
+ Minimum test coverage enforced:
13
+
14
+ ````--lines 90 --functions 90 --branches 70````
15
+
16
+ To check test coverage:
17
+
18
+ run `npm test:coverage`
19
+
20
+ To lint:
21
+
22
+ run `npm run lint`
23
+
24
+ To check if your code will pass CI pipeline:
25
+
26
+ run `npm run test:ci`
27
+ aws apigateway put-integration \
28
+ --rest-api-id api-id \
29
+ --resource-id resource-id \
30
+ --http-method POST \
31
+ --type AWS \
32
+ --integration-http-method POST \
33
+ --uri arn:aws:apigateway:aws-region:lambda:path/2015-03-31/functions/arn:aws:lambda:aws-region:aws-acct-id:function:your-lambda-function-name/invocations
34
+ To publish:
35
+
36
+ run `npm version x.x.x`
@@ -0,0 +1,12 @@
1
+ {
2
+ "state": "ACTIVE",
3
+ "lastUpdateTime": "2018-02-14T04:12:02.103Z",
4
+ "creationTime": "2018-02-14T04:12:02.103Z",
5
+ "name": "ABC Company",
6
+ "createdBy": "b0824b76-ce73-4fcf-81f8-1b63edb1114e",
7
+ "poiCredits": 23,
8
+ "features": {
9
+ "tags": true,
10
+ "beacons": false
11
+ }
12
+ }
@@ -0,0 +1,8 @@
1
+ module.exports = {
2
+ requiredFields: ['name'],
3
+ customValidators: [
4
+ {name: 'poiCredits', invalidInputs: ['a string']},
5
+ {name: 'creationTime', invalidInputs: ['21/07/2017', 'thursday']},
6
+ {name: 'lastUpdateTime', invalidInputs: ['21/07/2017', 'saturday']}
7
+ ]
8
+ }
@@ -0,0 +1,83 @@
1
+ let mongoose = require('mongoose')
2
+
3
+ let AccountModel = require('../../Models').Account(mongoose)
4
+ let AccountModelBuiltInMongoose = require('../../Models').Account()
5
+ let testCase = require('mocha').describe
6
+ let assertions = require('mocha').it
7
+ let rules = require('./account.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 account
14
+
15
+ beforeEach(() => {
16
+ account = JSON.parse(JSON.stringify(require('./account.data.json')))
17
+ })
18
+
19
+ testCase('Account', () => {
20
+ testCase('Valid Account ', () => {
21
+ assertions('should validate a valid account when initializing the model with an external mongoose instance', (done) => {
22
+ let Account = new AccountModel(account)
23
+
24
+ Account.validate((err, res) => {
25
+ assert.notExists(res)
26
+ assert(err === null, 'err equals null')
27
+ done()
28
+ })
29
+ })
30
+
31
+ assertions('should validate a valid account', (done) => {
32
+ let Account = new AccountModelBuiltInMongoose(account)
33
+
34
+ Account.validate((err, res) => {
35
+ assert.notExists(res)
36
+ assert(err === null, 'err equals null')
37
+ done()
38
+ })
39
+ })
40
+ })
41
+
42
+ testCase('Invalid Account', () => {
43
+ testCase('recursive property check', () => {
44
+ let requiredFields = rules.requiredFields
45
+ requiredFields.forEach((requiredField) => {
46
+ assertions(`should throw an error with property '${requiredField}' if '${requiredField}' is not present`, (done) => {
47
+ account = JSON.parse(JSON.stringify(account))
48
+ delete account[requiredField]
49
+ let Account = new AccountModel(account)
50
+ Account.validate((err, res) => {
51
+ assert.notExists(res)
52
+ assert.exists(err, 'err object should exist')
53
+ assert.isObject(err)
54
+ assert.nestedProperty(err, `errors.${requiredField}`, `error should have a ${requiredField} property`)
55
+ done()
56
+ })
57
+ })
58
+ })
59
+ })
60
+ })
61
+
62
+ testCase('recursive invalid entry check', () => {
63
+ const { customValidators } = rules
64
+
65
+ customValidators.forEach((customValidator) => {
66
+ customValidator.invalidInputs.forEach((invalidInput) => {
67
+ assertions(`should throw an error with property '${customValidator.name}' if '${customValidator.name}' is invalid => ${customValidator.name} = ${invalidInput}`, (done) => {
68
+ account = JSON.parse(JSON.stringify(account))
69
+ account[customValidator.name] = invalidInput
70
+ let Account = new AccountModel(account)
71
+
72
+ Account.validate((err, res) => {
73
+ assert.notExists(res)
74
+ assert.exists(err, 'err object should exist')
75
+ assert.isObject(err)
76
+ assert.nestedProperty(err, `errors.${customValidator.name}`, `error should have a ${customValidator.name} property`)
77
+ done()
78
+ })
79
+ })
80
+ })
81
+ })
82
+ })
83
+ })
@@ -0,0 +1,5 @@
1
+ {
2
+ "type": "message",
3
+ "message": "hello",
4
+ "title": "hello"
5
+ }
@@ -0,0 +1,3 @@
1
+ {
2
+ "requiredFields":["message", "title"]
3
+ }
@@ -0,0 +1,61 @@
1
+ let mongoose = require('mongoose')
2
+
3
+ mongoose.Promise = global.Promise
4
+
5
+ let MessageActionModel = require('../../../Models').MessageAction(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
+ let rules = require('./messageAction.rules.json')
14
+
15
+ let messageAction
16
+
17
+ beforeEach(() => {
18
+ messageAction = JSON.parse(JSON.stringify(require('./messageAction.data.json')))
19
+ })
20
+
21
+ testCase('MessageAction', () => {
22
+ testCase('Valid MessageAction', () => {
23
+ assertions('should validate a valid messageAction ', (done) => {
24
+ let MessageAction = new MessageActionModel(messageAction)
25
+ MessageAction.validate((err, res) => {
26
+ assert.notExists(res)
27
+ assert(err === null, 'err should equals null')
28
+ done()
29
+ })
30
+ })
31
+ })
32
+
33
+ testCase('Invalid MessageAction', () => {
34
+ assertions('should not validate a messageAction with invalid MessageAction', (done) => {
35
+ delete messageAction[rules.requiredFields[0]]
36
+ let MessageAction = new MessageActionModel(messageAction)
37
+ MessageAction.validate((err, res) => {
38
+ assert.exists(err, 'err object should exist')
39
+ assert.isObject(err)
40
+ done()
41
+ })
42
+ })
43
+ testCase('check each required property of the model and validate that it is present', () => {
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
+ // delete i from geofeatures' messageAction child
48
+ delete messageAction[i]
49
+ let MessageAction = new MessageActionModel(messageAction)
50
+ MessageAction.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
+ })
@@ -0,0 +1,4 @@
1
+ {
2
+ "type": "url",
3
+ "url": "https://www.google.com"
4
+ }
@@ -0,0 +1,3 @@
1
+ {
2
+ "requiredFields":["url"]
3
+ }
@@ -0,0 +1,74 @@
1
+ let mongoose = require('mongoose')
2
+
3
+ mongoose.Promise = global.Promise
4
+
5
+ let UrlactionModel = require('../../../Models').UrlAction(mongoose)
6
+ let UrlactionModelBuiltInMongoose = require('../../../Models').UrlAction()
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('./urlAction.rules.json')
16
+
17
+ let urlaction
18
+
19
+ beforeEach(() => {
20
+ urlaction = JSON.parse(JSON.stringify(require('./urlAction.data.json')))
21
+ })
22
+
23
+ testCase('Urlaction', () => {
24
+ testCase('Valid Urlaction', () => {
25
+ assertions('should validate a valid urlaction ', (done) => {
26
+ let Urlaction = new UrlactionModel(urlaction)
27
+ Urlaction.validate((err, res) => {
28
+ assert.notExists(res)
29
+ assert(err === null, 'err should equals null')
30
+ done()
31
+ })
32
+ })
33
+ })
34
+
35
+ testCase('Valid Urlaction (Built in mongoose)', () => {
36
+ assertions('should validate a valid urlaction ', (done) => {
37
+ let Urlaction = new UrlactionModelBuiltInMongoose(urlaction)
38
+ Urlaction.validate((err, res) => {
39
+ assert.notExists(res)
40
+ assert(err === null, 'err should equals null')
41
+ done()
42
+ })
43
+ })
44
+ })
45
+
46
+ testCase('Invalid Urlaction', () => {
47
+ assertions('should not validate a urlaction with invalid Urlaction', (done) => {
48
+ delete urlaction[rules.requiredFields[0]]
49
+ let Urlaction = new UrlactionModel(urlaction)
50
+ Urlaction.validate((err, res) => {
51
+ assert.exists(err, 'err object should exist')
52
+ assert.isObject(err)
53
+ done()
54
+ })
55
+ })
56
+ testCase('check each required property of the model and validate that it is present', () => {
57
+ let requiredFields = rules.requiredFields
58
+ requiredFields.map((i) => {
59
+ assertions(`should throw an error with property '${i}' if '${i}' is not present`, (done) => {
60
+ // delete i from geofeatures' urlaction child
61
+ delete urlaction[i]
62
+ let Urlaction = new UrlactionModel(urlaction)
63
+ Urlaction.validate((err, res) => {
64
+ assert.notExists(res)
65
+ assert.exists(err, 'err object should exist')
66
+ assert.isObject(err)
67
+ assert.nestedProperty(err, `errors.${i}`, `error should have a ${i} property`)
68
+ done()
69
+ })
70
+ })
71
+ })
72
+ })
73
+ })
74
+ })
@@ -0,0 +1,15 @@
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
+ "macAddress": "01:17:c5:31:84:19",
14
+ "accountId": "90a2ed18-86be-48e7-948b-393b8b679ef6"
15
+ }
@@ -0,0 +1,13 @@
1
+ {
2
+ "requiredFields":["name", "location", "beaconType"],
3
+ "dependentRequiredFields": [
4
+ {
5
+ "property": "beaconType",
6
+ "pairings": [
7
+ {"value": "ios", "requiredFields": ["proximityUUID", "major", "minor"]},
8
+ {"value": "android", "requiredFields": ["macAddress"]},
9
+ {"value": "both", "requiredFields": ["proximityUUID", "major", "minor", "macAddress"]}
10
+ ]
11
+ }
12
+ ]
13
+ }