@natlibfi/melinda-commons 14.0.0 → 14.0.1-alpha.1
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/dist/subRecordPicker.js +27 -8
- package/dist/subRecordPicker.js.map +2 -2
- package/dist/subRecordPicker.test.js +13 -3
- package/dist/subRecordPicker.test.js.map +2 -2
- package/dist/utils.js +33 -0
- package/dist/utils.js.map +3 -3
- package/dist/utils.test.js +77 -1
- package/dist/utils.test.js.map +2 -2
- package/package.json +1 -1
- package/src/subRecordPicker.js +37 -8
- package/src/subRecordPicker.test.js +16 -3
- package/src/utils.js +74 -0
- package/src/utils.test.js +97 -2
- package/test-fixtures/subRecordPicker/readAllSubrecords/01/metadata.json +1 -0
- package/test-fixtures/subRecordPicker/readAllSubrecords/02/expected-records.json +632 -0
- package/test-fixtures/subRecordPicker/readAllSubrecords/02/metadata.json +22 -0
- package/test-fixtures/subRecordPicker/readAllSubrecords/02/response01.xml +136 -0
- package/test-fixtures/subRecordPicker/readAllSubrecords/02/response02.xml +71 -0
- package/test-fixtures/subRecordPicker/readAllSubrecords/03/expected-records.json +1 -0
- package/test-fixtures/subRecordPicker/readAllSubrecords/03/metadata.json +17 -0
- package/test-fixtures/subRecordPicker/readAllSubrecords/03/response01.xml +4 -0
- package/test-fixtures/subRecordPicker/readSomeSubrecords/01/metadata.json +1 -0
- package/test-fixtures/subRecordPicker/readSubrecordAmount/01/metadata.json +16 -0
- package/test-fixtures/subRecordPicker/readSubrecordAmount/01/response01.xml +4 -0
- package/test-fixtures/utils/isComponentRecord/record1.json +35 -0
- package/test-fixtures/utils/isComponentRecord/record2.json +35 -0
- package/test-fixtures/utils/isComponentRecord/record3.json +20 -0
- package/test-fixtures/utils/isComponentRecord/record4.json +20 -0
- package/test-fixtures/utils/isComponentRecord/record5.json +20 -0
- package/test-fixtures/utils/isComponentRecord/record6.json +35 -0
- package/test-fixtures/utils/isComponentRecord/record7.json +35 -0
- package/test-fixtures/utils/isTestRecord/record1.json +29 -0
- package/test-fixtures/utils/isTestRecord/record2.json +29 -0
- package/test-fixtures/utils/isTestRecord/record3.json +29 -0
- package/test-fixtures/utils/isTestRecord/record4.json +29 -0
- package/test-fixtures/utils/isTestRecord/record5.json +29 -0
- package/test-fixtures/utils/isTestRecord/record6.json +29 -0
package/src/utils.test.js
CHANGED
|
@@ -4,14 +4,15 @@ import {describe, it} from 'node:test';
|
|
|
4
4
|
import assert from 'node:assert';
|
|
5
5
|
import {MarcRecord} from '@natlibfi/marc-record';
|
|
6
6
|
import {
|
|
7
|
-
|
|
8
|
-
getRecordTitle, getRecordStandardIdentifiers
|
|
7
|
+
generateAuthorizationHeader, isDeletedRecord, isTestRecord, parseBoolean, clone,
|
|
8
|
+
getRecordTitle, getRecordStandardIdentifiers, isComponentRecord
|
|
9
9
|
} from './utils.js';
|
|
10
10
|
|
|
11
11
|
MarcRecord.setValidationOptions({subfieldValues: false});
|
|
12
12
|
|
|
13
13
|
const FIXTURES_PATH = path.join(import.meta.dirname, '../test-fixtures/utils');
|
|
14
14
|
|
|
15
|
+
// eslint-disable-next-line max-lines-per-function
|
|
15
16
|
describe('utils', () => {
|
|
16
17
|
describe('generateAuthorizationHeader', () => {
|
|
17
18
|
it('Should create a proper Authorization header', () => {
|
|
@@ -70,6 +71,46 @@ describe('utils', () => {
|
|
|
70
71
|
});
|
|
71
72
|
});
|
|
72
73
|
|
|
74
|
+
describe('isTestRecord', () => {
|
|
75
|
+
it('Should find the record a test record (STA)', () => {
|
|
76
|
+
const data = fs.readFileSync(path.join(FIXTURES_PATH, 'isTestRecord/record1.json'), 'utf8');
|
|
77
|
+
const record = new MarcRecord(JSON.parse(data));
|
|
78
|
+
assert.equal(isTestRecord(record), true);
|
|
79
|
+
});
|
|
80
|
+
|
|
81
|
+
it('Should find the record a test record (f500 "Testitietue.")', () => {
|
|
82
|
+
const data = fs.readFileSync(path.join(FIXTURES_PATH, 'isTestRecord/record2.json'), 'utf8');
|
|
83
|
+
const record = new MarcRecord(JSON.parse(data));
|
|
84
|
+
assert.equal(isTestRecord(record), true);
|
|
85
|
+
});
|
|
86
|
+
|
|
87
|
+
it('Should find the record a test record (f500 "Foobar TESTITIETUE baz.")', () => {
|
|
88
|
+
const data = fs.readFileSync(path.join(FIXTURES_PATH, 'isTestRecord/record3.json'), 'utf8');
|
|
89
|
+
const record = new MarcRecord(JSON.parse(data));
|
|
90
|
+
assert.equal(isTestRecord(record), true);
|
|
91
|
+
});
|
|
92
|
+
|
|
93
|
+
it('Should find the record a test record (f500 "test record")', () => {
|
|
94
|
+
const data = fs.readFileSync(path.join(FIXTURES_PATH, 'isTestRecord/record4.json'), 'utf8');
|
|
95
|
+
const record = new MarcRecord(JSON.parse(data));
|
|
96
|
+
assert.equal(isTestRecord(record), true);
|
|
97
|
+
});
|
|
98
|
+
|
|
99
|
+
it('Should find the record not a test record', () => {
|
|
100
|
+
const data = fs.readFileSync(path.join(FIXTURES_PATH, 'isTestRecord/record5.json'), 'utf8');
|
|
101
|
+
const record = new MarcRecord(JSON.parse(data));
|
|
102
|
+
assert.equal(isTestRecord(record), false);
|
|
103
|
+
});
|
|
104
|
+
|
|
105
|
+
it('Should find the record not a test record (f500 "test record", but configured not test f500)', () => {
|
|
106
|
+
const data = fs.readFileSync(path.join(FIXTURES_PATH, 'isTestRecord/record4.json'), 'utf8');
|
|
107
|
+
const record = new MarcRecord(JSON.parse(data));
|
|
108
|
+
assert.equal(isTestRecord(record, false), false);
|
|
109
|
+
});
|
|
110
|
+
|
|
111
|
+
});
|
|
112
|
+
|
|
113
|
+
|
|
73
114
|
describe('parseBoolean', () => {
|
|
74
115
|
it('Should parse undefined as false', () => {
|
|
75
116
|
assert.equal(parseBoolean(undefined), false);
|
|
@@ -105,6 +146,60 @@ describe('utils', () => {
|
|
|
105
146
|
|
|
106
147
|
});
|
|
107
148
|
|
|
149
|
+
describe('isComponentRecord', () => {
|
|
150
|
+
it('Should find out that the record is a component record (f773)', () => {
|
|
151
|
+
const data = fs.readFileSync(path.join(FIXTURES_PATH, 'isComponentRecord/record1.json'), 'utf8');
|
|
152
|
+
const record = new MarcRecord(JSON.parse(data));
|
|
153
|
+
assert.equal(isComponentRecord(record), true);
|
|
154
|
+
});
|
|
155
|
+
|
|
156
|
+
it('Should find out that the record is a component record (f773 + LDR/07 "a")', () => {
|
|
157
|
+
const data = fs.readFileSync(path.join(FIXTURES_PATH, 'isComponentRecord/record2.json'), 'utf8');
|
|
158
|
+
const record = new MarcRecord(JSON.parse(data));
|
|
159
|
+
assert.equal(isComponentRecord(record), true);
|
|
160
|
+
});
|
|
161
|
+
|
|
162
|
+
it('Should find out that the record is a component (LDR/07 "d")', () => {
|
|
163
|
+
const data = fs.readFileSync(path.join(FIXTURES_PATH, 'isComponentRecord/record3.json'), 'utf8');
|
|
164
|
+
const record = new MarcRecord(JSON.parse(data));
|
|
165
|
+
assert.equal(isComponentRecord(record), true);
|
|
166
|
+
});
|
|
167
|
+
|
|
168
|
+
it('Should find out that the record is not a component record', () => {
|
|
169
|
+
const data = fs.readFileSync(path.join(FIXTURES_PATH, 'isComponentRecord/record4.json'), 'utf8');
|
|
170
|
+
const record = new MarcRecord(JSON.parse(data));
|
|
171
|
+
assert.equal(isComponentRecord(record), false);
|
|
172
|
+
});
|
|
173
|
+
|
|
174
|
+
it('Should find out that the record is not a component record when ignoring collections', () => {
|
|
175
|
+
const data = fs.readFileSync(path.join(FIXTURES_PATH, 'isComponentRecord/record4.json'), 'utf8');
|
|
176
|
+
const record = new MarcRecord(JSON.parse(data));
|
|
177
|
+
assert.equal(isComponentRecord(record, true), false);
|
|
178
|
+
});
|
|
179
|
+
|
|
180
|
+
|
|
181
|
+
it('Should find out that the record is not a component record when ignoring collections (LDR/07 "d")', () => {
|
|
182
|
+
const data = fs.readFileSync(path.join(FIXTURES_PATH, 'isComponentRecord/record5.json'), 'utf8');
|
|
183
|
+
const record = new MarcRecord(JSON.parse(data));
|
|
184
|
+
assert.equal(isComponentRecord(record, true), false);
|
|
185
|
+
});
|
|
186
|
+
|
|
187
|
+
|
|
188
|
+
it('Should find out that the record is not a component record when ignoring collections (LDR/07 "c" and f773)', () => {
|
|
189
|
+
const data = fs.readFileSync(path.join(FIXTURES_PATH, 'isComponentRecord/record6.json'), 'utf8');
|
|
190
|
+
const record = new MarcRecord(JSON.parse(data));
|
|
191
|
+
assert.equal(isComponentRecord(record, true), false);
|
|
192
|
+
});
|
|
193
|
+
|
|
194
|
+
it('Should find out that the record is a component record when using additional host fields (f973)', () => {
|
|
195
|
+
const data = fs.readFileSync(path.join(FIXTURES_PATH, 'isComponentRecord/record7.json'), 'utf8');
|
|
196
|
+
const record = new MarcRecord(JSON.parse(data));
|
|
197
|
+
assert.equal(isComponentRecord(record, false, ['973']), true);
|
|
198
|
+
});
|
|
199
|
+
|
|
200
|
+
});
|
|
201
|
+
|
|
202
|
+
|
|
108
203
|
describe('getRecordTitle', () => {
|
|
109
204
|
[
|
|
110
205
|
'Should find a title',
|