@natlibfi/marc-record-validators-melinda 8.4.5 → 9.0.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/.drone.yml +7 -7
- package/dist/field-exclusion.js +7 -5
- package/dist/field-exclusion.js.map +1 -1
- package/dist/field-exclusion.spec.js +266 -32
- package/dist/field-exclusion.spec.js.map +1 -1
- package/dist/fields-present.spec.js +38 -1
- package/dist/fields-present.spec.js.map +1 -1
- package/package.json +7 -10
- package/src/field-exclusion.js +6 -4
- package/src/field-exclusion.spec.js +140 -32
- package/src/fields-present.spec.js +30 -1
|
@@ -314,20 +314,20 @@ describe('field-exclusion', () => {
|
|
|
314
314
|
|
|
315
315
|
it('Finds the record valid (spec)', async () => {
|
|
316
316
|
const validator = await validatorFactory(config);
|
|
317
|
-
const
|
|
318
|
-
expect(
|
|
317
|
+
const {valid, message} = await validator.validate(recordValid);
|
|
318
|
+
expect({valid, message}).to.eql({valid: true, message: []});
|
|
319
319
|
});
|
|
320
320
|
|
|
321
321
|
it('Finds the record invalid (spec)', async () => {
|
|
322
322
|
const validator = await validatorFactory(config);
|
|
323
|
-
const
|
|
324
|
-
expect(
|
|
323
|
+
const {valid, message} = await validator.validate(recordInvalid);
|
|
324
|
+
expect({valid, message}).to.eql({valid: false, message: ['Field $500 should be excluded']});
|
|
325
325
|
});
|
|
326
326
|
|
|
327
327
|
it('Finds the record invalid - double', async () => {
|
|
328
328
|
const validator = await validatorFactory(config);
|
|
329
|
-
const
|
|
330
|
-
expect(
|
|
329
|
+
const {valid, message} = await validator.validate(recordInvalidDouble);
|
|
330
|
+
expect({valid, message}).to.eql({valid: false, message: ['Field $500 should be excluded', 'Field $500 should be excluded']});
|
|
331
331
|
});
|
|
332
332
|
|
|
333
333
|
it('Repairs invalid record', async () => {
|
|
@@ -425,20 +425,20 @@ describe('field-exclusion', () => {
|
|
|
425
425
|
|
|
426
426
|
it('Finds the record valid (spec)', async () => {
|
|
427
427
|
const validator = await validatorFactory(config);
|
|
428
|
-
const
|
|
429
|
-
expect(
|
|
428
|
+
const {valid, message} = await validator.validate(recordValid);
|
|
429
|
+
expect({valid, message}).to.eql({valid: true, message: []});
|
|
430
430
|
});
|
|
431
431
|
|
|
432
432
|
it('Finds the record invalid (spec)', async () => {
|
|
433
433
|
const validator = await validatorFactory(config);
|
|
434
|
-
const
|
|
435
|
-
expect(
|
|
434
|
+
const {valid, message} = await validator.validate(recordInvalid);
|
|
435
|
+
expect({valid, message}).to.eql({valid: false, message: ['Field $648 should be excluded']});
|
|
436
436
|
});
|
|
437
437
|
|
|
438
438
|
it('Finds the record invalid - double', async () => {
|
|
439
439
|
const validator = await validatorFactory(config);
|
|
440
|
-
const
|
|
441
|
-
expect(
|
|
440
|
+
const {valid, message} = await validator.validate(recordInvalidDouble);
|
|
441
|
+
expect({valid, message}).to.eql({valid: false, message: ['Field $648 should be excluded', 'Field $650 should be excluded']});
|
|
442
442
|
});
|
|
443
443
|
|
|
444
444
|
it('Repairs invalid record', async () => {
|
|
@@ -454,6 +454,114 @@ describe('field-exclusion', () => {
|
|
|
454
454
|
});
|
|
455
455
|
});
|
|
456
456
|
|
|
457
|
+
// Simple multi tag configuration
|
|
458
|
+
describe('#validate: Simple multi tag configuration - No object (spec)', () => {
|
|
459
|
+
const config = [/^(648|650|651|655)$/u]; // eslint-disable-line prefer-named-capture-group
|
|
460
|
+
|
|
461
|
+
const recordValid = new MarcRecord({
|
|
462
|
+
leader: 'foo',
|
|
463
|
+
fields: [
|
|
464
|
+
{
|
|
465
|
+
tag: '245',
|
|
466
|
+
ind1: ' ',
|
|
467
|
+
ind2: ' ',
|
|
468
|
+
subfields: [{code: 'a', value: 'Fubar'}]
|
|
469
|
+
}
|
|
470
|
+
]
|
|
471
|
+
});
|
|
472
|
+
|
|
473
|
+
const recordInvalid = new MarcRecord({
|
|
474
|
+
leader: 'foo',
|
|
475
|
+
fields: [
|
|
476
|
+
{
|
|
477
|
+
tag: '245',
|
|
478
|
+
ind1: ' ',
|
|
479
|
+
ind2: ' ',
|
|
480
|
+
subfields: [{code: 'a', value: 'Fubar'}]
|
|
481
|
+
}, {
|
|
482
|
+
tag: '648',
|
|
483
|
+
ind1: ' ',
|
|
484
|
+
ind2: ' ',
|
|
485
|
+
subfields: [
|
|
486
|
+
{code: 'a', value: 'Foo Bar Foo Bar Foo Bar'},
|
|
487
|
+
{code: '9', value: 'ALMA<KEEP>'}
|
|
488
|
+
]
|
|
489
|
+
}
|
|
490
|
+
]
|
|
491
|
+
});
|
|
492
|
+
|
|
493
|
+
const recordInvalidDouble = new MarcRecord({
|
|
494
|
+
leader: 'foo',
|
|
495
|
+
fields: [
|
|
496
|
+
{
|
|
497
|
+
tag: '245',
|
|
498
|
+
ind1: ' ',
|
|
499
|
+
ind2: ' ',
|
|
500
|
+
subfields: [{code: 'a', value: 'Fubar'}]
|
|
501
|
+
}, {
|
|
502
|
+
tag: '648',
|
|
503
|
+
ind1: ' ',
|
|
504
|
+
ind2: ' ',
|
|
505
|
+
subfields: [
|
|
506
|
+
{code: 'a', value: 'Foo'},
|
|
507
|
+
{code: '9', value: 'ALMA<KEEP>'}
|
|
508
|
+
]
|
|
509
|
+
}, {
|
|
510
|
+
tag: '650',
|
|
511
|
+
ind1: ' ',
|
|
512
|
+
ind2: ' ',
|
|
513
|
+
subfields: [
|
|
514
|
+
{code: 'a', value: 'Bar'},
|
|
515
|
+
{code: '9', value: 'ALMA<KEEP>'}
|
|
516
|
+
]
|
|
517
|
+
}
|
|
518
|
+
]
|
|
519
|
+
});
|
|
520
|
+
|
|
521
|
+
const recordInvalidFixed = new MarcRecord({
|
|
522
|
+
leader: 'foo',
|
|
523
|
+
fields: [
|
|
524
|
+
{
|
|
525
|
+
tag: '245',
|
|
526
|
+
ind1: ' ',
|
|
527
|
+
ind2: ' ',
|
|
528
|
+
subfields: [{code: 'a', value: 'Fubar'}]
|
|
529
|
+
}
|
|
530
|
+
]
|
|
531
|
+
});
|
|
532
|
+
|
|
533
|
+
it('Finds the record valid (spec)', async () => {
|
|
534
|
+
const validator = await validatorFactory(config);
|
|
535
|
+
const {valid, message} = await validator.validate(recordValid);
|
|
536
|
+
expect({valid, message}).to.eql({valid: true, message: []});
|
|
537
|
+
});
|
|
538
|
+
|
|
539
|
+
it('Finds the record invalid (spec)', async () => {
|
|
540
|
+
const validator = await validatorFactory(config);
|
|
541
|
+
const {valid, message} = await validator.validate(recordInvalid);
|
|
542
|
+
expect({valid, message}).to.eql({valid: false, message: ['Field $648 should be excluded']});
|
|
543
|
+
});
|
|
544
|
+
|
|
545
|
+
it('Finds the record invalid - double', async () => {
|
|
546
|
+
const validator = await validatorFactory(config);
|
|
547
|
+
const {valid, message} = await validator.validate(recordInvalidDouble);
|
|
548
|
+
expect({valid, message}).to.eql({valid: false, message: ['Field $648 should be excluded', 'Field $650 should be excluded']});
|
|
549
|
+
});
|
|
550
|
+
|
|
551
|
+
it('Repairs invalid record', async () => {
|
|
552
|
+
const validator = await validatorFactory(config);
|
|
553
|
+
await validator.fix(recordInvalid);
|
|
554
|
+
expect(recordInvalid.equalsTo(recordInvalidFixed)).to.eql(true);
|
|
555
|
+
});
|
|
556
|
+
|
|
557
|
+
it('Repairs invalid record - double', async () => {
|
|
558
|
+
const validator = await validatorFactory(config);
|
|
559
|
+
await validator.fix(recordInvalidDouble);
|
|
560
|
+
expect(recordInvalidDouble.equalsTo(recordInvalidFixed)).to.eql(true);
|
|
561
|
+
});
|
|
562
|
+
});
|
|
563
|
+
|
|
564
|
+
|
|
457
565
|
// Complex configuration https://github.com/NatLibFi/marc-record-validators-melinda/issues/45
|
|
458
566
|
describe('#validate: Complex configuration (spec)', () => {
|
|
459
567
|
const config = [
|
|
@@ -517,14 +625,14 @@ describe('field-exclusion', () => {
|
|
|
517
625
|
|
|
518
626
|
it('Finds the record valid (spec)', async () => {
|
|
519
627
|
const validator = await validatorFactory(config);
|
|
520
|
-
const
|
|
521
|
-
expect(
|
|
628
|
+
const {valid, message} = await validator.validate(recordValid);
|
|
629
|
+
expect({valid, message}).to.eql({valid: true, message: []});
|
|
522
630
|
});
|
|
523
631
|
|
|
524
632
|
it('Finds the record invalid (spec)', async () => {
|
|
525
633
|
const validator = await validatorFactory(config);
|
|
526
|
-
const
|
|
527
|
-
expect(
|
|
634
|
+
const {valid, message} = await validator.validate(recordInvalid);
|
|
635
|
+
expect({valid, message}).to.eql({valid: false, message: ['Field $500 should be excluded']});
|
|
528
636
|
});
|
|
529
637
|
|
|
530
638
|
it('Repairs invalid record', async () => {
|
|
@@ -634,20 +742,20 @@ describe('field-exclusion', () => {
|
|
|
634
742
|
|
|
635
743
|
it('Finds the record valid (spec)', async () => {
|
|
636
744
|
const validator = await validatorFactory(config);
|
|
637
|
-
const
|
|
638
|
-
expect(
|
|
745
|
+
const {valid, message} = await validator.validate(recordValid);
|
|
746
|
+
expect({valid, message}).to.eql({valid: true, message: []});
|
|
639
747
|
});
|
|
640
748
|
|
|
641
749
|
it('Finds the record invalid (spec)', async () => {
|
|
642
750
|
const validator = await validatorFactory(config);
|
|
643
|
-
const
|
|
644
|
-
expect(
|
|
751
|
+
const {valid, message} = await validator.validate(recordInvalid);
|
|
752
|
+
expect({valid, message}).to.eql({valid: false, message: ['Field $650 should be excluded']});
|
|
645
753
|
});
|
|
646
754
|
|
|
647
755
|
it('Finds the record invalid (spec)', async () => {
|
|
648
756
|
const validator = await validatorFactory(config);
|
|
649
|
-
const
|
|
650
|
-
expect(
|
|
757
|
+
const {valid, message} = await validator.validate(recordInvalidMulti);
|
|
758
|
+
expect({valid, message}).to.eql({valid: false, message: [
|
|
651
759
|
'Field $648 should be excluded',
|
|
652
760
|
'Field $650 should be excluded',
|
|
653
761
|
'Field $650 should be excluded',
|
|
@@ -750,26 +858,26 @@ describe('field-exclusion', () => {
|
|
|
750
858
|
|
|
751
859
|
it('Finds the record valid - Ind1&Ind2', async () => {
|
|
752
860
|
const validator = await validatorFactory(configInd);
|
|
753
|
-
const
|
|
754
|
-
expect(
|
|
861
|
+
const {valid, message} = await validator.validate(recordValid);
|
|
862
|
+
expect({valid, message}).to.eql({valid: true, message: []});
|
|
755
863
|
});
|
|
756
864
|
|
|
757
865
|
it('Finds the record valid - Value', async () => {
|
|
758
866
|
const validator = await validatorFactory(configValue);
|
|
759
|
-
const
|
|
760
|
-
expect(
|
|
867
|
+
const {valid, message} = await validator.validate(recordValid);
|
|
868
|
+
expect({valid, message}).to.eql({valid: true, message: []});
|
|
761
869
|
});
|
|
762
870
|
|
|
763
871
|
it('Finds the record invalid - Ind', async () => {
|
|
764
872
|
const validator = await validatorFactory(configInd);
|
|
765
|
-
const
|
|
766
|
-
expect(
|
|
873
|
+
const {valid, message} = await validator.validate(recordIndInvalid);
|
|
874
|
+
expect({valid, message}).to.eql({valid: false, message: ['Field $500 should be excluded']});
|
|
767
875
|
});
|
|
768
876
|
|
|
769
877
|
it('Finds the record invalid - Value', async () => {
|
|
770
878
|
const validator = await validatorFactory(configValue);
|
|
771
|
-
const
|
|
772
|
-
expect(
|
|
879
|
+
const {valid, message} = await validator.validate(recordValueInvalid);
|
|
880
|
+
expect({valid, message}).to.eql({valid: false, message: ['Field $500 should be excluded']});
|
|
773
881
|
});
|
|
774
882
|
|
|
775
883
|
it('Repairs invalid record - Ind', async () => {
|
|
@@ -807,9 +915,9 @@ describe('field-exclusion', () => {
|
|
|
807
915
|
});
|
|
808
916
|
|
|
809
917
|
const validator = await validatorFactory(config);
|
|
810
|
-
const
|
|
918
|
+
const {valid, message} = await validator.validate(record);
|
|
811
919
|
|
|
812
|
-
expect(
|
|
920
|
+
expect({valid, message}).to.eql({valid: false, message: ['Field $041 should be excluded']});
|
|
813
921
|
});
|
|
814
922
|
});
|
|
815
923
|
});
|
|
@@ -79,6 +79,29 @@ describe('fields-present', () => {
|
|
|
79
79
|
|
|
80
80
|
expect(result).to.eql({valid: true, messages: []});
|
|
81
81
|
});
|
|
82
|
+
it('Finds the record valid', async () => {
|
|
83
|
+
const tagPatterns = [/^(020|022|024)$/u]; // eslint-disable-line
|
|
84
|
+
const validator = await validatorFactory(tagPatterns);
|
|
85
|
+
const record = new MarcRecord({
|
|
86
|
+
fields: [
|
|
87
|
+
{
|
|
88
|
+
tag: '020',
|
|
89
|
+
ind1: ' ',
|
|
90
|
+
ind2: '0',
|
|
91
|
+
subfields: [{code: 'a', value: 'foo'}]
|
|
92
|
+
},
|
|
93
|
+
{
|
|
94
|
+
tag: '040',
|
|
95
|
+
ind1: ' ',
|
|
96
|
+
ind2: '0',
|
|
97
|
+
subfields: [{code: 'a', value: 'foo'}]
|
|
98
|
+
}
|
|
99
|
+
]
|
|
100
|
+
});
|
|
101
|
+
const result = await validator.validate(record);
|
|
102
|
+
|
|
103
|
+
expect(result).to.eql({valid: true, messages: []});
|
|
104
|
+
});
|
|
82
105
|
it('Finds the record invalid', async () => {
|
|
83
106
|
const tagPatterns = [/^5..$/u, /^FOO$/u];
|
|
84
107
|
const validator = await validatorFactory(tagPatterns);
|
|
@@ -90,6 +113,12 @@ describe('fields-present', () => {
|
|
|
90
113
|
ind2: '0',
|
|
91
114
|
subfields: [{code: 'a', value: 'foo'}]
|
|
92
115
|
},
|
|
116
|
+
{
|
|
117
|
+
tag: '500',
|
|
118
|
+
ind1: ' ',
|
|
119
|
+
ind2: '0',
|
|
120
|
+
subfields: [{code: 'a', value: 'foo'}]
|
|
121
|
+
},
|
|
93
122
|
{
|
|
94
123
|
tag: 'BAR',
|
|
95
124
|
ind1: '1',
|
|
@@ -100,7 +129,7 @@ describe('fields-present', () => {
|
|
|
100
129
|
});
|
|
101
130
|
const result = await validator.validate(record);
|
|
102
131
|
|
|
103
|
-
expect(result).to.eql({valid: false, messages: ['The following tag patterns are not present in the record tag field:
|
|
132
|
+
expect(result).to.eql({valid: false, messages: ['The following tag patterns are not present in the record tag field: /^FOO$/u']});
|
|
104
133
|
});
|
|
105
134
|
});
|
|
106
135
|
});
|