@natlibfi/marc-record-merge 6.0.0-beta.2 → 6.0.0-beta.6

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.
Files changed (224) hide show
  1. package/.github/CODEOWNERS +9 -0
  2. package/.github/dependabot.yml +41 -0
  3. package/.github/workflows/melinda-node-tests.yml +60 -0
  4. package/LICENSE +21 -0
  5. package/README.md +106 -2
  6. package/dist/index.js +2 -37
  7. package/dist/index.js.map +1 -1
  8. package/dist/reducers/copy.js +310 -109
  9. package/dist/reducers/copy.js.map +1 -1
  10. package/dist/reducers/copy.spec.js +52 -99
  11. package/dist/reducers/copy.spec.js.map +1 -1
  12. package/dist/reducers/index.js +0 -27
  13. package/dist/reducers/index.js.map +1 -1
  14. package/dist/reducers/select.js +12 -50
  15. package/dist/reducers/select.js.map +1 -1
  16. package/dist/reducers/select.spec.js +49 -83
  17. package/dist/reducers/select.spec.js.map +1 -1
  18. package/package.json +30 -27
  19. package/src/index.js +1 -33
  20. package/src/reducers/copy.js +306 -115
  21. package/src/reducers/copy.spec.js +44 -66
  22. package/src/reducers/index.js +0 -27
  23. package/src/reducers/select.js +8 -51
  24. package/src/reducers/select.spec.js +37 -58
  25. package/test-fixtures/reducers/copy/{01/base.json → 01 - copy/01/base.json } +1 -1
  26. package/test-fixtures/reducers/copy/{01 → 01 - copy/01}/merged.json +0 -0
  27. package/test-fixtures/reducers/copy/01 - copy/01/metadata.json +4 -0
  28. package/test-fixtures/reducers/copy/{01 → 01 - copy/01}/source.json +0 -0
  29. package/test-fixtures/reducers/copy/{02/source.json → 01 - copy/02/base.json} +0 -0
  30. package/test-fixtures/reducers/copy/{02 → 01 - copy/02}/merged.json +0 -0
  31. package/test-fixtures/reducers/copy/01 - copy/02/metadata.json +4 -0
  32. package/test-fixtures/reducers/copy/{02/base.json → 01 - copy/02/source.json } +1 -1
  33. package/test-fixtures/reducers/copy/{03/base.json → 01 - copy/03/base.json } +1 -1
  34. package/test-fixtures/reducers/copy/{03 → 01 - copy/03}/merged.json +0 -0
  35. package/test-fixtures/reducers/copy/01 - copy/03/metadata.json +4 -0
  36. package/test-fixtures/reducers/copy/{03 → 01 - copy/03}/source.json +0 -0
  37. package/test-fixtures/reducers/copy/{05/base.json → 01 - copy/04/base.json } +1 -1
  38. package/test-fixtures/reducers/copy/{04/merged.json → 01 - copy/04/merged.json } +1 -1
  39. package/test-fixtures/reducers/copy/01 - copy/04/metadata.json +4 -0
  40. package/test-fixtures/reducers/copy/{04/source.json → 01 - copy/04/source.json } +1 -1
  41. package/test-fixtures/reducers/copy/{04/base.json → 01 - copy/05/base.json } +1 -1
  42. package/test-fixtures/reducers/copy/{05 → 01 - copy/05}/merged.json +0 -0
  43. package/test-fixtures/reducers/copy/01 - copy/05/metadata.json +4 -0
  44. package/test-fixtures/reducers/copy/{05 → 01 - copy/05}/source.json +0 -0
  45. package/test-fixtures/reducers/copy/01 - copy/06/base.json +24 -0
  46. package/test-fixtures/reducers/copy/01 - copy/06/merged.json +39 -0
  47. package/test-fixtures/reducers/copy/01 - copy/06/metadata.json +4 -0
  48. package/test-fixtures/reducers/copy/01 - copy/06/source.json +24 -0
  49. package/test-fixtures/reducers/copy/01 - copy/07/base.json +39 -0
  50. package/test-fixtures/reducers/copy/01 - copy/07/merged.json +39 -0
  51. package/test-fixtures/reducers/copy/01 - copy/07/metadata.json +5 -0
  52. package/test-fixtures/reducers/copy/01 - copy/07/source.json +24 -0
  53. package/test-fixtures/reducers/copy/01 - copy/08/base.json +28 -0
  54. package/test-fixtures/reducers/copy/01 - copy/08/merged.json +28 -0
  55. package/test-fixtures/reducers/copy/01 - copy/08/metadata.json +4 -0
  56. package/test-fixtures/reducers/copy/01 - copy/08/source.json +24 -0
  57. package/test-fixtures/reducers/copy/02 - doNotCopyIfFieldPresent/01/base.json +17 -0
  58. package/test-fixtures/reducers/copy/02 - doNotCopyIfFieldPresent/01/merged.json +20 -0
  59. package/test-fixtures/reducers/copy/02 - doNotCopyIfFieldPresent/01/metadata.json +6 -0
  60. package/test-fixtures/reducers/copy/02 - doNotCopyIfFieldPresent/01/source.json +20 -0
  61. package/test-fixtures/reducers/copy/02 - doNotCopyIfFieldPresent/02/base.json +9 -0
  62. package/test-fixtures/reducers/copy/02 - doNotCopyIfFieldPresent/02/merged.json +20 -0
  63. package/test-fixtures/reducers/copy/02 - doNotCopyIfFieldPresent/02/metadata.json +6 -0
  64. package/test-fixtures/reducers/copy/02 - doNotCopyIfFieldPresent/02/source.json +20 -0
  65. package/test-fixtures/reducers/copy/{06 → 03 - compareTagsOnly/01}/base.json +0 -0
  66. package/test-fixtures/reducers/copy/{06 → 03 - compareTagsOnly/01}/merged.json +0 -0
  67. package/test-fixtures/reducers/copy/03 - compareTagsOnly/01/metadata.json +5 -0
  68. package/test-fixtures/reducers/copy/{06 → 03 - compareTagsOnly/01}/source.json +0 -0
  69. package/test-fixtures/reducers/copy/{09 → 03 - compareTagsOnly/02}/base.json +0 -0
  70. package/test-fixtures/reducers/copy/{09 → 03 - compareTagsOnly/02}/merged.json +0 -0
  71. package/test-fixtures/reducers/copy/03 - compareTagsOnly/02/metadata.json +5 -0
  72. package/test-fixtures/reducers/copy/{09 → 03 - compareTagsOnly/02}/source.json +0 -0
  73. package/test-fixtures/reducers/copy/04 - compareWithoutIndicators/01/base.json +24 -0
  74. package/test-fixtures/reducers/copy/04 - compareWithoutIndicators/01/merged.json +24 -0
  75. package/test-fixtures/reducers/copy/04 - compareWithoutIndicators/01/metadata.json +5 -0
  76. package/test-fixtures/reducers/copy/04 - compareWithoutIndicators/01/source.json +24 -0
  77. package/test-fixtures/reducers/copy/04 - compareWithoutIndicators/02/base.json +24 -0
  78. package/test-fixtures/reducers/copy/04 - compareWithoutIndicators/02/merged.json +39 -0
  79. package/test-fixtures/reducers/copy/04 - compareWithoutIndicators/02/metadata.json +5 -0
  80. package/test-fixtures/reducers/copy/04 - compareWithoutIndicators/02/source.json +24 -0
  81. package/test-fixtures/reducers/copy/05 - copyUnless/01/base.json +9 -0
  82. package/test-fixtures/reducers/copy/05 - copyUnless/01/merged.json +24 -0
  83. package/test-fixtures/reducers/copy/05 - copyUnless/01/metadata.json +5 -0
  84. package/test-fixtures/reducers/copy/05 - copyUnless/01/source.json +47 -0
  85. package/test-fixtures/reducers/copy/06 - subfieldsMustBeIdentical/01/base.json +24 -0
  86. package/test-fixtures/reducers/copy/06 - subfieldsMustBeIdentical/01/merged.json +39 -0
  87. package/test-fixtures/reducers/copy/06 - subfieldsMustBeIdentical/01/metadata.json +5 -0
  88. package/test-fixtures/reducers/copy/06 - subfieldsMustBeIdentical/01/source.json +24 -0
  89. package/test-fixtures/reducers/copy/06 - subfieldsMustBeIdentical/02/base.json +24 -0
  90. package/test-fixtures/reducers/copy/06 - subfieldsMustBeIdentical/02/merged.json +24 -0
  91. package/test-fixtures/reducers/copy/06 - subfieldsMustBeIdentical/02/metadata.json +5 -0
  92. package/test-fixtures/reducers/copy/06 - subfieldsMustBeIdentical/02/source.json +24 -0
  93. package/test-fixtures/reducers/copy/06 - subfieldsMustBeIdentical/03/base.json +28 -0
  94. package/test-fixtures/reducers/copy/06 - subfieldsMustBeIdentical/03/merged.json +43 -0
  95. package/test-fixtures/reducers/copy/06 - subfieldsMustBeIdentical/03/metadata.json +5 -0
  96. package/test-fixtures/reducers/copy/06 - subfieldsMustBeIdentical/03/source.json +24 -0
  97. package/test-fixtures/reducers/copy/06 - subfieldsMustBeIdentical/04/base.json +28 -0
  98. package/test-fixtures/reducers/copy/06 - subfieldsMustBeIdentical/04/merged.json +28 -0
  99. package/test-fixtures/reducers/copy/06 - subfieldsMustBeIdentical/04/metadata.json +5 -0
  100. package/test-fixtures/reducers/copy/06 - subfieldsMustBeIdentical/04/source.json +24 -0
  101. package/test-fixtures/reducers/copy/06 - subfieldsMustBeIdentical/05/base.json +20 -0
  102. package/test-fixtures/reducers/copy/06 - subfieldsMustBeIdentical/05/merged.json +35 -0
  103. package/test-fixtures/reducers/copy/06 - subfieldsMustBeIdentical/05/metadata.json +5 -0
  104. package/test-fixtures/reducers/copy/06 - subfieldsMustBeIdentical/05/source.json +24 -0
  105. package/test-fixtures/reducers/copy/06 - subfieldsMustBeIdentical/06/base.json +20 -0
  106. package/test-fixtures/reducers/copy/06 - subfieldsMustBeIdentical/06/merged.json +35 -0
  107. package/test-fixtures/reducers/copy/06 - subfieldsMustBeIdentical/06/metadata.json +5 -0
  108. package/test-fixtures/reducers/copy/06 - subfieldsMustBeIdentical/06/source.json +24 -0
  109. package/test-fixtures/reducers/copy/{07 → 07 - excludeSubfields/01}/base.json +0 -0
  110. package/test-fixtures/reducers/copy/{07 → 07 - excludeSubfields/01}/merged.json +0 -0
  111. package/test-fixtures/reducers/copy/07 - excludeSubfields/01/metadata.json +8 -0
  112. package/test-fixtures/reducers/copy/{07 → 07 - excludeSubfields/01}/source.json +0 -0
  113. package/test-fixtures/reducers/copy/07 - excludeSubfields/02/base.json +39 -0
  114. package/test-fixtures/reducers/copy/07 - excludeSubfields/02/merged.json +58 -0
  115. package/test-fixtures/reducers/copy/07 - excludeSubfields/02/metadata.json +5 -0
  116. package/test-fixtures/reducers/copy/07 - excludeSubfields/02/source.json +43 -0
  117. package/test-fixtures/reducers/copy/{08 → 08 - dropSubfields/01}/base.json +0 -0
  118. package/test-fixtures/reducers/copy/{08/merged.json → 08 - dropSubfields/01/merged.json } +8 -0
  119. package/test-fixtures/reducers/copy/08 - dropSubfields/01/metadata.json +5 -0
  120. package/test-fixtures/reducers/copy/{08 → 08 - dropSubfields/01}/source.json +0 -0
  121. package/test-fixtures/reducers/copy/08 - dropSubfields/02/base.json +43 -0
  122. package/test-fixtures/reducers/copy/08 - dropSubfields/02/merged.json +58 -0
  123. package/test-fixtures/reducers/copy/08 - dropSubfields/02/metadata.json +5 -0
  124. package/test-fixtures/reducers/copy/08 - dropSubfields/02/source.json +32 -0
  125. package/test-fixtures/reducers/copy/08 - dropSubfields/03/base.json +43 -0
  126. package/test-fixtures/reducers/copy/08 - dropSubfields/03/merged.json +58 -0
  127. package/test-fixtures/reducers/copy/08 - dropSubfields/03/metadata.json +5 -0
  128. package/test-fixtures/reducers/copy/08 - dropSubfields/03/source.json +32 -0
  129. package/test-fixtures/reducers/copy/08 - dropSubfields/04/base.json +43 -0
  130. package/test-fixtures/reducers/copy/08 - dropSubfields/04/merged.json +43 -0
  131. package/test-fixtures/reducers/copy/08 - dropSubfields/04/metadata.json +5 -0
  132. package/test-fixtures/reducers/copy/08 - dropSubfields/04/source.json +32 -0
  133. package/test-fixtures/reducers/copy/09 - swapSubfieldCode/01/base.json +9 -0
  134. package/test-fixtures/reducers/copy/09 - swapSubfieldCode/01/merged.json +20 -0
  135. package/test-fixtures/reducers/copy/09 - swapSubfieldCode/01/metadata.json +6 -0
  136. package/test-fixtures/reducers/copy/09 - swapSubfieldCode/01/source.json +20 -0
  137. package/test-fixtures/reducers/copy/09 - swapSubfieldCode/02/base.json +9 -0
  138. package/test-fixtures/reducers/copy/09 - swapSubfieldCode/02/merged.json +20 -0
  139. package/test-fixtures/reducers/copy/09 - swapSubfieldCode/02/metadata.json +6 -0
  140. package/test-fixtures/reducers/copy/09 - swapSubfieldCode/02/source.json +20 -0
  141. package/test-fixtures/reducers/copy/09 - swapSubfieldCode/03/base.json +9 -0
  142. package/test-fixtures/reducers/copy/09 - swapSubfieldCode/03/merged.json +31 -0
  143. package/test-fixtures/reducers/copy/09 - swapSubfieldCode/03/metadata.json +6 -0
  144. package/test-fixtures/reducers/copy/09 - swapSubfieldCode/03/source.json +31 -0
  145. package/test-fixtures/reducers/copy/09 - swapSubfieldCode/04/base.json +9 -0
  146. package/test-fixtures/reducers/copy/09 - swapSubfieldCode/04/merged.json +42 -0
  147. package/test-fixtures/reducers/copy/09 - swapSubfieldCode/04/metadata.json +6 -0
  148. package/test-fixtures/reducers/copy/09 - swapSubfieldCode/04/source.json +42 -0
  149. package/test-fixtures/reducers/copy/10 - swapTag/01/base.json +17 -0
  150. package/test-fixtures/reducers/copy/10 - swapTag/01/merged.json +28 -0
  151. package/test-fixtures/reducers/copy/10 - swapTag/01/metadata.json +6 -0
  152. package/test-fixtures/reducers/copy/10 - swapTag/01/source.json +20 -0
  153. package/test-fixtures/reducers/metadata.json +4 -0
  154. package/test-fixtures/reducers/select/01/metadata.json +5 -0
  155. package/test-fixtures/reducers/select/02/metadata.json +4 -0
  156. package/test-fixtures/reducers/select/03/metadata.json +4 -0
  157. package/test-fixtures/reducers/select/04/metadata.json +5 -0
  158. package/test-fixtures/reducers/select/05/metadata.json +4 -0
  159. package/test-fixtures/reducers/select/06/metadata.json +4 -0
  160. package/test-fixtures/reducers/select/07/metadata.json +5 -0
  161. package/test-fixtures/reducers/select/08/metadata.json +4 -0
  162. package/test-fixtures/reducers/select/09/metadata.json +4 -0
  163. package/test-fixtures/reducers/select/10/metadata.json +5 -0
  164. package/test-fixtures/reducers/select/11/metadata.json +4 -0
  165. package/test-fixtures/reducers/select/12/metadata.json +5 -0
  166. package/test-fixtures/reducers/select/13/metadata.json +4 -0
  167. package/test-fixtures/reducers/select/14/metadata.json +4 -0
  168. package/.drone.yml +0 -92
  169. package/.nyc_output/72717fff-b4ac-4aef-a145-37cae88e07f8.json +0 -1
  170. package/.nyc_output/processinfo/72717fff-b4ac-4aef-a145-37cae88e07f8.json +0 -1
  171. package/.nyc_output/processinfo/index.json +0 -1
  172. package/LICENSE.txt +0 -165
  173. package/coverage/base.css +0 -224
  174. package/coverage/block-navigation.js +0 -79
  175. package/coverage/copy.js.html +0 -500
  176. package/coverage/favicon.png +0 -0
  177. package/coverage/index.html +0 -126
  178. package/coverage/lcov-report/base.css +0 -224
  179. package/coverage/lcov-report/block-navigation.js +0 -79
  180. package/coverage/lcov-report/copy.js.html +0 -500
  181. package/coverage/lcov-report/favicon.png +0 -0
  182. package/coverage/lcov-report/index.html +0 -126
  183. package/coverage/lcov-report/prettify.css +0 -1
  184. package/coverage/lcov-report/prettify.js +0 -2
  185. package/coverage/lcov-report/select.js.html +0 -539
  186. package/coverage/lcov-report/sort-arrow-sprite.png +0 -0
  187. package/coverage/lcov-report/sorter.js +0 -170
  188. package/coverage/lcov.info +0 -274
  189. package/coverage/prettify.css +0 -1
  190. package/coverage/prettify.js +0 -2
  191. package/coverage/select.js.html +0 -539
  192. package/coverage/sort-arrow-sprite.png +0 -0
  193. package/coverage/sorter.js +0 -170
  194. package/test-fixtures/reducers/copy/01/tagPattern.txt +0 -1
  195. package/test-fixtures/reducers/copy/02/tagPattern.txt +0 -1
  196. package/test-fixtures/reducers/copy/03/tagPattern.txt +0 -1
  197. package/test-fixtures/reducers/copy/04/tagPattern.txt +0 -1
  198. package/test-fixtures/reducers/copy/05/tagPattern.txt +0 -1
  199. package/test-fixtures/reducers/copy/06/compareTagsOnly.txt +0 -1
  200. package/test-fixtures/reducers/copy/06/tagPattern.txt +0 -1
  201. package/test-fixtures/reducers/copy/07/excludeSubfields.json +0 -1
  202. package/test-fixtures/reducers/copy/07/tagPattern.txt +0 -1
  203. package/test-fixtures/reducers/copy/08/dropSubfields.json +0 -1
  204. package/test-fixtures/reducers/copy/08/tagPattern.txt +0 -1
  205. package/test-fixtures/reducers/copy/09/compareTagsOnly.txt +0 -1
  206. package/test-fixtures/reducers/copy/09/tagPattern.txt +0 -1
  207. package/test-fixtures/reducers/select/01/expected-error.txt +0 -1
  208. package/test-fixtures/reducers/select/01/pattern.txt +0 -1
  209. package/test-fixtures/reducers/select/02/pattern.txt +0 -1
  210. package/test-fixtures/reducers/select/03/pattern.txt +0 -1
  211. package/test-fixtures/reducers/select/04/pattern.txt +0 -1
  212. package/test-fixtures/reducers/select/05/pattern.txt +0 -1
  213. package/test-fixtures/reducers/select/06/pattern.txt +0 -1
  214. package/test-fixtures/reducers/select/07/equalityFunction.txt +0 -1
  215. package/test-fixtures/reducers/select/07/pattern.txt +0 -1
  216. package/test-fixtures/reducers/select/08/pattern.txt +0 -1
  217. package/test-fixtures/reducers/select/09/pattern.txt +0 -1
  218. package/test-fixtures/reducers/select/10/equalityFunction.txt +0 -1
  219. package/test-fixtures/reducers/select/10/pattern.txt +0 -1
  220. package/test-fixtures/reducers/select/11/pattern.txt +0 -1
  221. package/test-fixtures/reducers/select/12/equalityFunction.txt +0 -1
  222. package/test-fixtures/reducers/select/12/pattern.txt +0 -1
  223. package/test-fixtures/reducers/select/13/pattern.txt +0 -1
  224. package/test-fixtures/reducers/select/14/pattern.txt +0 -1
