@intuned/browser-dev 0.1.5-dev.1 → 0.1.6-dev.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/RELEASE.md +11 -9
- package/dist/ai/export.d.ts +1 -7
- package/dist/ai/extractStructuredData.js +1 -1
- package/dist/ai/extractStructuredDataUsingAi.js +23 -2
- package/dist/ai/extractionHelpers/validateSchema.js +34 -2
- package/dist/ai/index.d.ts +1 -7
- package/dist/ai/tests/testExtractStructuredData.spec.js +150 -18
- package/dist/ai/tests/testIsPageLoaded.spec.js +1 -1
- package/dist/ai/types/models.js +2 -5
- package/dist/ai/validators.js +1 -1
- package/dist/common/aiModelsValidations.js +2 -4
- package/dist/helpers/downloadFile.js +1 -3
- package/dist/helpers/frame_utils/checkFrameAllowsAsyncScripts.js +20 -0
- package/dist/helpers/frame_utils/findAllIframes.js +4 -1
- package/dist/helpers/frame_utils/tests/testFindAllIframes.spec.js +43 -0
- package/dist/helpers/tests/testDownloadFile.spec.js +3 -4
- package/dist/helpers/tests/testResolveUrl.spec.js +4 -4
- package/dist/helpers/tests/testValidateDataUsingSchema.spec.js +1041 -4
- package/dist/helpers/tests/testWithDomSettledWait.spec.js +23 -0
- package/dist/helpers/tests/testWithNetworkIdleWait.spec.js +1 -1
- package/dist/helpers/uploadFileToS3.js +6 -0
- package/dist/helpers/utils/getS3Client.js +2 -2
- package/dist/helpers/validateDataUsingSchema.js +93 -7
- package/dist/helpers/waitForDomSettled.js +17 -8
- package/dist/optimized-extractors/listExtractionHelpers/__tests__/testArrayExtractorFromLocator.spec.js +1 -1
- package/dist/optimized-extractors/objectExtractionHelpers/__tests__/testObjectExtractorFromLocator.spec.js +1 -1
- package/dist/optimized-extractors/objectExtractionHelpers/__tests__/testObjectExtractorFromPage.spec.js +1 -1
- package/dist/optimized-extractors/types/aiModelsValidation.js +1 -3
- package/package.json +4 -3
|
@@ -2,6 +2,7 @@
|
|
|
2
2
|
|
|
3
3
|
var _types = require("../types");
|
|
4
4
|
var _validateDataUsingSchema = require("../validateDataUsingSchema");
|
|
5
|
+
var _Attachment = require("../types/Attachment");
|
|
5
6
|
var _extendedTest = require("../../common/extendedTest");
|
|
6
7
|
(0, _extendedTest.describe)("Data Validation Tests", () => {
|
|
7
8
|
(0, _extendedTest.describe)("validate_data_using_schema function", () => {
|
|
@@ -55,7 +56,7 @@ var _extendedTest = require("../../common/extendedTest");
|
|
|
55
56
|
});
|
|
56
57
|
} catch (error) {
|
|
57
58
|
(0, _extendedTest.expect)(error).toBeInstanceOf(_types.ValidationError);
|
|
58
|
-
(0, _extendedTest.expect)(error.message).toContain("
|
|
59
|
+
(0, _extendedTest.expect)(error.message).toContain("Validation failed");
|
|
59
60
|
(0, _extendedTest.expect)(error.data).toEqual(invalidData);
|
|
60
61
|
}
|
|
61
62
|
});
|
|
@@ -124,7 +125,7 @@ var _extendedTest = require("../../common/extendedTest");
|
|
|
124
125
|
} catch (error) {
|
|
125
126
|
console.log(`exc_info: ${error}`);
|
|
126
127
|
(0, _extendedTest.expect)(error).toBeInstanceOf(_types.ValidationError);
|
|
127
|
-
(0, _extendedTest.expect)(error.message).toContain("
|
|
128
|
+
(0, _extendedTest.expect)(error.message).toContain("Validation failed");
|
|
128
129
|
(0, _extendedTest.expect)(error.data).toEqual(invalidData);
|
|
129
130
|
}
|
|
130
131
|
});
|
|
@@ -188,7 +189,7 @@ var _extendedTest = require("../../common/extendedTest");
|
|
|
188
189
|
});
|
|
189
190
|
} catch (error) {
|
|
190
191
|
(0, _extendedTest.expect)(error).toBeInstanceOf(_types.ValidationError);
|
|
191
|
-
(0, _extendedTest.expect)(error.message).toContain("
|
|
192
|
+
(0, _extendedTest.expect)(error.message).toContain("Validation failed");
|
|
192
193
|
(0, _extendedTest.expect)(error.data).toEqual(invalidData);
|
|
193
194
|
}
|
|
194
195
|
});
|
|
@@ -274,7 +275,7 @@ var _extendedTest = require("../../common/extendedTest");
|
|
|
274
275
|
});
|
|
275
276
|
} catch (error) {
|
|
276
277
|
(0, _extendedTest.expect)(error).toBeInstanceOf(_types.ValidationError);
|
|
277
|
-
(0, _extendedTest.expect)(error.message).toContain("
|
|
278
|
+
(0, _extendedTest.expect)(error.message).toContain("Validation failed");
|
|
278
279
|
(0, _extendedTest.expect)(error.data).toEqual(invalidData);
|
|
279
280
|
}
|
|
280
281
|
});
|
|
@@ -342,5 +343,1041 @@ var _extendedTest = require("../../common/extendedTest");
|
|
|
342
343
|
schema
|
|
343
344
|
})).toThrow(_types.ValidationError);
|
|
344
345
|
});
|
|
346
|
+
(0, _extendedTest.test)("should validate data using schema with nullable attachment type", async () => {
|
|
347
|
+
const schema = {
|
|
348
|
+
type: "object",
|
|
349
|
+
properties: {
|
|
350
|
+
file: {
|
|
351
|
+
type: ["attachment", "null"]
|
|
352
|
+
},
|
|
353
|
+
name: {
|
|
354
|
+
type: "string"
|
|
355
|
+
}
|
|
356
|
+
},
|
|
357
|
+
required: ["file", "name"]
|
|
358
|
+
};
|
|
359
|
+
const validDataWithAttachment = {
|
|
360
|
+
file: {
|
|
361
|
+
fileName: "report.pdf",
|
|
362
|
+
bucket: "my-bucket",
|
|
363
|
+
region: "us-east-1",
|
|
364
|
+
key: "files/report.pdf",
|
|
365
|
+
suggestedFileName: "Report.pdf"
|
|
366
|
+
},
|
|
367
|
+
name: "Test With File"
|
|
368
|
+
};
|
|
369
|
+
(0, _extendedTest.expect)(() => (0, _validateDataUsingSchema.validateDataUsingSchema)({
|
|
370
|
+
data: validDataWithAttachment,
|
|
371
|
+
schema
|
|
372
|
+
})).not.toThrow();
|
|
373
|
+
const validDataWithNull = {
|
|
374
|
+
file: null,
|
|
375
|
+
name: "Test Without File"
|
|
376
|
+
};
|
|
377
|
+
(0, _extendedTest.expect)(() => (0, _validateDataUsingSchema.validateDataUsingSchema)({
|
|
378
|
+
data: validDataWithNull,
|
|
379
|
+
schema
|
|
380
|
+
})).not.toThrow();
|
|
381
|
+
});
|
|
382
|
+
(0, _extendedTest.test)("should validate data using schema with nullable attachment type receiving invalid value", async () => {
|
|
383
|
+
const schema = {
|
|
384
|
+
type: "object",
|
|
385
|
+
properties: {
|
|
386
|
+
file: {
|
|
387
|
+
type: ["attachment", "null"]
|
|
388
|
+
},
|
|
389
|
+
name: {
|
|
390
|
+
type: "string"
|
|
391
|
+
}
|
|
392
|
+
},
|
|
393
|
+
required: ["file", "name"]
|
|
394
|
+
};
|
|
395
|
+
const invalidData = {
|
|
396
|
+
file: "not-an-attachment",
|
|
397
|
+
name: "Test"
|
|
398
|
+
};
|
|
399
|
+
(0, _extendedTest.expect)(() => (0, _validateDataUsingSchema.validateDataUsingSchema)({
|
|
400
|
+
data: invalidData,
|
|
401
|
+
schema
|
|
402
|
+
})).toThrow(_types.ValidationError);
|
|
403
|
+
try {
|
|
404
|
+
(0, _validateDataUsingSchema.validateDataUsingSchema)({
|
|
405
|
+
data: invalidData,
|
|
406
|
+
schema
|
|
407
|
+
});
|
|
408
|
+
} catch (error) {
|
|
409
|
+
(0, _extendedTest.expect)(error).toBeInstanceOf(_types.ValidationError);
|
|
410
|
+
(0, _extendedTest.expect)(error.message).toContain("Validation failed");
|
|
411
|
+
(0, _extendedTest.expect)(error.data).toEqual(invalidData);
|
|
412
|
+
}
|
|
413
|
+
});
|
|
414
|
+
(0, _extendedTest.test)("should validate data using schema with nested empty values filtered", async () => {
|
|
415
|
+
const schema = {
|
|
416
|
+
type: "object",
|
|
417
|
+
properties: {
|
|
418
|
+
user: {
|
|
419
|
+
type: "object",
|
|
420
|
+
properties: {
|
|
421
|
+
name: {
|
|
422
|
+
type: "string"
|
|
423
|
+
},
|
|
424
|
+
age: {
|
|
425
|
+
type: "integer"
|
|
426
|
+
},
|
|
427
|
+
email: {
|
|
428
|
+
type: "string"
|
|
429
|
+
},
|
|
430
|
+
metadata: {
|
|
431
|
+
type: "object",
|
|
432
|
+
properties: {
|
|
433
|
+
notes: {
|
|
434
|
+
type: "string"
|
|
435
|
+
}
|
|
436
|
+
}
|
|
437
|
+
}
|
|
438
|
+
},
|
|
439
|
+
required: ["name", "age"]
|
|
440
|
+
},
|
|
441
|
+
items: {
|
|
442
|
+
type: "array",
|
|
443
|
+
items: {
|
|
444
|
+
type: "object",
|
|
445
|
+
properties: {
|
|
446
|
+
title: {
|
|
447
|
+
type: "string"
|
|
448
|
+
},
|
|
449
|
+
description: {
|
|
450
|
+
type: "string"
|
|
451
|
+
}
|
|
452
|
+
},
|
|
453
|
+
required: ["title"]
|
|
454
|
+
}
|
|
455
|
+
}
|
|
456
|
+
},
|
|
457
|
+
required: ["user", "items"]
|
|
458
|
+
};
|
|
459
|
+
const dataWithNestedEmpty = {
|
|
460
|
+
user: {
|
|
461
|
+
name: "John Doe",
|
|
462
|
+
age: 30,
|
|
463
|
+
email: "",
|
|
464
|
+
metadata: {
|
|
465
|
+
notes: null
|
|
466
|
+
}
|
|
467
|
+
},
|
|
468
|
+
items: [{
|
|
469
|
+
title: "Item 1",
|
|
470
|
+
description: ""
|
|
471
|
+
}, {
|
|
472
|
+
title: "Item 2",
|
|
473
|
+
description: " "
|
|
474
|
+
}]
|
|
475
|
+
};
|
|
476
|
+
(0, _extendedTest.expect)(() => (0, _validateDataUsingSchema.validateDataUsingSchema)({
|
|
477
|
+
data: dataWithNestedEmpty,
|
|
478
|
+
schema
|
|
479
|
+
})).not.toThrow();
|
|
480
|
+
});
|
|
481
|
+
(0, _extendedTest.test)("should validate data using schema with empty values in arrays filtered", async () => {
|
|
482
|
+
const schema = {
|
|
483
|
+
type: "array",
|
|
484
|
+
items: {
|
|
485
|
+
type: "object",
|
|
486
|
+
properties: {
|
|
487
|
+
name: {
|
|
488
|
+
type: "string"
|
|
489
|
+
},
|
|
490
|
+
value: {
|
|
491
|
+
type: "string"
|
|
492
|
+
}
|
|
493
|
+
},
|
|
494
|
+
required: ["name"]
|
|
495
|
+
}
|
|
496
|
+
};
|
|
497
|
+
const dataWithEmptyInArray = [{
|
|
498
|
+
name: "Item 1",
|
|
499
|
+
value: ""
|
|
500
|
+
}, {
|
|
501
|
+
name: "Item 2",
|
|
502
|
+
value: null
|
|
503
|
+
}, {
|
|
504
|
+
name: "Item 3"
|
|
505
|
+
}];
|
|
506
|
+
(0, _extendedTest.expect)(() => (0, _validateDataUsingSchema.validateDataUsingSchema)({
|
|
507
|
+
data: dataWithEmptyInArray,
|
|
508
|
+
schema
|
|
509
|
+
})).not.toThrow();
|
|
510
|
+
});
|
|
511
|
+
(0, _extendedTest.test)("should validate that existing nullable optional fields are valid", async () => {
|
|
512
|
+
const schema = {
|
|
513
|
+
type: "object",
|
|
514
|
+
properties: {
|
|
515
|
+
name: {
|
|
516
|
+
type: "string"
|
|
517
|
+
}
|
|
518
|
+
}
|
|
519
|
+
};
|
|
520
|
+
const data = {
|
|
521
|
+
name: null
|
|
522
|
+
};
|
|
523
|
+
(0, _extendedTest.expect)(() => (0, _validateDataUsingSchema.validateDataUsingSchema)({
|
|
524
|
+
data,
|
|
525
|
+
schema
|
|
526
|
+
})).not.toThrow();
|
|
527
|
+
});
|
|
528
|
+
(0, _extendedTest.test)("should validate data using schema with capital Attachment type", async () => {
|
|
529
|
+
const schema = {
|
|
530
|
+
type: "object",
|
|
531
|
+
properties: {
|
|
532
|
+
file: {
|
|
533
|
+
type: "Attachment"
|
|
534
|
+
},
|
|
535
|
+
name: {
|
|
536
|
+
type: "string"
|
|
537
|
+
}
|
|
538
|
+
},
|
|
539
|
+
required: ["file", "name"]
|
|
540
|
+
};
|
|
541
|
+
const validData = {
|
|
542
|
+
file: {
|
|
543
|
+
fileName: "documents/report.pdf",
|
|
544
|
+
bucket: "my-bucket",
|
|
545
|
+
region: "us-east-1",
|
|
546
|
+
key: "documents/report.pdf",
|
|
547
|
+
endpoint: null,
|
|
548
|
+
suggestedFileName: "Monthly Report.pdf",
|
|
549
|
+
fileType: "document"
|
|
550
|
+
},
|
|
551
|
+
name: "Test File Upload"
|
|
552
|
+
};
|
|
553
|
+
(0, _extendedTest.expect)(() => (0, _validateDataUsingSchema.validateDataUsingSchema)({
|
|
554
|
+
data: validData,
|
|
555
|
+
schema
|
|
556
|
+
})).not.toThrow();
|
|
557
|
+
});
|
|
558
|
+
(0, _extendedTest.test)("should validate data using schema with capital Attachment comprehensive", async () => {
|
|
559
|
+
const schema = {
|
|
560
|
+
type: "object",
|
|
561
|
+
properties: {
|
|
562
|
+
requiredFile: {
|
|
563
|
+
type: "Attachment"
|
|
564
|
+
},
|
|
565
|
+
optionalFile: {
|
|
566
|
+
type: "Attachment"
|
|
567
|
+
},
|
|
568
|
+
nullableFile: {
|
|
569
|
+
type: ["Attachment", "null"]
|
|
570
|
+
},
|
|
571
|
+
filesArray: {
|
|
572
|
+
type: "array",
|
|
573
|
+
items: {
|
|
574
|
+
type: "Attachment"
|
|
575
|
+
}
|
|
576
|
+
},
|
|
577
|
+
flexibleField: {
|
|
578
|
+
type: ["Attachment", "string", "null"]
|
|
579
|
+
}
|
|
580
|
+
},
|
|
581
|
+
required: ["requiredFile", "nullableFile", "filesArray", "flexibleField"]
|
|
582
|
+
};
|
|
583
|
+
const validData = {
|
|
584
|
+
requiredFile: {
|
|
585
|
+
fileName: "required.pdf",
|
|
586
|
+
bucket: "my-bucket",
|
|
587
|
+
region: "us-east-1",
|
|
588
|
+
key: "files/required.pdf",
|
|
589
|
+
suggestedFileName: "Required.pdf"
|
|
590
|
+
},
|
|
591
|
+
nullableFile: null,
|
|
592
|
+
filesArray: [{
|
|
593
|
+
fileName: "file1.pdf",
|
|
594
|
+
bucket: "my-bucket",
|
|
595
|
+
region: "us-east-1",
|
|
596
|
+
key: "files/file1.pdf",
|
|
597
|
+
suggestedFileName: "File 1.pdf"
|
|
598
|
+
}, {
|
|
599
|
+
fileName: "file2.pdf",
|
|
600
|
+
bucket: "my-bucket",
|
|
601
|
+
region: "us-west-2",
|
|
602
|
+
key: "files/file2.pdf",
|
|
603
|
+
suggestedFileName: "File 2.pdf"
|
|
604
|
+
}],
|
|
605
|
+
flexibleField: "just a string"
|
|
606
|
+
};
|
|
607
|
+
(0, _extendedTest.expect)(() => (0, _validateDataUsingSchema.validateDataUsingSchema)({
|
|
608
|
+
data: validData,
|
|
609
|
+
schema
|
|
610
|
+
})).not.toThrow();
|
|
611
|
+
const validDataWithAttachment = {
|
|
612
|
+
requiredFile: {
|
|
613
|
+
fileName: "required.pdf",
|
|
614
|
+
bucket: "my-bucket",
|
|
615
|
+
region: "us-east-1",
|
|
616
|
+
key: "files/required.pdf",
|
|
617
|
+
suggestedFileName: "Required.pdf"
|
|
618
|
+
},
|
|
619
|
+
nullableFile: {
|
|
620
|
+
fileName: "nullable.pdf",
|
|
621
|
+
bucket: "my-bucket",
|
|
622
|
+
region: "us-east-1",
|
|
623
|
+
key: "files/nullable.pdf",
|
|
624
|
+
suggestedFileName: "Nullable.pdf"
|
|
625
|
+
},
|
|
626
|
+
filesArray: [],
|
|
627
|
+
flexibleField: {
|
|
628
|
+
fileName: "flexible.pdf",
|
|
629
|
+
bucket: "my-bucket",
|
|
630
|
+
region: "us-east-1",
|
|
631
|
+
key: "files/flexible.pdf",
|
|
632
|
+
suggestedFileName: "Flexible.pdf"
|
|
633
|
+
}
|
|
634
|
+
};
|
|
635
|
+
(0, _extendedTest.expect)(() => (0, _validateDataUsingSchema.validateDataUsingSchema)({
|
|
636
|
+
data: validDataWithAttachment,
|
|
637
|
+
schema
|
|
638
|
+
})).not.toThrow();
|
|
639
|
+
const validDataWithNull = {
|
|
640
|
+
requiredFile: {
|
|
641
|
+
fileName: "required.pdf",
|
|
642
|
+
bucket: "my-bucket",
|
|
643
|
+
region: "us-east-1",
|
|
644
|
+
key: "files/required.pdf",
|
|
645
|
+
suggestedFileName: "Required.pdf"
|
|
646
|
+
},
|
|
647
|
+
nullableFile: null,
|
|
648
|
+
filesArray: [],
|
|
649
|
+
flexibleField: null
|
|
650
|
+
};
|
|
651
|
+
(0, _extendedTest.expect)(() => (0, _validateDataUsingSchema.validateDataUsingSchema)({
|
|
652
|
+
data: validDataWithNull,
|
|
653
|
+
schema
|
|
654
|
+
})).not.toThrow();
|
|
655
|
+
});
|
|
656
|
+
(0, _extendedTest.test)("should validate data using schema with nested Attachment in objects", async () => {
|
|
657
|
+
const schema = {
|
|
658
|
+
type: "object",
|
|
659
|
+
properties: {
|
|
660
|
+
documents: {
|
|
661
|
+
type: "array",
|
|
662
|
+
items: {
|
|
663
|
+
type: "object",
|
|
664
|
+
properties: {
|
|
665
|
+
metadata: {
|
|
666
|
+
type: "object",
|
|
667
|
+
properties: {
|
|
668
|
+
file: {
|
|
669
|
+
type: "Attachment"
|
|
670
|
+
},
|
|
671
|
+
name: {
|
|
672
|
+
type: "string"
|
|
673
|
+
}
|
|
674
|
+
},
|
|
675
|
+
required: ["file", "name"]
|
|
676
|
+
}
|
|
677
|
+
},
|
|
678
|
+
required: ["metadata"]
|
|
679
|
+
}
|
|
680
|
+
}
|
|
681
|
+
},
|
|
682
|
+
required: ["documents"]
|
|
683
|
+
};
|
|
684
|
+
const validData = {
|
|
685
|
+
documents: [{
|
|
686
|
+
metadata: {
|
|
687
|
+
file: {
|
|
688
|
+
fileName: "doc1.pdf",
|
|
689
|
+
bucket: "my-bucket",
|
|
690
|
+
region: "us-east-1",
|
|
691
|
+
key: "files/doc1.pdf",
|
|
692
|
+
suggestedFileName: "Document 1.pdf"
|
|
693
|
+
},
|
|
694
|
+
name: "First Document"
|
|
695
|
+
}
|
|
696
|
+
}, {
|
|
697
|
+
metadata: {
|
|
698
|
+
file: {
|
|
699
|
+
fileName: "doc2.pdf",
|
|
700
|
+
bucket: "my-bucket",
|
|
701
|
+
region: "us-west-2",
|
|
702
|
+
key: "files/doc2.pdf",
|
|
703
|
+
suggestedFileName: "Document 2.pdf"
|
|
704
|
+
},
|
|
705
|
+
name: "Second Document"
|
|
706
|
+
}
|
|
707
|
+
}]
|
|
708
|
+
};
|
|
709
|
+
(0, _extendedTest.expect)(() => (0, _validateDataUsingSchema.validateDataUsingSchema)({
|
|
710
|
+
data: validData,
|
|
711
|
+
schema
|
|
712
|
+
})).not.toThrow();
|
|
713
|
+
});
|
|
714
|
+
(0, _extendedTest.test)("should validate data using schema with deeply nested Attachment", async () => {
|
|
715
|
+
const schema = {
|
|
716
|
+
type: "object",
|
|
717
|
+
properties: {
|
|
718
|
+
level1: {
|
|
719
|
+
type: "object",
|
|
720
|
+
properties: {
|
|
721
|
+
level2: {
|
|
722
|
+
type: "object",
|
|
723
|
+
properties: {
|
|
724
|
+
level3: {
|
|
725
|
+
type: "object",
|
|
726
|
+
properties: {
|
|
727
|
+
requiredFile: {
|
|
728
|
+
type: "Attachment"
|
|
729
|
+
},
|
|
730
|
+
optionalFile: {
|
|
731
|
+
type: "Attachment"
|
|
732
|
+
},
|
|
733
|
+
level4: {
|
|
734
|
+
type: "object",
|
|
735
|
+
properties: {
|
|
736
|
+
deepFile: {
|
|
737
|
+
type: "ATTACHMENT"
|
|
738
|
+
}
|
|
739
|
+
}
|
|
740
|
+
}
|
|
741
|
+
},
|
|
742
|
+
required: ["requiredFile"]
|
|
743
|
+
}
|
|
744
|
+
},
|
|
745
|
+
required: ["level3"]
|
|
746
|
+
}
|
|
747
|
+
},
|
|
748
|
+
required: ["level2"]
|
|
749
|
+
}
|
|
750
|
+
},
|
|
751
|
+
required: ["level1"]
|
|
752
|
+
};
|
|
753
|
+
const validData = {
|
|
754
|
+
level1: {
|
|
755
|
+
level2: {
|
|
756
|
+
level3: {
|
|
757
|
+
requiredFile: {
|
|
758
|
+
fileName: "level3.pdf",
|
|
759
|
+
bucket: "my-bucket",
|
|
760
|
+
region: "us-east-1",
|
|
761
|
+
key: "files/level3.pdf",
|
|
762
|
+
suggestedFileName: "Level 3.pdf"
|
|
763
|
+
},
|
|
764
|
+
level4: {
|
|
765
|
+
deepFile: {
|
|
766
|
+
fileName: "level4.pdf",
|
|
767
|
+
bucket: "my-bucket",
|
|
768
|
+
region: "us-east-1",
|
|
769
|
+
key: "files/level4.pdf",
|
|
770
|
+
suggestedFileName: "Level 4.pdf"
|
|
771
|
+
}
|
|
772
|
+
}
|
|
773
|
+
}
|
|
774
|
+
}
|
|
775
|
+
}
|
|
776
|
+
};
|
|
777
|
+
(0, _extendedTest.expect)(() => (0, _validateDataUsingSchema.validateDataUsingSchema)({
|
|
778
|
+
data: validData,
|
|
779
|
+
schema
|
|
780
|
+
})).not.toThrow();
|
|
781
|
+
});
|
|
782
|
+
(0, _extendedTest.test)("should validate data using schema with Attachment in oneOf", async () => {
|
|
783
|
+
const schema = {
|
|
784
|
+
type: "object",
|
|
785
|
+
properties: {
|
|
786
|
+
content: {
|
|
787
|
+
oneOf: [{
|
|
788
|
+
type: "object",
|
|
789
|
+
properties: {
|
|
790
|
+
type: {
|
|
791
|
+
const: "text"
|
|
792
|
+
},
|
|
793
|
+
value: {
|
|
794
|
+
type: "string"
|
|
795
|
+
}
|
|
796
|
+
},
|
|
797
|
+
required: ["type", "value"]
|
|
798
|
+
}, {
|
|
799
|
+
type: "object",
|
|
800
|
+
properties: {
|
|
801
|
+
type: {
|
|
802
|
+
const: "file"
|
|
803
|
+
},
|
|
804
|
+
file: {
|
|
805
|
+
type: "Attachment"
|
|
806
|
+
}
|
|
807
|
+
},
|
|
808
|
+
required: ["type", "file"]
|
|
809
|
+
}]
|
|
810
|
+
}
|
|
811
|
+
},
|
|
812
|
+
required: ["content"]
|
|
813
|
+
};
|
|
814
|
+
const validTextData = {
|
|
815
|
+
content: {
|
|
816
|
+
type: "text",
|
|
817
|
+
value: "Some text content"
|
|
818
|
+
}
|
|
819
|
+
};
|
|
820
|
+
(0, _extendedTest.expect)(() => (0, _validateDataUsingSchema.validateDataUsingSchema)({
|
|
821
|
+
data: validTextData,
|
|
822
|
+
schema
|
|
823
|
+
})).not.toThrow();
|
|
824
|
+
const validFileData = {
|
|
825
|
+
content: {
|
|
826
|
+
type: "file",
|
|
827
|
+
file: {
|
|
828
|
+
fileName: "document.pdf",
|
|
829
|
+
bucket: "my-bucket",
|
|
830
|
+
region: "us-east-1",
|
|
831
|
+
key: "files/document.pdf",
|
|
832
|
+
suggestedFileName: "Document.pdf"
|
|
833
|
+
}
|
|
834
|
+
}
|
|
835
|
+
};
|
|
836
|
+
(0, _extendedTest.expect)(() => (0, _validateDataUsingSchema.validateDataUsingSchema)({
|
|
837
|
+
data: validFileData,
|
|
838
|
+
schema
|
|
839
|
+
})).not.toThrow();
|
|
840
|
+
});
|
|
841
|
+
(0, _extendedTest.test)("should validate data using schema with Attachment in anyOf", async () => {
|
|
842
|
+
const schema = {
|
|
843
|
+
type: "object",
|
|
844
|
+
properties: {
|
|
845
|
+
resource: {
|
|
846
|
+
anyOf: [{
|
|
847
|
+
type: "string"
|
|
848
|
+
}, {
|
|
849
|
+
type: "Attachment"
|
|
850
|
+
}]
|
|
851
|
+
}
|
|
852
|
+
},
|
|
853
|
+
required: ["resource"]
|
|
854
|
+
};
|
|
855
|
+
const validStringData = {
|
|
856
|
+
resource: "https://example.com/file.pdf"
|
|
857
|
+
};
|
|
858
|
+
(0, _extendedTest.expect)(() => (0, _validateDataUsingSchema.validateDataUsingSchema)({
|
|
859
|
+
data: validStringData,
|
|
860
|
+
schema
|
|
861
|
+
})).not.toThrow();
|
|
862
|
+
const validAttachmentData = {
|
|
863
|
+
resource: {
|
|
864
|
+
fileName: "file.pdf",
|
|
865
|
+
bucket: "my-bucket",
|
|
866
|
+
region: "us-east-1",
|
|
867
|
+
key: "files/file.pdf",
|
|
868
|
+
suggestedFileName: "File.pdf"
|
|
869
|
+
}
|
|
870
|
+
};
|
|
871
|
+
(0, _extendedTest.expect)(() => (0, _validateDataUsingSchema.validateDataUsingSchema)({
|
|
872
|
+
data: validAttachmentData,
|
|
873
|
+
schema
|
|
874
|
+
})).not.toThrow();
|
|
875
|
+
});
|
|
876
|
+
(0, _extendedTest.test)("should validate data using schema with Attachment array constraints", async () => {
|
|
877
|
+
const schema = {
|
|
878
|
+
type: "object",
|
|
879
|
+
properties: {
|
|
880
|
+
files: {
|
|
881
|
+
type: "array",
|
|
882
|
+
items: {
|
|
883
|
+
type: "Attachment"
|
|
884
|
+
},
|
|
885
|
+
minItems: 1,
|
|
886
|
+
maxItems: 3
|
|
887
|
+
}
|
|
888
|
+
},
|
|
889
|
+
required: ["files"]
|
|
890
|
+
};
|
|
891
|
+
const validData = {
|
|
892
|
+
files: [{
|
|
893
|
+
fileName: "file1.pdf",
|
|
894
|
+
bucket: "my-bucket",
|
|
895
|
+
region: "us-east-1",
|
|
896
|
+
key: "files/file1.pdf",
|
|
897
|
+
suggestedFileName: "File 1.pdf"
|
|
898
|
+
}, {
|
|
899
|
+
fileName: "file2.pdf",
|
|
900
|
+
bucket: "my-bucket",
|
|
901
|
+
region: "us-east-1",
|
|
902
|
+
key: "files/file2.pdf",
|
|
903
|
+
suggestedFileName: "File 2.pdf"
|
|
904
|
+
}]
|
|
905
|
+
};
|
|
906
|
+
(0, _extendedTest.expect)(() => (0, _validateDataUsingSchema.validateDataUsingSchema)({
|
|
907
|
+
data: validData,
|
|
908
|
+
schema
|
|
909
|
+
})).not.toThrow();
|
|
910
|
+
const invalidDataEmpty = {
|
|
911
|
+
files: []
|
|
912
|
+
};
|
|
913
|
+
(0, _extendedTest.expect)(() => (0, _validateDataUsingSchema.validateDataUsingSchema)({
|
|
914
|
+
data: invalidDataEmpty,
|
|
915
|
+
schema
|
|
916
|
+
})).toThrow(_types.ValidationError);
|
|
917
|
+
});
|
|
918
|
+
(0, _extendedTest.test)("should validate data using schema with Attachment cross-field dependencies", async () => {
|
|
919
|
+
const schema = {
|
|
920
|
+
type: "object",
|
|
921
|
+
properties: {
|
|
922
|
+
hasAttachment: {
|
|
923
|
+
type: "boolean"
|
|
924
|
+
},
|
|
925
|
+
file: {
|
|
926
|
+
type: ["Attachment", "null"]
|
|
927
|
+
}
|
|
928
|
+
},
|
|
929
|
+
required: ["hasAttachment", "file"],
|
|
930
|
+
if: {
|
|
931
|
+
properties: {
|
|
932
|
+
hasAttachment: {
|
|
933
|
+
const: true
|
|
934
|
+
}
|
|
935
|
+
}
|
|
936
|
+
},
|
|
937
|
+
then: {
|
|
938
|
+
properties: {
|
|
939
|
+
file: {
|
|
940
|
+
type: "Attachment"
|
|
941
|
+
}
|
|
942
|
+
}
|
|
943
|
+
}
|
|
944
|
+
};
|
|
945
|
+
const validWithFile = {
|
|
946
|
+
hasAttachment: true,
|
|
947
|
+
file: {
|
|
948
|
+
fileName: "document.pdf",
|
|
949
|
+
bucket: "my-bucket",
|
|
950
|
+
region: "us-east-1",
|
|
951
|
+
key: "files/document.pdf",
|
|
952
|
+
suggestedFileName: "Document.pdf"
|
|
953
|
+
}
|
|
954
|
+
};
|
|
955
|
+
(0, _extendedTest.expect)(() => (0, _validateDataUsingSchema.validateDataUsingSchema)({
|
|
956
|
+
data: validWithFile,
|
|
957
|
+
schema
|
|
958
|
+
})).not.toThrow();
|
|
959
|
+
const validWithoutFile = {
|
|
960
|
+
hasAttachment: false,
|
|
961
|
+
file: null
|
|
962
|
+
};
|
|
963
|
+
(0, _extendedTest.expect)(() => (0, _validateDataUsingSchema.validateDataUsingSchema)({
|
|
964
|
+
data: validWithoutFile,
|
|
965
|
+
schema
|
|
966
|
+
})).not.toThrow();
|
|
967
|
+
});
|
|
968
|
+
(0, _extendedTest.test)("should validate data using schema with Attachment in definitions", async () => {
|
|
969
|
+
const schema = {
|
|
970
|
+
type: "object",
|
|
971
|
+
properties: {
|
|
972
|
+
document: {
|
|
973
|
+
$ref: "#/definitions/Document"
|
|
974
|
+
}
|
|
975
|
+
},
|
|
976
|
+
required: ["document"],
|
|
977
|
+
definitions: {
|
|
978
|
+
Document: {
|
|
979
|
+
type: "object",
|
|
980
|
+
properties: {
|
|
981
|
+
title: {
|
|
982
|
+
type: "string"
|
|
983
|
+
},
|
|
984
|
+
file: {
|
|
985
|
+
type: "Attachment"
|
|
986
|
+
},
|
|
987
|
+
attachments: {
|
|
988
|
+
type: "array",
|
|
989
|
+
items: {
|
|
990
|
+
type: "ATTACHMENT"
|
|
991
|
+
}
|
|
992
|
+
}
|
|
993
|
+
},
|
|
994
|
+
required: ["title", "file"]
|
|
995
|
+
}
|
|
996
|
+
}
|
|
997
|
+
};
|
|
998
|
+
const validData = {
|
|
999
|
+
document: {
|
|
1000
|
+
title: "Important Document",
|
|
1001
|
+
file: {
|
|
1002
|
+
fileName: "main.pdf",
|
|
1003
|
+
bucket: "my-bucket",
|
|
1004
|
+
region: "us-east-1",
|
|
1005
|
+
key: "files/main.pdf",
|
|
1006
|
+
suggestedFileName: "Main.pdf"
|
|
1007
|
+
},
|
|
1008
|
+
attachments: [{
|
|
1009
|
+
fileName: "attachment1.pdf",
|
|
1010
|
+
bucket: "my-bucket",
|
|
1011
|
+
region: "us-east-1",
|
|
1012
|
+
key: "files/attachment1.pdf",
|
|
1013
|
+
suggestedFileName: "Attachment 1.pdf"
|
|
1014
|
+
}]
|
|
1015
|
+
}
|
|
1016
|
+
};
|
|
1017
|
+
(0, _extendedTest.expect)(() => (0, _validateDataUsingSchema.validateDataUsingSchema)({
|
|
1018
|
+
data: validData,
|
|
1019
|
+
schema
|
|
1020
|
+
})).not.toThrow();
|
|
1021
|
+
});
|
|
1022
|
+
(0, _extendedTest.test)("should validate Attachment error messages are helpful", async () => {
|
|
1023
|
+
const schema = {
|
|
1024
|
+
type: "object",
|
|
1025
|
+
properties: {
|
|
1026
|
+
file: {
|
|
1027
|
+
type: "Attachment"
|
|
1028
|
+
}
|
|
1029
|
+
},
|
|
1030
|
+
required: ["file"]
|
|
1031
|
+
};
|
|
1032
|
+
const invalidData = {
|
|
1033
|
+
file: {
|
|
1034
|
+
fileName: "incomplete.pdf"
|
|
1035
|
+
}
|
|
1036
|
+
};
|
|
1037
|
+
(0, _extendedTest.expect)(() => (0, _validateDataUsingSchema.validateDataUsingSchema)({
|
|
1038
|
+
data: invalidData,
|
|
1039
|
+
schema
|
|
1040
|
+
})).toThrow(_types.ValidationError);
|
|
1041
|
+
try {
|
|
1042
|
+
(0, _validateDataUsingSchema.validateDataUsingSchema)({
|
|
1043
|
+
data: invalidData,
|
|
1044
|
+
schema
|
|
1045
|
+
});
|
|
1046
|
+
} catch (error) {
|
|
1047
|
+
(0, _extendedTest.expect)(error).toBeInstanceOf(_types.ValidationError);
|
|
1048
|
+
(0, _extendedTest.expect)(error.message).toContain("Validation failed");
|
|
1049
|
+
(0, _extendedTest.expect)(error.data).toEqual(invalidData);
|
|
1050
|
+
}
|
|
1051
|
+
});
|
|
1052
|
+
(0, _extendedTest.test)("should validate data using schema with mixed casing Attachment in arrays", async () => {
|
|
1053
|
+
const schema = {
|
|
1054
|
+
type: "object",
|
|
1055
|
+
properties: {
|
|
1056
|
+
field1: {
|
|
1057
|
+
type: ["Attachment", "string", "null"]
|
|
1058
|
+
},
|
|
1059
|
+
field2: {
|
|
1060
|
+
type: ["ATTACHMENT", "number", "null"]
|
|
1061
|
+
},
|
|
1062
|
+
field3: {
|
|
1063
|
+
type: ["attachment", "boolean", "null"]
|
|
1064
|
+
},
|
|
1065
|
+
field4: {
|
|
1066
|
+
type: ["AtTaChMeNt", "null"]
|
|
1067
|
+
}
|
|
1068
|
+
},
|
|
1069
|
+
required: ["field1", "field2", "field3", "field4"]
|
|
1070
|
+
};
|
|
1071
|
+
const validData = {
|
|
1072
|
+
field1: "string value",
|
|
1073
|
+
field2: 42,
|
|
1074
|
+
field3: true,
|
|
1075
|
+
field4: null
|
|
1076
|
+
};
|
|
1077
|
+
(0, _extendedTest.expect)(() => (0, _validateDataUsingSchema.validateDataUsingSchema)({
|
|
1078
|
+
data: validData,
|
|
1079
|
+
schema
|
|
1080
|
+
})).not.toThrow();
|
|
1081
|
+
const validWithAttachments = {
|
|
1082
|
+
field1: {
|
|
1083
|
+
fileName: "file1.pdf",
|
|
1084
|
+
bucket: "my-bucket",
|
|
1085
|
+
region: "us-east-1",
|
|
1086
|
+
key: "files/file1.pdf",
|
|
1087
|
+
suggestedFileName: "File 1.pdf"
|
|
1088
|
+
},
|
|
1089
|
+
field2: {
|
|
1090
|
+
fileName: "file2.pdf",
|
|
1091
|
+
bucket: "my-bucket",
|
|
1092
|
+
region: "us-east-1",
|
|
1093
|
+
key: "files/file2.pdf",
|
|
1094
|
+
suggestedFileName: "File 2.pdf"
|
|
1095
|
+
},
|
|
1096
|
+
field3: {
|
|
1097
|
+
fileName: "file3.pdf",
|
|
1098
|
+
bucket: "my-bucket",
|
|
1099
|
+
region: "us-east-1",
|
|
1100
|
+
key: "files/file3.pdf",
|
|
1101
|
+
suggestedFileName: "File 3.pdf"
|
|
1102
|
+
},
|
|
1103
|
+
field4: {
|
|
1104
|
+
fileName: "file4.pdf",
|
|
1105
|
+
bucket: "my-bucket",
|
|
1106
|
+
region: "us-east-1",
|
|
1107
|
+
key: "files/file4.pdf",
|
|
1108
|
+
suggestedFileName: "File 4.pdf"
|
|
1109
|
+
}
|
|
1110
|
+
};
|
|
1111
|
+
(0, _extendedTest.expect)(() => (0, _validateDataUsingSchema.validateDataUsingSchema)({
|
|
1112
|
+
data: validWithAttachments,
|
|
1113
|
+
schema
|
|
1114
|
+
})).not.toThrow();
|
|
1115
|
+
});
|
|
1116
|
+
(0, _extendedTest.test)("should validate data with Attachment class instance", async () => {
|
|
1117
|
+
const schema = {
|
|
1118
|
+
type: "object",
|
|
1119
|
+
properties: {
|
|
1120
|
+
name: {
|
|
1121
|
+
type: "string"
|
|
1122
|
+
},
|
|
1123
|
+
manufacturer: {
|
|
1124
|
+
type: "string"
|
|
1125
|
+
},
|
|
1126
|
+
description: {
|
|
1127
|
+
type: "string"
|
|
1128
|
+
},
|
|
1129
|
+
price: {
|
|
1130
|
+
type: "number"
|
|
1131
|
+
},
|
|
1132
|
+
productUrl: {
|
|
1133
|
+
type: "string"
|
|
1134
|
+
},
|
|
1135
|
+
partNumber: {
|
|
1136
|
+
type: "string"
|
|
1137
|
+
},
|
|
1138
|
+
upc: {
|
|
1139
|
+
type: "string"
|
|
1140
|
+
},
|
|
1141
|
+
images: {
|
|
1142
|
+
type: "array"
|
|
1143
|
+
},
|
|
1144
|
+
attributes: {
|
|
1145
|
+
type: "object"
|
|
1146
|
+
},
|
|
1147
|
+
features: {
|
|
1148
|
+
type: "array"
|
|
1149
|
+
},
|
|
1150
|
+
normallyStocked: {
|
|
1151
|
+
type: "boolean"
|
|
1152
|
+
},
|
|
1153
|
+
docs: {
|
|
1154
|
+
type: "array",
|
|
1155
|
+
items: {
|
|
1156
|
+
type: "Attachment"
|
|
1157
|
+
}
|
|
1158
|
+
},
|
|
1159
|
+
specSheet: {
|
|
1160
|
+
type: "Attachment"
|
|
1161
|
+
}
|
|
1162
|
+
},
|
|
1163
|
+
required: ["name", "manufacturer", "description", "price", "productUrl", "partNumber", "upc", "images", "attributes", "features", "normallyStocked"]
|
|
1164
|
+
};
|
|
1165
|
+
const data = {
|
|
1166
|
+
name: "P-R2-B3RX",
|
|
1167
|
+
manufacturer: "GracePorts®",
|
|
1168
|
+
description: "PANEL INTERFACE CONNECTOR WITH RJ45; UL TYPE 4, NO OUTLET",
|
|
1169
|
+
price: 176.0,
|
|
1170
|
+
productUrl: "https://www.mc-mc.com/Product/graceports-p-r2-b3rx",
|
|
1171
|
+
partNumber: "P-R2-B3RX",
|
|
1172
|
+
upc: "842864101475",
|
|
1173
|
+
images: ["https://res.cloudinary.com/mcrey/image/upload/f_auto,q_auto/w_350/v1655877314/Products/GRENPR2B3RX/IMG_50387534_GracePorts_P_R2_B3RX_1.jpg", "https://res.cloudinary.com/mcrey/image/upload/f_auto,q_auto/w_100/v1655877314/Products/GRENPR2B3RX/IMG_50387534_GracePorts_P_R2_B3RX_1.jpg", "https://res.cloudinary.com/mcrey/image/upload/f_auto,q_auto/w_100/v1655877306/Products/GRENPR2B3RX/IMG_50387535_GracePorts_P_R2_B3RX.jpg"],
|
|
1174
|
+
attributes: {
|
|
1175
|
+
Brand: "GracePorts®",
|
|
1176
|
+
Type: "Bulkhead",
|
|
1177
|
+
"Mounting Type": "Panel",
|
|
1178
|
+
"Voltage Rating": "30 VDC",
|
|
1179
|
+
"Connector Type": "Cat 5e Ethernet RJ45 F/F",
|
|
1180
|
+
"Housing Material": "Plastic",
|
|
1181
|
+
Dimensions: "3.15 in L x 1.65 in W x 1.72 in H"
|
|
1182
|
+
},
|
|
1183
|
+
features: ["Extension cable interfaces consist of fully shielded cable assemblies panel-mounted to the housing allowing a direct and cost effective method of interfacing to computers, printers, modems and networks", "Bulkhead interface method permits standard cable connections on both the front and the rear of the graceport unit", "Connections are made to and from the interface by way of user supplied computer cable assemblies, printed circuit assembly", "Low-profile circuit board interfaces simplify installation where backplane clearance is limited", "The compact design features a data connector on the front and terminal block connections on the rear for easy wiring", "Low voltage (data), limited to 30 VDC, high voltage supply (for computer use only)", "1 port", "6 point, NEMA 12/4, IP65, cast alloy base enclosure"],
|
|
1184
|
+
normallyStocked: true,
|
|
1185
|
+
docs: [new _Attachment.Attachment("123e1829-300b-4c34-9b58-19fa764c2e6b/SPEC_48757191_SpecificationSheet.pdf", "123e1829-300b-4c34-9b58-19fa764c2e6b/SPEC_48757191_SpecificationSheet.pdf", "intuned-poc", "us-west-2", "SPEC_48757191_SpecificationSheet.pdf", null, "document")],
|
|
1186
|
+
specSheet: new _Attachment.Attachment("123e1829-300b-4c34-9b58-19fa764c2e6b/SPEC_48757191_SpecificationSheet.pdf", "123e1829-300b-4c34-9b58-19fa764c2e6b/SPEC_48757191_SpecificationSheet.pdf", "intuned-poc", "us-west-2", "SPEC_48757191_SpecificationSheet.pdf", null, "document")
|
|
1187
|
+
};
|
|
1188
|
+
(0, _extendedTest.expect)(() => (0, _validateDataUsingSchema.validateDataUsingSchema)({
|
|
1189
|
+
data,
|
|
1190
|
+
schema
|
|
1191
|
+
})).not.toThrow();
|
|
1192
|
+
});
|
|
1193
|
+
(0, _extendedTest.test)("should validate data with array of Attachment class instances", async () => {
|
|
1194
|
+
const schema = {
|
|
1195
|
+
type: "object",
|
|
1196
|
+
properties: {
|
|
1197
|
+
title: {
|
|
1198
|
+
type: "string"
|
|
1199
|
+
},
|
|
1200
|
+
documents: {
|
|
1201
|
+
type: "array",
|
|
1202
|
+
items: {
|
|
1203
|
+
type: "Attachment"
|
|
1204
|
+
}
|
|
1205
|
+
}
|
|
1206
|
+
},
|
|
1207
|
+
required: ["title", "documents"]
|
|
1208
|
+
};
|
|
1209
|
+
const data = {
|
|
1210
|
+
title: "Project Documents",
|
|
1211
|
+
documents: [new _Attachment.Attachment("doc1.pdf", "files/doc1.pdf", "my-bucket", "us-east-1", "Document 1.pdf", null, "document"), new _Attachment.Attachment("doc2.pdf", "files/doc2.pdf", "another-bucket", "us-west-2", "Document 2.pdf", "https://custom-s3.example.com", "document"), new _Attachment.Attachment("doc3.pdf", "files/doc3.pdf", "third-bucket", "eu-west-1", "Document 3.pdf")]
|
|
1212
|
+
};
|
|
1213
|
+
(0, _extendedTest.expect)(() => (0, _validateDataUsingSchema.validateDataUsingSchema)({
|
|
1214
|
+
data,
|
|
1215
|
+
schema
|
|
1216
|
+
})).not.toThrow();
|
|
1217
|
+
});
|
|
1218
|
+
(0, _extendedTest.test)("should validate data with mixed Attachment instances and plain objects nested", async () => {
|
|
1219
|
+
const schema = {
|
|
1220
|
+
type: "object",
|
|
1221
|
+
properties: {
|
|
1222
|
+
project: {
|
|
1223
|
+
type: "object",
|
|
1224
|
+
properties: {
|
|
1225
|
+
name: {
|
|
1226
|
+
type: "string"
|
|
1227
|
+
},
|
|
1228
|
+
sections: {
|
|
1229
|
+
type: "array",
|
|
1230
|
+
items: {
|
|
1231
|
+
type: "object",
|
|
1232
|
+
properties: {
|
|
1233
|
+
sectionName: {
|
|
1234
|
+
type: "string"
|
|
1235
|
+
},
|
|
1236
|
+
primaryFile: {
|
|
1237
|
+
type: "Attachment"
|
|
1238
|
+
},
|
|
1239
|
+
backupFiles: {
|
|
1240
|
+
type: "array",
|
|
1241
|
+
items: {
|
|
1242
|
+
type: "ATTACHMENT"
|
|
1243
|
+
}
|
|
1244
|
+
},
|
|
1245
|
+
metadata: {
|
|
1246
|
+
type: "object",
|
|
1247
|
+
properties: {
|
|
1248
|
+
description: {
|
|
1249
|
+
type: "string"
|
|
1250
|
+
},
|
|
1251
|
+
optionalAttachment: {
|
|
1252
|
+
type: ["attachment", "null"]
|
|
1253
|
+
}
|
|
1254
|
+
}
|
|
1255
|
+
}
|
|
1256
|
+
},
|
|
1257
|
+
required: ["sectionName", "primaryFile"]
|
|
1258
|
+
}
|
|
1259
|
+
}
|
|
1260
|
+
},
|
|
1261
|
+
required: ["name", "sections"]
|
|
1262
|
+
},
|
|
1263
|
+
archivedFiles: {
|
|
1264
|
+
type: "array",
|
|
1265
|
+
items: {
|
|
1266
|
+
type: "Attachment"
|
|
1267
|
+
}
|
|
1268
|
+
}
|
|
1269
|
+
},
|
|
1270
|
+
required: ["project"]
|
|
1271
|
+
};
|
|
1272
|
+
const data = {
|
|
1273
|
+
project: {
|
|
1274
|
+
name: "Complex Project",
|
|
1275
|
+
sections: [{
|
|
1276
|
+
sectionName: "Introduction",
|
|
1277
|
+
primaryFile: new _Attachment.Attachment("intro.pdf", "sections/intro.pdf", "project-bucket", "us-east-1", "Introduction.pdf", null, "document"),
|
|
1278
|
+
backupFiles: [new _Attachment.Attachment("intro_backup1.pdf", "backups/intro_backup1.pdf", "backup-bucket", "us-west-2", "Intro Backup 1.pdf")],
|
|
1279
|
+
metadata: {
|
|
1280
|
+
description: "Project introduction section",
|
|
1281
|
+
optionalAttachment: new _Attachment.Attachment("intro_notes.pdf", "notes/intro_notes.pdf", "notes-bucket", "us-east-1", "Intro Notes.pdf")
|
|
1282
|
+
}
|
|
1283
|
+
}, {
|
|
1284
|
+
sectionName: "Conclusion",
|
|
1285
|
+
primaryFile: new _Attachment.Attachment("conclusion.pdf", "sections/conclusion.pdf", "project-bucket", "us-east-1", "Conclusion.pdf"),
|
|
1286
|
+
backupFiles: [],
|
|
1287
|
+
metadata: {
|
|
1288
|
+
description: "Project conclusion section",
|
|
1289
|
+
optionalAttachment: null
|
|
1290
|
+
}
|
|
1291
|
+
}]
|
|
1292
|
+
},
|
|
1293
|
+
archivedFiles: [new _Attachment.Attachment("archive1.pdf", "archives/archive1.pdf", "archive-bucket", "us-east-1", "Archive 1.pdf", "https://archive.s3.example.com"), new _Attachment.Attachment("archive2.pdf", "archives/archive2.pdf", "archive-bucket", "us-east-1", "Archive 2.pdf")]
|
|
1294
|
+
};
|
|
1295
|
+
(0, _extendedTest.expect)(() => (0, _validateDataUsingSchema.validateDataUsingSchema)({
|
|
1296
|
+
data,
|
|
1297
|
+
schema
|
|
1298
|
+
})).not.toThrow();
|
|
1299
|
+
});
|
|
1300
|
+
(0, _extendedTest.test)("should format error messages with multiple errors correctly", async () => {
|
|
1301
|
+
const schema = {
|
|
1302
|
+
type: "object",
|
|
1303
|
+
properties: {
|
|
1304
|
+
name: {
|
|
1305
|
+
type: "string"
|
|
1306
|
+
},
|
|
1307
|
+
age: {
|
|
1308
|
+
type: "integer"
|
|
1309
|
+
},
|
|
1310
|
+
email: {
|
|
1311
|
+
type: "string"
|
|
1312
|
+
}
|
|
1313
|
+
},
|
|
1314
|
+
required: ["name", "age", "email"]
|
|
1315
|
+
};
|
|
1316
|
+
const invalidData = {
|
|
1317
|
+
name: 123,
|
|
1318
|
+
age: "not-a-number"
|
|
1319
|
+
};
|
|
1320
|
+
(0, _extendedTest.expect)(() => (0, _validateDataUsingSchema.validateDataUsingSchema)({
|
|
1321
|
+
data: invalidData,
|
|
1322
|
+
schema
|
|
1323
|
+
})).toThrow(_types.ValidationError);
|
|
1324
|
+
try {
|
|
1325
|
+
(0, _validateDataUsingSchema.validateDataUsingSchema)({
|
|
1326
|
+
data: invalidData,
|
|
1327
|
+
schema
|
|
1328
|
+
});
|
|
1329
|
+
} catch (error) {
|
|
1330
|
+
(0, _extendedTest.expect)(error).toBeInstanceOf(_types.ValidationError);
|
|
1331
|
+
const errorMessage = error.message;
|
|
1332
|
+
(0, _extendedTest.expect)(errorMessage).toContain("Validation failed with");
|
|
1333
|
+
(0, _extendedTest.expect)(errorMessage).toContain("error(s):");
|
|
1334
|
+
const dashCount = (errorMessage.match(/-/g) || []).length;
|
|
1335
|
+
const errorCount = (errorMessage.match(/error/gi) || []).length;
|
|
1336
|
+
(0, _extendedTest.expect)(dashCount >= 2 || errorCount >= 2).toBe(true);
|
|
1337
|
+
(0, _extendedTest.expect)(errorMessage.includes("name") || errorMessage.includes("age") || errorMessage.includes("email")).toBe(true);
|
|
1338
|
+
(0, _extendedTest.expect)(error.data).toEqual(invalidData);
|
|
1339
|
+
}
|
|
1340
|
+
});
|
|
1341
|
+
(0, _extendedTest.test)("should format error messages with nested field paths correctly", async () => {
|
|
1342
|
+
const schema = {
|
|
1343
|
+
type: "object",
|
|
1344
|
+
properties: {
|
|
1345
|
+
user: {
|
|
1346
|
+
type: "object",
|
|
1347
|
+
properties: {
|
|
1348
|
+
name: {
|
|
1349
|
+
type: "string"
|
|
1350
|
+
},
|
|
1351
|
+
age: {
|
|
1352
|
+
type: "integer"
|
|
1353
|
+
}
|
|
1354
|
+
},
|
|
1355
|
+
required: ["name", "age"]
|
|
1356
|
+
}
|
|
1357
|
+
},
|
|
1358
|
+
required: ["user"]
|
|
1359
|
+
};
|
|
1360
|
+
const invalidData = {
|
|
1361
|
+
user: {
|
|
1362
|
+
name: "John Doe"
|
|
1363
|
+
}
|
|
1364
|
+
};
|
|
1365
|
+
(0, _extendedTest.expect)(() => (0, _validateDataUsingSchema.validateDataUsingSchema)({
|
|
1366
|
+
data: invalidData,
|
|
1367
|
+
schema
|
|
1368
|
+
})).toThrow(_types.ValidationError);
|
|
1369
|
+
try {
|
|
1370
|
+
(0, _validateDataUsingSchema.validateDataUsingSchema)({
|
|
1371
|
+
data: invalidData,
|
|
1372
|
+
schema
|
|
1373
|
+
});
|
|
1374
|
+
} catch (error) {
|
|
1375
|
+
(0, _extendedTest.expect)(error).toBeInstanceOf(_types.ValidationError);
|
|
1376
|
+
const errorMessage = error.message;
|
|
1377
|
+
(0, _extendedTest.expect)(errorMessage.includes("user") || errorMessage.includes("age")).toBe(true);
|
|
1378
|
+
(0, _extendedTest.expect)(errorMessage).toContain("Validation failed with");
|
|
1379
|
+
(0, _extendedTest.expect)(error.data).toEqual(invalidData);
|
|
1380
|
+
}
|
|
1381
|
+
});
|
|
345
1382
|
});
|
|
346
1383
|
});
|