@bluedot-innovation/models 9.1.0 → 10.0.0-beta
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/CHANGELOG.md +6 -0
- package/__tests__/account/account.spec.js +32 -47
- package/__tests__/condition/dayRange/dayRange.spec.js +26 -29
- package/__tests__/condition/percentageCrossed/travelPath.spec.js +16 -21
- package/__tests__/condition/speed/speed.spec.js +26 -29
- package/__tests__/condition/timeActive/timeActive.spec.js +27 -30
- package/__tests__/condition/travelDirection/travelDirection.spec.js +31 -33
- package/__tests__/cumulativeRulesRequests/checkDailyStats.js +10 -13
- package/__tests__/dailyStats/dailyStats.spec.js +29 -30
- package/__tests__/destination/destination.spec.js +114 -138
- package/__tests__/geofeature/boundingBox/boundingBox.spec.js +27 -33
- package/__tests__/geofeature/circle/circle.spec.js +23 -28
- package/__tests__/geofeature/geoline/geoline.spec.js +17 -22
- package/__tests__/geofeature/polygon/polygon.spec.js +38 -41
- package/__tests__/helpers.js +10 -8
- package/__tests__/monthlyStats/monthlyStats.spec.js +23 -26
- package/__tests__/project/project.data.json +0 -3
- package/__tests__/project/project.spec.js +447 -435
- package/__tests__/user/user.spec.js +53 -65
- package/__tests__/zone/zone.condition.spec.js +22 -24
- package/__tests__/zone/zone.geofeatures.spec.js +32 -30
- package/__tests__/zone/zone.spec.js +174 -166
- package/package.json +2 -2
- package/schemas/Integration.js +1 -3
- package/utils/DbInitialiser/indexInitialiser.js +1 -1
- package/utils/validators.js +0 -1
- package/schemas/UberEatsIntegration.js +0 -9
|
@@ -20,51 +20,36 @@ beforeEach(() => {
|
|
|
20
20
|
|
|
21
21
|
describe('User', () => {
|
|
22
22
|
describe('Valid User ', () => {
|
|
23
|
-
it('should validate a valid user when initializing the model with an external mongoose instance', (
|
|
23
|
+
it('should validate a valid user when initializing the model with an external mongoose instance', async () => {
|
|
24
24
|
let User = new UserModel(user)
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
assert.notExists(res)
|
|
28
|
-
assert(err === null, 'err equals null')
|
|
29
|
-
|
|
30
|
-
done()
|
|
31
|
-
})
|
|
25
|
+
const res = await User.validate()
|
|
26
|
+
assert.notExists(res)
|
|
32
27
|
})
|
|
33
28
|
|
|
34
|
-
it('should validate a valid user', (
|
|
29
|
+
it('should validate a valid user', async () => {
|
|
35
30
|
let User = new UserModelBuiltInMongoose(user)
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
assert.notExists(res)
|
|
39
|
-
assert(err === null, 'err equals null')
|
|
40
|
-
done()
|
|
41
|
-
})
|
|
31
|
+
const res = await User.validate()
|
|
32
|
+
assert.notExists(res)
|
|
42
33
|
})
|
|
43
34
|
|
|
44
|
-
it('should set mfaRequired to false if not present', (
|
|
35
|
+
it('should set mfaRequired to false if not present', async () => {
|
|
45
36
|
user = JSON.parse(JSON.stringify(user))
|
|
46
37
|
delete user.mfaRequired
|
|
47
38
|
|
|
48
39
|
const User = new UserModel(user)
|
|
49
40
|
assert(User.mfaRequired === false)
|
|
50
|
-
User.validate(
|
|
51
|
-
|
|
52
|
-
assert(err === null, 'err equals null')
|
|
53
|
-
done()
|
|
54
|
-
})
|
|
41
|
+
const res = await User.validate()
|
|
42
|
+
assert.notExists(res)
|
|
55
43
|
})
|
|
56
44
|
|
|
57
|
-
it('should set identityProvider to internal if not present', (
|
|
45
|
+
it('should set identityProvider to internal if not present', async () => {
|
|
58
46
|
user = JSON.parse(JSON.stringify(user))
|
|
59
47
|
delete user.identityProvider
|
|
60
48
|
|
|
61
49
|
const User = new UserModel(user)
|
|
62
50
|
assert(User.identityProvider === "internal")
|
|
63
|
-
User.validate(
|
|
64
|
-
|
|
65
|
-
assert(err === null, 'err equals null')
|
|
66
|
-
done()
|
|
67
|
-
})
|
|
51
|
+
const res = await User.validate()
|
|
52
|
+
assert.notExists(res)
|
|
68
53
|
})
|
|
69
54
|
})
|
|
70
55
|
|
|
@@ -72,32 +57,32 @@ describe('User', () => {
|
|
|
72
57
|
describe('recursive property check', () => {
|
|
73
58
|
let requiredFields = rules.requiredFields
|
|
74
59
|
requiredFields.forEach((requiredField) => {
|
|
75
|
-
it(`should throw an error with property '${requiredField}' if '${requiredField}' is not present`, (
|
|
60
|
+
it(`should throw an error with property '${requiredField}' if '${requiredField}' is not present`, async () => {
|
|
76
61
|
user = JSON.parse(JSON.stringify(user))
|
|
77
62
|
delete user[requiredField]
|
|
78
63
|
let User = new UserModel(user)
|
|
79
|
-
|
|
80
|
-
|
|
64
|
+
try {
|
|
65
|
+
await User.validate()
|
|
66
|
+
} catch (err) {
|
|
81
67
|
assert.exists(err, 'err object should exist')
|
|
82
68
|
assert.isObject(err.errors)
|
|
83
69
|
assert.nestedProperty(err, `errors.${requiredField}`, `error should have a ${requiredField} property`)
|
|
84
|
-
|
|
85
|
-
})
|
|
70
|
+
}
|
|
86
71
|
})
|
|
87
72
|
})
|
|
88
73
|
})
|
|
89
74
|
|
|
90
|
-
it('should not allow mfaRequired to be set to null', (
|
|
75
|
+
it('should not allow mfaRequired to be set to null', async () => {
|
|
91
76
|
user = JSON.parse(JSON.stringify(user))
|
|
92
77
|
user.mfaRequired = null
|
|
93
78
|
const User = new UserModel(user)
|
|
94
|
-
|
|
95
|
-
|
|
79
|
+
try {
|
|
80
|
+
await User.validate()
|
|
81
|
+
} catch (err) {
|
|
96
82
|
assert.exists(err, 'err object should exist')
|
|
97
83
|
assert.isObject(err.errors)
|
|
98
84
|
assert.nestedProperty(err, `errors.mfaRequired`, `error should have a mfaRequired property`)
|
|
99
|
-
|
|
100
|
-
})
|
|
85
|
+
}
|
|
101
86
|
})
|
|
102
87
|
})
|
|
103
88
|
|
|
@@ -106,66 +91,69 @@ describe('User', () => {
|
|
|
106
91
|
|
|
107
92
|
customValidators.forEach((customValidator) => {
|
|
108
93
|
customValidator.invalidInputs.forEach((invalidInput) => {
|
|
109
|
-
it(`should throw an error with property '${customValidator.name}' if '${customValidator.name}' is invalid => ${customValidator.name} = ${invalidInput}`, (
|
|
94
|
+
it(`should throw an error with property '${customValidator.name}' if '${customValidator.name}' is invalid => ${customValidator.name} = ${invalidInput}`, async () => {
|
|
110
95
|
user = JSON.parse(JSON.stringify(user))
|
|
111
96
|
user[customValidator.name] = invalidInput
|
|
112
97
|
let User = new UserModel(user)
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
98
|
+
try {
|
|
99
|
+
await User.validate()
|
|
100
|
+
} catch (err) {
|
|
116
101
|
assert.exists(err, 'err object should exist')
|
|
117
102
|
assert.isObject(err.errors)
|
|
118
103
|
assert.nestedProperty(err, `errors.${customValidator.name}`, `error should have a ${customValidator.name} property`)
|
|
119
|
-
|
|
120
|
-
})
|
|
104
|
+
}
|
|
121
105
|
})
|
|
122
106
|
})
|
|
123
107
|
})
|
|
124
108
|
})
|
|
125
109
|
|
|
126
110
|
describe('projectPermissions:', () => {
|
|
127
|
-
it('should fail if projectId is invalid', (
|
|
111
|
+
it('should fail if projectId is invalid', async () => {
|
|
128
112
|
user = JSON.parse(JSON.stringify(user))
|
|
129
113
|
user.projectPermissions[0].projectId = '8b1b5cb5-3c7b-452a-b9a7-'
|
|
130
114
|
const User = new UserModel(user)
|
|
131
|
-
|
|
132
|
-
|
|
115
|
+
try {
|
|
116
|
+
await User.validate()
|
|
117
|
+
} catch (err) {
|
|
118
|
+
assert.exists(err, 'err object should exist')
|
|
133
119
|
assert.match(err, /(projectId not in UUID v4 format)/i)
|
|
134
|
-
|
|
135
|
-
})
|
|
120
|
+
}
|
|
136
121
|
})
|
|
137
122
|
|
|
138
|
-
it('should fail if projectId is missing', (
|
|
123
|
+
it('should fail if projectId is missing', async () => {
|
|
139
124
|
user = JSON.parse(JSON.stringify(user))
|
|
140
125
|
user.projectPermissions[0].projectId = undefined
|
|
141
126
|
const User = new UserModel(user)
|
|
142
|
-
|
|
143
|
-
|
|
127
|
+
try {
|
|
128
|
+
await User.validate()
|
|
129
|
+
} catch (err) {
|
|
130
|
+
assert.exists(err, 'err object should exist')
|
|
144
131
|
assert.match(err, /(Path `projectId` is required.)/i)
|
|
145
|
-
|
|
146
|
-
})
|
|
132
|
+
}
|
|
147
133
|
})
|
|
148
134
|
|
|
149
|
-
it('should fail if permissionLevel is invalid', (
|
|
135
|
+
it('should fail if permissionLevel is invalid', async () => {
|
|
150
136
|
user = JSON.parse(JSON.stringify(user))
|
|
151
137
|
user.projectPermissions[0].permissionLevel = 'INVALID'
|
|
152
138
|
const User = new UserModel(user)
|
|
153
|
-
|
|
154
|
-
|
|
139
|
+
try {
|
|
140
|
+
await User.validate()
|
|
141
|
+
} catch (err) {
|
|
142
|
+
assert.exists(err, 'err object should exist')
|
|
155
143
|
assert.match(err, /(not a valid enum value)/i)
|
|
156
|
-
|
|
157
|
-
})
|
|
144
|
+
}
|
|
158
145
|
})
|
|
159
146
|
|
|
160
|
-
it('should fail if permissionLevel is missing', (
|
|
147
|
+
it('should fail if permissionLevel is missing', async () => {
|
|
161
148
|
user = JSON.parse(JSON.stringify(user))
|
|
162
149
|
user.projectPermissions[0].permissionLevel = undefined
|
|
163
150
|
const User = new UserModel(user)
|
|
164
|
-
|
|
165
|
-
|
|
151
|
+
try {
|
|
152
|
+
await User.validate()
|
|
153
|
+
} catch (err) {
|
|
154
|
+
assert.exists(err, 'err object should exist')
|
|
166
155
|
assert.match(err, /(Path `permissionLevel` is required.)/i)
|
|
167
|
-
|
|
168
|
-
})
|
|
156
|
+
}
|
|
169
157
|
})
|
|
170
158
|
})
|
|
171
159
|
|
|
@@ -174,8 +162,8 @@ describe('User', () => {
|
|
|
174
162
|
|
|
175
163
|
arrayTypeFields.map(arrayField => {
|
|
176
164
|
FALSY_VALUES.map(falsyValue => {
|
|
177
|
-
it(`should trow an error when it contains ${falsyValue} on a ${arrayField}`, (
|
|
178
|
-
helpers.testFalsyValue(falsyValue, arrayField, user, UserModel
|
|
165
|
+
it(`should trow an error when it contains ${falsyValue} on a ${arrayField}`, async () => {
|
|
166
|
+
await helpers.testFalsyValue(falsyValue, arrayField, user, UserModel)
|
|
179
167
|
})
|
|
180
168
|
})
|
|
181
169
|
})
|
|
@@ -26,37 +26,32 @@ beforeEach(() => {
|
|
|
26
26
|
|
|
27
27
|
testCase('Zone - Condition', () => {
|
|
28
28
|
testCase('Valid Zone - Condition', () => {
|
|
29
|
-
assertions('should not throw an error when a valid condition is instantiated within a zone', (
|
|
29
|
+
assertions('should not throw an error when a valid condition is instantiated within a zone', async () => {
|
|
30
30
|
let Zone = new ZoneModel(zone)
|
|
31
|
-
Zone.validate(
|
|
32
|
-
|
|
33
|
-
assert(err === null, 'err equals null')
|
|
34
|
-
done()
|
|
35
|
-
})
|
|
31
|
+
const res = await Zone.validate()
|
|
32
|
+
assert.notExists(res)
|
|
36
33
|
})
|
|
37
34
|
})
|
|
38
35
|
|
|
39
36
|
testCase('Invalid Zone - Condition', () => {
|
|
40
|
-
assertions('should throw an error when an invalid condition is instantiated within a zone', (
|
|
37
|
+
assertions('should throw an error when an invalid condition is instantiated within a zone', async () => {
|
|
41
38
|
zone.conditions[0].startDate = 'abc'
|
|
42
39
|
let Zone = new ZoneModel(zone)
|
|
43
|
-
|
|
40
|
+
try {
|
|
41
|
+
await Zone.validate()
|
|
42
|
+
} catch (err) {
|
|
44
43
|
assert.exists(err, 'err object should exist')
|
|
45
44
|
assert.isObject(err.errors)
|
|
46
45
|
assert('conditions.0.startDate' in err.errors)
|
|
47
46
|
assert.notNestedProperty(err, `errors.geofeatures`, 'error should have a url property')
|
|
48
|
-
|
|
49
|
-
})
|
|
47
|
+
}
|
|
50
48
|
})
|
|
51
|
-
assertions('should not throw an error when a valid condition is instantiated within a zone', (
|
|
49
|
+
assertions('should not throw an error when a valid condition is instantiated within a zone', async () => {
|
|
52
50
|
let Zone = new ZoneModel(zone)
|
|
53
|
-
Zone.validate(
|
|
54
|
-
|
|
55
|
-
assert(err === null, 'err equals null')
|
|
56
|
-
done()
|
|
57
|
-
})
|
|
51
|
+
const res = await Zone.validate()
|
|
52
|
+
assert.notExists(res)
|
|
58
53
|
})
|
|
59
|
-
assertions('should throw an error when the minimumGeofeaturesCrossed for a travel path condition is greater than the total number of geofeatures', (
|
|
54
|
+
assertions('should throw an error when the minimumGeofeaturesCrossed for a travel path condition is greater than the total number of geofeatures', async () => {
|
|
60
55
|
zone.geofeatures = geofeatures
|
|
61
56
|
zone.conditions.push({
|
|
62
57
|
"type" : "travelPath",
|
|
@@ -65,14 +60,15 @@ testCase('Zone - Condition', () => {
|
|
|
65
60
|
"sequential" : false
|
|
66
61
|
})
|
|
67
62
|
let Zone = new ZoneModel(zone)
|
|
68
|
-
|
|
63
|
+
try {
|
|
64
|
+
await Zone.validate()
|
|
65
|
+
} catch (err) {
|
|
69
66
|
assert.exists(err, 'err object should exist')
|
|
70
67
|
assert(err instanceof Error)
|
|
71
68
|
assert(err.message.includes("Zone must not have minimumGeofeaturesCrossed higher than geofeatures count"))
|
|
72
|
-
|
|
73
|
-
})
|
|
69
|
+
}
|
|
74
70
|
})
|
|
75
|
-
assertions('should throw an error when more than 1 travelpath condition is specified', (
|
|
71
|
+
assertions('should throw an error when more than 1 travelpath condition is specified', async () => {
|
|
76
72
|
const travelPath = {
|
|
77
73
|
type: "travelPath",
|
|
78
74
|
minimumGeofeaturesCrossed: 2,
|
|
@@ -84,11 +80,13 @@ testCase('Zone - Condition', () => {
|
|
|
84
80
|
zone.conditions.push(travelPath)
|
|
85
81
|
|
|
86
82
|
let Zone = new ZoneModel(zone)
|
|
87
|
-
|
|
83
|
+
try {
|
|
84
|
+
await Zone.validate()
|
|
85
|
+
} catch (err) {
|
|
86
|
+
assert.exists(err, 'err object should exist')
|
|
88
87
|
assert(err instanceof Error, "It should throw an error when more htan 1 travelpath condition is specified")
|
|
89
88
|
assert(err.message.includes("Zone must not have more than 1 travel path condition"), "It should throw a descriptive error when more than 1 travel path condition is specified")
|
|
90
|
-
|
|
91
|
-
})
|
|
89
|
+
}
|
|
92
90
|
})
|
|
93
91
|
})
|
|
94
92
|
})
|
|
@@ -29,78 +29,80 @@ beforeEach(() => {
|
|
|
29
29
|
|
|
30
30
|
testCase('Zone - Action', () => {
|
|
31
31
|
testCase('Valid Zone - Action', () => {
|
|
32
|
-
assertions('should not throw an error when a valid geofeature is instantiated within a zone', (
|
|
32
|
+
assertions('should not throw an error when a valid geofeature is instantiated within a zone', async () => {
|
|
33
33
|
let Zone = new ZoneModel(zone)
|
|
34
|
-
Zone.validate(
|
|
35
|
-
assert.notExists(err)
|
|
36
|
-
done()
|
|
37
|
-
})
|
|
34
|
+
const res = await Zone.validate()
|
|
38
35
|
})
|
|
39
36
|
})
|
|
40
37
|
|
|
41
38
|
testCase('Invalid Zone - Action', () => {
|
|
42
|
-
assertions('should throw an error when an invalid geofeature is instantiated within a zone', (
|
|
39
|
+
assertions('should throw an error when an invalid geofeature is instantiated within a zone', async () => {
|
|
43
40
|
delete zone.geofeatures[0].name
|
|
44
41
|
let Zone = new ZoneModel(zone)
|
|
45
|
-
|
|
42
|
+
try {
|
|
43
|
+
await Zone.validate()
|
|
44
|
+
} catch (err) {
|
|
46
45
|
assert.exists(err, 'err object should exist')
|
|
47
46
|
assert.isObject(err.errors)
|
|
48
47
|
assert('geofeatures.0.name' in err.errors)
|
|
49
|
-
|
|
50
|
-
})
|
|
48
|
+
}
|
|
51
49
|
})
|
|
52
|
-
assertions('should throw an error when an invalid geofeature (complex validation) is instantiated within a zone', (
|
|
50
|
+
assertions('should throw an error when an invalid geofeature (complex validation) is instantiated within a zone', async () => {
|
|
53
51
|
delete zone.geofeatures[0].radius
|
|
54
52
|
let Zone = new ZoneModel(zone)
|
|
55
|
-
|
|
53
|
+
try {
|
|
54
|
+
await Zone.validate()
|
|
55
|
+
} catch (err) {
|
|
56
56
|
assert.exists(err, 'err object should exist')
|
|
57
57
|
assert.isObject(err.errors)
|
|
58
|
-
console.log(err.errors)
|
|
59
58
|
assert('geofeatures.0.radius' in err.errors)
|
|
60
|
-
|
|
61
|
-
})
|
|
59
|
+
}
|
|
62
60
|
})
|
|
63
|
-
assertions('should throw an error when no geofeature is instantiated within a zone', (
|
|
61
|
+
assertions('should throw an error when no geofeature is instantiated within a zone', async () => {
|
|
64
62
|
zone.geofeatures = []
|
|
65
63
|
let Zone = new ZoneModel(zone)
|
|
66
|
-
|
|
64
|
+
try {
|
|
65
|
+
await Zone.validate()
|
|
66
|
+
} catch (err) {
|
|
67
67
|
assert.exists(err, 'err object should exist')
|
|
68
68
|
assert.match(err.message, /(geofeatures)/i)
|
|
69
|
-
|
|
70
|
-
})
|
|
69
|
+
}
|
|
71
70
|
})
|
|
72
71
|
|
|
73
|
-
assertions('should throw an error when a geofeature is missing a type', (
|
|
72
|
+
assertions('should throw an error when a geofeature is missing a type', async () => {
|
|
74
73
|
delete zone.geofeatures[0].type
|
|
75
74
|
let Zone = new ZoneModel(zone)
|
|
76
|
-
|
|
75
|
+
try {
|
|
76
|
+
await Zone.validate()
|
|
77
|
+
} catch (err) {
|
|
77
78
|
assert.exists(err, 'err object should exist')
|
|
78
79
|
assert.isObject(err.errors)
|
|
79
80
|
assert.match(err.message, /(Geofeature requires a type of `circle`, `polygon`, `geoline` or `boundingBox`.)/i)
|
|
80
|
-
|
|
81
|
-
})
|
|
81
|
+
}
|
|
82
82
|
})
|
|
83
83
|
|
|
84
|
-
assertions('should throw an error when a geofeature type is invalid', (
|
|
84
|
+
assertions('should throw an error when a geofeature type is invalid', async () => {
|
|
85
85
|
zone.geofeatures[0].type = 'test'
|
|
86
86
|
let Zone = new ZoneModel(zone)
|
|
87
|
-
|
|
87
|
+
try {
|
|
88
|
+
await Zone.validate()
|
|
89
|
+
} catch (err) {
|
|
88
90
|
assert.exists(err, 'err object should exist')
|
|
89
91
|
assert.isObject(err.errors)
|
|
90
92
|
assert.match(err.message, /(Geofeature requires a type of `circle`, `polygon`, `geoline` or `boundingBox`.)/i)
|
|
91
|
-
|
|
92
|
-
})
|
|
93
|
+
}
|
|
93
94
|
})
|
|
94
95
|
|
|
95
|
-
assertions('should throw an error when a geofeature object is empty', (
|
|
96
|
+
assertions('should throw an error when a geofeature object is empty', async () => {
|
|
96
97
|
zone.geofeatures = [{}]
|
|
97
98
|
let Zone = new ZoneModel(zone)
|
|
98
|
-
|
|
99
|
+
try {
|
|
100
|
+
await Zone.validate()
|
|
101
|
+
} catch (err) {
|
|
99
102
|
assert.exists(err, 'err object should exist')
|
|
100
103
|
assert.isObject(err.errors)
|
|
101
104
|
assert.match(err.message, /(Geofeature requires a type of `circle`, `polygon`, `geoline` or `boundingBox`.)/i)
|
|
102
|
-
|
|
103
|
-
})
|
|
105
|
+
}
|
|
104
106
|
})
|
|
105
107
|
})
|
|
106
108
|
})
|