@@ -1,72 +1,50 @@
1
- /**
2
- *
3
- * @licstart The following is the entire license notice for the JavaScript code in this file.
4
- *
5
- * Merge MARC records
6
- *
7
- * Copyright (C) 2015-2019 University Of Helsinki (The National Library Of Finland)
8
- *
9
- * This file is part of marc-record-merge-js
10
-
11
- * marc-record-merge-js program is free software: you can redistribute it and/or modify
12
- * it under the terms of the GNU Lesser General Public License as
13
- * published by the Free Software Foundation, either version 3 of the
14
- * License, or (at your option) any later version.
15
- *
16
- * marc-record-merge-js is distributed in the hope that it will be useful,
17
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
18
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
19
- * GNU Lesser General Public License for more details.
20
- *
21
- * You should have received a copy of the GNU Lesser General Public License
22
- * along with this program. If not, see <http://www.gnu.org/licenses/>.
23
- *
24
- * @licend The above is the entire license notice
25
- * for the JavaScript code in this file.
26
- *
27
- */
28
- import chai from 'chai';
29
- import fs from 'fs';
30
- import path from 'path';
1
+ import {expect} from 'chai';
2
+ import {READERS} from '@natlibfi/fixura';
31
3
  import {MarcRecord} from '@natlibfi/marc-record';
