@bluedot-innovation/models 2.0.0-beta.1 → 2.0.0-beta.10
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/.nyc_output/d9020767349457a911ef2b431e357310.json +1 -0
- package/Models.js +27 -15
- package/__tests__/account/account.data.json +12 -0
- package/__tests__/account/account.rules.js +8 -0
- package/__tests__/account/account.spec.js +83 -0
- package/__tests__/action/message/messageAction.spec.js +1 -1
- package/__tests__/action/url/urlAction.spec.js +13 -1
- package/__tests__/dailyStats/checkDailyStats.js +22 -21
- package/__tests__/filter/bearing/bearingFilter.spec.js +1 -1
- package/__tests__/filter/calendarDateRange/calendarDateRangeFilter.spec.js +2 -2
- package/__tests__/filter/percentageCrossed/percentageCrossedFilter.spec.js +2 -2
- package/__tests__/filter/speed/speedFilter.spec.js +1 -1
- package/__tests__/filter/timeOfDayRange/timeOfDayRange.spec.js +1 -1
- package/__tests__/geofeature/beacon/beacon.spec.js +2 -2
- package/__tests__/geofeature/boundingBox/boundingBox.spec.js +3 -2
- package/__tests__/geofeature/circle/circle.spec.js +11 -2
- package/__tests__/geofeature/polygon/polygon.spec.js +11 -2
- package/__tests__/geofeature/polyline/polyline.spec.js +11 -2
- package/__tests__/monthlyStats/monthlyStats.spec.js +36 -8
- package/__tests__/project/project.data.json +14 -0
- package/__tests__/project/project.rules.json +9 -0
- package/__tests__/project/project.spec.js +81 -0
- package/__tests__/ruleRequestAggregation/ruleRequestAggregation.data.json +8 -0
- package/__tests__/ruleRequestAggregation/ruleRequestAggregation.spec.js +69 -0
- package/__tests__/user/user.data.js +13 -0
- package/__tests__/user/user.rules.js +8 -0
- package/__tests__/user/user.spec.js +83 -0
- package/__tests__/zone/zone.action.spec.js +1 -1
- package/__tests__/zone/zone.data.json +4 -2
- package/__tests__/zone/zone.filter.spec.js +1 -1
- package/__tests__/zone/zone.geofeatures.spec.js +1 -1
- package/__tests__/zone/zone.spec.js +10 -1
- package/helpers.js +14 -0
- package/models/Account.js +49 -0
- package/models/Beacon.js +1 -1
- package/models/BeaconFilter.js +1 -1
- package/models/BearingFilter.js +1 -1
- package/models/BoundingBox.js +2 -1
- package/models/CalendarDateRangeFilter.js +1 -1
- package/models/Circle.js +2 -1
- package/models/MessageAction.js +1 -1
- package/models/MonthlyStats.js +12 -7
- package/models/PercentageCrossedFilter.js +1 -1
- package/models/Polygon.js +2 -1
- package/models/Polyline.js +1 -1
- package/models/Project.js +54 -0
- package/models/RuleRequestAggregation.js +29 -10
- package/models/SpeedFilter.js +1 -1
- package/models/TimeOfDayRangeFilter.js +1 -1
- package/models/UrlAction.js +1 -1
- package/models/User.js +59 -0
- package/models/Zone.js +4 -4
- package/package.json +2 -2
- package/schemas/Webhook.js +22 -0
- package/yarn.lock +2796 -0
- package/.npmignore +0 -3
- package/.nyc_output/295801a153bad60b994d5c6b5a8016d9.json +0 -1
- package/.nyc_output/5fc62324d665599db6649363a937708e.json +0 -1
- package/.nyc_output/95eec4b77e4566b36a6300f0cf8bea0b.json +0 -1
- package/models/AdminUser.js +0 -11
- package/models/Application.js +0 -39
- package/models/Customer.js +0 -38
- package/package-lock.json +0 -3503
- /package/.nyc_output/{2963e30f6030a94b16dd86e7b5594ebe.json → b3865a46e2cec635045d586cfc79e5c6.json} +0 -0
|
@@ -2,7 +2,8 @@ let mongoose = require('mongoose')
|
|
|
2
2
|
|
|
3
3
|
mongoose.Promise = global.Promise
|
|
4
4
|
|
|
5
|
-
let PolygonModel = require('../../../
|
|
5
|
+
let PolygonModel = require('../../../Models').Polygon(mongoose)
|
|
6
|
+
let PolygonModelBuiltInMongoose = require('../../../Models').Polygon()
|
|
6
7
|
let testCase = require('mocha').describe
|
|
7
8
|
let assertions = require('mocha').it
|
|
8
9
|
let chai = require('chai')
|
|
@@ -28,6 +29,14 @@ testCase('Polygon', () => {
|
|
|
28
29
|
done()
|
|
29
30
|
})
|
|
30
31
|
})
|
|
32
|
+
assertions('should validate a valid polygon (built in mongoose)', (done) => {
|
|
33
|
+
let Polygon = new PolygonModelBuiltInMongoose(polygon)
|
|
34
|
+
Polygon.validate((err, res) => {
|
|
35
|
+
assert.notExists(res)
|
|
36
|
+
assert(err === null, 'err should equals null')
|
|
37
|
+
done()
|
|
38
|
+
})
|
|
39
|
+
})
|
|
31
40
|
})
|
|
32
41
|
|
|
33
42
|
testCase('Invalid Polygon', () => {
|
|
@@ -51,7 +60,7 @@ testCase('Polygon', () => {
|
|
|
51
60
|
assert.notExists(res)
|
|
52
61
|
assert.exists(err, 'err object should exist')
|
|
53
62
|
assert.isObject(err)
|
|
54
|
-
assert.nestedProperty(err, `errors.${i}`,
|
|
63
|
+
assert.nestedProperty(err, `errors.${i}`, `error should have a ${i} property`)
|
|
55
64
|
done()
|
|
56
65
|
})
|
|
57
66
|
})
|
|
@@ -2,7 +2,8 @@ let mongoose = require('mongoose')
|
|
|
2
2
|
|
|
3
3
|
mongoose.Promise = global.Promise
|
|
4
4
|
|
|
5
|
-
let PolylineModel = require('../../../
|
|
5
|
+
let PolylineModel = require('../../../Models').Polyline(mongoose)
|
|
6
|
+
let PolylineModelBuiltInMongoose = require('../../../Models').Polyline()
|
|
6
7
|
let testCase = require('mocha').describe
|
|
7
8
|
let assertions = require('mocha').it
|
|
8
9
|
let chai = require('chai')
|
|
@@ -28,6 +29,14 @@ testCase('Polyline', () => {
|
|
|
28
29
|
done()
|
|
29
30
|
})
|
|
30
31
|
})
|
|
32
|
+
assertions('should validate a valid polyline (built in mongoose)', (done) => {
|
|
33
|
+
let Polyline = new PolylineModelBuiltInMongoose(polyline)
|
|
34
|
+
Polyline.validate((err, res) => {
|
|
35
|
+
assert.notExists(res)
|
|
36
|
+
assert(err === null, 'err should equals null')
|
|
37
|
+
done()
|
|
38
|
+
})
|
|
39
|
+
})
|
|
31
40
|
})
|
|
32
41
|
|
|
33
42
|
testCase('Invalid Polyline', () => {
|
|
@@ -51,7 +60,7 @@ testCase('Polyline', () => {
|
|
|
51
60
|
assert.notExists(res)
|
|
52
61
|
assert.exists(err, 'err object should exist')
|
|
53
62
|
assert.isObject(err)
|
|
54
|
-
assert.nestedProperty(err, `errors.${i}`,
|
|
63
|
+
assert.nestedProperty(err, `errors.${i}`, `error should have a ${i} property`)
|
|
55
64
|
done()
|
|
56
65
|
})
|
|
57
66
|
})
|
|
@@ -2,7 +2,7 @@ let mongoose = require('mongoose')
|
|
|
2
2
|
|
|
3
3
|
mongoose.Promise = global.Promise
|
|
4
4
|
|
|
5
|
-
let MonthlyStatsModel = require('../../
|
|
5
|
+
let MonthlyStatsModel = require('../../Models').MonthlyStat(mongoose)
|
|
6
6
|
let testCase = require('mocha').describe
|
|
7
7
|
let assertions = require('mocha').it
|
|
8
8
|
let chai = require('chai')
|
|
@@ -17,9 +17,9 @@ beforeEach(() => {
|
|
|
17
17
|
monthlyStats = JSON.parse(JSON.stringify(require('./monthlyStats.data.json')))
|
|
18
18
|
})
|
|
19
19
|
|
|
20
|
-
testCase('
|
|
21
|
-
testCase('Valid
|
|
22
|
-
assertions('should validate a valid
|
|
20
|
+
testCase('MonthlyStat', () => {
|
|
21
|
+
testCase('Valid MonthlyStat document', () => {
|
|
22
|
+
assertions('should validate a valid MonthlyStat document ', (done) => {
|
|
23
23
|
let MonthlyStats = new MonthlyStatsModel(monthlyStats)
|
|
24
24
|
MonthlyStats.validate((err, res) => {
|
|
25
25
|
assert.notExists(res)
|
|
@@ -27,12 +27,40 @@ testCase('MonthlyStats', () => {
|
|
|
27
27
|
done()
|
|
28
28
|
})
|
|
29
29
|
})
|
|
30
|
-
assertions('should accept a
|
|
31
|
-
monthlyStats.customerId = '
|
|
30
|
+
assertions('should not accept a invalid customerId', (done) => {
|
|
31
|
+
monthlyStats.customerId = 'invalid-customerId'
|
|
32
32
|
let MonthlyStats = new MonthlyStatsModel(monthlyStats)
|
|
33
33
|
MonthlyStats.validate((err, res) => {
|
|
34
|
-
assert.
|
|
35
|
-
assert(err
|
|
34
|
+
assert.exists(err, 'invalid customerId')
|
|
35
|
+
assert.isObject(err)
|
|
36
|
+
done()
|
|
37
|
+
})
|
|
38
|
+
})
|
|
39
|
+
assertions('should not accept a invalid applicationId', (done) => {
|
|
40
|
+
const invalidAppId = {
|
|
41
|
+
applicationId: 'invalid-applicationId',
|
|
42
|
+
monthlyUsers: 0
|
|
43
|
+
}
|
|
44
|
+
monthlyStats.applications.push(invalidAppId)
|
|
45
|
+
let MonthlyStats = new MonthlyStatsModel(monthlyStats)
|
|
46
|
+
MonthlyStats.validate((err, res) => {
|
|
47
|
+
console.log(err)
|
|
48
|
+
assert.exists(err, 'invalid customerId')
|
|
49
|
+
assert.isObject(err)
|
|
50
|
+
done()
|
|
51
|
+
})
|
|
52
|
+
})
|
|
53
|
+
assertions('should not accept a negative monthlyUsers value', (done) => {
|
|
54
|
+
const invalidAppId = {
|
|
55
|
+
applicationId: 'd49fdf10-3744-462c-84f8-abad444d7044',
|
|
56
|
+
monthlyUsers: -100
|
|
57
|
+
}
|
|
58
|
+
monthlyStats.applications.push(invalidAppId)
|
|
59
|
+
let MonthlyStats = new MonthlyStatsModel(monthlyStats)
|
|
60
|
+
MonthlyStats.validate((err, res) => {
|
|
61
|
+
console.log(err)
|
|
62
|
+
assert.exists(err, 'Path `monthlyUsers` (-100) is less than minimum allowed value (0)')
|
|
63
|
+
assert.isObject(err)
|
|
36
64
|
done()
|
|
37
65
|
})
|
|
38
66
|
})
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
{
|
|
2
|
+
"state": "ACTIVE",
|
|
3
|
+
"nextRuleUpdateInterval": 3600,
|
|
4
|
+
"lastUpdateTime": "2018-02-14T04:12:02.103Z",
|
|
5
|
+
"creationTime": "2018-02-14T04:12:02.103Z",
|
|
6
|
+
"name": "A New Project",
|
|
7
|
+
"accountId":"b0824b76-ce73-4fcf-81f8-1b63edb1114e",
|
|
8
|
+
"webhooks": {
|
|
9
|
+
"type": "trigger",
|
|
10
|
+
"url": "https://webhooklistener.bluedotinnovation.com",
|
|
11
|
+
"enabled": true
|
|
12
|
+
},
|
|
13
|
+
"firebaseApiKey": "88888888-4444-4444-4444-121212121212"
|
|
14
|
+
}
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
{
|
|
2
|
+
"requiredFields": ["name", "nextRuleUpdateInterval", "lastUpdateTime", "creationTime", "accountId"],
|
|
3
|
+
"customValidators": [
|
|
4
|
+
{"name": "nextRuleUpdateInterval", "invalidInput": [5000.5556]},
|
|
5
|
+
{"name": "lastUpdateTime", "invalidInput": ["21/07/2017", "saturday"]},
|
|
6
|
+
{"name": "creationTime", "invalidInput": ["21/07/2017", "thursday"]},
|
|
7
|
+
{"name": "accountId", "invalidInput": ["21/07/2017", 21072017, "qwe123-21321-ad"]}
|
|
8
|
+
]
|
|
9
|
+
}
|
|
@@ -0,0 +1,81 @@
|
|
|
1
|
+
let mongoose = require('mongoose')
|
|
2
|
+
|
|
3
|
+
mongoose.Promise = global.Promise
|
|
4
|
+
|
|
5
|
+
let ProjectModel = require('../../Models').Project(mongoose)
|
|
6
|
+
let ProjectModelBuiltInMongoose = require('../../Models').Project()
|
|
7
|
+
let testCase = require('mocha').describe
|
|
8
|
+
let assertions = require('mocha').it
|
|
9
|
+
let chai = require('chai')
|
|
10
|
+
let assert = chai.assert
|
|
11
|
+
let mocha = require('mocha')
|
|
12
|
+
let beforeEach = mocha.beforeEach
|
|
13
|
+
let rules = require('./project.rules.json')
|
|
14
|
+
|
|
15
|
+
let project
|
|
16
|
+
|
|
17
|
+
beforeEach(() => {
|
|
18
|
+
project = JSON.parse(JSON.stringify(require('./project.data.json')))
|
|
19
|
+
})
|
|
20
|
+
|
|
21
|
+
testCase('Project', () => {
|
|
22
|
+
testCase('Valid Project ', () => {
|
|
23
|
+
assertions('should validate a valid project ', (done) => {
|
|
24
|
+
let Project = new ProjectModel(project)
|
|
25
|
+
Project.validate((err, res) => {
|
|
26
|
+
assert.notExists(res)
|
|
27
|
+
assert(err === null, 'err equals null')
|
|
28
|
+
done()
|
|
29
|
+
})
|
|
30
|
+
})
|
|
31
|
+
})
|
|
32
|
+
testCase('Valid Project ', () => {
|
|
33
|
+
assertions('should validate a valid project ', (done) => {
|
|
34
|
+
let Project = new ProjectModelBuiltInMongoose(project)
|
|
35
|
+
Project.validate((err, res) => {
|
|
36
|
+
assert.notExists(res)
|
|
37
|
+
assert(err === null, 'err equals null')
|
|
38
|
+
done()
|
|
39
|
+
})
|
|
40
|
+
})
|
|
41
|
+
})
|
|
42
|
+
testCase('Invalid Zone ', () => {
|
|
43
|
+
testCase('recursive property check', () => {
|
|
44
|
+
let requiredFields = rules.requiredFields
|
|
45
|
+
requiredFields.map((i) => {
|
|
46
|
+
assertions(`should throw an error with property '${i}' if '${i}' is not present`, (done) => {
|
|
47
|
+
project = JSON.parse(JSON.stringify(project))
|
|
48
|
+
delete project[i]
|
|
49
|
+
let Project = new ProjectModel(project)
|
|
50
|
+
Project.validate((err, res) => {
|
|
51
|
+
assert.notExists(res)
|
|
52
|
+
assert.exists(err, 'err object should exist')
|
|
53
|
+
assert.isObject(err)
|
|
54
|
+
assert.nestedProperty(err, `errors.${i}`, 'error should have a radius property')
|
|
55
|
+
done()
|
|
56
|
+
})
|
|
57
|
+
})
|
|
58
|
+
})
|
|
59
|
+
})
|
|
60
|
+
|
|
61
|
+
testCase('recursive invalid entry check', () => {
|
|
62
|
+
let invalidProps = rules.customValidators
|
|
63
|
+
invalidProps.map((i) => {
|
|
64
|
+
i.invalidInput.map((j) => {
|
|
65
|
+
assertions(`should throw an error with property '${i.name}' if '${i.name}' is invalid => ${i.name} = ${j}`, (done) => {
|
|
66
|
+
project = JSON.parse(JSON.stringify(project))
|
|
67
|
+
project[i.name] = j
|
|
68
|
+
let Project = new ProjectModel(project)
|
|
69
|
+
Project.validate((err, res) => {
|
|
70
|
+
assert.notExists(res)
|
|
71
|
+
assert.exists(err, 'err object should exist')
|
|
72
|
+
assert.isObject(err)
|
|
73
|
+
assert.nestedProperty(err, `errors.${i.name}`, `error should have a ${i} property`)
|
|
74
|
+
done()
|
|
75
|
+
})
|
|
76
|
+
})
|
|
77
|
+
})
|
|
78
|
+
})
|
|
79
|
+
})
|
|
80
|
+
})
|
|
81
|
+
})
|
|
@@ -0,0 +1,69 @@
|
|
|
1
|
+
let mongoose = require('mongoose')
|
|
2
|
+
|
|
3
|
+
mongoose.Promise = global.Promise
|
|
4
|
+
|
|
5
|
+
let RuleRequestAggregationModel = require('../../Models').RuleRequestAggregation(mongoose)
|
|
6
|
+
let testCase = require('mocha').describe
|
|
7
|
+
let assertions = require('mocha').it
|
|
8
|
+
let chai = require('chai')
|
|
9
|
+
|
|
10
|
+
let assert = chai.assert
|
|
11
|
+
let mocha = require('mocha')
|
|
12
|
+
let beforeEach = mocha.beforeEach
|
|
13
|
+
|
|
14
|
+
let ruleRequestAggregation
|
|
15
|
+
|
|
16
|
+
beforeEach(() => {
|
|
17
|
+
ruleRequestAggregation = JSON.parse(JSON.stringify(require('./ruleRequestAggregation.data.json')))
|
|
18
|
+
})
|
|
19
|
+
|
|
20
|
+
testCase('RuleRequestAggregation', () => {
|
|
21
|
+
testCase('Valid RuleRequestAggregation document', () => {
|
|
22
|
+
assertions('should validate a valid RuleRequestAggregation document ', (done) => {
|
|
23
|
+
let RuleRequestAggregation = new RuleRequestAggregationModel(ruleRequestAggregation)
|
|
24
|
+
RuleRequestAggregation.validate((err, res) => {
|
|
25
|
+
assert.notExists(res)
|
|
26
|
+
assert(err === null, 'err should equals null')
|
|
27
|
+
done()
|
|
28
|
+
})
|
|
29
|
+
})
|
|
30
|
+
assertions('should not accept a invalid customerId', (done) => {
|
|
31
|
+
ruleRequestAggregation.customerId = 'invalid-customerId'
|
|
32
|
+
let RuleRequestAggregation = new RuleRequestAggregationModel(ruleRequestAggregation)
|
|
33
|
+
RuleRequestAggregation.validate((err, res) => {
|
|
34
|
+
assert.exists(err, 'invalid customerId')
|
|
35
|
+
assert.isObject(err)
|
|
36
|
+
done()
|
|
37
|
+
})
|
|
38
|
+
})
|
|
39
|
+
assertions('should not accept a invalid appplicationId', (done) => {
|
|
40
|
+
ruleRequestAggregation.appplicationId = 'invalid-applicationId'
|
|
41
|
+
let RuleRequestAggregation = new RuleRequestAggregationModel(ruleRequestAggregation)
|
|
42
|
+
RuleRequestAggregation.validate((err, res) => {
|
|
43
|
+
assert.exists(err, 'invalid aplicationId')
|
|
44
|
+
assert.isObject(err)
|
|
45
|
+
done()
|
|
46
|
+
})
|
|
47
|
+
})
|
|
48
|
+
assertions('should not accept a negative iosCount value', (done) => {
|
|
49
|
+
const negativeIosCount = -100
|
|
50
|
+
ruleRequestAggregation.iosCount = negativeIosCount
|
|
51
|
+
let RuleRequestAggregation = new RuleRequestAggregationModel(ruleRequestAggregation)
|
|
52
|
+
RuleRequestAggregation.validate((err, res) => {
|
|
53
|
+
assert.exists(err, 'Path `androidCount` (' + negativeIosCount + ') is less than minimum allowed value (0)')
|
|
54
|
+
assert.isObject(err)
|
|
55
|
+
done()
|
|
56
|
+
})
|
|
57
|
+
})
|
|
58
|
+
assertions('should not accept a negative androidCount value', (done) => {
|
|
59
|
+
const negativeAndroidCount = -100
|
|
60
|
+
ruleRequestAggregation.androidCount = negativeAndroidCount
|
|
61
|
+
let RuleRequestAggregation = new RuleRequestAggregationModel(ruleRequestAggregation)
|
|
62
|
+
RuleRequestAggregation.validate((err, res) => {
|
|
63
|
+
assert.exists(err, 'Path `androidCount` (' + negativeAndroidCount + ') is less than minimum allowed value (0)')
|
|
64
|
+
assert.isObject(err)
|
|
65
|
+
done()
|
|
66
|
+
})
|
|
67
|
+
})
|
|
68
|
+
})
|
|
69
|
+
})
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
module.exports = {
|
|
2
|
+
username: 'test@bluedot.io',
|
|
3
|
+
emailAddress: '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
|
+
}
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
module.exports = {
|
|
2
|
+
requiredFields: ['username', 'password', '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
|
+
}
|
|
@@ -0,0 +1,83 @@
|
|
|
1
|
+
let mongoose = require('mongoose')
|
|
2
|
+
|
|
3
|
+
let UserModel = require('../../Models').User(mongoose)
|
|
4
|
+
let UserModelBuiltInMongoose = require('../../Models').User()
|
|
5
|
+
let testCase = require('mocha').describe
|
|
6
|
+
let assertions = 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
|
+
testCase('User', () => {
|
|
20
|
+
testCase('Valid User ', () => {
|
|
21
|
+
assertions('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
|
+
done()
|
|
28
|
+
})
|
|
29
|
+
})
|
|
30
|
+
|
|
31
|
+
assertions('should validate a valid user', (done) => {
|
|
32
|
+
let User = new UserModelBuiltInMongoose(user)
|
|
33
|
+
|
|
34
|
+
User.validate((err, res) => {
|
|
35
|
+
assert.notExists(res)
|
|
36
|
+
assert(err === null, 'err equals null')
|
|
37
|
+
done()
|
|
38
|
+
})
|
|
39
|
+
})
|
|
40
|
+
})
|
|
41
|
+
|
|
42
|
+
testCase('Invalid User', () => {
|
|
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
|
+
user = JSON.parse(JSON.stringify(user))
|
|
48
|
+
delete user[requiredField]
|
|
49
|
+
let User = new UserModel(user)
|
|
50
|
+
User.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
|
+
user = JSON.parse(JSON.stringify(user))
|
|
69
|
+
user[customValidator.name] = invalidInput
|
|
70
|
+
let User = new UserModel(user)
|
|
71
|
+
|
|
72
|
+
User.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
|
+
})
|
|
@@ -2,7 +2,7 @@ let mongoose = require('mongoose')
|
|
|
2
2
|
|
|
3
3
|
mongoose.Promise = global.Promise
|
|
4
4
|
|
|
5
|
-
let ZoneModel = require('../../
|
|
5
|
+
let ZoneModel = require('../../Models').Zone(mongoose)
|
|
6
6
|
let testCase = require('mocha').describe
|
|
7
7
|
let assertions = require('mocha').it
|
|
8
8
|
let chai = require('chai')
|
|
@@ -2,7 +2,9 @@
|
|
|
2
2
|
"name": "TDD zone",
|
|
3
3
|
"minimumRetriggerTime": "60",
|
|
4
4
|
"checkout": true,
|
|
5
|
-
"
|
|
5
|
+
"lastUpdateTime": "2018-02-14T04:12:02.103Z",
|
|
6
|
+
"creationTime": "2018-02-14T04:12:02.103Z",
|
|
7
|
+
"projectId": "c7058934-f1e6-4176-8730-a0bd28e8e0a9",
|
|
6
8
|
"customData": [
|
|
7
9
|
{
|
|
8
10
|
"name1": "A Custom action1"
|
|
@@ -151,4 +153,4 @@
|
|
|
151
153
|
}
|
|
152
154
|
]
|
|
153
155
|
}]
|
|
154
|
-
}
|
|
156
|
+
}
|
|
@@ -2,7 +2,7 @@ let mongoose = require('mongoose')
|
|
|
2
2
|
|
|
3
3
|
mongoose.Promise = global.Promise
|
|
4
4
|
|
|
5
|
-
let ZoneModel = require('../../models/Zone').
|
|
5
|
+
let ZoneModel = require('../../models/Zone').Model(mongoose)
|
|
6
6
|
let testCase = require('mocha').describe
|
|
7
7
|
let assertions = require('mocha').it
|
|
8
8
|
let chai = require('chai')
|
|
@@ -2,7 +2,7 @@ let mongoose = require('mongoose')
|
|
|
2
2
|
|
|
3
3
|
mongoose.Promise = global.Promise
|
|
4
4
|
|
|
5
|
-
let ZoneModel = require('../../
|
|
5
|
+
let ZoneModel = require('../../Models').Zone(mongoose)
|
|
6
6
|
let testCase = require('mocha').describe
|
|
7
7
|
let assertions = require('mocha').it
|
|
8
8
|
let chai = require('chai')
|
|
@@ -2,7 +2,8 @@ let mongoose = require('mongoose')
|
|
|
2
2
|
|
|
3
3
|
mongoose.Promise = global.Promise
|
|
4
4
|
|
|
5
|
-
let ZoneModel = require('../../
|
|
5
|
+
let ZoneModel = require('../../Models').Zone(mongoose)
|
|
6
|
+
let ZoneModelBuiltInMongoose = require('../../Models').Zone()
|
|
6
7
|
let testCase = require('mocha').describe
|
|
7
8
|
let assertions = require('mocha').it
|
|
8
9
|
let chai = require('chai')
|
|
@@ -26,6 +27,14 @@ testCase('Zone', () => {
|
|
|
26
27
|
done()
|
|
27
28
|
})
|
|
28
29
|
})
|
|
30
|
+
assertions('should validate a valid zone ', (done) => {
|
|
31
|
+
let Zone = new ZoneModelBuiltInMongoose(zone)
|
|
32
|
+
Zone.validate((err, res) => {
|
|
33
|
+
assert.notExists(res)
|
|
34
|
+
assert(err === null, 'err equals null')
|
|
35
|
+
done()
|
|
36
|
+
})
|
|
37
|
+
})
|
|
29
38
|
assertions('should instantiate a circle', (done) => {
|
|
30
39
|
zone.geofeatures = zone.geofeatures.filter(gf => gf.type.match(/^circle$/))
|
|
31
40
|
let Zone = new ZoneModel(zone)
|
package/helpers.js
ADDED
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
let helpers = {}
|
|
2
|
+
|
|
3
|
+
helpers.validateUUIDv4 = function (id) {
|
|
4
|
+
const expression = '^[0-9A-F]{8}-[0-9A-F]{4}-4[0-9A-F]{3}-[89AB][0-9A-F]{3}-[0-9A-F]{12}$'
|
|
5
|
+
const regex = new RegExp(expression, 'i')
|
|
6
|
+
return regex.test(id)
|
|
7
|
+
}
|
|
8
|
+
|
|
9
|
+
helpers.validateEmail = function (value) {
|
|
10
|
+
const regex = /^(([^<>()\[\]\\.,;:\s@"]+(\.[^<>()\[\]\\.,;:\s@"]+)*)|(".+"))@((\[[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\])|(([a-zA-Z\-0-9]+\.)+[a-zA-Z]{2,}))$/
|
|
11
|
+
return regex.test(value);
|
|
12
|
+
}
|
|
13
|
+
|
|
14
|
+
module.exports = helpers
|
|
@@ -0,0 +1,49 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Created by Richard Tan on 27/02/18.
|
|
3
|
+
* Copyright : Bluedot Innovation.
|
|
4
|
+
*/
|
|
5
|
+
|
|
6
|
+
let mongoose = require('mongoose')
|
|
7
|
+
// let Schema = mongoose.Schema
|
|
8
|
+
let StateEnum = require('@bluedot-innovation/enums').StateEnum
|
|
9
|
+
let uuidv4 = require('uuid/v4')
|
|
10
|
+
let patcher = require('mongoose-json-patch')
|
|
11
|
+
const helpers = require('../helpers')
|
|
12
|
+
|
|
13
|
+
let AccountSchema = new mongoose.Schema({
|
|
14
|
+
_id: {type: String, default: uuidv4},
|
|
15
|
+
name: {type: String, required: true},
|
|
16
|
+
createdBy: {
|
|
17
|
+
// type: Schema.Types.ObjectId,
|
|
18
|
+
type: String,
|
|
19
|
+
validator: helpers.validateUUIDv4,
|
|
20
|
+
required: true,
|
|
21
|
+
// Adding a default to allow the lambdas to pass until we know who
|
|
22
|
+
// the createdBy will be.
|
|
23
|
+
default: uuidv4
|
|
24
|
+
},
|
|
25
|
+
state: {type: String, default: StateEnum.active},
|
|
26
|
+
poiCredits: Number,
|
|
27
|
+
integrations: Object,
|
|
28
|
+
features: Object,
|
|
29
|
+
creationTime: {type: Date, required: [true, 'creationTime is required'], select: false},
|
|
30
|
+
lastUpdateTime: {type: Date, required: [true, 'lastUpdateTime is required'], select: false}
|
|
31
|
+
},
|
|
32
|
+
{collection: 'account'})
|
|
33
|
+
|
|
34
|
+
AccountSchema.plugin(patcher)
|
|
35
|
+
|
|
36
|
+
// optional mongoose
|
|
37
|
+
let model = (mongooseInstance) => {
|
|
38
|
+
let Account
|
|
39
|
+
if (mongooseInstance) {
|
|
40
|
+
Account = mongooseInstance.model('Account', AccountSchema)
|
|
41
|
+
} else {
|
|
42
|
+
Account = mongoose.model('Account', AccountSchema)
|
|
43
|
+
}
|
|
44
|
+
|
|
45
|
+
return Account
|
|
46
|
+
}
|
|
47
|
+
|
|
48
|
+
// Exports Mongoose Model, Mongoose Schema, JSON schema (required locally for discriminators)
|
|
49
|
+
module.exports = { Model: model, Schema: AccountSchema }
|
package/models/Beacon.js
CHANGED
|
@@ -104,4 +104,4 @@ let model = (mongooseInstance) => {
|
|
|
104
104
|
return Beacon
|
|
105
105
|
}
|
|
106
106
|
// Exports Mongoose Model, Mongoose Schema, JSON schema (required locally for discriminators)
|
|
107
|
-
module.exports = {
|
|
107
|
+
module.exports = { Model: model, Schema: BeaconSchema, beaconSchema: schema }
|
package/models/BeaconFilter.js
CHANGED
|
@@ -36,4 +36,4 @@ let model = (mongooseInstance) => {
|
|
|
36
36
|
return BeaconFilter
|
|
37
37
|
}
|
|
38
38
|
// Exports Mongoose Model, Mongoose Schema, JSON schema (required locally for discriminators)
|
|
39
|
-
module.exports = {
|
|
39
|
+
module.exports = { Model: model, Schema: BeaconFilterSchema, beaconFilterSchema: schema }
|
package/models/BearingFilter.js
CHANGED
|
@@ -56,4 +56,4 @@ let model = (mongooseInstance) => {
|
|
|
56
56
|
return BearingFilter
|
|
57
57
|
}
|
|
58
58
|
// Exports Mongoose Model, Mongoose Schema, JSON schema (required locally for discriminators)
|
|
59
|
-
module.exports = {
|
|
59
|
+
module.exports = { Model: model, Schema: BearingFilterSchema, bearingFilterSchema: schema }
|
package/models/BoundingBox.js
CHANGED
|
@@ -6,6 +6,7 @@ let Point = require('../schemas/Point')
|
|
|
6
6
|
const schema = {
|
|
7
7
|
guid: {type: String, default: uuidv4},
|
|
8
8
|
name: {type: String, required: [true, 'name is required. ']},
|
|
9
|
+
color: String,
|
|
9
10
|
northEast: {type: Point, required: [true, 'northEast is required. ']},
|
|
10
11
|
southWest: {type: Point, required: [true, 'southWest is required. ']},
|
|
11
12
|
creationTime: {type: Date, default: Date.now},
|
|
@@ -37,4 +38,4 @@ let model = (mongooseInstance) => {
|
|
|
37
38
|
return BoundingBox
|
|
38
39
|
}
|
|
39
40
|
// Exports Mongoose Model, Mongoose Schema, JSON schema (required locally for discriminators)
|
|
40
|
-
module.exports = {
|
|
41
|
+
module.exports = { Model: model, Schema: BoundingBoxSchema, boundingBoxSchema: schema }
|
|
@@ -39,4 +39,4 @@ let model = (mongooseInstance) => {
|
|
|
39
39
|
return CalendarDateRangeFilter
|
|
40
40
|
}
|
|
41
41
|
// Exports Mongoose Model, Mongoose Schema, JSON schema (required locally for discriminators)
|
|
42
|
-
module.exports = {
|
|
42
|
+
module.exports = { Model: model, Schema: CalendarDateRangeFilterSchema, calendarDateRangeFilterSchema: schema }
|
package/models/Circle.js
CHANGED
|
@@ -6,6 +6,7 @@ let uuidv4 = require('uuid/v4')
|
|
|
6
6
|
let schema = {
|
|
7
7
|
guid: {type: String, default: uuidv4},
|
|
8
8
|
name: {type: String, required: [true, 'name is required. ']},
|
|
9
|
+
color: String,
|
|
9
10
|
radius: {type: Number, required: [true, 'radius is required. '], min: 5},
|
|
10
11
|
center: {type: Point, required: [true, 'center is required. ']},
|
|
11
12
|
creationTime: {type: Date, default: Date.now},
|
|
@@ -37,4 +38,4 @@ let model = (mongooseInstance) => {
|
|
|
37
38
|
return Circle
|
|
38
39
|
}
|
|
39
40
|
// Exports Mongoose Model, Mongoose Schema, JSON schema (required locally for discriminators)
|
|
40
|
-
module.exports = {
|
|
41
|
+
module.exports = { Model: model, Schema: CircleSchema, circleSchema: schema }
|
package/models/MessageAction.js
CHANGED
|
@@ -34,4 +34,4 @@ let model = (mongooseInstance) => {
|
|
|
34
34
|
return MessageAction
|
|
35
35
|
}
|
|
36
36
|
// Exports Mongoose Model, Mongoose Schema, JSON schema (required locally for discriminators)
|
|
37
|
-
module.exports = {
|
|
37
|
+
module.exports = { Model: model, Schema: MessageActionSchema, messageActionSchema: schema }
|