piper-utils 1.1.27 → 1.1.30

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.
@@ -358,7 +358,60 @@ describe('requestResponse', () => {
358
358
  ]
359
359
  };
360
360
  const r = detectJoyError(body);
361
- expect(r).toEqual({ message: '"value" does not match any of the allowed types "businessId" is required "encryptedAccount" is required', statusCode: 400, errorCode: '4000' });
361
+ expect(r).toEqual({ message: '"businessId" is required, "encryptedAccount" is required', statusCode: 400, errorCode: '4000' });
362
+ });
363
+ it('should extract leaf messages from deeply nested Joy errors', () => {
364
+ const body = {
365
+ details: [
366
+ {
367
+ message: '"customer.contacts[2]" does not match any of the allowed types',
368
+ path: ['customer', 'contacts', 2],
369
+ type: 'alternatives.any',
370
+ context: {
371
+ details: [
372
+ {
373
+ message: '"customer.contacts[2]" does not match any of the allowed types',
374
+ details: [
375
+ {
376
+ message: '"customer.contacts[2].email" is required',
377
+ path: ['customer', 'contacts', 2, 'email'],
378
+ type: 'any.required',
379
+ context: { label: 'customer.contacts[2].email', key: 'email' }
380
+ },
381
+ {
382
+ message: '"customer.contacts[2].phone" is required',
383
+ path: ['customer', 'contacts', 2, 'phone'],
384
+ type: 'any.required',
385
+ context: { label: 'customer.contacts[2].phone', key: 'phone' }
386
+ }
387
+ ]
388
+ }
389
+ ],
390
+ label: 'customer.contacts[2]'
391
+ }
392
+ }
393
+ ]
394
+ };
395
+ const r = detectJoyError(body);
396
+ expect(r).toEqual({
397
+ message: '"customer.contacts[2].email" is required, "customer.contacts[2].phone" is required',
398
+ statusCode: 400,
399
+ errorCode: '4000'
400
+ });
401
+ });
402
+ it('should handle simple non-nested Joy errors', () => {
403
+ const body = {
404
+ details: [
405
+ {
406
+ message: '"name" is required',
407
+ path: ['name'],
408
+ type: 'any.required',
409
+ context: { label: 'name', key: 'name' }
410
+ }
411
+ ]
412
+ };
413
+ const r = detectJoyError(body);
414
+ expect(r).toEqual({ message: '"name" is required', statusCode: 400, errorCode: '4000' });
362
415
  });
363
416
  });
364
417
  });