32
4
  import createReducer from './copy';
33
- import fixturesFactory, {READERS} from '@natlibfi/fixura';
34
-
35
- MarcRecord.setValidationOptions({subfieldValues: false});
5
+ import generateTests from '@natlibfi/fixugen';
36
6
 
37
- describe('reducers/copy', () => {
38
- const {expect} = chai;
39
- const fixturesPath = path.join(__dirname, '..', '..', 'test-fixtures', 'reducers', 'copy');
7
+ //import createDebugLogger from 'debug'; // <---
8
+ //const debug = createDebugLogger('@natlibfi/marc-record-merge/copy.spec.js'); // <---
40
9
 
41
- fs.readdirSync(fixturesPath).forEach(subDir => {
42
- const {getFixture} = fixturesFactory({root: [fixturesPath, subDir], reader: READERS.JSON, failWhenNotFound: false});
43
- it(subDir, () => {
44
- const base = new MarcRecord(getFixture('base.json'));
45
- const source = new MarcRecord(getFixture('source.json'));
46
- const tagPattern = new RegExp(getFixture({components: ['tagPattern.txt'], reader: READERS.TEXT}), 'u');
47
- const compareTagsOnly = getCompareTagsOnly();
48
- const excludeSubfields = getExcludeSubfields();
49
- const dropSubfields = getDropSubfields();
50
- const expectedRecord = getFixture('merged.json');
51
- const mergedRecord = createReducer({tagPattern, compareTagsOnly, excludeSubfields, dropSubfields})(base, source);
52
- expect(mergedRecord.toObject()).to.eql(expectedRecord);
10
+ generateTests({
11
+ callback,
12
+ path: [__dirname, '..', '..', 'test-fixtures', 'reducers', 'copy'],
13
+ useMetadataFile: true,
14
+ recurse: true,
15
+ fixura: {
16
+ reader: READERS.JSON,
17
+ failWhenNotFound: false
18
+ }
19
+ });
53
20
 
54
- // Non-repeatable MARC fields are copied from source only if they are missing from base
55
- function getCompareTagsOnly() {
56
- const functionName = getFixture({components: ['compareTagsOnly.txt'], reader: READERS.TEXT});
57
- return functionName === 'true' ? 'true' : undefined;
58
- }
59
- // Check whether excludeSubfields.json exists and if it does, return its contents. If not, do nothing.
60
- function getExcludeSubfields() {
61
- const subfieldsToExclude = getFixture({components: ['excludeSubfields.json'], reader: READERS.JSON});
62
- return subfieldsToExclude ? subfieldsToExclude : undefined;
63
- }
21
+ function callback({
22
+ getFixture,
23
+ tagPatternRegExp,
24
+ compareTagsOnly = false,
25
+ compareWithoutIndicators = false,
26
+ subfieldsMustBeIdentical = false,
27
+ copyUnless = undefined,
28
+ excludeSubfields = undefined,
29
+ dropSubfields = undefined,
30
+ swapSubfieldCode = [],
31
+ swapTag = [],
32
+ doNotCopyIfFieldPresent = false
33
+ }) {
34
+ const base = new MarcRecord(getFixture('base.json'), {subfieldValues: false});
35
+ const source = new MarcRecord(getFixture('source.json'), {subfieldValues: false});
36
+ const tagPattern = new RegExp(tagPatternRegExp, 'u');
37
+ const expectedRecord = getFixture('merged.json');
64
38
 
65
- // Check whether dropSubfields.json exists and if it does, return its contents. If not, do nothing.
66
- function getDropSubfields() {
67
- const subfieldsToDrop = getFixture({components: ['dropSubfields.json'], reader: READERS.JSON});
68
- return subfieldsToDrop ? subfieldsToDrop : undefined;
69
- }
70
- });
71
- });
72
- });
39
+ const mergedRecord = createReducer({
40
+ tagPattern, compareTagsOnly, compareWithoutIndicators,
41
+ copyUnless, subfieldsMustBeIdentical, excludeSubfields,
42
+ dropSubfields, swapSubfieldCode, swapTag,
43
+ doNotCopyIfFieldPresent
44
+ })(base, source);
45
+ //debug(`*** mergedRecord: `, mergedRecord); //<--
46
+ //debug(`*** mergedRecord,Strfy: `, JSON.stringify(mergedRecord)); //<--
47
+ //debug(`*** expectedRecord: `, expectedRecord); //<--
48
+ //debug(`*** expectedRecord,Strfy: `, JSON.stringify(expectedRecord)); //<--
49
+ expect(mergedRecord).to.eql(expectedRecord);
50
+ }
@@ -1,30 +1,3 @@
1
- /**
2
- *
3
- * @licstart The following is the entire license notice for the JavaScript code in this file.
4
- *
5
- * Merge MARC records
6
- *
7
- * Copyright (C) 2015-2019 University Of Helsinki (The National Library Of Finland)
8
- *
9
- * This file is part of marc-record-merge-js
10
-
11
- * marc-record-merge-js program is free software: you can redistribute it and/or modify
12
- * it under the terms of the GNU Lesser General Public License as
13
- * published by the Free Software Foundation, either version 3 of the
14
- * License, or (at your option) any later version.
15
- *
16
- * marc-record-merge-js is distributed in the hope that it will be useful,
17
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
18
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
19
- * GNU Lesser General Public License for more details.
20
- *
21
- * You should have received a copy of the GNU Lesser General Public License
22
- * along with this program. If not, see <http://www.gnu.org/licenses/>.
23
- *
24
- * @licend The above is the entire license notice
25
- * for the JavaScript code in this file.
26
- *
27
- */
28
1
  import copy from './copy';
