@b-jones-rfd/qualtrics-api-tasks 0.2.0 → 0.3.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +6 -0
- package/README.md +155 -0
- package/dist/index.d.mts +356 -1
- package/dist/index.d.ts +356 -1
- package/dist/index.js +539 -81
- package/dist/index.mjs +528 -81
- package/package.json +1 -1
- package/tests/utils.test.ts +360 -0
package/tests/utils.test.ts
CHANGED
|
@@ -5,6 +5,15 @@ import {
|
|
|
5
5
|
safeParseTestResponse,
|
|
6
6
|
safeParseStartFileExportResponse,
|
|
7
7
|
safeParseFileProgressResponse,
|
|
8
|
+
safeParseCreateMailingListResponse,
|
|
9
|
+
safeParseStartContactsImportResponse,
|
|
10
|
+
safeParseContactsImportSummary,
|
|
11
|
+
safeParseContactsImportStatus,
|
|
12
|
+
safeParseCreateDistributionResponse,
|
|
13
|
+
safeParseCreateReminderResponse,
|
|
14
|
+
safeParseListLibraryMessages,
|
|
15
|
+
safeParseListDistributions,
|
|
16
|
+
safeParseGetDistribution,
|
|
8
17
|
} from '../src/utils/parsers'
|
|
9
18
|
|
|
10
19
|
describe('safeParseBearerToken', () => {
|
|
@@ -139,3 +148,354 @@ describe('safeParseTestResponse', () => {
|
|
|
139
148
|
expect(parsed).toStrictEqual(expected)
|
|
140
149
|
})
|
|
141
150
|
})
|
|
151
|
+
|
|
152
|
+
describe('safeParseCreateMailingListResponse', () => {
|
|
153
|
+
const fixture = {
|
|
154
|
+
result: {
|
|
155
|
+
id: 'testId',
|
|
156
|
+
},
|
|
157
|
+
}
|
|
158
|
+
|
|
159
|
+
it('should pass with correct data', () => {
|
|
160
|
+
const res = fixture
|
|
161
|
+
const expected = success(fixture.result.id)
|
|
162
|
+
const parsed = safeParseCreateMailingListResponse(res)
|
|
163
|
+
expect(parsed).toStrictEqual(expected)
|
|
164
|
+
})
|
|
165
|
+
|
|
166
|
+
it('should fail when response is incorrect type', () => {
|
|
167
|
+
const res = {
|
|
168
|
+
meta: 'bad result',
|
|
169
|
+
}
|
|
170
|
+
const expected = failure(`Unable to parse Create Mailing List Response`)
|
|
171
|
+
const parsed = safeParseCreateMailingListResponse(res)
|
|
172
|
+
expect(parsed).toStrictEqual(expected)
|
|
173
|
+
})
|
|
174
|
+
|
|
175
|
+
it('should fail when id is not in response', () => {
|
|
176
|
+
const res = {
|
|
177
|
+
result: {
|
|
178
|
+
badProp: 'Test',
|
|
179
|
+
},
|
|
180
|
+
}
|
|
181
|
+
const expected = failure(`Id missing in Create Mailing List Response`)
|
|
182
|
+
const parsed = safeParseCreateMailingListResponse(res)
|
|
183
|
+
expect(parsed).toStrictEqual(expected)
|
|
184
|
+
})
|
|
185
|
+
})
|
|
186
|
+
|
|
187
|
+
describe('safeParseStartContactsImportResponse', () => {
|
|
188
|
+
const fixture = {
|
|
189
|
+
result: {
|
|
190
|
+
id: 'someId',
|
|
191
|
+
contacts: [{ name: 'some name' }],
|
|
192
|
+
tracking: {},
|
|
193
|
+
status: 'Progress',
|
|
194
|
+
},
|
|
195
|
+
}
|
|
196
|
+
|
|
197
|
+
it('should pass with correct data', () => {
|
|
198
|
+
const res = fixture
|
|
199
|
+
const expected = success(fixture.result)
|
|
200
|
+
const parsed = safeParseStartContactsImportResponse(res)
|
|
201
|
+
expect(parsed).toStrictEqual(expected)
|
|
202
|
+
})
|
|
203
|
+
|
|
204
|
+
it('should fail with missing props', () => {
|
|
205
|
+
const res = {
|
|
206
|
+
result: {
|
|
207
|
+
contacts: [{ name: 'some name' }],
|
|
208
|
+
tracking: {},
|
|
209
|
+
status: 'Progress',
|
|
210
|
+
},
|
|
211
|
+
}
|
|
212
|
+
const expected = failure('Start contacts import response invalid format')
|
|
213
|
+
const parsed = safeParseStartContactsImportResponse(res)
|
|
214
|
+
expect(parsed).toStrictEqual(expected)
|
|
215
|
+
})
|
|
216
|
+
})
|
|
217
|
+
|
|
218
|
+
describe('safeParseContactImportSummary', () => {
|
|
219
|
+
const fixture = {
|
|
220
|
+
result: {
|
|
221
|
+
percentComplete: 0,
|
|
222
|
+
contacts: {
|
|
223
|
+
count: {
|
|
224
|
+
added: 100,
|
|
225
|
+
updated: 20,
|
|
226
|
+
failed: 0,
|
|
227
|
+
},
|
|
228
|
+
},
|
|
229
|
+
invalidEmails: ['someone@anyisp.com'],
|
|
230
|
+
transactions: {
|
|
231
|
+
count: {
|
|
232
|
+
created: 100,
|
|
233
|
+
},
|
|
234
|
+
},
|
|
235
|
+
status: 'Complete',
|
|
236
|
+
},
|
|
237
|
+
}
|
|
238
|
+
|
|
239
|
+
it('should pass with correct data', () => {
|
|
240
|
+
const res = fixture
|
|
241
|
+
const expected = success(fixture.result)
|
|
242
|
+
const parsed = safeParseContactsImportSummary(res)
|
|
243
|
+
expect(parsed).toStrictEqual(expected)
|
|
244
|
+
})
|
|
245
|
+
|
|
246
|
+
it('should fail when error response', () => {
|
|
247
|
+
const res = {
|
|
248
|
+
error: {
|
|
249
|
+
errorCode: '401',
|
|
250
|
+
errorMessage: 'Some error',
|
|
251
|
+
},
|
|
252
|
+
}
|
|
253
|
+
const expected = failure(`Unable to parse Contacts Import Summary Response`)
|
|
254
|
+
const parsed = safeParseContactsImportSummary(res)
|
|
255
|
+
expect(parsed).toStrictEqual(expected)
|
|
256
|
+
})
|
|
257
|
+
|
|
258
|
+
it('should fail with missing props', () => {
|
|
259
|
+
const res = {
|
|
260
|
+
result: {
|
|
261
|
+
percentComplete: 0,
|
|
262
|
+
status: 'inProgress',
|
|
263
|
+
},
|
|
264
|
+
}
|
|
265
|
+
const expected = failure('Contacts import summary response invalid format')
|
|
266
|
+
const parsed = safeParseContactsImportSummary(res)
|
|
267
|
+
expect(parsed).toStrictEqual(expected)
|
|
268
|
+
})
|
|
269
|
+
})
|
|
270
|
+
|
|
271
|
+
describe('safeParseContactImportStatus', () => {
|
|
272
|
+
const fixture = {
|
|
273
|
+
result: {
|
|
274
|
+
percentComplete: 0,
|
|
275
|
+
contacts: {
|
|
276
|
+
count: {
|
|
277
|
+
added: 100,
|
|
278
|
+
updated: 20,
|
|
279
|
+
failed: 0,
|
|
280
|
+
},
|
|
281
|
+
},
|
|
282
|
+
transactions: {
|
|
283
|
+
count: {
|
|
284
|
+
created: 100,
|
|
285
|
+
},
|
|
286
|
+
},
|
|
287
|
+
status: 'inProgress',
|
|
288
|
+
},
|
|
289
|
+
}
|
|
290
|
+
|
|
291
|
+
it('should pass with correct data', () => {
|
|
292
|
+
const res = fixture
|
|
293
|
+
const expected = success(fixture.result)
|
|
294
|
+
const parsed = safeParseContactsImportStatus(res)
|
|
295
|
+
expect(parsed).toStrictEqual(expected)
|
|
296
|
+
})
|
|
297
|
+
|
|
298
|
+
it('should fail when error response', () => {
|
|
299
|
+
const res = {
|
|
300
|
+
error: {
|
|
301
|
+
errorCode: '401',
|
|
302
|
+
errorMessage: 'Some error',
|
|
303
|
+
},
|
|
304
|
+
}
|
|
305
|
+
const expected = failure(`Unable to parse Contacts Import Summary Response`)
|
|
306
|
+
const parsed = safeParseContactsImportStatus(res)
|
|
307
|
+
expect(parsed).toStrictEqual(expected)
|
|
308
|
+
})
|
|
309
|
+
|
|
310
|
+
it('should fail with missing props', () => {
|
|
311
|
+
const res = {
|
|
312
|
+
result: {
|
|
313
|
+
percentComplete: 0,
|
|
314
|
+
status: 'inProgress',
|
|
315
|
+
},
|
|
316
|
+
}
|
|
317
|
+
const expected = failure('Contacts import summary response invalid format')
|
|
318
|
+
const parsed = safeParseContactsImportStatus(res)
|
|
319
|
+
expect(parsed).toStrictEqual(expected)
|
|
320
|
+
})
|
|
321
|
+
})
|
|
322
|
+
|
|
323
|
+
describe('safeParseCreateDistributionResponse', () => {
|
|
324
|
+
const fixture = {
|
|
325
|
+
result: {
|
|
326
|
+
id: 'testId',
|
|
327
|
+
},
|
|
328
|
+
}
|
|
329
|
+
|
|
330
|
+
it('should pass with correct data', () => {
|
|
331
|
+
const res = fixture
|
|
332
|
+
const expected = success(fixture.result.id)
|
|
333
|
+
const parsed = safeParseCreateDistributionResponse(res)
|
|
334
|
+
expect(parsed).toStrictEqual(expected)
|
|
335
|
+
})
|
|
336
|
+
|
|
337
|
+
it('should fail when response is incorrect type', () => {
|
|
338
|
+
const res = {
|
|
339
|
+
meta: 'bad result',
|
|
340
|
+
}
|
|
341
|
+
const expected = failure(`Unable to parse Create Distribution Response`)
|
|
342
|
+
const parsed = safeParseCreateDistributionResponse(res)
|
|
343
|
+
expect(parsed).toStrictEqual(expected)
|
|
344
|
+
})
|
|
345
|
+
|
|
346
|
+
it('should fail when id is not in response', () => {
|
|
347
|
+
const res = {
|
|
348
|
+
result: {
|
|
349
|
+
badProp: 'Test',
|
|
350
|
+
},
|
|
351
|
+
}
|
|
352
|
+
const expected = failure(`Id missing in Create Distribution Response`)
|
|
353
|
+
const parsed = safeParseCreateDistributionResponse(res)
|
|
354
|
+
expect(parsed).toStrictEqual(expected)
|
|
355
|
+
})
|
|
356
|
+
})
|
|
357
|
+
|
|
358
|
+
describe('safeParseCreateReminderResponse', () => {
|
|
359
|
+
const fixture = {
|
|
360
|
+
result: {
|
|
361
|
+
distributionId: 'testId',
|
|
362
|
+
},
|
|
363
|
+
}
|
|
364
|
+
|
|
365
|
+
it('should pass with correct data', () => {
|
|
366
|
+
const res = fixture
|
|
367
|
+
const expected = success(fixture.result.distributionId)
|
|
368
|
+
const parsed = safeParseCreateReminderResponse(res)
|
|
369
|
+
expect(parsed).toStrictEqual(expected)
|
|
370
|
+
})
|
|
371
|
+
|
|
372
|
+
it('should fail when response is incorrect type', () => {
|
|
373
|
+
const res = {
|
|
374
|
+
meta: 'bad result',
|
|
375
|
+
}
|
|
376
|
+
const expected = failure(`Unable to parse Create Reminder Response`)
|
|
377
|
+
const parsed = safeParseCreateReminderResponse(res)
|
|
378
|
+
expect(parsed).toStrictEqual(expected)
|
|
379
|
+
})
|
|
380
|
+
|
|
381
|
+
it('should fail when id is not in response', () => {
|
|
382
|
+
const res = {
|
|
383
|
+
result: {
|
|
384
|
+
badProp: 'Test',
|
|
385
|
+
},
|
|
386
|
+
}
|
|
387
|
+
const expected = failure(
|
|
388
|
+
`distributionId missing in Create Reminder Response`
|
|
389
|
+
)
|
|
390
|
+
const parsed = safeParseCreateReminderResponse(res)
|
|
391
|
+
expect(parsed).toStrictEqual(expected)
|
|
392
|
+
})
|
|
393
|
+
})
|
|
394
|
+
|
|
395
|
+
describe('safeParseListLibraryMessages', () => {
|
|
396
|
+
const fixture = {
|
|
397
|
+
result: {
|
|
398
|
+
elements: [],
|
|
399
|
+
},
|
|
400
|
+
}
|
|
401
|
+
|
|
402
|
+
it('should pass with correct data', () => {
|
|
403
|
+
const res = fixture
|
|
404
|
+
const expected = success(fixture.result)
|
|
405
|
+
const parsed = safeParseListLibraryMessages(res)
|
|
406
|
+
expect(parsed).toStrictEqual(expected)
|
|
407
|
+
})
|
|
408
|
+
|
|
409
|
+
it('should fail when response is incorrect type', () => {
|
|
410
|
+
const res = {
|
|
411
|
+
meta: 'bad result',
|
|
412
|
+
}
|
|
413
|
+
const expected = failure(`Unable to parse List Library Messages response`)
|
|
414
|
+
const parsed = safeParseListLibraryMessages(res)
|
|
415
|
+
expect(parsed).toStrictEqual(expected)
|
|
416
|
+
})
|
|
417
|
+
|
|
418
|
+
it('should fail when id is not in response', () => {
|
|
419
|
+
const res = {
|
|
420
|
+
result: {
|
|
421
|
+
badProp: 'Test',
|
|
422
|
+
},
|
|
423
|
+
}
|
|
424
|
+
const expected = failure(
|
|
425
|
+
`elements missing in List Library Messages response`
|
|
426
|
+
)
|
|
427
|
+
const parsed = safeParseListLibraryMessages(res)
|
|
428
|
+
expect(parsed).toStrictEqual(expected)
|
|
429
|
+
})
|
|
430
|
+
})
|
|
431
|
+
|
|
432
|
+
describe('safeParseGetDistribution', () => {
|
|
433
|
+
const fixture = {
|
|
434
|
+
result: {
|
|
435
|
+
id: 'testID',
|
|
436
|
+
stats: {},
|
|
437
|
+
},
|
|
438
|
+
}
|
|
439
|
+
|
|
440
|
+
it('should pass with correct data', () => {
|
|
441
|
+
const res = fixture
|
|
442
|
+
const expected = success(fixture.result)
|
|
443
|
+
const parsed = safeParseGetDistribution(res)
|
|
444
|
+
expect(parsed).toStrictEqual(expected)
|
|
445
|
+
})
|
|
446
|
+
|
|
447
|
+
it('should fail when response is incorrect type', () => {
|
|
448
|
+
const res = {
|
|
449
|
+
meta: 'bad result',
|
|
450
|
+
}
|
|
451
|
+
const expected = failure(`Unable to parse Get Distribution response`)
|
|
452
|
+
const parsed = safeParseGetDistribution(res)
|
|
453
|
+
expect(parsed).toStrictEqual(expected)
|
|
454
|
+
})
|
|
455
|
+
|
|
456
|
+
it('should fail when id is not in response', () => {
|
|
457
|
+
const res = {
|
|
458
|
+
result: {
|
|
459
|
+
badProp: 'Test',
|
|
460
|
+
},
|
|
461
|
+
}
|
|
462
|
+
const expected = failure(`Properties missing in Get Distribution response`)
|
|
463
|
+
const parsed = safeParseGetDistribution(res)
|
|
464
|
+
expect(parsed).toStrictEqual(expected)
|
|
465
|
+
})
|
|
466
|
+
})
|
|
467
|
+
|
|
468
|
+
describe('safeParseListDistributions', () => {
|
|
469
|
+
const fixture = {
|
|
470
|
+
result: {
|
|
471
|
+
elements: [],
|
|
472
|
+
},
|
|
473
|
+
}
|
|
474
|
+
|
|
475
|
+
it('should pass with correct data', () => {
|
|
476
|
+
const res = fixture
|
|
477
|
+
const expected = success(fixture.result)
|
|
478
|
+
const parsed = safeParseListDistributions(res)
|
|
479
|
+
expect(parsed).toStrictEqual(expected)
|
|
480
|
+
})
|
|
481
|
+
|
|
482
|
+
it('should fail when response is incorrect type', () => {
|
|
483
|
+
const res = {
|
|
484
|
+
meta: 'bad result',
|
|
485
|
+
}
|
|
486
|
+
const expected = failure(`Unable to parse List Distribution response`)
|
|
487
|
+
const parsed = safeParseListDistributions(res)
|
|
488
|
+
expect(parsed).toStrictEqual(expected)
|
|
489
|
+
})
|
|
490
|
+
|
|
491
|
+
it('should fail when id is not in response', () => {
|
|
492
|
+
const res = {
|
|
493
|
+
result: {
|
|
494
|
+
badProp: 'Test',
|
|
495
|
+
},
|
|
496
|
+
}
|
|
497
|
+
const expected = failure(`elements missing in List Distributions response`)
|
|
498
|
+
const parsed = safeParseListDistributions(res)
|
|
499
|
+
expect(parsed).toStrictEqual(expected)
|
|
500
|
+
})
|
|
501
|
+
})
|