@bluedot-innovation/models 9.1.1 → 10.0.0-beta-1
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 +3 -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.spec.js +447 -423
- 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 +3 -3
- package/utils/DbInitialiser/indexInitialiser.js +1 -1
- package/utils/validators.js +0 -1
|
@@ -22,37 +22,29 @@ beforeEach(() => {
|
|
|
22
22
|
|
|
23
23
|
describe('Project', () => {
|
|
24
24
|
describe('Valid Project ', () => {
|
|
25
|
-
assertions('should validate a valid project ', (
|
|
25
|
+
assertions('should validate a valid project ', async () => {
|
|
26
26
|
let Project = new ProjectModel(project)
|
|
27
|
-
Project.validate(
|
|
28
|
-
|
|
29
|
-
assert.notExists(res)
|
|
30
|
-
assert(err === null, 'err equals null')
|
|
31
|
-
done()
|
|
32
|
-
})
|
|
27
|
+
const res = await Project.validate()
|
|
28
|
+
assert.notExists(res)
|
|
33
29
|
})
|
|
34
30
|
|
|
35
|
-
assertions('should validate a valid project with android config', (
|
|
31
|
+
assertions('should validate a valid project with android config', async () => {
|
|
36
32
|
let project = JSON.parse(JSON.stringify(require('./project.remote.config.json')))
|
|
37
33
|
let Project = new ProjectModel(project)
|
|
38
|
-
Project.validate(
|
|
39
|
-
|
|
40
|
-
done()
|
|
41
|
-
})
|
|
34
|
+
const res = await Project.validate()
|
|
35
|
+
assert.notExists(res)
|
|
42
36
|
})
|
|
43
37
|
|
|
44
|
-
assertions('should set the value of shouldSync to false when it is not defined', (
|
|
38
|
+
assertions('should set the value of shouldSync to false when it is not defined', async () => {
|
|
45
39
|
let project = JSON.parse(JSON.stringify(require('./project.remote.config.json')))
|
|
46
40
|
delete project.shouldSync
|
|
47
41
|
let Project = new ProjectModel(project)
|
|
48
42
|
assert.equal(Project.shouldSync, false, "shouldSync should be set to false")
|
|
49
|
-
Project.validate(
|
|
50
|
-
|
|
51
|
-
done()
|
|
52
|
-
})
|
|
43
|
+
const res = await Project.validate()
|
|
44
|
+
assert.notExists(res)
|
|
53
45
|
})
|
|
54
46
|
|
|
55
|
-
assertions('should parse new IosConfig native mode fields successfully', (
|
|
47
|
+
assertions('should parse new IosConfig native mode fields successfully', async () => {
|
|
56
48
|
let projectJson = JSON.parse(JSON.stringify(require('./project.remote.config.json')))
|
|
57
49
|
let project = new ProjectModel(projectJson)
|
|
58
50
|
let iosConfig = project.configurationParameters.iosConfig
|
|
@@ -60,13 +52,11 @@ describe('Project', () => {
|
|
|
60
52
|
assert.equal(iosConfig.nativeCheckoutDistanceAccuracy, 151)
|
|
61
53
|
assert.equal(iosConfig.nativeMinLocationUpdateInterval, 0.6)
|
|
62
54
|
assert.equal(iosConfig.nativeMaxMonitoringRegions, 19)
|
|
63
|
-
project.validate(
|
|
64
|
-
|
|
65
|
-
done()
|
|
66
|
-
})
|
|
55
|
+
const res = await project.validate()
|
|
56
|
+
assert.notExists(res)
|
|
67
57
|
})
|
|
68
58
|
|
|
69
|
-
assertions('should fallback to default values for new IosConfig native mode fields if not available', (
|
|
59
|
+
assertions('should fallback to default values for new IosConfig native mode fields if not available', async () => {
|
|
70
60
|
let projectJson = JSON.parse(JSON.stringify(require('./project.remote.config.json')))
|
|
71
61
|
// delete native mode json fields
|
|
72
62
|
delete projectJson.configurationParameters.iosConfig.nativeCheckinAccuracyThreshold
|
|
@@ -80,23 +70,18 @@ describe('Project', () => {
|
|
|
80
70
|
assert.equal(iosConfig.nativeCheckoutDistanceAccuracy, 150, "nativeCheckoutDistanceAccuracy should be set to default value 150")
|
|
81
71
|
assert.equal(iosConfig.nativeMinLocationUpdateInterval, 0.5, "nativeMinLocationUpdateInterval should be set to default value 0.5")
|
|
82
72
|
assert.equal(iosConfig.nativeMaxMonitoringRegions, 18, "nativeMaxMonitoringRegions should be set to default value 18")
|
|
83
|
-
project.validate(
|
|
84
|
-
|
|
85
|
-
done()
|
|
86
|
-
})
|
|
73
|
+
const res = await project.validate()
|
|
74
|
+
assert.notExists(res)
|
|
87
75
|
})
|
|
88
76
|
|
|
89
|
-
it('should validate a valid project with a webhook with empty header and body object', (
|
|
77
|
+
it('should validate a valid project with a webhook with empty header and body object', async () => {
|
|
90
78
|
project.webhooks = [{url: "https://mirror.com", type: "tempo", structure: "standard", body: {}, headers: {}}]
|
|
91
79
|
let Project = new ProjectModel(project)
|
|
92
|
-
Project.validate(
|
|
93
|
-
|
|
94
|
-
assert(err === null, 'err equals null')
|
|
95
|
-
done()
|
|
96
|
-
})
|
|
80
|
+
const res = await Project.validate()
|
|
81
|
+
assert.notExists(res)
|
|
97
82
|
})
|
|
98
83
|
|
|
99
|
-
it('should validate a valid project with a tealium webhook with required tealium body fields', (
|
|
84
|
+
it('should validate a valid project with a tealium webhook with required tealium body fields', async () => {
|
|
100
85
|
project.webhooks = [{
|
|
101
86
|
url: "https://mirror.com",
|
|
102
87
|
type: "tempo",
|
|
@@ -108,24 +93,18 @@ describe('Project', () => {
|
|
|
108
93
|
headers: {}
|
|
109
94
|
}]
|
|
110
95
|
let Project = new ProjectModel(project)
|
|
111
|
-
Project.validate(
|
|
112
|
-
|
|
113
|
-
assert(err === null, 'err equals null')
|
|
114
|
-
done()
|
|
115
|
-
})
|
|
96
|
+
const res = await Project.validate()
|
|
97
|
+
assert.notExists(res)
|
|
116
98
|
})
|
|
117
99
|
|
|
118
|
-
it('should validate a valid project without ssoLinkingCode', (
|
|
100
|
+
it('should validate a valid project without ssoLinkingCode', async () => {
|
|
119
101
|
delete project.hello.ssoLinkingCode
|
|
120
102
|
let Project = new ProjectModel(project)
|
|
121
|
-
Project.validate(
|
|
122
|
-
|
|
123
|
-
assert(err === null, 'err equals null')
|
|
124
|
-
done()
|
|
125
|
-
})
|
|
103
|
+
const res = await Project.validate()
|
|
104
|
+
assert.notExists(res)
|
|
126
105
|
})
|
|
127
106
|
|
|
128
|
-
it(`should set default structure is 2.0 when the type is trigger`, (
|
|
107
|
+
it(`should set default structure is 2.0 when the type is trigger`, async () => {
|
|
129
108
|
project.webhooks = [
|
|
130
109
|
{
|
|
131
110
|
"type": "trigger",
|
|
@@ -176,120 +155,123 @@ describe('Project', () => {
|
|
|
176
155
|
"retryEnabled": false
|
|
177
156
|
}
|
|
178
157
|
])
|
|
179
|
-
Project.validate(
|
|
180
|
-
|
|
181
|
-
done()
|
|
182
|
-
})
|
|
158
|
+
const res = await Project.validate()
|
|
159
|
+
assert.notExists(res)
|
|
183
160
|
})
|
|
184
161
|
})
|
|
185
162
|
testCase('Valid Project ', () => {
|
|
186
|
-
assertions('should validate a valid project ', (
|
|
163
|
+
assertions('should validate a valid project ', async () => {
|
|
187
164
|
let Project = new ProjectModelBuiltInMongoose(project)
|
|
188
|
-
Project.validate(
|
|
189
|
-
|
|
190
|
-
assert(err === null, 'err equals null')
|
|
191
|
-
done()
|
|
192
|
-
})
|
|
165
|
+
const res = await Project.validate()
|
|
166
|
+
assert.notExists(res)
|
|
193
167
|
})
|
|
194
168
|
})
|
|
195
169
|
describe('Invalid Project ', () => {
|
|
196
170
|
testCase('mparticle integration check', () => {
|
|
197
|
-
assertions('should throw an error if the mparticle integration has empty key ', (
|
|
171
|
+
assertions('should throw an error if the mparticle integration has empty key ', async () => {
|
|
198
172
|
|
|
199
173
|
project.integrations.mparticle.androidApiKey = null
|
|
200
174
|
|
|
201
175
|
let Project = new ProjectModel(project)
|
|
202
|
-
|
|
203
|
-
|
|
176
|
+
try {
|
|
177
|
+
await Project.validate()
|
|
178
|
+
} catch (err) {
|
|
179
|
+
assert.exists(err, 'err object should exist')
|
|
204
180
|
assert.match(err.message, /androidApiKey should be a non-empty string/)
|
|
205
|
-
|
|
206
|
-
})
|
|
181
|
+
}
|
|
207
182
|
})
|
|
208
|
-
assertions('should throw an error if the mparticle integration has a key with empty string ', (
|
|
183
|
+
assertions('should throw an error if the mparticle integration has a key with empty string ', async () => {
|
|
209
184
|
|
|
210
185
|
project.integrations.mparticle.iosApiKey = ''
|
|
211
186
|
let Project = new ProjectModel(project)
|
|
212
|
-
|
|
213
|
-
|
|
187
|
+
try {
|
|
188
|
+
await Project.validate()
|
|
189
|
+
} catch (err) {
|
|
190
|
+
assert.exists(err, 'err object should exist')
|
|
214
191
|
assert.match(err.message, /iosApiKey should be a non-empty string/)
|
|
215
|
-
|
|
216
|
-
})
|
|
192
|
+
}
|
|
217
193
|
})
|
|
218
194
|
|
|
219
|
-
assertions('should throw an error if the mparticle integration misses all keys ', (
|
|
195
|
+
assertions('should throw an error if the mparticle integration misses all keys ', async () => {
|
|
220
196
|
|
|
221
197
|
project.integrations.mparticle = {}
|
|
222
198
|
|
|
223
199
|
let Project = new ProjectModel(project)
|
|
224
|
-
|
|
225
|
-
|
|
200
|
+
try {
|
|
201
|
+
await Project.validate()
|
|
202
|
+
} catch (err) {
|
|
203
|
+
assert.exists(err, 'err object should exist')
|
|
226
204
|
assert.match(err.message, /At least one of Android, iOS or Web keys need to be provided/)
|
|
227
|
-
|
|
228
|
-
})
|
|
205
|
+
}
|
|
229
206
|
})
|
|
230
207
|
|
|
231
|
-
assertions('should throw an error if trigger is selected but no android or ios keys provided', (
|
|
208
|
+
assertions('should throw an error if trigger is selected but no android or ios keys provided', async () => {
|
|
232
209
|
project.integrations.mparticle.trigger = true
|
|
233
210
|
delete project.integrations.mparticle.androidApiKey
|
|
234
211
|
delete project.integrations.mparticle.iosApiKey
|
|
235
212
|
|
|
236
213
|
let Project = new ProjectModel(project)
|
|
237
|
-
|
|
238
|
-
|
|
214
|
+
try {
|
|
215
|
+
await Project.validate()
|
|
216
|
+
} catch (err) {
|
|
217
|
+
console.log(err)
|
|
218
|
+
assert.exists(err, 'err object should exist')
|
|
239
219
|
assert.match(err.message, /Either Android or iOS keys need to be provided/)
|
|
240
|
-
|
|
241
|
-
})
|
|
220
|
+
}
|
|
242
221
|
})
|
|
243
|
-
assertions('should throw an error if tempo is selected but no android or ios keys provided', (
|
|
222
|
+
assertions('should throw an error if tempo is selected but no android or ios keys provided', async () => {
|
|
244
223
|
project.integrations.mparticle.tempo = true
|
|
245
224
|
delete project.integrations.mparticle.androidApiKey
|
|
246
225
|
delete project.integrations.mparticle.iosApiKey
|
|
247
226
|
|
|
248
227
|
let Project = new ProjectModel(project)
|
|
249
|
-
|
|
250
|
-
|
|
228
|
+
try {
|
|
229
|
+
await Project.validate()
|
|
230
|
+
} catch (err) {
|
|
231
|
+
assert.exists(err, 'err object should exist')
|
|
251
232
|
assert.match(err.message, /Either Android or iOS keys need to be provided/)
|
|
252
|
-
|
|
253
|
-
})
|
|
233
|
+
}
|
|
254
234
|
})
|
|
255
235
|
|
|
256
|
-
assertions('should throw an error if wave is selected but no web keys provided', (
|
|
236
|
+
assertions('should throw an error if wave is selected but no web keys provided', async () => {
|
|
257
237
|
project.integrations.mparticle.wave = true
|
|
258
238
|
delete project.integrations.mparticle.webApiKey
|
|
259
239
|
|
|
260
240
|
let Project = new ProjectModel(project)
|
|
261
|
-
|
|
262
|
-
|
|
241
|
+
try {
|
|
242
|
+
await Project.validate()
|
|
243
|
+
} catch (err) {
|
|
244
|
+
assert.exists(err, 'err object should exist')
|
|
263
245
|
assert.match(err.message, /Web keys need to be provided/)
|
|
264
|
-
|
|
265
|
-
})
|
|
246
|
+
}
|
|
266
247
|
})
|
|
267
|
-
assertions('should throw an error if hello is selected but no web keys provided', (
|
|
248
|
+
assertions('should throw an error if hello is selected but no web keys provided', async () => {
|
|
268
249
|
project.integrations.mparticle.hello = true
|
|
269
250
|
delete project.integrations.mparticle.webApiKey
|
|
270
251
|
|
|
271
252
|
let Project = new ProjectModel(project)
|
|
272
|
-
|
|
273
|
-
|
|
253
|
+
try {
|
|
254
|
+
await Project.validate()
|
|
255
|
+
} catch (err) {
|
|
256
|
+
assert.exists(err, 'err object should exist')
|
|
274
257
|
assert.match(err.message, /Web keys need to be provided/)
|
|
275
|
-
|
|
276
|
-
})
|
|
258
|
+
}
|
|
277
259
|
})
|
|
278
260
|
})
|
|
279
261
|
testCase('recursive property check', () => {
|
|
280
262
|
let requiredFields = rules.requiredFields
|
|
281
263
|
requiredFields.map((i) => {
|
|
282
|
-
assertions(`should throw an error with property '${i}' if '${i}' is not present`, (
|
|
264
|
+
assertions(`should throw an error with property '${i}' if '${i}' is not present`, async () => {
|
|
283
265
|
project = JSON.parse(JSON.stringify(project))
|
|
284
266
|
delete project[i]
|
|
285
267
|
let Project = new ProjectModel(project)
|
|
286
|
-
|
|
287
|
-
|
|
268
|
+
try {
|
|
269
|
+
await Project.validate()
|
|
270
|
+
} catch (err) {
|
|
288
271
|
assert.exists(err, 'err object should exist')
|
|
289
272
|
assert.isObject(err.errors)
|
|
290
273
|
assert.nestedProperty(err, `errors.${i}`, 'error should have a radius property')
|
|
291
|
-
|
|
292
|
-
})
|
|
274
|
+
}
|
|
293
275
|
})
|
|
294
276
|
})
|
|
295
277
|
})
|
|
@@ -298,120 +280,126 @@ describe('Project', () => {
|
|
|
298
280
|
let invalidProps = rules.customValidators
|
|
299
281
|
invalidProps.map((i) => {
|
|
300
282
|
i.invalidInput.map((j) => {
|
|
301
|
-
assertions(`should throw an error with property '${i.name}' if '${i.name}' is invalid => ${i.name} = ${j}`, (
|
|
283
|
+
assertions(`should throw an error with property '${i.name}' if '${i.name}' is invalid => ${i.name} = ${j}`, async () => {
|
|
302
284
|
project = JSON.parse(JSON.stringify(project))
|
|
303
285
|
project[i.name] = j
|
|
304
286
|
let Project = new ProjectModel(project)
|
|
305
|
-
|
|
306
|
-
|
|
287
|
+
try {
|
|
288
|
+
await Project.validate()
|
|
289
|
+
} catch (err) {
|
|
307
290
|
assert.exists(err, 'err object should exist')
|
|
308
|
-
|
|
309
|
-
// assert.nestedProperty(err, `errors.${i.name}`, `error should have a ${i} property`)
|
|
310
|
-
done()
|
|
311
|
-
})
|
|
291
|
+
}
|
|
312
292
|
})
|
|
313
293
|
})
|
|
314
294
|
})
|
|
315
295
|
})
|
|
316
296
|
|
|
317
|
-
it(`should throw an error when firebaseApiKey is null`, (
|
|
297
|
+
it(`should throw an error when firebaseApiKey is null`, async () => {
|
|
318
298
|
project = JSON.parse(JSON.stringify(project))
|
|
319
299
|
project.firebaseApiKey = null
|
|
320
|
-
helpers.testNullValue(project, ProjectModel
|
|
300
|
+
await helpers.testNullValue(project, ProjectModel)
|
|
321
301
|
})
|
|
322
302
|
|
|
323
|
-
it('should not validate if tempo.isochroneBracketInterval contains items other than integer', (
|
|
303
|
+
it('should not validate if tempo.isochroneBracketInterval contains items other than integer', async () => {
|
|
324
304
|
project.tempo.isochroneBracketInterval = [900, 600, 1.5, 120]
|
|
325
305
|
let Project = new ProjectModel(project)
|
|
326
|
-
|
|
327
|
-
|
|
306
|
+
try {
|
|
307
|
+
await Project.validate()
|
|
308
|
+
} catch (err) {
|
|
309
|
+
assert.exists(err, 'err object should exist')
|
|
328
310
|
assert.match(err.message, /tempo.isochroneBracketInterval should contain integer numbers only/)
|
|
329
|
-
|
|
330
|
-
})
|
|
311
|
+
}
|
|
331
312
|
})
|
|
332
313
|
|
|
333
|
-
it('should not validate if hello.activeTtl is not an integer', (
|
|
314
|
+
it('should not validate if hello.activeTtl is not an integer', async () => {
|
|
334
315
|
project.hello.activeTtl = 1.5
|
|
335
316
|
let Project = new ProjectModel(project)
|
|
336
|
-
|
|
337
|
-
|
|
317
|
+
try {
|
|
318
|
+
await Project.validate()
|
|
319
|
+
} catch (err) {
|
|
320
|
+
assert.exists(err, 'err object should exist')
|
|
338
321
|
assert.match(err.message, /hello.activeTtl should be an integer number/)
|
|
339
|
-
|
|
340
|
-
})
|
|
322
|
+
}
|
|
341
323
|
})
|
|
342
324
|
|
|
343
|
-
it('should not validate if hello.finalTtl is not an integer', (
|
|
325
|
+
it('should not validate if hello.finalTtl is not an integer', async () => {
|
|
344
326
|
project.hello.finalTtl = 1.5
|
|
345
327
|
let Project = new ProjectModel(project)
|
|
346
|
-
|
|
347
|
-
|
|
328
|
+
try {
|
|
329
|
+
await Project.validate()
|
|
330
|
+
} catch (err) {
|
|
331
|
+
assert.exists(err, 'err object should exist')
|
|
348
332
|
assert.match(err.message, /hello.finalTtl should be an integer number/)
|
|
349
|
-
|
|
350
|
-
})
|
|
333
|
+
}
|
|
351
334
|
})
|
|
352
335
|
|
|
353
|
-
it('should not validate if hello.finalTtl is a negative', (
|
|
336
|
+
it('should not validate if hello.finalTtl is a negative', async () => {
|
|
354
337
|
project.hello.finalTtl = -2
|
|
355
338
|
let Project = new ProjectModel(project)
|
|
356
|
-
|
|
357
|
-
|
|
339
|
+
try {
|
|
340
|
+
await Project.validate()
|
|
341
|
+
} catch (err) {
|
|
342
|
+
assert.exists(err, 'err object should exist')
|
|
358
343
|
assert.match(err.message, /finalTtl` \(-2\) is less than minimum allowed value \(0\)/)
|
|
359
|
-
|
|
360
|
-
})
|
|
344
|
+
}
|
|
361
345
|
})
|
|
362
346
|
|
|
363
|
-
it('should not validate if hello.activeTtl is a negative', (
|
|
347
|
+
it('should not validate if hello.activeTtl is a negative', async () => {
|
|
364
348
|
project.hello.activeTtl = -2
|
|
365
349
|
let Project = new ProjectModel(project)
|
|
366
|
-
|
|
367
|
-
|
|
350
|
+
try {
|
|
351
|
+
await Project.validate()
|
|
352
|
+
} catch (err) {
|
|
353
|
+
assert.exists(err, 'err object should exist')
|
|
368
354
|
assert.match(err.message, /activeTtl` \(-2\) is less than minimum allowed value \(0\)/)
|
|
369
|
-
|
|
370
|
-
})
|
|
355
|
+
}
|
|
371
356
|
})
|
|
372
357
|
|
|
373
|
-
it('should not validate if hello.finalTtl is a greater than the maximum', (
|
|
358
|
+
it('should not validate if hello.finalTtl is a greater than the maximum', async () => {
|
|
374
359
|
project.hello.finalTtl = 1209601
|
|
375
360
|
let Project = new ProjectModel(project)
|
|
376
|
-
|
|
377
|
-
|
|
378
|
-
|
|
361
|
+
try {
|
|
362
|
+
await Project.validate()
|
|
363
|
+
} catch (err) {
|
|
364
|
+
assert.exists(err, 'err object should exist')
|
|
379
365
|
assert.match(err.message, /finalTtl` \(1209601\) is more than maximum allowed value/)
|
|
380
|
-
|
|
381
|
-
})
|
|
366
|
+
}
|
|
382
367
|
})
|
|
383
368
|
|
|
384
|
-
it('should not validate if hello.activeTtl is a greater than the maximum', (
|
|
369
|
+
it('should not validate if hello.activeTtl is a greater than the maximum', async () => {
|
|
385
370
|
project.hello.activeTtl = 1209601
|
|
386
371
|
let Project = new ProjectModel(project)
|
|
387
|
-
|
|
388
|
-
|
|
372
|
+
try {
|
|
373
|
+
await Project.validate()
|
|
374
|
+
} catch (err) {
|
|
375
|
+
assert.exists(err, 'err object should exist')
|
|
389
376
|
assert.match(err.message, /activeTtl` \(1209601\) is more than maximum allowed value/)
|
|
390
|
-
|
|
391
|
-
})
|
|
377
|
+
}
|
|
392
378
|
})
|
|
393
379
|
|
|
394
380
|
describe("webhook validation", () => {
|
|
395
|
-
assertions(`should not validate if webhook protocol is not valid `, (
|
|
381
|
+
assertions(`should not validate if webhook protocol is not valid `, async () => {
|
|
396
382
|
project.webhooks[0].url = 'htt://test.com'
|
|
397
383
|
let Project = new ProjectModel(project)
|
|
398
|
-
|
|
399
|
-
|
|
384
|
+
try {
|
|
385
|
+
await Project.validate()
|
|
386
|
+
} catch (err) {
|
|
387
|
+
assert.exists(err, 'err object should exist')
|
|
400
388
|
assert.match(err.message, /Please enter a valid URL/)
|
|
401
|
-
|
|
402
|
-
})
|
|
389
|
+
}
|
|
403
390
|
})
|
|
404
|
-
assertions(`should not validate if webhook domain is not valid `, (
|
|
391
|
+
assertions(`should not validate if webhook domain is not valid `, async () => {
|
|
405
392
|
project.webhooks[0].url = 'https://@'
|
|
406
393
|
let Project = new ProjectModel(project)
|
|
407
|
-
|
|
408
|
-
|
|
394
|
+
try {
|
|
395
|
+
await Project.validate()
|
|
396
|
+
} catch (err) {
|
|
397
|
+
assert.exists(err, 'err object should exist')
|
|
409
398
|
assert.match(err.message, /Please enter a valid URL/)
|
|
410
|
-
|
|
411
|
-
})
|
|
399
|
+
}
|
|
412
400
|
})
|
|
413
401
|
|
|
414
|
-
assertions(`should not validate if one of webhooks have a type other than 'tempo', 'wave' or 'trigger'`, (
|
|
402
|
+
assertions(`should not validate if one of webhooks have a type other than 'tempo', 'wave' or 'trigger'`, async () => {
|
|
415
403
|
project.webhooks.push({
|
|
416
404
|
"type": "sandwich",
|
|
417
405
|
"url": "https://webhooklistener.bluedotinnovation.com",
|
|
@@ -420,245 +408,265 @@ describe('Project', () => {
|
|
|
420
408
|
}
|
|
421
409
|
})
|
|
422
410
|
let Project = new ProjectModel(project)
|
|
423
|
-
|
|
424
|
-
|
|
411
|
+
try {
|
|
412
|
+
await Project.validate()
|
|
413
|
+
} catch (err) {
|
|
414
|
+
assert.exists(err, 'err object should exist')
|
|
425
415
|
assert.match(err.message, /`sandwich` is not a valid enum value for path `type`/)
|
|
426
|
-
|
|
427
|
-
})
|
|
416
|
+
}
|
|
428
417
|
})
|
|
429
418
|
|
|
430
|
-
it(`should throw an error when webhooks is null`, (
|
|
419
|
+
it(`should throw an error when webhooks is null`, async () => {
|
|
431
420
|
project = JSON.parse(JSON.stringify(project))
|
|
432
421
|
project.webhooks = null
|
|
433
|
-
helpers.testNullValue(project, ProjectModel
|
|
422
|
+
await helpers.testNullValue(project, ProjectModel)
|
|
434
423
|
})
|
|
435
424
|
|
|
436
|
-
it(`should throw an error when webhooks has primitive value in headers`, (
|
|
425
|
+
it(`should throw an error when webhooks has primitive value in headers`, async () => {
|
|
437
426
|
project = JSON.parse(JSON.stringify(project))
|
|
438
427
|
project.webhooks[0].headers = 'primitive'
|
|
439
|
-
helpers.testNullValue(project, ProjectModel
|
|
428
|
+
await helpers.testNullValue(project, ProjectModel)
|
|
440
429
|
})
|
|
441
|
-
it(`should throw an error when webhooks has array in headers`, (
|
|
430
|
+
it(`should throw an error when webhooks has array in headers`, async () => {
|
|
442
431
|
project = JSON.parse(JSON.stringify(project))
|
|
443
432
|
project.webhooks[0].headers = ['array']
|
|
444
|
-
helpers.testNullValue(project, ProjectModel
|
|
433
|
+
await helpers.testNullValue(project, ProjectModel)
|
|
445
434
|
})
|
|
446
435
|
|
|
447
|
-
it(`should throw an error when webhooks has a number as a value in headers`, (
|
|
436
|
+
it(`should throw an error when webhooks has a number as a value in headers`, async () => {
|
|
448
437
|
project = JSON.parse(JSON.stringify(project))
|
|
449
438
|
project.webhooks[0].headers["newValue"] = 420
|
|
450
439
|
let Project = new ProjectModel(project)
|
|
451
|
-
|
|
452
|
-
|
|
440
|
+
try {
|
|
441
|
+
await Project.validate()
|
|
442
|
+
} catch (err) {
|
|
443
|
+
assert.exists(err, 'err object should exist')
|
|
453
444
|
assert.match(err.message, /webhook header keys and values must be strings/)
|
|
454
|
-
|
|
455
|
-
})
|
|
445
|
+
}
|
|
456
446
|
})
|
|
457
447
|
|
|
458
|
-
it(`should throw an error when webhooks has a number as a value in body`, (
|
|
448
|
+
it(`should throw an error when webhooks has a number as a value in body`, async () => {
|
|
459
449
|
project = JSON.parse(JSON.stringify(project))
|
|
460
450
|
project.webhooks[0].body = {"newValue": 420}
|
|
461
451
|
let Project = new ProjectModel(project)
|
|
462
|
-
|
|
463
|
-
|
|
452
|
+
try {
|
|
453
|
+
await Project.validate()
|
|
454
|
+
} catch (err) {
|
|
455
|
+
assert.exists(err, 'err object should exist')
|
|
464
456
|
assert.match(err.message, /webhook body keys and values must be strings/)
|
|
465
|
-
|
|
466
|
-
})
|
|
457
|
+
}
|
|
467
458
|
})
|
|
468
459
|
|
|
469
|
-
it(`should throw an error if a structure is used that is not tealium or standard`, (
|
|
460
|
+
it(`should throw an error if a structure is used that is not tealium or standard`, async () => {
|
|
470
461
|
project = JSON.parse(JSON.stringify(project))
|
|
471
462
|
project.webhooks[0].structure = "different"
|
|
472
463
|
let Project = new ProjectModel(project)
|
|
473
|
-
|
|
474
|
-
|
|
464
|
+
try {
|
|
465
|
+
await Project.validate()
|
|
466
|
+
} catch (err) {
|
|
467
|
+
assert.exists(err, 'err object should exist')
|
|
475
468
|
assert.match(err.message, /is not a valid enum value for path `structure`/)
|
|
476
|
-
|
|
477
|
-
})
|
|
469
|
+
}
|
|
478
470
|
})
|
|
479
471
|
|
|
480
|
-
it(`should throw an error if structure is tealium and tealium_account is not a body field`, (
|
|
472
|
+
it(`should throw an error if structure is tealium and tealium_account is not a body field`, async () => {
|
|
481
473
|
project.webhooks[0].structure = "tealium"
|
|
482
474
|
project.webhooks[0].body = {"tealium_profile": "test-value"}
|
|
483
475
|
let Project = new ProjectModel(project)
|
|
484
|
-
|
|
485
|
-
|
|
476
|
+
try {
|
|
477
|
+
await Project.validate()
|
|
478
|
+
} catch (err) {
|
|
479
|
+
assert.exists(err, 'err object should exist')
|
|
486
480
|
assert.match(err.message, /tealium webhooks require "tealium_account" and "tealium_profile" body fields to be present/)
|
|
487
|
-
|
|
488
|
-
})
|
|
481
|
+
}
|
|
489
482
|
})
|
|
490
483
|
|
|
491
|
-
it(`should throw an error if structure is tealium and tealium_profile is not a body field`, (
|
|
484
|
+
it(`should throw an error if structure is tealium and tealium_profile is not a body field`, async () => {
|
|
492
485
|
project.webhooks[0].structure = "tealium"
|
|
493
486
|
project.webhooks[0].body = {"tealium_account": "test-value"}
|
|
494
487
|
let Project = new ProjectModel(project)
|
|
495
|
-
|
|
496
|
-
|
|
488
|
+
try {
|
|
489
|
+
await Project.validate()
|
|
490
|
+
} catch (err) {
|
|
491
|
+
assert.exists(err, 'err object should exist')
|
|
497
492
|
assert.match(err.message, /tealium webhooks require "tealium_account" and "tealium_profile" body fields to be present/)
|
|
498
|
-
|
|
499
|
-
})
|
|
493
|
+
}
|
|
500
494
|
})
|
|
501
495
|
|
|
502
|
-
it(`should not validate if structure is tealium and body is not present`, (
|
|
496
|
+
it(`should not validate if structure is tealium and body is not present`, async () => {
|
|
503
497
|
project.webhooks[0].structure = "tealium"
|
|
504
498
|
delete project.webhooks[0].body
|
|
505
499
|
let Project = new ProjectModel(project)
|
|
506
|
-
|
|
507
|
-
|
|
500
|
+
try {
|
|
501
|
+
await Project.validate()
|
|
502
|
+
} catch (err) {
|
|
503
|
+
assert.exists(err, 'err object should exist')
|
|
508
504
|
assert.match(err.message, /tealium webhooks require "tealium_account" and "tealium_profile" body fields to be present/)
|
|
509
|
-
|
|
510
|
-
})
|
|
505
|
+
}
|
|
511
506
|
})
|
|
512
507
|
|
|
513
|
-
it(`should not validate if structure is tealium and body is an empty object`, (
|
|
508
|
+
it(`should not validate if structure is tealium and body is an empty object`, async () => {
|
|
514
509
|
project.webhooks[0].structure = "tealium"
|
|
515
510
|
project.webhooks[0].body = {}
|
|
516
511
|
let Project = new ProjectModel(project)
|
|
517
|
-
|
|
518
|
-
|
|
512
|
+
try {
|
|
513
|
+
await Project.validate()
|
|
514
|
+
} catch (err) {
|
|
515
|
+
assert.exists(err, 'err object should exist')
|
|
519
516
|
assert.match(err.message, /tealium webhooks require "tealium_account" and "tealium_profile" body fields to be present/)
|
|
520
|
-
|
|
521
|
-
})
|
|
517
|
+
}
|
|
522
518
|
})
|
|
523
|
-
it(`should throw an error if structure is mobivity and taregt_id is not a body field`, (
|
|
519
|
+
it(`should throw an error if structure is mobivity and taregt_id is not a body field`, async () => {
|
|
524
520
|
project.webhooks[0].type = "register"
|
|
525
521
|
project.webhooks[0].structure = "mobivity"
|
|
526
522
|
project.webhooks[0].body = {"message_text": "test-value", "username": "test-value"}
|
|
527
523
|
let Project = new ProjectModel(project)
|
|
528
|
-
|
|
529
|
-
|
|
524
|
+
try {
|
|
525
|
+
await Project.validate()
|
|
526
|
+
} catch (err) {
|
|
527
|
+
assert.exists(err, 'err object should exist')
|
|
530
528
|
assert.match(err.message, /mobivity webhooks require "username", "target_id" and "message_text" body fields to be present/)
|
|
531
|
-
|
|
532
|
-
})
|
|
529
|
+
}
|
|
533
530
|
})
|
|
534
531
|
|
|
535
|
-
it(`should throw an error if structure is mobivity and message_text is not a body field`, (
|
|
532
|
+
it(`should throw an error if structure is mobivity and message_text is not a body field`, async () => {
|
|
536
533
|
project.webhooks[0].type = "register"
|
|
537
534
|
project.webhooks[0].structure = "mobivity"
|
|
538
535
|
project.webhooks[0].body = {"target_id": "test-value", "username": "test-value"}
|
|
539
536
|
let Project = new ProjectModel(project)
|
|
540
|
-
|
|
541
|
-
|
|
537
|
+
try {
|
|
538
|
+
await Project.validate()
|
|
539
|
+
} catch (err) {
|
|
540
|
+
assert.exists(err, 'err object should exist')
|
|
542
541
|
assert.match(err.message, /mobivity webhooks require "username", "target_id" and "message_text" body fields to be present/)
|
|
543
|
-
|
|
544
|
-
})
|
|
542
|
+
}
|
|
545
543
|
})
|
|
546
544
|
|
|
547
|
-
it(`should throw an error if structure is mobivity and username is not a body field`, (
|
|
545
|
+
it(`should throw an error if structure is mobivity and username is not a body field`, async () => {
|
|
548
546
|
project.webhooks[0].type = "register"
|
|
549
547
|
project.webhooks[0].structure = "mobivity"
|
|
550
548
|
project.webhooks[0].body = {"target_id": "test-value", "message_text": "est-value"}
|
|
551
549
|
let Project = new ProjectModel(project)
|
|
552
|
-
|
|
553
|
-
|
|
550
|
+
try {
|
|
551
|
+
await Project.validate()
|
|
552
|
+
} catch (err) {
|
|
553
|
+
assert.exists(err, 'err object should exist')
|
|
554
554
|
assert.match(err.message, /mobivity webhooks require "username", "target_id" and "message_text" body fields to be present/)
|
|
555
|
-
|
|
556
|
-
})
|
|
555
|
+
}
|
|
557
556
|
})
|
|
558
557
|
|
|
559
|
-
it(`should not validate if structure is mobivity and body is not present`, (
|
|
558
|
+
it(`should not validate if structure is mobivity and body is not present`, async () => {
|
|
560
559
|
project.webhooks[0].type = "register"
|
|
561
560
|
project.webhooks[0].structure = "mobivity"
|
|
562
561
|
delete project.webhooks[0].body
|
|
563
562
|
let Project = new ProjectModel(project)
|
|
564
|
-
|
|
565
|
-
|
|
563
|
+
try {
|
|
564
|
+
await Project.validate()
|
|
565
|
+
} catch (err) {
|
|
566
|
+
assert.exists(err, 'err object should exist')
|
|
566
567
|
assert.match(err.message, /mobivity webhooks require "username", "target_id" and "message_text" body fields to be present/)
|
|
567
|
-
|
|
568
|
-
})
|
|
568
|
+
}
|
|
569
569
|
})
|
|
570
570
|
|
|
571
|
-
it(`should not validate if structure is mobivity and body is an empty object`, (
|
|
571
|
+
it(`should not validate if structure is mobivity and body is an empty object`, async () => {
|
|
572
572
|
project.webhooks[0].type = "register"
|
|
573
573
|
project.webhooks[0].structure = "mobivity"
|
|
574
574
|
project.webhooks[0].body = {}
|
|
575
575
|
let Project = new ProjectModel(project)
|
|
576
|
-
|
|
577
|
-
|
|
576
|
+
try {
|
|
577
|
+
await Project.validate()
|
|
578
|
+
} catch (err) {
|
|
579
|
+
assert.exists(err, 'err object should exist')
|
|
578
580
|
assert.match(err.message, /mobivity webhooks require "username", "target_id" and "message_text" body fields to be present/)
|
|
579
|
-
|
|
580
|
-
})
|
|
581
|
+
}
|
|
581
582
|
})
|
|
582
583
|
|
|
583
|
-
it(`should not validate if structure is mobivity and the type is not register`, (
|
|
584
|
+
it(`should not validate if structure is mobivity and the type is not register`, async () => {
|
|
584
585
|
project.webhooks[0].type = "trigger"
|
|
585
586
|
project.webhooks[0].structure = "mobivity"
|
|
586
587
|
let Project = new ProjectModel(project)
|
|
587
|
-
|
|
588
|
-
|
|
588
|
+
try {
|
|
589
|
+
await Project.validate()
|
|
590
|
+
} catch (err) {
|
|
591
|
+
assert.exists(err, 'err object should exist')
|
|
589
592
|
assert.match(err.message, /type "register" can only have structure "mobivity"/)
|
|
590
|
-
|
|
591
|
-
})
|
|
593
|
+
}
|
|
592
594
|
})
|
|
593
|
-
it(`should not validate if the type is register and the structure is not mobivity`, (
|
|
595
|
+
it(`should not validate if the type is register and the structure is not mobivity`, async () => {
|
|
594
596
|
project.webhooks[0].type = "register"
|
|
595
597
|
project.webhooks[0].structure = "standard"
|
|
596
598
|
let Project = new ProjectModel(project)
|
|
597
|
-
|
|
598
|
-
|
|
599
|
+
try {
|
|
600
|
+
await Project.validate()
|
|
601
|
+
} catch (err) {
|
|
602
|
+
assert.exists(err, 'err object should exist')
|
|
599
603
|
assert.match(err.message, /type "register" can only have structure "mobivity"/)
|
|
600
|
-
|
|
601
|
-
})
|
|
604
|
+
}
|
|
602
605
|
})
|
|
603
606
|
|
|
604
|
-
it(`should not validate if the type is hellOrder and the structure is not default`, (
|
|
607
|
+
it(`should not validate if the type is hellOrder and the structure is not default`, async () => {
|
|
605
608
|
project.webhooks[0].type = "helloOrder"
|
|
606
609
|
project.webhooks[0].structure = "standard"
|
|
607
610
|
let Project = new ProjectModel(project)
|
|
608
|
-
|
|
609
|
-
|
|
611
|
+
try {
|
|
612
|
+
await Project.validate()
|
|
613
|
+
} catch (err) {
|
|
614
|
+
assert.exists(err, 'err object should exist')
|
|
610
615
|
assert.match(err.message, /type "helloOrder" can only have structure "default"/)
|
|
611
|
-
|
|
612
|
-
})
|
|
616
|
+
}
|
|
613
617
|
})
|
|
614
|
-
it(`should not validate if structure is default and the type is not helloOrder`, (
|
|
618
|
+
it(`should not validate if structure is default and the type is not helloOrder`, async () => {
|
|
615
619
|
project.webhooks[0].type = "trigger"
|
|
616
620
|
project.webhooks[0].structure = "default"
|
|
617
621
|
let Project = new ProjectModel(project)
|
|
618
|
-
|
|
619
|
-
|
|
622
|
+
try {
|
|
623
|
+
await Project.validate()
|
|
624
|
+
} catch (err) {
|
|
625
|
+
assert.exists(err, 'err object should exist')
|
|
620
626
|
assert.match(err.message, /type "helloOrder" can only have structure "default"/)
|
|
621
|
-
|
|
622
|
-
})
|
|
627
|
+
}
|
|
623
628
|
})
|
|
624
629
|
|
|
625
|
-
it(`should not validate if structure is 2.0 and the type is not trigger`, (
|
|
630
|
+
it(`should not validate if structure is 2.0 and the type is not trigger`, async () => {
|
|
626
631
|
project.webhooks[0].type = "tempo"
|
|
627
632
|
project.webhooks[0].url = "http://test-url.com"
|
|
628
633
|
project.webhooks[0].structure = "2.0"
|
|
629
634
|
let Project = new ProjectModel(project)
|
|
630
|
-
|
|
631
|
-
|
|
635
|
+
try {
|
|
636
|
+
await Project.validate()
|
|
637
|
+
} catch (err) {
|
|
638
|
+
assert.exists(err, 'err object should exist')
|
|
632
639
|
assert.match(err.message, /Only type "trigger" can have structure 2.0/)
|
|
633
|
-
|
|
634
|
-
})
|
|
640
|
+
}
|
|
635
641
|
})
|
|
636
642
|
|
|
637
|
-
it("should not validate webhook if body contains keys with spaces", (
|
|
643
|
+
it("should not validate webhook if body contains keys with spaces", async () => {
|
|
638
644
|
project.webhooks[0].body = { "key with spaces": "value" }
|
|
639
645
|
let Project = new ProjectModel(project)
|
|
640
|
-
|
|
641
|
-
|
|
646
|
+
try {
|
|
647
|
+
await Project.validate()
|
|
648
|
+
} catch (err) {
|
|
649
|
+
assert.exists(err, 'err object should exist')
|
|
642
650
|
assert.match(err.message, /webhook body keys cannot contain spaces/)
|
|
643
|
-
|
|
644
|
-
})
|
|
651
|
+
}
|
|
645
652
|
})
|
|
646
653
|
|
|
647
|
-
it("should not validate webhook if headers contains keys with spaces", (
|
|
654
|
+
it("should not validate webhook if headers contains keys with spaces", async () => {
|
|
648
655
|
project.webhooks[0].headers = { "key with spaces": "value" }
|
|
649
656
|
let Project = new ProjectModel(project)
|
|
650
|
-
|
|
651
|
-
|
|
657
|
+
try {
|
|
658
|
+
await Project.validate()
|
|
659
|
+
} catch (err) {
|
|
660
|
+
assert.exists(err, 'err object should exist')
|
|
652
661
|
assert.match(err.message, /webhook header keys cannot contain spaces/)
|
|
653
|
-
|
|
654
|
-
})
|
|
662
|
+
}
|
|
655
663
|
})
|
|
656
664
|
|
|
657
665
|
describe('should not validate if webhooks contains a webhook of the same type and url but different structure', () => {
|
|
658
666
|
const webhookTypes = ['tempo', 'wave', 'trigger']
|
|
659
667
|
|
|
660
668
|
webhookTypes.map(webhookType => {
|
|
661
|
-
it(`should not validate if there are duplicate ${webhookType} webhooks`, (
|
|
669
|
+
it(`should not validate if there are duplicate ${webhookType} webhooks`, async () => {
|
|
662
670
|
project.webhooks.push({
|
|
663
671
|
"type": webhookType,
|
|
664
672
|
"url": "https://webhooklistener.bluedotinnovation.com",
|
|
@@ -669,265 +677,283 @@ describe('Project', () => {
|
|
|
669
677
|
})
|
|
670
678
|
|
|
671
679
|
let Project = new ProjectModel(project)
|
|
672
|
-
|
|
673
|
-
|
|
680
|
+
try {
|
|
681
|
+
await Project.validate()
|
|
682
|
+
} catch (err) {
|
|
683
|
+
assert.exists(err, 'err object should exist')
|
|
674
684
|
assert.match(err.message, /Duplicate webhooks found with the same type and url as another. Only one is allowed/)
|
|
675
|
-
|
|
676
|
-
})
|
|
685
|
+
}
|
|
677
686
|
})
|
|
678
687
|
})
|
|
679
688
|
})
|
|
680
689
|
})
|
|
681
690
|
|
|
682
691
|
describe("olo integration validation", () => {
|
|
683
|
-
it('should throw an error when sharedSecret is missing', (
|
|
692
|
+
it('should throw an error when sharedSecret is missing', async () => {
|
|
684
693
|
delete project.integrations.olo.sharedSecret
|
|
685
694
|
let Project = new ProjectModel(project)
|
|
686
|
-
|
|
687
|
-
|
|
695
|
+
try {
|
|
696
|
+
await Project.validate()
|
|
697
|
+
} catch (err) {
|
|
698
|
+
assert.exists(err, 'err object should exist')
|
|
688
699
|
assert.match(err.message, /`sharedSecret` is required/)
|
|
689
|
-
|
|
690
|
-
})
|
|
700
|
+
}
|
|
691
701
|
})
|
|
692
702
|
})
|
|
693
703
|
|
|
694
704
|
describe("oneSignal integration validation", () => {
|
|
695
|
-
it('should throw an error when appId is missing', (
|
|
705
|
+
it('should throw an error when appId is missing', async () => {
|
|
696
706
|
delete project.integrations.oneSignal.appId
|
|
697
707
|
let Project = new ProjectModel(project)
|
|
698
|
-
|
|
699
|
-
|
|
708
|
+
try {
|
|
709
|
+
await Project.validate()
|
|
710
|
+
} catch (err) {
|
|
711
|
+
assert.exists(err, 'err object should exist')
|
|
700
712
|
assert.match(err.message, /`appId` is required/)
|
|
701
|
-
|
|
702
|
-
})
|
|
713
|
+
}
|
|
703
714
|
})
|
|
704
715
|
|
|
705
|
-
it('should throw an error when wave is non boolean', (
|
|
716
|
+
it('should throw an error when wave is non boolean', async () => {
|
|
706
717
|
project.integrations.oneSignal.wave = "invalid"
|
|
707
718
|
let Project = new ProjectModel(project)
|
|
708
|
-
|
|
709
|
-
|
|
719
|
+
try {
|
|
720
|
+
await Project.validate()
|
|
721
|
+
} catch (err) {
|
|
722
|
+
assert.exists(err, 'err object should exist')
|
|
710
723
|
assert.match(err.message, /Cast to Boolean failed for value "invalid" .* at path "wave"/)
|
|
711
|
-
|
|
712
|
-
})
|
|
724
|
+
}
|
|
713
725
|
})
|
|
714
726
|
})
|
|
715
727
|
describe("Attentive integration validation", () => {
|
|
716
|
-
it('should throw an error when trigger is non boolean', (
|
|
728
|
+
it('should throw an error when trigger is non boolean', async () => {
|
|
717
729
|
project.integrations.attentive.trigger = "invalid"
|
|
718
730
|
let Project = new ProjectModel(project)
|
|
719
|
-
|
|
720
|
-
|
|
731
|
+
try {
|
|
732
|
+
await Project.validate()
|
|
733
|
+
} catch (err) {
|
|
734
|
+
assert.exists(err, 'err object should exist')
|
|
721
735
|
assert.match(err.message, /Cast to Boolean failed for value "invalid" .* at path "trigger"/)
|
|
722
|
-
|
|
723
|
-
})
|
|
736
|
+
}
|
|
724
737
|
})
|
|
725
738
|
|
|
726
|
-
it('should throw an error when helloRegister is non boolean', (
|
|
739
|
+
it('should throw an error when helloRegister is non boolean', async () => {
|
|
727
740
|
project.integrations.attentive.helloRegister = "invalid"
|
|
728
741
|
let Project = new ProjectModel(project)
|
|
729
|
-
|
|
730
|
-
|
|
742
|
+
try {
|
|
743
|
+
await Project.validate()
|
|
744
|
+
} catch (err) {
|
|
745
|
+
assert.exists(err, 'err object should exist')
|
|
731
746
|
assert.match(err.message, /Cast to Boolean failed for value "invalid" .* at path "helloRegister"/)
|
|
732
|
-
|
|
733
|
-
})
|
|
747
|
+
}
|
|
734
748
|
})
|
|
735
749
|
})
|
|
736
750
|
|
|
737
751
|
describe("Incentivio integration validation", () => {
|
|
738
|
-
it('should throw an error when clientId is missing', (
|
|
752
|
+
it('should throw an error when clientId is missing', async () => {
|
|
739
753
|
delete project.integrations.incentivio.clientId
|
|
740
754
|
let Project = new ProjectModel(project)
|
|
741
|
-
|
|
742
|
-
|
|
755
|
+
try {
|
|
756
|
+
await Project.validate()
|
|
757
|
+
} catch (err) {
|
|
758
|
+
assert.exists(err, 'err object should exist')
|
|
743
759
|
assert.match(err.message, /`clientId` is required/)
|
|
744
|
-
|
|
745
|
-
})
|
|
760
|
+
}
|
|
746
761
|
})
|
|
747
762
|
|
|
748
|
-
it('should throw an error when nowReadyEnabled is non boolean', (
|
|
763
|
+
it('should throw an error when nowReadyEnabled is non boolean', async () => {
|
|
749
764
|
project.integrations.incentivio.nowReadyEnabled = "invalid"
|
|
750
765
|
let Project = new ProjectModel(project)
|
|
751
|
-
|
|
752
|
-
|
|
766
|
+
try {
|
|
767
|
+
await Project.validate()
|
|
768
|
+
} catch (err) {
|
|
769
|
+
assert.exists(err, 'err object should exist')
|
|
753
770
|
assert.match(err.message, /Cast to Boolean failed for value "invalid" .* at path "nowReadyEnabled"/)
|
|
754
|
-
|
|
755
|
-
})
|
|
771
|
+
}
|
|
756
772
|
})
|
|
757
773
|
})
|
|
758
774
|
|
|
759
775
|
describe("SSO linking code validation", () => {
|
|
760
|
-
it("should throw an error if ssoLinkingCode is shorter than 12 characters", (
|
|
776
|
+
it("should throw an error if ssoLinkingCode is shorter than 12 characters", async () => {
|
|
761
777
|
project.hello.ssoLinkingCode = "HGDUS69SD"
|
|
762
778
|
let Project = new ProjectModel(project)
|
|
763
|
-
|
|
764
|
-
|
|
765
|
-
|
|
779
|
+
try {
|
|
780
|
+
await Project.validate()
|
|
781
|
+
} catch (err) {
|
|
782
|
+
assert.exists(err, 'err object should exist')
|
|
766
783
|
assert.match(err.message, /SSO linking code must be a 12 character capital alphanumeric text/)
|
|
767
|
-
|
|
768
|
-
})
|
|
784
|
+
}
|
|
769
785
|
})
|
|
770
786
|
|
|
771
|
-
it("should throw an error if ssoLinkingCode is longer than 12 characters", (
|
|
787
|
+
it("should throw an error if ssoLinkingCode is longer than 12 characters", async () => {
|
|
772
788
|
project.hello.ssoLinkingCode = "HGDUS69SDASLDKJSFDHWUER7Y"
|
|
773
789
|
let Project = new ProjectModel(project)
|
|
774
|
-
|
|
775
|
-
|
|
776
|
-
|
|
790
|
+
try {
|
|
791
|
+
await Project.validate()
|
|
792
|
+
} catch (err) {
|
|
793
|
+
assert.exists(err, 'err object should exist')
|
|
777
794
|
assert.match(err.message, /SSO linking code must be a 12 character capital alphanumeric text/)
|
|
778
|
-
|
|
779
|
-
})
|
|
795
|
+
}
|
|
780
796
|
})
|
|
781
797
|
|
|
782
|
-
it("should throw an error if ssoLinkingCode include lowercase characters", (
|
|
798
|
+
it("should throw an error if ssoLinkingCode include lowercase characters", async () => {
|
|
783
799
|
project.hello.ssoLinkingCode = "3HgDUs69SD95"
|
|
784
800
|
let Project = new ProjectModel(project)
|
|
785
|
-
|
|
786
|
-
|
|
787
|
-
|
|
801
|
+
try {
|
|
802
|
+
await Project.validate()
|
|
803
|
+
} catch (err) {
|
|
804
|
+
assert.exists(err, 'err object should exist')
|
|
788
805
|
assert.match(err.message, /SSO linking code must be a 12 character capital alphanumeric text/)
|
|
789
|
-
|
|
790
|
-
})
|
|
806
|
+
}
|
|
791
807
|
})
|
|
792
808
|
|
|
793
|
-
it("should throw an error if ssoLinkingCode is empty", (
|
|
809
|
+
it("should throw an error if ssoLinkingCode is empty", async () => {
|
|
794
810
|
project.hello.ssoLinkingCode = ""
|
|
795
811
|
let Project = new ProjectModel(project)
|
|
796
|
-
|
|
797
|
-
|
|
798
|
-
|
|
812
|
+
try {
|
|
813
|
+
await Project.validate()
|
|
814
|
+
} catch (err) {
|
|
815
|
+
assert.exists(err, 'err object should exist')
|
|
799
816
|
assert.match(err.message, /SSO linking code must be a 12 character capital alphanumeric text/)
|
|
800
|
-
|
|
801
|
-
})
|
|
817
|
+
}
|
|
802
818
|
})
|
|
803
819
|
})
|
|
804
820
|
|
|
805
821
|
describe("Klaviyo integration validation", () => {
|
|
806
|
-
it('should throw an error when enabled is non boolean', (
|
|
822
|
+
it('should throw an error when enabled is non boolean', async () => {
|
|
807
823
|
project.integrations.klaviyo.enabled = "invalid"
|
|
808
824
|
let Project = new ProjectModel(project)
|
|
809
|
-
|
|
810
|
-
|
|
825
|
+
try {
|
|
826
|
+
await Project.validate()
|
|
827
|
+
} catch (err) {
|
|
828
|
+
assert.exists(err, 'err object should exist')
|
|
811
829
|
assert.match(err.message, /Cast to Boolean failed for value "invalid" .* at path "enabled"/)
|
|
812
|
-
|
|
813
|
-
})
|
|
830
|
+
}
|
|
814
831
|
})
|
|
815
|
-
it('should throw an error when trigger is non boolean', (
|
|
832
|
+
it('should throw an error when trigger is non boolean', async () => {
|
|
816
833
|
project.integrations.klaviyo.trigger = "invalid"
|
|
817
834
|
let Project = new ProjectModel(project)
|
|
818
|
-
|
|
819
|
-
|
|
835
|
+
try {
|
|
836
|
+
await Project.validate()
|
|
837
|
+
} catch (err) {
|
|
838
|
+
assert.exists(err, 'err object should exist')
|
|
820
839
|
assert.match(err.message, /Cast to Boolean failed for value "invalid" .* at path "trigger"/)
|
|
821
|
-
|
|
822
|
-
})
|
|
840
|
+
}
|
|
823
841
|
})
|
|
824
|
-
it('should throw an error when tempo is non boolean', (
|
|
842
|
+
it('should throw an error when tempo is non boolean', async () => {
|
|
825
843
|
project.integrations.klaviyo.tempo = "invalid"
|
|
826
844
|
let Project = new ProjectModel(project)
|
|
827
|
-
|
|
828
|
-
|
|
845
|
+
try {
|
|
846
|
+
await Project.validate()
|
|
847
|
+
} catch (err) {
|
|
848
|
+
assert.exists(err, 'err object should exist')
|
|
829
849
|
assert.match(err.message, /Cast to Boolean failed for value "invalid" .* at path "tempo"/)
|
|
830
|
-
|
|
831
|
-
})
|
|
850
|
+
}
|
|
832
851
|
})
|
|
833
|
-
it('should throw an error when wave is non boolean', (
|
|
852
|
+
it('should throw an error when wave is non boolean', async () => {
|
|
834
853
|
project.integrations.klaviyo.wave = "invalid"
|
|
835
854
|
let Project = new ProjectModel(project)
|
|
836
|
-
|
|
837
|
-
|
|
855
|
+
try {
|
|
856
|
+
await Project.validate()
|
|
857
|
+
} catch (err) {
|
|
858
|
+
assert.exists(err, 'err object should exist')
|
|
838
859
|
assert.match(err.message, /Cast to Boolean failed for value "invalid" .* at path "wave"/)
|
|
839
|
-
|
|
840
|
-
})
|
|
860
|
+
}
|
|
841
861
|
})
|
|
842
|
-
it('should throw an error when hello is non boolean', (
|
|
862
|
+
it('should throw an error when hello is non boolean', async () => {
|
|
843
863
|
project.integrations.klaviyo.hello = "invalid"
|
|
844
864
|
let Project = new ProjectModel(project)
|
|
845
|
-
|
|
846
|
-
|
|
865
|
+
try {
|
|
866
|
+
await Project.validate()
|
|
867
|
+
} catch (err) {
|
|
868
|
+
assert.exists(err, 'err object should exist')
|
|
847
869
|
assert.match(err.message, /Cast to Boolean failed for value "invalid" .* at path "hello"/)
|
|
848
|
-
|
|
849
|
-
})
|
|
870
|
+
}
|
|
850
871
|
})
|
|
851
872
|
})
|
|
852
873
|
|
|
853
874
|
describe("reportConfigurations validation", () => {
|
|
854
|
-
it('Should successfully create project without reportConfigurations', (
|
|
875
|
+
it('Should successfully create project without reportConfigurations', async () => {
|
|
855
876
|
delete project.reportConfigurations
|
|
856
877
|
let Project = new ProjectModel(project)
|
|
857
|
-
Project.validate(
|
|
858
|
-
|
|
859
|
-
done()
|
|
860
|
-
})
|
|
878
|
+
const res = await Project.validate()
|
|
879
|
+
assert.notExists(res)
|
|
861
880
|
})
|
|
862
|
-
it('Should throw an error when reportConfigurations is null', (
|
|
881
|
+
it('Should throw an error when reportConfigurations is null', async () => {
|
|
863
882
|
project.reportConfigurations = null
|
|
864
883
|
let Project = new ProjectModel(project)
|
|
865
|
-
|
|
866
|
-
|
|
884
|
+
try {
|
|
885
|
+
await Project.validate()
|
|
886
|
+
} catch (err) {
|
|
887
|
+
assert.exists(err, 'err object should exist')
|
|
867
888
|
assert.match(err.message, /Validator failed for path `reportConfigurations` with value `null`/)
|
|
868
|
-
|
|
869
|
-
})
|
|
889
|
+
}
|
|
870
890
|
})
|
|
871
|
-
it('Should throw an error when frequency is undefined', (
|
|
891
|
+
it('Should throw an error when frequency is undefined', async () => {
|
|
872
892
|
delete project.reportConfigurations[0].frequency
|
|
873
893
|
let Project = new ProjectModel(project)
|
|
874
|
-
|
|
875
|
-
|
|
894
|
+
try {
|
|
895
|
+
await Project.validate()
|
|
896
|
+
} catch (err) {
|
|
897
|
+
assert.exists(err, 'err object should exist')
|
|
876
898
|
assert.match(err.message, /Path `frequency` is required/)
|
|
877
|
-
|
|
878
|
-
})
|
|
899
|
+
}
|
|
879
900
|
})
|
|
880
901
|
|
|
881
|
-
it('Should throw an error when frequency is invalid', (
|
|
902
|
+
it('Should throw an error when frequency is invalid', async () => {
|
|
882
903
|
project.reportConfigurations[0].frequency = 'invalid'
|
|
883
904
|
let Project = new ProjectModel(project)
|
|
884
|
-
|
|
885
|
-
|
|
905
|
+
try {
|
|
906
|
+
await Project.validate()
|
|
907
|
+
} catch (err) {
|
|
908
|
+
assert.exists(err, 'err object should exist')
|
|
886
909
|
assert.match(err.message, /`invalid` is not a valid enum value for path `frequency`/)
|
|
887
|
-
|
|
888
|
-
})
|
|
910
|
+
}
|
|
889
911
|
})
|
|
890
912
|
|
|
891
|
-
it('Should throw an error when frequency is weekly and reportDay is not in range 0-6', (
|
|
913
|
+
it('Should throw an error when frequency is weekly and reportDay is not in range 0-6', async () => {
|
|
892
914
|
project.reportConfigurations[0].frequency = 'weekly'
|
|
893
915
|
project.reportConfigurations[0].reportDay = 7
|
|
894
916
|
let Project = new ProjectModel(project)
|
|
895
|
-
|
|
896
|
-
|
|
917
|
+
try {
|
|
918
|
+
await Project.validate()
|
|
919
|
+
} catch (err) {
|
|
920
|
+
assert.exists(err, 'err object should exist')
|
|
897
921
|
assert.match(err.message, /reportDay must be an integer number in range of 0-6 for weekly frequency/)
|
|
898
|
-
|
|
899
|
-
})
|
|
922
|
+
}
|
|
900
923
|
})
|
|
901
|
-
it('Should throw an error when frequency is monthly and reportDay is not in range 1-31', (
|
|
924
|
+
it('Should throw an error when frequency is monthly and reportDay is not in range 1-31', async () => {
|
|
902
925
|
project.reportConfigurations[0].frequency = 'monthly'
|
|
903
926
|
project.reportConfigurations[0].reportDay = 0
|
|
904
927
|
let Project = new ProjectModel(project)
|
|
905
|
-
|
|
906
|
-
|
|
928
|
+
try {
|
|
929
|
+
await Project.validate()
|
|
930
|
+
} catch (err) {
|
|
931
|
+
assert.exists(err, 'err object should exist')
|
|
907
932
|
assert.match(err.message, /reportDay must be an integer number in range of 1-31 for monthly frequency/)
|
|
908
|
-
|
|
909
|
-
})
|
|
933
|
+
}
|
|
910
934
|
})
|
|
911
|
-
it('Should throw an error when frequency is monthly and reportDay is a decimal number', (
|
|
935
|
+
it('Should throw an error when frequency is monthly and reportDay is a decimal number', async () => {
|
|
912
936
|
project.reportConfigurations[0].frequency = 'monthly'
|
|
913
937
|
project.reportConfigurations[0].reportDay = 1.5
|
|
914
938
|
let Project = new ProjectModel(project)
|
|
915
|
-
|
|
916
|
-
|
|
939
|
+
try {
|
|
940
|
+
await Project.validate()
|
|
941
|
+
} catch (err) {
|
|
942
|
+
assert.exists(err, 'err object should exist')
|
|
917
943
|
assert.match(err.message, /reportDay must be an integer number in range of 1-31 for monthly frequency/)
|
|
918
|
-
|
|
919
|
-
})
|
|
944
|
+
}
|
|
920
945
|
})
|
|
921
|
-
it('Should throw an error when reportDay is not a number', (
|
|
946
|
+
it('Should throw an error when reportDay is not a number', async () => {
|
|
922
947
|
project.reportConfigurations[0].reportDay = "dump"
|
|
923
948
|
let Project = new ProjectModel(project)
|
|
924
|
-
|
|
925
|
-
|
|
949
|
+
try {
|
|
950
|
+
await Project.validate()
|
|
951
|
+
} catch (err) {
|
|
952
|
+
assert.exists(err, 'err object should exist')
|
|
926
953
|
assert.match(err.message, /Cast to Number failed for value "dump" \(type string\) at path "reportDay"/)
|
|
927
|
-
|
|
928
|
-
})
|
|
954
|
+
}
|
|
929
955
|
})
|
|
930
|
-
it('Should throw an error when there are multiple report config with the same type', (
|
|
956
|
+
it('Should throw an error when there are multiple report config with the same type', async () => {
|
|
931
957
|
project.reportConfigurations.push({
|
|
932
958
|
"type": "hello",
|
|
933
959
|
"frequency": "monthly",
|
|
@@ -936,14 +962,15 @@ describe('Project', () => {
|
|
|
936
962
|
"recipients": "xyz@example.com"
|
|
937
963
|
})
|
|
938
964
|
let Project = new ProjectModel(project)
|
|
939
|
-
|
|
940
|
-
|
|
965
|
+
try {
|
|
966
|
+
await Project.validate()
|
|
967
|
+
} catch (err) {
|
|
968
|
+
assert.exists(err, 'err object should exist')
|
|
941
969
|
assert.match(err.message, /Multiple reports of the same type are not allowed/)
|
|
942
|
-
|
|
943
|
-
})
|
|
970
|
+
}
|
|
944
971
|
})
|
|
945
972
|
|
|
946
|
-
it('Should be successfull when there are multiple report types per project', (
|
|
973
|
+
it('Should be successfull when there are multiple report types per project', async () => {
|
|
947
974
|
project.reportConfigurations.push({
|
|
948
975
|
"type": "geo-trigger",
|
|
949
976
|
"frequency": "monthly",
|
|
@@ -952,62 +979,59 @@ describe('Project', () => {
|
|
|
952
979
|
"recipients": "xyz@example.com"
|
|
953
980
|
})
|
|
954
981
|
let Project = new ProjectModel(project)
|
|
955
|
-
Project.validate(
|
|
956
|
-
|
|
957
|
-
done()
|
|
958
|
-
})
|
|
982
|
+
const res = await Project.validate()
|
|
983
|
+
assert.notExists(res)
|
|
959
984
|
})
|
|
960
985
|
|
|
961
|
-
it('Should be successfully when the frequency is daily and reportDay is undefined', (
|
|
986
|
+
it('Should be successfully when the frequency is daily and reportDay is undefined', async () => {
|
|
962
987
|
project.reportConfigurations[0].frequency = "daily"
|
|
963
988
|
delete project.reportConfigurations[0].reportDay
|
|
964
989
|
let Project = new ProjectModel(project)
|
|
965
|
-
Project.validate(
|
|
966
|
-
|
|
967
|
-
done()
|
|
968
|
-
})
|
|
990
|
+
const res = await Project.validate()
|
|
991
|
+
assert.notExists(res)
|
|
969
992
|
})
|
|
970
993
|
|
|
971
|
-
it('Should be successfully when the frequency is daily and reportDay is any number', (
|
|
994
|
+
it('Should be successfully when the frequency is daily and reportDay is any number', async () => {
|
|
972
995
|
project.reportConfigurations[0].frequency = "daily"
|
|
973
996
|
project.reportConfigurations[0].reportDay = 100
|
|
974
997
|
let Project = new ProjectModel(project)
|
|
975
|
-
Project.validate(
|
|
976
|
-
|
|
977
|
-
done()
|
|
978
|
-
})
|
|
998
|
+
const res = await Project.validate()
|
|
999
|
+
assert.notExists(res)
|
|
979
1000
|
})
|
|
980
1001
|
|
|
981
|
-
it('Should throw an error when timezone is invalid', (
|
|
1002
|
+
it('Should throw an error when timezone is invalid', async () => {
|
|
982
1003
|
project.reportConfigurations[0].timezone = "Invalid"
|
|
983
1004
|
let Project = new ProjectModel(project)
|
|
984
|
-
|
|
985
|
-
|
|
1005
|
+
try {
|
|
1006
|
+
await Project.validate()
|
|
1007
|
+
} catch (err) {
|
|
1008
|
+
assert.exists(err, 'err object should exist')
|
|
986
1009
|
assert.match(err.message, /Invalid timezone/)
|
|
987
|
-
|
|
988
|
-
})
|
|
1010
|
+
}
|
|
989
1011
|
})
|
|
990
1012
|
|
|
991
|
-
it('Should throw an error when recipients are invalid', (
|
|
1013
|
+
it('Should throw an error when recipients are invalid', async () => {
|
|
992
1014
|
project.reportConfigurations[0].recipients = "abc@example.com, invalid-1, invalid-2@example"
|
|
993
1015
|
let Project = new ProjectModel(project)
|
|
994
|
-
|
|
995
|
-
|
|
1016
|
+
try {
|
|
1017
|
+
await Project.validate()
|
|
1018
|
+
} catch (err) {
|
|
1019
|
+
assert.exists(err, 'err object should exist')
|
|
996
1020
|
assert.match(err.message, /Invalid email address\(es\): invalid-1,invalid-2@example/)
|
|
997
|
-
|
|
998
|
-
})
|
|
1021
|
+
}
|
|
999
1022
|
})
|
|
1000
1023
|
})
|
|
1001
1024
|
|
|
1002
1025
|
describe("Doordash integration validation", () => {
|
|
1003
|
-
it('should throw an error when authorizationToken is missing', (
|
|
1026
|
+
it('should throw an error when authorizationToken is missing', async () => {
|
|
1004
1027
|
delete project.integrations.doordash.authorizationToken
|
|
1005
1028
|
let Project = new ProjectModel(project)
|
|
1006
|
-
|
|
1007
|
-
|
|
1029
|
+
try {
|
|
1030
|
+
await Project.validate()
|
|
1031
|
+
} catch (err) {
|
|
1032
|
+
assert.exists(err, 'err object should exist')
|
|
1008
1033
|
assert.match(err.message, /`authorizationToken` is required/)
|
|
1009
|
-
|
|
1010
|
-
})
|
|
1034
|
+
}
|
|
1011
1035
|
})
|
|
1012
1036
|
})
|
|
1013
1037
|
})
|
|
@@ -1017,8 +1041,8 @@ describe('Project', () => {
|
|
|
1017
1041
|
|
|
1018
1042
|
arrayTypeFields.map(arrayField => {
|
|
1019
1043
|
FALSY_VALUES.map(falsyValue => {
|
|
1020
|
-
it(`should throw an error when it contains ${falsyValue} on a ${arrayField}`, (
|
|
1021
|
-
helpers.testFalsyValue(falsyValue, arrayField, project, ProjectModel
|
|
1044
|
+
it(`should throw an error when it contains ${falsyValue} on a ${arrayField}`, async () => {
|
|
1045
|
+
await helpers.testFalsyValue(falsyValue, arrayField, project, ProjectModel)
|
|
1022
1046
|
})
|
|
1023
1047
|
})
|
|
1024
1048
|
})
|