29
2
  import select, {strictEquality, subsetEquality} from './select';
30
3
 
@@ -1,66 +1,23 @@
1
- /**
2
- *
3
- * @licstart The following is the entire license notice for the JavaScript code in this file.
4
- *
5
- * Merge MARC records
6
- *
7
- * Copyright (C) 2015-2019 University Of Helsinki (The National Library Of Finland)
8
- *
9
- * This file is part of marc-record-merge-js
10
-
11
- * marc-record-merge-js program is free software: you can redistribute it and/or modify
12
- * it under the terms of the GNU Lesser General Public License as
13
- * published by the Free Software Foundation, either version 3 of the
14
- * License, or (at your option) any later version.
15
- *
16
- * marc-record-merge-js is distributed in the hope that it will be useful,
17
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
18
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
19
- * GNU Lesser General Public License for more details.
20
- *
21
- * You should have received a copy of the GNU Lesser General Public License
22
- * along with this program. If not, see <http://www.gnu.org/licenses/>.
23
- *
24
- * @licend The above is the entire license notice
25
- * for the JavaScript code in this file.
26
- *
27
- */
28
- /**
29
- * Test 01: The field is a control field (contains 'value') --> error message
30
- * Test 02: If there are multiple fields, return base
31
- * Test 03: Base and source tags are equal for one field --> return base
32
- * Test 04: Base and source tags are not equal --> return base
33
- * Note: to test for this, tagPattern has to allow two tags,
34
- * otherwise the unequal tag does not even pass source.get(tagPattern)
35
- * Test 05: Normalize subfield values (base and source are equal) --> return base
36
- * Test 06: Two subfields, both equal --> return base
37
- * Test 07: Two subfields, same codes, values of source are subsets of values of base --> replaceBasefieldWithSourcefield
38
- * Test 08: Two subfields, one is a subset, one has a different code --> return base
39
- * Test 09: Two subfields, same codes, values are not subsets --> return base
40
- * Test 10: sourceField is a proper superset of baseField (subfields a and b are equal, c is new) --> replaceBasefieldWithSourcefield
41
- * Test 11: sourceField is not a proper superset of baseField (different values in a and b, also new subfield c) --> return base
42
- * Test 12: sourceField is a proper superset of baseField (base values a and b are subsets of source values a and b, c is new in source) --> replaceBasefieldWithSourcefield
43
- * Test 13: Opposite of test 12, baseField is a proper superset of sourceField --> return base
44
- * Test 14: Normalization test with Cyrillic characters
45
- */
46
-
47
1
  import {normalizeSync} from 'normalize-diacritics';
