@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.
@@ -22,37 +22,29 @@ beforeEach(() => {
22
22
 
23
23
  describe('Project', () => {
24
24
  describe('Valid Project ', () => {
25
- assertions('should validate a valid project ', (done) => {
25
+ assertions('should validate a valid project ', async () => {
26
26
  let Project = new ProjectModel(project)
27
- Project.validate((err, res) => {
28
- console.log(err)
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', (done) => {
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((err, res) => {
39
- assert.notExists(err)
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', (done) => {
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((err, res) => {
50
- assert.notExists(err)
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', (done) => {
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((err, res) => {
64
- assert.notExists(err)
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', (done) => {
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((err, res) => {
84
- assert.notExists(err)
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', (done) => {
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((err, res) => {
93
- assert.notExists(res)
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', (done) => {
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((err, res) => {
112
- assert.notExists(res)
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', (done) => {
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((err, res) => {
122
- assert.notExists(res)
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`, (done) => {
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((err, res) => {
180
- assert.notExists(err)
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 ', (done) => {
163
+ assertions('should validate a valid project ', async () => {
187
164
  let Project = new ProjectModelBuiltInMongoose(project)
188
- Project.validate((err, res) => {
189
- assert.notExists(res)
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 ', (done) => {
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
- Project.validate((err, res) => {
203
- assert.exists(err)
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
- done()
206
- })
181
+ }
207
182
  })
208
- assertions('should throw an error if the mparticle integration has a key with empty string ', (done) => {
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
- Project.validate((err, res) => {
213
- assert.exists(err)
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
- done()
216
- })
192
+ }
217
193
  })
218
194
 
219
- assertions('should throw an error if the mparticle integration misses all keys ', (done) => {
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
- Project.validate((err, res) => {
225
- assert.exists(err)
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
- done()
228
- })
205
+ }
229
206
  })
230
207
 
231
- assertions('should throw an error if trigger is selected but no android or ios keys provided', (done) => {
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
- Project.validate((err, res) => {
238
- assert.exists(err)
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
- done()
241
- })
220
+ }
242
221
  })
243
- assertions('should throw an error if tempo is selected but no android or ios keys provided', (done) => {
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
- Project.validate((err, res) => {
250
- assert.exists(err)
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
- done()
253
- })
233
+ }
254
234
  })
255
235
 
256
- assertions('should throw an error if wave is selected but no web keys provided', (done) => {
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
- Project.validate((err, res) => {
262
- assert.exists(err)
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
- done()
265
- })
246
+ }
266
247
  })
267
- assertions('should throw an error if hello is selected but no web keys provided', (done) => {
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
- Project.validate((err, res) => {
273
- assert.exists(err)
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
- done()
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`, (done) => {
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
- Project.validate((err, res) => {
287
- assert.notExists(res)
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
- done()
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}`, (done) => {
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
- Project.validate((err, res) => {
306
- assert.notExists(res)
287
+ try {
288
+ await Project.validate()
289
+ } catch (err) {
307
290
  assert.exists(err, 'err object should exist')
308
- // assert.isObject(err.errors)
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`, (done) => {
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, done)
300
+ await helpers.testNullValue(project, ProjectModel)
321
301
  })
322
302
 
323
- it('should not validate if tempo.isochroneBracketInterval contains items other than integer', (done) => {
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
- Project.validate((err, res) => {
327
- assert.exists(err)
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
- done()
330
- })
311
+ }
331
312
  })
332
313
 
333
- it('should not validate if hello.activeTtl is not an integer', (done) => {
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
- Project.validate((err, res) => {
337
- assert.exists(err)
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
- done()
340
- })
322
+ }
341
323
  })
342
324
 
343
- it('should not validate if hello.finalTtl is not an integer', (done) => {
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
- Project.validate((err, res) => {
347
- assert.exists(err)
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
- done()
350
- })
333
+ }
351
334
  })
352
335
 
353
- it('should not validate if hello.finalTtl is a negative', (done) => {
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
- Project.validate((err, res) => {
357
- assert.exists(err)
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
- done()
360
- })
344
+ }
361
345
  })
362
346
 
363
- it('should not validate if hello.activeTtl is a negative', (done) => {
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
- Project.validate((err, res) => {
367
- assert.exists(err)
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
- done()
370
- })
355
+ }
371
356
  })
372
357
 
373
- it('should not validate if hello.finalTtl is a greater than the maximum', (done) => {
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
- Project.validate((err, res) => {
377
- console.log(err)
378
- assert.exists(err)
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
- done()
381
- })
366
+ }
382
367
  })
383
368
 
384
- it('should not validate if hello.activeTtl is a greater than the maximum', (done) => {
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
- Project.validate((err, res) => {
388
- assert.exists(err)
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
- done()
391
- })
377
+ }
392
378
  })
393
379
 
394
380
  describe("webhook validation", () => {
395
- assertions(`should not validate if webhook protocol is not valid `, (done) => {
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
- Project.validate((err, res) => {
399
- assert.exists(err)
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
- done()
402
- })
389
+ }
403
390
  })
404
- assertions(`should not validate if webhook domain is not valid `, (done) => {
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
- Project.validate((err, res) => {
408
- assert.exists(err)
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
- done()
411
- })
399
+ }
412
400
  })
413
401
 
414
- assertions(`should not validate if one of webhooks have a type other than 'tempo', 'wave' or 'trigger'`, (done) => {
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
- Project.validate((err, res) => {
424
- assert.exists(err)
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
- done()
427
- })
416
+ }
428
417
  })
429
418
 
430
- it(`should throw an error when webhooks is null`, (done) => {
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, done)
422
+ await helpers.testNullValue(project, ProjectModel)
434
423
  })
435
424
 
436
- it(`should throw an error when webhooks has primitive value in headers`, (done) => {
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, done)
428
+ await helpers.testNullValue(project, ProjectModel)
440
429
  })
441
- it(`should throw an error when webhooks has array in headers`, (done) => {
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, done)
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`, (done) => {
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
- Project.validate((err, res) => {
452
- assert.exists(err)
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
- done()
455
- })
445
+ }
456
446
  })
457
447
 
458
- it(`should throw an error when webhooks has a number as a value in body`, (done) => {
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
- Project.validate((err, res) => {
463
- assert.exists(err)
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
- done()
466
- })
457
+ }
467
458
  })
468
459
 
469
- it(`should throw an error if a structure is used that is not tealium or standard`, (done) => {
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
- Project.validate((err, res) => {
474
- assert.exists(err)
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
- done()
477
- })
469
+ }
478
470
  })
479
471
 
480
- it(`should throw an error if structure is tealium and tealium_account is not a body field`, (done) => {
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
- Project.validate((err, res) => {
485
- assert.exists(err)
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
- done()
488
- })
481
+ }
489
482
  })
490
483
 
491
- it(`should throw an error if structure is tealium and tealium_profile is not a body field`, (done) => {
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
- Project.validate((err, res) => {
496
- assert.exists(err)
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
- done()
499
- })
493
+ }
500
494
  })
501
495
 
502
- it(`should not validate if structure is tealium and body is not present`, (done) => {
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
- Project.validate((err, res) => {
507
- assert.exists(err)
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
- done()
510
- })
505
+ }
511
506
  })
512
507
 
513
- it(`should not validate if structure is tealium and body is an empty object`, (done) => {
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
- Project.validate((err, res) => {
518
- assert.exists(err)
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
- done()
521
- })
517
+ }
522
518
  })
523
- it(`should throw an error if structure is mobivity and taregt_id is not a body field`, (done) => {
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
- Project.validate((err, res) => {
529
- assert.exists(err)
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
- done()
532
- })
529
+ }
533
530
  })
534
531
 
535
- it(`should throw an error if structure is mobivity and message_text is not a body field`, (done) => {
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
- Project.validate((err, res) => {
541
- assert.exists(err)
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
- done()
544
- })
542
+ }
545
543
  })
546
544
 
547
- it(`should throw an error if structure is mobivity and username is not a body field`, (done) => {
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
- Project.validate((err, res) => {
553
- assert.exists(err)
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
- done()
556
- })
555
+ }
557
556
  })
558
557
 
559
- it(`should not validate if structure is mobivity and body is not present`, (done) => {
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
- Project.validate((err, res) => {
565
- assert.exists(err)
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
- done()
568
- })
568
+ }
569
569
  })
570
570
 
571
- it(`should not validate if structure is mobivity and body is an empty object`, (done) => {
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
- Project.validate((err, res) => {
577
- assert.exists(err)
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
- done()
580
- })
581
+ }
581
582
  })
582
583
 
583
- it(`should not validate if structure is mobivity and the type is not register`, (done) => {
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
- Project.validate((err, res) => {
588
- assert.exists(err)
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
- done()
591
- })
593
+ }
592
594
  })
593
- it(`should not validate if the type is register and the structure is not mobivity`, (done) => {
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
- Project.validate((err, res) => {
598
- assert.exists(err)
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
- done()
601
- })
604
+ }
602
605
  })
603
606
 
604
- it(`should not validate if the type is hellOrder and the structure is not default`, (done) => {
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
- Project.validate((err, res) => {
609
- assert.exists(err)
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
- done()
612
- })
616
+ }
613
617
  })
614
- it(`should not validate if structure is default and the type is not helloOrder`, (done) => {
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
- Project.validate((err, res) => {
619
- assert.exists(err)
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
- done()
622
- })
627
+ }
623
628
  })
624
629
 
625
- it(`should not validate if structure is 2.0 and the type is not trigger`, (done) => {
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
- Project.validate((err, res) => {
631
- assert.exists(err)
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
- done()
634
- })
640
+ }
635
641
  })
636
642
 
637
- it("should not validate webhook if body contains keys with spaces", (done) => {
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
- Project.validate((err, res) => {
641
- assert.exists(err)
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
- done()
644
- })
651
+ }
645
652
  })
646
653
 
647
- it("should not validate webhook if headers contains keys with spaces", (done) => {
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
- Project.validate((err, res) => {
651
- assert.exists(err)
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
- done()
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`, (done) => {
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
- Project.validate((err, res) => {
673
- assert.exists(err)
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
- done()
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', (done) => {
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
- Project.validate((err, res) => {
687
- assert.exists(err)
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
- done()
690
- })
700
+ }
691
701
  })
692
702
  })
693
703
 
694
704
  describe("oneSignal integration validation", () => {
695
- it('should throw an error when appId is missing', (done) => {
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
- Project.validate((err, res) => {
699
- assert.exists(err)
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
- done()
702
- })
713
+ }
703
714
  })
704
715
 
705
- it('should throw an error when wave is non boolean', (done) => {
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
- Project.validate((err, res) => {
709
- assert.exists(err)
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
- done()
712
- })
724
+ }
713
725
  })
714
726
  })
715
727
  describe("Attentive integration validation", () => {
716
- it('should throw an error when trigger is non boolean', (done) => {
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
- Project.validate((err, res) => {
720
- assert.exists(err)
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
- done()
723
- })
736
+ }
724
737
  })
725
738
 
726
- it('should throw an error when helloRegister is non boolean', (done) => {
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
- Project.validate((err, res) => {
730
- assert.exists(err)
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
- done()
733
- })
747
+ }
734
748
  })
735
749
  })
736
750
 
737
751
  describe("Incentivio integration validation", () => {
738
- it('should throw an error when clientId is missing', (done) => {
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
- Project.validate((err, res) => {
742
- assert.exists(err)
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
- done()
745
- })
760
+ }
746
761
  })
747
762
 
748
- it('should throw an error when nowReadyEnabled is non boolean', (done) => {
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
- Project.validate((err, res) => {
752
- assert.exists(err)
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
- done()
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", (done) => {
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
- Project.validate((err, res) => {
764
- assert.notExists(res)
765
- assert.exists(err)
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
- done()
768
- })
784
+ }
769
785
  })
770
786
 
771
- it("should throw an error if ssoLinkingCode is longer than 12 characters", (done) => {
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
- Project.validate((err, res) => {
775
- assert.notExists(res)
776
- assert.exists(err)
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
- done()
779
- })
795
+ }
780
796
  })
781
797
 
782
- it("should throw an error if ssoLinkingCode include lowercase characters", (done) => {
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
- Project.validate((err, res) => {
786
- assert.notExists(res)
787
- assert.exists(err)
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
- done()
790
- })
806
+ }
791
807
  })
792
808
 
793
- it("should throw an error if ssoLinkingCode is empty", (done) => {
809
+ it("should throw an error if ssoLinkingCode is empty", async () => {
794
810
  project.hello.ssoLinkingCode = ""
795
811
  let Project = new ProjectModel(project)
796
- Project.validate((err, res) => {
797
- assert.notExists(res)
798
- assert.exists(err)
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
- done()
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', (done) => {
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
- Project.validate((err, res) => {
810
- assert.exists(err)
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
- done()
813
- })
830
+ }
814
831
  })
815
- it('should throw an error when trigger is non boolean', (done) => {
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
- Project.validate((err, res) => {
819
- assert.exists(err)
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
- done()
822
- })
840
+ }
823
841
  })
824
- it('should throw an error when tempo is non boolean', (done) => {
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
- Project.validate((err, res) => {
828
- assert.exists(err)
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
- done()
831
- })
850
+ }
832
851
  })
833
- it('should throw an error when wave is non boolean', (done) => {
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
- Project.validate((err, res) => {
837
- assert.exists(err)
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
- done()
840
- })
860
+ }
841
861
  })
842
- it('should throw an error when hello is non boolean', (done) => {
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
- Project.validate((err, res) => {
846
- assert.exists(err)
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
- done()
849
- })
870
+ }
850
871
  })
851
872
  })
852
873
 
853
874
  describe("reportConfigurations validation", () => {
854
- it('Should successfully create project without reportConfigurations', (done) => {
875
+ it('Should successfully create project without reportConfigurations', async () => {
855
876
  delete project.reportConfigurations
856
877
  let Project = new ProjectModel(project)
857
- Project.validate((err, res) => {
858
- assert.notExists(err)
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', (done) => {
881
+ it('Should throw an error when reportConfigurations is null', async () => {
863
882
  project.reportConfigurations = null
864
883
  let Project = new ProjectModel(project)
865
- Project.validate((err, res) => {
866
- assert.exists(err)
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
- done()
869
- })
889
+ }
870
890
  })
871
- it('Should throw an error when frequency is undefined', (done) => {
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
- Project.validate((err, res) => {
875
- assert.exists(err)
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
- done()
878
- })
899
+ }
879
900
  })
880
901
 
881
- it('Should throw an error when frequency is invalid', (done) => {
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
- Project.validate((err, res) => {
885
- assert.exists(err)
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
- done()
888
- })
910
+ }
889
911
  })
890
912
 
891
- it('Should throw an error when frequency is weekly and reportDay is not in range 0-6', (done) => {
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
- Project.validate((err, res) => {
896
- assert.exists(err)
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
- done()
899
- })
922
+ }
900
923
  })
901
- it('Should throw an error when frequency is monthly and reportDay is not in range 1-31', (done) => {
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
- Project.validate((err, res) => {
906
- assert.exists(err)
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
- done()
909
- })
933
+ }
910
934
  })
911
- it('Should throw an error when frequency is monthly and reportDay is a decimal number', (done) => {
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
- Project.validate((err, res) => {
916
- assert.exists(err)
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
- done()
919
- })
944
+ }
920
945
  })
921
- it('Should throw an error when reportDay is not a number', (done) => {
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
- Project.validate((err, res) => {
925
- assert.exists(err)
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
- done()
928
- })
954
+ }
929
955
  })
930
- it('Should throw an error when there are multiple report config with the same type', (done) => {
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
- Project.validate((err, res) => {
940
- assert.exists(err)
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
- done()
943
- })
970
+ }
944
971
  })
945
972
 
946
- it('Should be successfull when there are multiple report types per project', (done) => {
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,74 +979,59 @@ describe('Project', () => {
952
979
  "recipients": "xyz@example.com"
953
980
  })
954
981
  let Project = new ProjectModel(project)
955
- Project.validate((err, res) => {
956
- assert.notExists(err)
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', (done) => {
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((err, res) => {
966
- assert.notExists(err)
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', (done) => {
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((err, res) => {
976
- assert.notExists(err)
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', (done) => {
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
- Project.validate((err, res) => {
985
- assert.exists(err)
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
- done()
988
- })
1010
+ }
989
1011
  })
990
1012
 
991
- it('Should throw an error when recipients are invalid', (done) => {
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
- Project.validate((err, res) => {
995
- assert.exists(err)
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
- done()
998
- })
1021
+ }
999
1022
  })
1000
1023
  })
1001
1024
 
1002
1025
  describe("Doordash integration validation", () => {
1003
- it('should throw an error when authorizationToken is missing', (done) => {
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
- Project.validate((err, res) => {
1007
- assert.exists(err)
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
- done()
1010
- })
1011
- })
1012
- })
1013
-
1014
- describe("UberEats integration validation", () => {
1015
- it('should throw an error when signingKey is missing', (done) => {
1016
- delete project.integrations.uberEats.signingKey
1017
- let Project = new ProjectModel(project)
1018
- Project.validate((err, res) => {
1019
- assert.exists(err)
1020
- assert.match(err.message, /`signingKey` is required/)
1021
- done()
1022
- })
1034
+ }
1023
1035
  })
1024
1036
  })
1025
1037
  })
@@ -1029,8 +1041,8 @@ describe('Project', () => {
1029
1041
 
1030
1042
  arrayTypeFields.map(arrayField => {
1031
1043
  FALSY_VALUES.map(falsyValue => {
1032
- it(`should throw an error when it contains ${falsyValue} on a ${arrayField}`, (done) => {
1033
- helpers.testFalsyValue(falsyValue, arrayField, project, ProjectModel, done)
1044
+ it(`should throw an error when it contains ${falsyValue} on a ${arrayField}`, async () => {
1045
+ await helpers.testFalsyValue(falsyValue, arrayField, project, ProjectModel)
1034
1046
  })
1035
1047
  })
1036
1048
  })