@bluedot-innovation/models 3.1.1 → 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.
- package/Models.js +10 -55
- package/models/AdminPortalUser.js +11 -10
- package/models/AdminUser.js +10 -0
- package/models/Application.js +38 -0
- package/models/ApplicationNotificationAction.js +30 -0
- package/models/ApplicationUsage.js +11 -0
- package/models/Beacon.js +32 -84
- package/models/BeaconFilter.js +23 -0
- package/models/BearingFilter.js +19 -0
- package/models/BoundingBox.js +17 -0
- package/models/Circle.js +21 -0
- package/models/ConfigurationParameters.js +20 -0
- package/models/Contract.js +38 -37
- package/models/Customer.js +38 -0
- package/models/CustomerLogin.js +10 -9
- package/models/DBEvent.js +14 -13
- package/models/DailyStats.js +7 -7
- package/models/DateRangeFilter.js +20 -0
- package/models/DeviceRulesRequest.js +28 -27
- package/models/Fence.js +21 -0
- package/models/FormattedBeacon.js +16 -0
- package/models/FormattedCircle.js +12 -0
- package/models/FormattedConditions.js +11 -0
- package/models/FormattedDateRange.js +11 -0
- package/models/FormattedPercentageCrossed.js +12 -0
- package/models/FormattedPoint.js +10 -0
- package/models/FormattedPolygon.js +11 -0
- package/models/FormattedPolyline.js +11 -0
- package/models/FormattedRectangle.js +12 -0
- package/models/FormattedTimeActive.js +17 -0
- package/models/FormattedZone.js +28 -0
- package/models/GeoFence.js +23 -0
- package/models/Geofeature.js +26 -0
- package/models/MessageAction.js +26 -28
- package/models/MonthlyStats.js +19 -35
- package/models/NotificationLogEntry.js +8 -7
- package/models/POILocation.js +7 -6
- package/models/POILookup.js +9 -8
- package/models/POIResult.js +8 -7
- package/models/PartnerCustomer.js +13 -12
- package/models/PartnerPasswordReset.js +9 -8
- package/models/PartnerUser.js +11 -10
- package/models/Partners.js +12 -11
- package/models/PercentageCrossedFilter.js +19 -0
- package/models/Point.js +20 -0
- package/models/Polygon.js +18 -0
- package/models/Polyline.js +18 -0
- package/models/PropertyMapping.js +17 -0
- package/models/Reference.js +19 -0
- package/models/RuleRequestAggregation.js +17 -33
- package/models/SequenceFilter.js +18 -0
- package/models/SimpleCheckInZone.js +29 -0
- package/models/SingleUseToken.js +8 -7
- package/models/SoundAction.js +28 -0
- package/models/SpeedFilter.js +19 -0
- package/models/TestDevice.js +12 -11
- package/models/TestDeviceCluster.js +10 -9
- package/models/TestInstance.js +10 -9
- package/models/TestScenario.js +10 -9
- package/models/TimeOfDayRange.js +16 -16
- package/models/TimeOfDayRangeFilter.js +19 -0
- package/models/URLAction.js +31 -0
- package/models/VibrationAction.js +28 -0
- package/models/ZoneUIState.js +18 -18
- package/models/property.js +25 -0
- package/package-lock.json.bak +170 -0
- package/package.json +6 -30
- package/.eslintrc.js +0 -42
- package/.gitlab-ci.yml +0 -43
- package/CHANGELOG.md +0 -152
- package/README.MD +0 -36
- package/__tests__/account/account.data.json +0 -12
- package/__tests__/account/account.rules.js +0 -8
- package/__tests__/account/account.spec.js +0 -83
- package/__tests__/action/message/messageAction.data.json +0 -5
- package/__tests__/action/message/messageAction.rules.json +0 -3
- package/__tests__/action/message/messageAction.spec.js +0 -61
- package/__tests__/action/url/urlAction.data.json +0 -4
- package/__tests__/action/url/urlAction.rules.json +0 -3
- package/__tests__/action/url/urlAction.spec.js +0 -74
- package/__tests__/beacon/beacon.data.json +0 -15
- package/__tests__/beacon/beacon.rules.json +0 -13
- package/__tests__/beacon/beacon.spec.js +0 -104
- package/__tests__/condition/beacon/beaconFilter.data.json +0 -1
- package/__tests__/condition/beacon/beaconFilter.rules.json +0 -3
- package/__tests__/condition/beacon/beaconFilter.spec.js +0 -1
- package/__tests__/condition/dayRange/dayRange.data.json +0 -5
- package/__tests__/condition/dayRange/dayRange.rules.json +0 -3
- package/__tests__/condition/dayRange/dayRange.spec.js +0 -74
- package/__tests__/condition/percentageCrossed/travelPath.data.json +0 -5
- package/__tests__/condition/percentageCrossed/travelPath.rules.json +0 -3
- package/__tests__/condition/percentageCrossed/travelPath.spec.js +0 -62
- package/__tests__/condition/speed/speed.data.json +0 -5
- package/__tests__/condition/speed/speed.rules.json +0 -3
- package/__tests__/condition/speed/speed.spec.js +0 -73
- package/__tests__/condition/timeActive/timeActive.data.json +0 -5
- package/__tests__/condition/timeActive/timeActive.rules.json +0 -7
- package/__tests__/condition/timeActive/timeActive.spec.js +0 -94
- package/__tests__/condition/travelDirection/travelDirection.data.json +0 -5
- package/__tests__/condition/travelDirection/travelDirection.rules.json +0 -3
- package/__tests__/condition/travelDirection/travelDirection.spec.js +0 -132
- package/__tests__/dailyStats/checkDailyStats.js +0 -31
- package/__tests__/geofeature/boundingBox/boundingBox.data.json +0 -12
- package/__tests__/geofeature/boundingBox/boundingBox.rules.json +0 -3
- package/__tests__/geofeature/boundingBox/boundingBox.spec.js +0 -78
- package/__tests__/geofeature/circle/circle.data.json +0 -9
- package/__tests__/geofeature/circle/circle.rules.json +0 -3
- package/__tests__/geofeature/circle/circle.spec.js +0 -71
- package/__tests__/geofeature/geoline/geoline.data.json +0 -46
- package/__tests__/geofeature/geoline/geoline.rules.json +0 -3
- package/__tests__/geofeature/geoline/geoline.spec.js +0 -70
- package/__tests__/geofeature/polygon/polygon.data.json +0 -46
- package/__tests__/geofeature/polygon/polygon.rules.json +0 -3
- package/__tests__/geofeature/polygon/polygon.spec.js +0 -127
- package/__tests__/geofeature/zoneBeacon/zoneBeacon.data.json +0 -16
- package/__tests__/geofeature/zoneBeacon/zoneBeacon.rules.json +0 -13
- package/__tests__/geofeature/zoneBeacon/zoneBeacon.spec.js +0 -62
- package/__tests__/monthlyStats/monthlyStats.data.json +0 -29
- package/__tests__/monthlyStats/monthlyStats.spec.js +0 -66
- package/__tests__/project/project.data.json +0 -18
- package/__tests__/project/project.rules.json +0 -9
- package/__tests__/project/project.spec.js +0 -81
- package/__tests__/ruleRequestAggregation/ruleRequestAggregation.data.json +0 -8
- package/__tests__/ruleRequestAggregation/ruleRequestAggregation.spec.js +0 -69
- package/__tests__/setup.js +0 -7
- package/__tests__/user/user.data.js +0 -19
- package/__tests__/user/user.rules.js +0 -8
- package/__tests__/user/user.spec.js +0 -130
- package/__tests__/utils/utils.spec.js +0 -24
- package/__tests__/zone/zone.action.spec.js +0 -50
- package/__tests__/zone/zone.condition.spec.js +0 -76
- package/__tests__/zone/zone.data.json +0 -157
- package/__tests__/zone/zone.geofeatures.spec.js +0 -75
- package/__tests__/zone/zone.spec.js +0 -134
- package/constants/errorMessages.js +0 -2
- package/helpers.js +0 -102
- package/models/Account.js +0 -50
- package/models/Project.js +0 -55
- package/models/UrlAction.js +0 -46
- package/models/User.js +0 -61
- package/models/Zone.js +0 -123
- package/models/conditions/DayRange.js +0 -52
- package/models/conditions/Speed.js +0 -42
- package/models/conditions/TimeActive.js +0 -50
- package/models/conditions/TravelDirection.js +0 -67
- package/models/conditions/TravelPath.js +0 -36
- package/models/geofeatures/BoundingBox.js +0 -44
- package/models/geofeatures/Circle.js +0 -39
- package/models/geofeatures/Geoline.js +0 -34
- package/models/geofeatures/Polygon.js +0 -45
- package/models/geofeatures/ZoneBeacon.js +0 -28
- package/schemas/MultiLineStringGeometry.js +0 -14
- package/schemas/Point.js +0 -13
- package/schemas/PointGeometry.js +0 -14
- package/schemas/PolygonGeometry.js +0 -14
- package/schemas/ProjectPermission.js +0 -21
- package/schemas/Webhook.js +0 -22
- package/utils/index.js +0 -39
- package/validators/checkDistanceBetweenVertices.js +0 -21
- 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,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
|
-
})
|
package/__tests__/setup.js
DELETED
|
@@ -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
|
-
})
|