48
2
  import createDebugLogger from 'debug';
3
+ import {MarcRecord} from '@natlibfi/marc-record';
49
4
 
50
5
  export function strictEquality(subfieldA, subfieldB) {
51
6
  return subfieldA.code === subfieldB.code &&
52
- subfieldA.value === subfieldB.value;
7
+ subfieldA.value === subfieldB.value;
53
8
  }
54
9
 
55
10
  export function subsetEquality(subfieldA, subfieldB) {
56
11
  return subfieldA.code === subfieldB.code &&
57
- (subfieldA.value.indexOf(subfieldB.value) !== -1 || subfieldB.value.indexOf(subfieldA.value) !== -1);
12
+ (subfieldA.value.indexOf(subfieldB.value) !== -1 || subfieldB.value.indexOf(subfieldA.value) !== -1);
58
13
  }
59
14
  // EqualityFunction can be either strictEquality or subsetEquality
60
15
  export default ({tagPattern, equalityFunction = strictEquality}) => (base, source) => {
61
- const debug = createDebugLogger('@natlibfi/marc-record-merge');
62
- const baseFields = base.get(tagPattern);
63
- const sourceFields = source.get(tagPattern);
16
+ const debug = createDebugLogger('@natlibfi/marc-record-merge:select');
17
+ const baseRecord = new MarcRecord(base, {subfieldValues: false});
18
+ const sourceRecord = new MarcRecord(source, {subfieldValues: false});
19
+ const baseFields = baseRecord.get(tagPattern);
20
+ const sourceFields = sourceRecord.get(tagPattern);
64
21
  const fieldTag = sourceFields.map(field => field.tag);
65
22
  debug(`Comparing field ${fieldTag}`);
66
23
 
@@ -1,66 +1,45 @@
1
- /**
2
- *
3
- * @licstart The following is the entire license notice for the JavaScript code in this file.
4
- *
5
- * Merge MARC records
6
- *
7
- * Copyright (C) 2015-2019 University Of Helsinki (The National Library Of Finland)
8
- *
9
- * This file is part of marc-record-merge-js
10
-
11
- * marc-record-merge-js program is free software: you can redistribute it and/or modify
12
- * it under the terms of the GNU Lesser General Public License as
13
- * published by the Free Software Foundation, either version 3 of the
14
- * License, or (at your option) any later version.
15
- *
16
- * marc-record-merge-js is distributed in the hope that it will be useful,
17
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
18
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
19
- * GNU Lesser General Public License for more details.
20
- *
21
- * You should have received a copy of the GNU Lesser General Public License
22
- * along with this program. If not, see <http://www.gnu.org/licenses/>.
23
- *
24
- * @licend The above is the entire license notice
25
- * for the JavaScript code in this file.
26
- *
27
- */
28
- import chai from 'chai';
29
- import fs from 'fs';
30
- import path from 'path';
1
+ import {expect} from 'chai';
31
2
  import {MarcRecord} from '@natlibfi/marc-record';
32
3
  import createReducer, {subsetEquality} from './select';
33
- import fixturesFactory, {READERS} from '@natlibfi/fixura';
4
+ import {READERS} from '@natlibfi/fixura';
5
+ import generateTests from '@natlibfi/fixugen';
34
6
 
35
7
  MarcRecord.setValidationOptions({subfieldValues: false});
36
8
 
37
- describe('reducers/select', () => {
38
- const {expect} = chai;
39
- const fixturesPath = path.join(__dirname, '..', '..', 'test-fixtures', 'reducers', 'select');
9
+ generateTests({
10
+ callback,
11
+ path: [__dirname, '..', '..', 'test-fixtures', 'reducers', 'select'],
12
+ useMetadataFile: true,
13
+ recurse: false,
14
+ fixura: {
15
+ reader: READERS.JSON,
16
+ failWhenNotFound: false
17
+ }
18
+ });
40
19
 
41
- fs.readdirSync(fixturesPath).forEach(subDir => {
42
- const {getFixture} = fixturesFactory({root: [fixturesPath, subDir], reader: READERS.JSON, failWhenNotFound: false});
43
- it(subDir, () => {
44
- const base = new MarcRecord(getFixture('base.json'));
45
- const source = new MarcRecord(getFixture('source.json'));
46
- const tagPattern = new RegExp(getFixture({components: ['pattern.txt'], reader: READERS.TEXT}), 'u');
47
- const expectedRecord = getFixture('merged.json');
48
- const expectedError = getFixture({components: ['expected-error.txt'], reader: READERS.TEXT});
49
- const equalityFunction = getEqualityFunction();
20
+ function callback({
21
+ getFixture,
22
+ disabled = false,
23
+ tagPatternRegExp = false,
24
+ expectedError = false,
25
+ useSubsetEquality = false
26
+ }) {
27
+ if (disabled) {
28
+ console.log('TEST DISABLED!'); // eslint-disable-line no-console
29
+ return;
30
+ }
31
+ const base = new MarcRecord(getFixture('base.json'), {subfieldValues: false});
32
+ const source = new MarcRecord(getFixture('source.json'), {subfieldValues: false});
33
+ const tagPattern = new RegExp(tagPatternRegExp, 'u');
34
+ const expectedRecord = getFixture('merged.json');
35
+ const equalityFunction = useSubsetEquality ? subsetEquality : undefined;
50
36
 
51
- // Bypass expected error in testing
52
- if (expectedError) {
53
- expect(() => createReducer.to.throw(Error, 'control field'));
54
- return;
55
- }
56
- const mergedRecord = createReducer({tagPattern, equalityFunction})(base, source);
57
- expect(mergedRecord.toObject()).to.eql(expectedRecord);
37
+ // Bypass expected error in testing
38
+ if (expectedError) {
39
+ expect(() => createReducer.to.throw(Error, 'control field'));
40
+ return;
41
+ }
58
42
 
59
- // Choose which equality function to use
60
- function getEqualityFunction() {
61
- const functionName = getFixture({components: ['equalityFunction.txt'], reader: READERS.TEXT});
62
- return functionName === 'subsetEquality' ? subsetEquality : undefined;
63
- }
64
- });
65
- });
66
- });
43
+ const mergedRecord = createReducer({tagPattern, equalityFunction})(base, source);
44
+ expect(mergedRecord.toObject()).to.eql(expectedRecord);
45
+ }
@@ -4,6 +4,6 @@
4
4
  {
5
5
  "tag": "001",
6
6
  "value": "007346734"
7
- }
7
+ }
8
8
  ]
9
9
  }
@@ -0,0 +1,4 @@
1
+ {
2
+ "description": "If base does not contain the field at all, it is copied from source to base",
3
+ "tagPatternRegExp": "^010$"
4
+ }
@@ -0,0 +1,4 @@
1
+ {
2
+ "description": "Identical control fields are not copied",
3
+ "tagPatternRegExp": "^001$"
4
+ }
@@ -15,6 +15,6 @@
15
15
  "value": "##2002021346"
16
16
  }
17
17
  ]
18
- }
18
+ }
19
19
  ]
20
20
  }
@@ -15,6 +15,6 @@
15
15
  "value": "##2002021346"
16
16
  }
17
17
  ]
18
- }
18
+ }
19
19
  ]
20
20
  }
@@ -0,0 +1,4 @@
1
+ {
2
+ "description": "Add missing control field to base",
3
+ "tagPatternRegExp": "^001$"
4
+ }
@@ -34,6 +34,6 @@
34
34
  "value": "##2002021357"
35
35
  }
36
36
  ]
37
- }
37
+ }
38
38
  ]
39
39
  }
@@ -34,6 +34,6 @@
34
34
  "value": "##2002021357"
35
35
  }
36
36
  ]
37
- }
37
+ }
38
38
  ]
39
39
  }
@@ -0,0 +1,4 @@
1
+ {
2
+ "description": "Identical data fields in base and source, not copied",
3
+ "tagPatternRegExp": "^010$"
4
+ }
@@ -34,6 +34,6 @@
34
34
  "value": "##2002021357"
35
35
  }
36
36
  ]
37
- }
37
+ }
38
38
  ]
39
39
  }
@@ -34,6 +34,6 @@
34
34
  "value": "##2002021357"
35
35
  }
36
36
  ]
37
- }
37
+ }
38
38
  ]
39
39
  }
@@ -0,0 +1,4 @@
1
+ {
2
+ "description": "Different data fields are copied from source to base (multiple fields)",
3
+ "tagPatternRegExp": "^010$"
4
+ }
@@ -0,0 +1,24 @@
1
+ {
2
+ "leader": "01331cam a22003494i 4500",
3
+ "fields": [
4
+ {
5
+ "tag": "001",
6
+ "value": "007346734"
7
+ },
8
+ {
9
+ "tag": "010",
10
+ "ind1": " ",
11
+ "ind2": " ",
12
+ "subfields": [
13
+ {
14
+ "code": "a",
15
+ "value": "##2002021346"
16
+ },
17
+ {
18
+ "code": "b",
19
+ "value": "##2002021356"
20
+ }
21
+ ]
22
+ }
23
+ ]
24
+ }
@@ -0,0 +1,39 @@
1
+ {
2
+ "leader": "01331cam a22003494i 4500",
3
+ "fields": [
4
+ {
5
+ "tag": "001",
6
+ "value": "007346734"
7
+ },
8
+ {
9
+ "tag": "010",
10
+ "ind1": " ",
11
+ "ind2": " ",
12
+ "subfields": [
13
+ {
14
+ "code": "a",
15
+ "value": "##2002021346"
16
+ },
17
+ {
18
+ "code": "b",
19
+ "value": "##2002021356"
20
+ }
21
+ ]
22
+ },
23
+ {
24
+ "tag": "010",
25
+ "ind1": " ",
26
+ "ind2": "1",
27
+ "subfields": [
28
+ {
29
+ "code": "a",
30
+ "value": "##2002021346"
31
+ },
32
+ {
33
+ "code": "b",
34
+ "value": "##2002021356"
35
+ }
36
+ ]
37
+ }
38
+ ]
39
+ }
@@ -0,0 +1,4 @@
1
+ {
2
+ "description": "Different data fields are copied from source to base (Ind2 diff)",
3
+ "tagPatternRegExp": "^010$"
4
+ }
@@ -0,0 +1,24 @@
1
+ {
2
+ "leader": "01331cam a22003494i 4500",
3
+ "fields": [
4
+ {
5
+ "tag": "001",
6
+ "value": "007346734"
7
+ },
8
+ {
9
+ "tag": "010",
10
+ "ind1": " ",
11
+ "ind2": "1",
12
+ "subfields": [
13
+ {
14
+ "code": "a",
15
+ "value": "##2002021346"
16
+ },
17
+ {
18
+ "code": "b",
19
+ "value": "##2002021356"
20
+ }
21
+ ]
22
+ }
23
+ ]
24
+ }
@@ -0,0 +1,39 @@
1
+ {
2
+ "leader": "01331cam a22003494i 4500",
3
+ "fields": [
4
+ {
5
+ "tag": "001",
6
+ "value": "007346734"
7
+ },
8
+ {
9
+ "tag": "010",
10
+ "ind1": " ",
11
+ "ind2": " ",
12
+ "subfields": [
13
+ {
14
+ "code": "a",
15
+ "value": "##2002021346"
16
+ },
17
+ {
18
+ "code": "b",
19
+ "value": "##2002021356"
20
+ }
21
+ ]
22
+ },
23
+ {
24
+ "tag": "010",
25
+ "ind1": " ",
26
+ "ind2": "1",
27
+ "subfields": [
28
+ {
29
+ "code": "a",
30
+ "value": "##2002021346"
31
+ },
32
+ {
33
+ "code": "b",
34
+ "value": "##2002021356"
35
+ }
36
+ ]
37
+ }
38
+ ]
39
+ }
@@ -0,0 +1,39 @@
1
+ {
2
+ "leader": "01331cam a22003494i 4500",
3
+ "fields": [
4
+ {
5
+ "tag": "001",
6
+ "value": "007346734"
7
+ },
8
+ {
9
+ "tag": "010",
10
+ "ind1": " ",
11
+ "ind2": " ",
12
+ "subfields": [
13
+ {
14
+ "code": "a",
15
+ "value": "##2002021346"
16
+ },
17
+ {
18
+ "code": "b",
19
+ "value": "##2002021356"
20
+ }
21
+ ]
22
+ },
23
+ {
24
+ "tag": "010",
25
+ "ind1": " ",
26
+ "ind2": "1",
27
+ "subfields": [
28
+ {
29
+ "code": "a",
30
+ "value": "##2002021346"
31
+ },
32
+ {
33
+ "code": "b",
34
+ "value": "##2002021356"
35
+ }
36
+ ]
37
+ }
38
+ ]
39
+ }
@@ -0,0 +1,5 @@
1
+ {
2
+ "description": "Different data fields are copied from source to base (Ind2 diff, multiple fields in base)",
3
+ "tagPatternRegExp": "^010$",
4
+ "only": false
5
+ }
@@ -0,0 +1,24 @@
1
+ {
2
+ "leader": "01331cam a22003494i 4500",
3
+ "fields": [
4
+ {
5
+ "tag": "001",
6
+ "value": "007346734"
7
+ },
8
+ {
9
+ "tag": "010",
10
+ "ind1": " ",
11
+ "ind2": "1",
12
+ "subfields": [
13
+ {
14
+ "code": "a",
15
+ "value": "##2002021346"
16
+ },
17
+ {
18
+ "code": "b",
19
+ "value": "##2002021356"
20
+ }
21
+ ]
22
+ }
23
+ ]
24
+ }