@natlibfi/marc-record-validators-melinda 3.2.0 → 3.3.14-alpha.3

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 (593) hide show
  1. package/.github/CODEOWNERS +2 -0
  2. package/.github/dependabot.yml +40 -0
  3. package/.github/workflows/melinda-node-tests.yml +61 -0
  4. package/LICENSE.txt +21 -661
  5. package/README.md +4 -5
  6. package/dist/access-rights.js +94 -0
  7. package/dist/access-rights.js.map +1 -0
  8. package/dist/access-rights.spec.js +150 -0
  9. package/dist/access-rights.spec.js.map +1 -0
  10. package/dist/double-commas.js +17 -27
  11. package/dist/double-commas.js.map +1 -1
  12. package/dist/double-commas.spec.js +72 -27
  13. package/dist/double-commas.spec.js.map +1 -1
  14. package/dist/duplicates-ind1.js +47 -27
  15. package/dist/duplicates-ind1.js.map +1 -1
  16. package/dist/duplicates-ind1.spec.js +44 -27
  17. package/dist/duplicates-ind1.spec.js.map +1 -1
  18. package/dist/empty-fields.js +79 -29
  19. package/dist/empty-fields.js.map +1 -1
  20. package/dist/empty-fields.spec.js +113 -27
  21. package/dist/empty-fields.spec.js.map +1 -1
  22. package/dist/ending-punctuation-conf.js +772 -129
  23. package/dist/ending-punctuation-conf.js.map +1 -1
  24. package/dist/ending-punctuation.js +291 -72
  25. package/dist/ending-punctuation.js.map +1 -1
  26. package/dist/ending-punctuation.spec.js +2638 -118
  27. package/dist/ending-punctuation.spec.js.map +1 -1
  28. package/dist/ending-whitespace.js +58 -0
  29. package/dist/ending-whitespace.js.map +1 -0
  30. package/dist/ending-whitespace.spec.js +42 -0
  31. package/dist/ending-whitespace.spec.js.map +1 -0
  32. package/dist/field-521-fix.js +96 -0
  33. package/dist/field-521-fix.js.map +1 -0
  34. package/dist/field-521-fix.spec.js +51 -0
  35. package/dist/field-521-fix.spec.js.map +1 -0
  36. package/dist/field-exclusion.js +214 -63
  37. package/dist/field-exclusion.js.map +1 -1
  38. package/dist/field-exclusion.spec.js +1057 -31
  39. package/dist/field-exclusion.spec.js.map +1 -1
  40. package/dist/field-structure.js +249 -78
  41. package/dist/field-structure.js.map +1 -1
  42. package/dist/field-structure.spec.js +534 -31
  43. package/dist/field-structure.spec.js.map +1 -1
  44. package/dist/fields-present.js +31 -27
  45. package/dist/fields-present.js.map +1 -1
  46. package/dist/fields-present.spec.js +120 -27
  47. package/dist/fields-present.spec.js.map +1 -1
  48. package/dist/fixed-fields.js +72 -27
  49. package/dist/fixed-fields.js.map +1 -1
  50. package/dist/fixed-fields.spec.js +139 -27
  51. package/dist/fixed-fields.spec.js.map +1 -1
  52. package/dist/identical-fields.js +42 -28
  53. package/dist/identical-fields.js.map +1 -1
  54. package/dist/identical-fields.spec.js +98 -27
  55. package/dist/identical-fields.spec.js.map +1 -1
  56. package/dist/index.js +202 -27
  57. package/dist/index.js.map +1 -1
  58. package/dist/indicator-fixes.js +191 -0
  59. package/dist/indicator-fixes.js.map +1 -0
  60. package/dist/indicator-fixes.spec.js +51 -0
  61. package/dist/indicator-fixes.spec.js.map +1 -0
  62. package/dist/isbn-issn.js +266 -27
  63. package/dist/isbn-issn.js.map +1 -1
  64. package/dist/isbn-issn.spec.js +594 -27
  65. package/dist/isbn-issn.spec.js.map +1 -1
  66. package/dist/item-language.js +171 -27
  67. package/dist/item-language.js.map +1 -1
  68. package/dist/item-language.spec.js +305 -27
  69. package/dist/item-language.spec.js.map +1 -1
  70. package/dist/mergeField500Lisapainokset.js +155 -0
  71. package/dist/mergeField500Lisapainokset.js.map +1 -0
  72. package/dist/mergeField500Lisapainokset.spec.js +51 -0
  73. package/dist/mergeField500Lisapainokset.spec.js.map +1 -0
  74. package/dist/mergeRelatorTermFields.js +140 -0
  75. package/dist/mergeRelatorTermFields.js.map +1 -0
  76. package/dist/mergeRelatorTermFields.spec.js +51 -0
  77. package/dist/mergeRelatorTermFields.spec.js.map +1 -0
  78. package/dist/multiple-subfield-0.js +120 -0
  79. package/dist/multiple-subfield-0.js.map +1 -0
  80. package/dist/multiple-subfield-0.spec.js +51 -0
  81. package/dist/multiple-subfield-0.spec.js.map +1 -0
  82. package/dist/non-breaking-space.js +61 -0
  83. package/dist/non-breaking-space.js.map +1 -0
  84. package/dist/non-breaking-space.spec.js +42 -0
  85. package/dist/non-breaking-space.spec.js.map +1 -0
  86. package/dist/normalize-identifiers.js +210 -0
  87. package/dist/normalize-identifiers.js.map +1 -0
  88. package/dist/normalize-identifiers.spec.js +51 -0
  89. package/dist/normalize-identifiers.spec.js.map +1 -0
  90. package/dist/normalize-utf8-diacritics.js +140 -0
  91. package/dist/normalize-utf8-diacritics.js.map +1 -0
  92. package/dist/normalize-utf8-diacritics.spec.js +51 -0
  93. package/dist/normalize-utf8-diacritics.spec.js.map +1 -0
  94. package/dist/punctuation/index.js +281 -0
  95. package/dist/punctuation/index.js.map +1 -0
  96. package/dist/punctuation/rules/aut.js +332 -0
  97. package/dist/punctuation/rules/aut.js.map +1 -0
  98. package/dist/punctuation/rules/bib.js +374 -0
  99. package/dist/punctuation/rules/bib.js.map +1 -0
  100. package/dist/punctuation/rules/index.js +21 -0
  101. package/dist/punctuation/rules/index.js.map +1 -0
  102. package/dist/punctuation.spec.js +51 -0
  103. package/dist/punctuation.spec.js.map +1 -0
  104. package/dist/punctuation2.js +726 -0
  105. package/dist/punctuation2.js.map +1 -0
  106. package/dist/punctuation2.spec.js +51 -0
  107. package/dist/punctuation2.spec.js.map +1 -0
  108. package/dist/reindexSubfield6OccurenceNumbers.js +199 -0
  109. package/dist/reindexSubfield6OccurenceNumbers.js.map +1 -0
  110. package/dist/reindexSubfield6OccurenceNumbers.spec.js +51 -0
  111. package/dist/reindexSubfield6OccurenceNumbers.spec.js.map +1 -0
  112. package/dist/removeDuplicateDataFields.js +405 -0
  113. package/dist/removeDuplicateDataFields.js.map +1 -0
  114. package/dist/removeDuplicateDataFields.spec.js +51 -0
  115. package/dist/removeDuplicateDataFields.spec.js.map +1 -0
  116. package/dist/removeInferiorDataFields.js +245 -0
  117. package/dist/removeInferiorDataFields.js.map +1 -0
  118. package/dist/removeInferiorDataFields.spec.js +51 -0
  119. package/dist/removeInferiorDataFields.spec.js.map +1 -0
  120. package/dist/resolvable-ext-references-melinda.js +112 -31
  121. package/dist/resolvable-ext-references-melinda.js.map +1 -1
  122. package/dist/resolvable-ext-references-melinda.spec.js +166 -27
  123. package/dist/resolvable-ext-references-melinda.spec.js.map +1 -1
  124. package/dist/resolveOrphanedSubfield6s.js +116 -0
  125. package/dist/resolveOrphanedSubfield6s.js.map +1 -0
  126. package/dist/resolveOrphanedSubfield6s.spec.js +51 -0
  127. package/dist/resolveOrphanedSubfield6s.spec.js.map +1 -0
  128. package/dist/sanitize-vocabulary-source-codes.js +93 -0
  129. package/dist/sanitize-vocabulary-source-codes.js.map +1 -0
  130. package/dist/sanitize-vocabulary-source-codes.spec.js +51 -0
  131. package/dist/sanitize-vocabulary-source-codes.spec.js.map +1 -0
  132. package/dist/sort-tags.js +53 -27
  133. package/dist/sort-tags.js.map +1 -1
  134. package/dist/sort-tags.spec.js +206 -27
  135. package/dist/sort-tags.spec.js.map +1 -1
  136. package/dist/sortRelatorTerms.js +135 -0
  137. package/dist/sortRelatorTerms.js.map +1 -0
  138. package/dist/sortRelatorTerms.spec.js +51 -0
  139. package/dist/sortRelatorTerms.spec.js.map +1 -0
  140. package/dist/sortSubfields.js +279 -0
  141. package/dist/sortSubfields.js.map +1 -0
  142. package/dist/sortSubfields.spec.js +51 -0
  143. package/dist/sortSubfields.spec.js.map +1 -0
  144. package/dist/stripPunctuation.js +49 -0
  145. package/dist/stripPunctuation.js.map +1 -0
  146. package/dist/stripPunctuation.spec.js +51 -0
  147. package/dist/stripPunctuation.spec.js.map +1 -0
  148. package/dist/subfield-exclusion.js +174 -57
  149. package/dist/subfield-exclusion.js.map +1 -1
  150. package/dist/subfield-exclusion.spec.js +521 -31
  151. package/dist/subfield-exclusion.spec.js.map +1 -1
  152. package/dist/subfield6Utils.js +457 -0
  153. package/dist/subfield6Utils.js.map +1 -0
  154. package/dist/subfield8Utils.js +99 -0
  155. package/dist/subfield8Utils.js.map +1 -0
  156. package/dist/typeOfDate-008.js +48 -0
  157. package/dist/typeOfDate-008.js.map +1 -0
  158. package/dist/typeOfDate-008.spec.js +47 -0
  159. package/dist/typeOfDate-008.spec.js.map +1 -0
  160. package/dist/unicode-decomposition.js +139 -30
  161. package/dist/unicode-decomposition.js.map +1 -1
  162. package/dist/unicode-decomposition.spec.js +90 -27
  163. package/dist/unicode-decomposition.spec.js.map +1 -1
  164. package/dist/update-field-540.js +119 -0
  165. package/dist/update-field-540.js.map +1 -0
  166. package/dist/update-field-540.spec.js +51 -0
  167. package/dist/update-field-540.spec.js.map +1 -0
  168. package/dist/urn.js +185 -0
  169. package/dist/urn.js.map +1 -0
  170. package/dist/urn.spec.js +238 -0
  171. package/dist/urn.spec.js.map +1 -0
  172. package/dist/utils.js +58 -0
  173. package/dist/utils.js.map +1 -0
  174. package/package.json +114 -124
  175. package/src/access-rights.js +84 -0
  176. package/src/access-rights.spec.js +126 -0
  177. package/src/double-commas.js +12 -49
  178. package/src/double-commas.spec.js +50 -82
  179. package/src/duplicates-ind1.js +34 -74
  180. package/src/duplicates-ind1.spec.js +39 -117
  181. package/src/empty-fields.js +62 -74
  182. package/src/empty-fields.spec.js +134 -207
  183. package/src/ending-punctuation-conf.js +679 -644
  184. package/src/ending-punctuation.js +260 -250
  185. package/src/ending-punctuation.spec.js +2545 -2322
  186. package/src/ending-whitespace.js +40 -0
  187. package/src/ending-whitespace.spec.js +44 -0
  188. package/src/field-521-fix.js +92 -0
  189. package/src/field-521-fix.spec.js +52 -0
  190. package/src/field-exclusion.js +197 -215
  191. package/src/field-exclusion.spec.js +883 -481
  192. package/src/field-structure.js +213 -271
  193. package/src/field-structure.spec.js +597 -474
  194. package/src/fields-present.js +19 -49
  195. package/src/fields-present.spec.js +90 -91
  196. package/src/fixed-fields.js +61 -94
  197. package/src/fixed-fields.spec.js +81 -125
  198. package/src/identical-fields.js +29 -48
  199. package/src/identical-fields.spec.js +114 -146
  200. package/src/index.js +41 -46
  201. package/src/indicator-fixes.js +211 -0
  202. package/src/indicator-fixes.spec.js +52 -0
  203. package/src/isbn-issn.js +254 -106
  204. package/src/isbn-issn.spec.js +399 -172
  205. package/src/item-language.js +158 -195
  206. package/src/item-language.spec.js +314 -306
  207. package/src/mergeField500Lisapainokset.js +153 -0
  208. package/src/mergeField500Lisapainokset.spec.js +52 -0
  209. package/src/mergeRelatorTermFields.js +143 -0
  210. package/src/mergeRelatorTermFields.spec.js +52 -0
  211. package/src/multiple-subfield-0.js +129 -0
  212. package/src/multiple-subfield-0.spec.js +52 -0
  213. package/src/non-breaking-space.js +49 -0
  214. package/src/non-breaking-space.spec.js +44 -0
  215. package/src/normalize-identifiers.js +197 -0
  216. package/src/normalize-identifiers.spec.js +52 -0
  217. package/src/normalize-utf8-diacritics.js +141 -0
  218. package/src/normalize-utf8-diacritics.spec.js +52 -0
  219. package/src/punctuation/index.js +292 -0
  220. package/src/punctuation/rules/aut.js +372 -0
  221. package/src/punctuation/rules/bib.js +420 -0
  222. package/src/punctuation/rules/index.js +7 -0
  223. package/src/punctuation.spec.js +52 -0
  224. package/src/punctuation2.js +441 -0
  225. package/src/punctuation2.spec.js +52 -0
  226. package/src/reindexSubfield6OccurenceNumbers.js +210 -0
  227. package/src/reindexSubfield6OccurenceNumbers.spec.js +52 -0
  228. package/src/removeDuplicateDataFields.js +447 -0
  229. package/src/removeDuplicateDataFields.spec.js +52 -0
  230. package/src/removeInferiorDataFields.js +259 -0
  231. package/src/removeInferiorDataFields.spec.js +52 -0
  232. package/src/resolvable-ext-references-melinda.js +89 -122
  233. package/src/resolvable-ext-references-melinda.spec.js +168 -198
  234. package/src/resolveOrphanedSubfield6s.js +115 -0
  235. package/src/resolveOrphanedSubfield6s.spec.js +52 -0
  236. package/src/sanitize-vocabulary-source-codes.js +99 -0
  237. package/src/sanitize-vocabulary-source-codes.spec.js +52 -0
  238. package/src/sort-tags.js +34 -60
  239. package/src/sort-tags.spec.js +256 -290
  240. package/src/sortRelatorTerms.js +142 -0
  241. package/src/sortRelatorTerms.spec.js +52 -0
  242. package/src/sortSubfields.js +176 -0
  243. package/src/sortSubfields.spec.js +52 -0
  244. package/src/stripPunctuation.js +42 -0
  245. package/src/stripPunctuation.spec.js +52 -0
  246. package/src/subfield-exclusion.js +157 -180
  247. package/src/subfield-exclusion.spec.js +507 -453
  248. package/src/subfield6Utils.js +485 -0
  249. package/src/subfield8Utils.js +102 -0
  250. package/src/typeOfDate-008.js +40 -0
  251. package/src/typeOfDate-008.spec.js +47 -0
  252. package/src/unicode-decomposition.js +130 -145
  253. package/src/unicode-decomposition.spec.js +89 -115
  254. package/src/update-field-540.js +99 -0
  255. package/src/update-field-540.spec.js +52 -0
  256. package/src/urn.js +164 -0
  257. package/src/urn.spec.js +231 -0
  258. package/src/utils.js +52 -0
  259. package/test-fixtures/duplicates-ind1/01/expectedResult.json +4 -0
  260. package/test-fixtures/duplicates-ind1/01/metadata.json +4 -0
  261. package/test-fixtures/duplicates-ind1/01/record.json +16 -0
  262. package/test-fixtures/duplicates-ind1/02/expectedResult.json +6 -0
  263. package/test-fixtures/duplicates-ind1/02/metadata.json +4 -0
  264. package/test-fixtures/duplicates-ind1/02/record.json +16 -0
  265. package/test-fixtures/duplicates-ind1/03/expectedResult.json +13 -0
  266. package/test-fixtures/duplicates-ind1/03/metadata.json +6 -0
  267. package/test-fixtures/duplicates-ind1/03/record.json +16 -0
  268. package/test-fixtures/ending-whitespace/01/expectedResult.json +4 -0
  269. package/test-fixtures/ending-whitespace/01/metadata.json +6 -0
  270. package/test-fixtures/ending-whitespace/01/record.json +15 -0
  271. package/test-fixtures/ending-whitespace/02/expectedResult.json +4 -0
  272. package/test-fixtures/ending-whitespace/02/metadata.json +6 -0
  273. package/test-fixtures/ending-whitespace/02/record.json +15 -0
  274. package/test-fixtures/ending-whitespace/03/expectedResult.json +17 -0
  275. package/test-fixtures/ending-whitespace/03/metadata.json +6 -0
  276. package/test-fixtures/ending-whitespace/03/record.json +15 -0
  277. package/test-fixtures/ending-whitespace/04/expectedResult.json +10 -0
  278. package/test-fixtures/ending-whitespace/04/metadata.json +6 -0
  279. package/test-fixtures/ending-whitespace/04/record.json +8 -0
  280. package/test-fixtures/fix521/01/expectedResult.json +6 -0
  281. package/test-fixtures/fix521/01/metadata.json +5 -0
  282. package/test-fixtures/fix521/01/record.json +13 -0
  283. package/test-fixtures/fix521/02/expectedResult.json +15 -0
  284. package/test-fixtures/fix521/02/metadata.json +5 -0
  285. package/test-fixtures/fix521/02/record.json +13 -0
  286. package/test-fixtures/fix521/03/expectedResult.json +5 -0
  287. package/test-fixtures/fix521/03/metadata.json +5 -0
  288. package/test-fixtures/fix521/03/record.json +13 -0
  289. package/test-fixtures/indicator-fixes/01/expectedResult.json +9 -0
  290. package/test-fixtures/indicator-fixes/01/metadata.json +5 -0
  291. package/test-fixtures/indicator-fixes/01/record.json +64 -0
  292. package/test-fixtures/indicator-fixes/02/expectedResult.json +66 -0
  293. package/test-fixtures/indicator-fixes/02/metadata.json +5 -0
  294. package/test-fixtures/indicator-fixes/02/record.json +64 -0
  295. package/test-fixtures/indicator-fixes/03/expectedResult.json +55 -0
  296. package/test-fixtures/indicator-fixes/03/metadata.json +5 -0
  297. package/test-fixtures/indicator-fixes/03/record.json +54 -0
  298. package/test-fixtures/indicator-fixes/04/expectedResult.json +66 -0
  299. package/test-fixtures/indicator-fixes/04/metadata.json +5 -0
  300. package/test-fixtures/indicator-fixes/04/record.json +65 -0
  301. package/test-fixtures/indicator-fixes/05/expectedResult.json +66 -0
  302. package/test-fixtures/indicator-fixes/05/metadata.json +5 -0
  303. package/test-fixtures/indicator-fixes/05/record.json +65 -0
  304. package/test-fixtures/indicator-fixes/06/expectedResult.json +75 -0
  305. package/test-fixtures/indicator-fixes/06/metadata.json +5 -0
  306. package/test-fixtures/indicator-fixes/06/record.json +74 -0
  307. package/test-fixtures/lisapainokset/fixer/01/expectedResult.json +37 -0
  308. package/test-fixtures/lisapainokset/fixer/01/metadata.json +6 -0
  309. package/test-fixtures/lisapainokset/fixer/01/record.json +61 -0
  310. package/test-fixtures/lisapainokset/fixer/02/expectedResult.json +44 -0
  311. package/test-fixtures/lisapainokset/fixer/02/metadata.json +6 -0
  312. package/test-fixtures/lisapainokset/fixer/02/record.json +45 -0
  313. package/test-fixtures/lisapainokset/fixer/03/expectedResult.json +21 -0
  314. package/test-fixtures/lisapainokset/fixer/03/metadata.json +6 -0
  315. package/test-fixtures/lisapainokset/fixer/03/record.json +45 -0
  316. package/test-fixtures/lisapainokset/validator/01/expectedResult.json +7 -0
  317. package/test-fixtures/lisapainokset/validator/01/metadata.json +6 -0
  318. package/test-fixtures/lisapainokset/validator/01/record.json +45 -0
  319. package/test-fixtures/lisapainokset/validator/02/expectedResult.json +6 -0
  320. package/test-fixtures/lisapainokset/validator/02/metadata.json +6 -0
  321. package/test-fixtures/lisapainokset/validator/02/record.json +61 -0
  322. package/test-fixtures/lisapainokset/validator/03/expectedResult.json +4 -0
  323. package/test-fixtures/lisapainokset/validator/03/metadata.json +6 -0
  324. package/test-fixtures/lisapainokset/validator/03/record.json +37 -0
  325. package/test-fixtures/mergeRelatorTermFields/fixer/01/expectedResult.json +14 -0
  326. package/test-fixtures/mergeRelatorTermFields/fixer/01/metadata.json +6 -0
  327. package/test-fixtures/mergeRelatorTermFields/fixer/01/record.json +16 -0
  328. package/test-fixtures/mergeRelatorTermFields/fixer/02/expectedResult.json +17 -0
  329. package/test-fixtures/mergeRelatorTermFields/fixer/02/metadata.json +6 -0
  330. package/test-fixtures/mergeRelatorTermFields/fixer/02/record.json +23 -0
  331. package/test-fixtures/mergeRelatorTermFields/validator/01/expectedResult.json +6 -0
  332. package/test-fixtures/mergeRelatorTermFields/validator/01/metadata.json +6 -0
  333. package/test-fixtures/mergeRelatorTermFields/validator/01/record.json +16 -0
  334. package/test-fixtures/mergeRelatorTermFields/validator/02/expectedResult.json +4 -0
  335. package/test-fixtures/mergeRelatorTermFields/validator/02/metadata.json +6 -0
  336. package/test-fixtures/mergeRelatorTermFields/validator/02/record.json +16 -0
  337. package/test-fixtures/non-breaking-space/01/expectedResult.json +4 -0
  338. package/test-fixtures/non-breaking-space/01/metadata.json +6 -0
  339. package/test-fixtures/non-breaking-space/01/record.json +15 -0
  340. package/test-fixtures/non-breaking-space/02/expectedResult.json +4 -0
  341. package/test-fixtures/non-breaking-space/02/metadata.json +6 -0
  342. package/test-fixtures/non-breaking-space/02/record.json +15 -0
  343. package/test-fixtures/non-breaking-space/03/expectedResult.json +17 -0
  344. package/test-fixtures/non-breaking-space/03/metadata.json +6 -0
  345. package/test-fixtures/non-breaking-space/03/record.json +15 -0
  346. package/test-fixtures/non-breaking-space/04/expectedResult.json +21 -0
  347. package/test-fixtures/non-breaking-space/04/metadata.json +6 -0
  348. package/test-fixtures/non-breaking-space/04/record.json +19 -0
  349. package/test-fixtures/normalize-identifiers/01/expectedResult.json +8 -0
  350. package/test-fixtures/normalize-identifiers/01/metadata.json +5 -0
  351. package/test-fixtures/normalize-identifiers/01/record.json +81 -0
  352. package/test-fixtures/normalize-identifiers/02/expectedResult.json +92 -0
  353. package/test-fixtures/normalize-identifiers/02/metadata.json +5 -0
  354. package/test-fixtures/normalize-identifiers/02/record.json +92 -0
  355. package/test-fixtures/normalize-identifiers/03/expectedResult.json +63 -0
  356. package/test-fixtures/normalize-identifiers/03/metadata.json +5 -0
  357. package/test-fixtures/normalize-identifiers/03/record.json +61 -0
  358. package/test-fixtures/normalize-identifiers/04/expectedResult.json +79 -0
  359. package/test-fixtures/normalize-identifiers/04/metadata.json +5 -0
  360. package/test-fixtures/normalize-identifiers/04/record.json +77 -0
  361. package/test-fixtures/normalize-utf8-diacritics/01/expectedResult.json +7 -0
  362. package/test-fixtures/normalize-utf8-diacritics/01/metadata.json +5 -0
  363. package/test-fixtures/normalize-utf8-diacritics/01/record.json +39 -0
  364. package/test-fixtures/normalize-utf8-diacritics/02/expectedResult.json +41 -0
  365. package/test-fixtures/normalize-utf8-diacritics/02/metadata.json +5 -0
  366. package/test-fixtures/normalize-utf8-diacritics/02/record.json +39 -0
  367. package/test-fixtures/normalize-utf8-diacritics/03/expectedResult.json +5 -0
  368. package/test-fixtures/normalize-utf8-diacritics/03/metadata.json +5 -0
  369. package/test-fixtures/normalize-utf8-diacritics/03/record.json +37 -0
  370. package/test-fixtures/normalize-utf8-diacritics/04/expectedResult.json +41 -0
  371. package/test-fixtures/normalize-utf8-diacritics/04/metadata.json +5 -0
  372. package/test-fixtures/normalize-utf8-diacritics/04/record.json +39 -0
  373. package/test-fixtures/normalize-utf8-diacritics/05/expectedResult.json +41 -0
  374. package/test-fixtures/normalize-utf8-diacritics/05/metadata.json +5 -0
  375. package/test-fixtures/normalize-utf8-diacritics/05/record.json +41 -0
  376. package/test-fixtures/punctuation/01/expectedResult.json +3 -0
  377. package/test-fixtures/punctuation/01/metadata.json +4 -0
  378. package/test-fixtures/punctuation/01/record.json +18 -0
  379. package/test-fixtures/punctuation/02/expectedResult.json +3 -0
  380. package/test-fixtures/punctuation/02/metadata.json +4 -0
  381. package/test-fixtures/punctuation/02/record.json +18 -0
  382. package/test-fixtures/punctuation/03/expectedResult.json +21 -0
  383. package/test-fixtures/punctuation/03/metadata.json +5 -0
  384. package/test-fixtures/punctuation/03/record.json +19 -0
  385. package/test-fixtures/punctuation/04/expectedResult.json +21 -0
  386. package/test-fixtures/punctuation/04/metadata.json +5 -0
  387. package/test-fixtures/punctuation/04/record.json +19 -0
  388. package/test-fixtures/punctuation/05/expectedResult.json +44 -0
  389. package/test-fixtures/punctuation/05/metadata.json +5 -0
  390. package/test-fixtures/punctuation/05/record.json +42 -0
  391. package/test-fixtures/punctuation2/01/expectedResult.json +12 -0
  392. package/test-fixtures/punctuation2/01/metadata.json +6 -0
  393. package/test-fixtures/punctuation2/01/record.json +37 -0
  394. package/test-fixtures/punctuation2/02/expectedResult.json +4 -0
  395. package/test-fixtures/punctuation2/02/metadata.json +6 -0
  396. package/test-fixtures/punctuation2/02/record.json +14 -0
  397. package/test-fixtures/punctuation2/04/expectedResult.json +7 -0
  398. package/test-fixtures/punctuation2/04/metadata.json +6 -0
  399. package/test-fixtures/punctuation2/04/record.json +22 -0
  400. package/test-fixtures/punctuation2/05/expectedResult.json +6 -0
  401. package/test-fixtures/punctuation2/05/metadata.json +6 -0
  402. package/test-fixtures/punctuation2/05/record.json +12 -0
  403. package/test-fixtures/punctuation2/98/expectedResult.json +45 -0
  404. package/test-fixtures/punctuation2/98/metadata.json +6 -0
  405. package/test-fixtures/punctuation2/98/record.json +43 -0
  406. package/test-fixtures/punctuation2/99/expectedResult.json +15 -0
  407. package/test-fixtures/punctuation2/99/metadata.json +6 -0
  408. package/test-fixtures/punctuation2/99/record.json +14 -0
  409. package/test-fixtures/reindex-sf6-occurence-numbers/f01/expectedResult.json +35 -0
  410. package/test-fixtures/reindex-sf6-occurence-numbers/f01/metadata.json +6 -0
  411. package/test-fixtures/reindex-sf6-occurence-numbers/f01/record.json +34 -0
  412. package/test-fixtures/reindex-sf6-occurence-numbers/f02/expectedResult.json +53 -0
  413. package/test-fixtures/reindex-sf6-occurence-numbers/f02/metadata.json +6 -0
  414. package/test-fixtures/reindex-sf6-occurence-numbers/f02/record.json +51 -0
  415. package/test-fixtures/reindex-sf6-occurence-numbers/f03/expectedResult.json +46 -0
  416. package/test-fixtures/reindex-sf6-occurence-numbers/f03/metadata.json +7 -0
  417. package/test-fixtures/reindex-sf6-occurence-numbers/f03/record.json +44 -0
  418. package/test-fixtures/reindex-sf6-occurence-numbers/v01/expectedResult.json +6 -0
  419. package/test-fixtures/reindex-sf6-occurence-numbers/v01/metadata.json +5 -0
  420. package/test-fixtures/reindex-sf6-occurence-numbers/v01/record.json +31 -0
  421. package/test-fixtures/reindex-sf6-occurence-numbers/v02/expectedResult.json +6 -0
  422. package/test-fixtures/reindex-sf6-occurence-numbers/v02/metadata.json +6 -0
  423. package/test-fixtures/reindex-sf6-occurence-numbers/v02/record.json +38 -0
  424. package/test-fixtures/reindex-sf6-occurence-numbers/v03/expectedResult.json +6 -0
  425. package/test-fixtures/reindex-sf6-occurence-numbers/v03/metadata.json +6 -0
  426. package/test-fixtures/reindex-sf6-occurence-numbers/v03/record.json +30 -0
  427. package/test-fixtures/remove-duplicate-datafields/f01/expectedResult.json +35 -0
  428. package/test-fixtures/remove-duplicate-datafields/f01/metadata.json +6 -0
  429. package/test-fixtures/remove-duplicate-datafields/f01/record.json +34 -0
  430. package/test-fixtures/remove-duplicate-datafields/f03/expectedResult.json +20 -0
  431. package/test-fixtures/remove-duplicate-datafields/f03/metadata.json +6 -0
  432. package/test-fixtures/remove-duplicate-datafields/f03/record.json +33 -0
  433. package/test-fixtures/remove-duplicate-datafields/f03b/expectedResult.json +20 -0
  434. package/test-fixtures/remove-duplicate-datafields/f03b/metadata.json +6 -0
  435. package/test-fixtures/remove-duplicate-datafields/f03b/record.json +35 -0
  436. package/test-fixtures/remove-duplicate-datafields/f03c/expectedResult.json +25 -0
  437. package/test-fixtures/remove-duplicate-datafields/f03c/metadata.json +6 -0
  438. package/test-fixtures/remove-duplicate-datafields/f03c/record.json +43 -0
  439. package/test-fixtures/remove-duplicate-datafields/f04/expectedResult.json +31 -0
  440. package/test-fixtures/remove-duplicate-datafields/f04/metadata.json +6 -0
  441. package/test-fixtures/remove-duplicate-datafields/f04/record.json +41 -0
  442. package/test-fixtures/remove-duplicate-datafields/f05/expectedResult.json +23 -0
  443. package/test-fixtures/remove-duplicate-datafields/f05/metadata.json +6 -0
  444. package/test-fixtures/remove-duplicate-datafields/f05/record.json +29 -0
  445. package/test-fixtures/remove-duplicate-datafields/f06/expectedResult.json +24 -0
  446. package/test-fixtures/remove-duplicate-datafields/f06/metadata.json +6 -0
  447. package/test-fixtures/remove-duplicate-datafields/f06/record.json +41 -0
  448. package/test-fixtures/remove-duplicate-datafields/f07/expectedResult.json +15 -0
  449. package/test-fixtures/remove-duplicate-datafields/f07/metadata.json +6 -0
  450. package/test-fixtures/remove-duplicate-datafields/f07/record.json +21 -0
  451. package/test-fixtures/remove-duplicate-datafields/f08/expectedResult.json +21 -0
  452. package/test-fixtures/remove-duplicate-datafields/f08/metadata.json +6 -0
  453. package/test-fixtures/remove-duplicate-datafields/f08/record.json +33 -0
  454. package/test-fixtures/remove-duplicate-datafields/f09/expectedResult.json +6 -0
  455. package/test-fixtures/remove-duplicate-datafields/f09/metadata.json +6 -0
  456. package/test-fixtures/remove-duplicate-datafields/f09/record.json +9 -0
  457. package/test-fixtures/remove-duplicate-datafields/f10/expectedResult.json +15 -0
  458. package/test-fixtures/remove-duplicate-datafields/f10/metadata.json +6 -0
  459. package/test-fixtures/remove-duplicate-datafields/f10/record.json +24 -0
  460. package/test-fixtures/remove-duplicate-datafields/f11/expectedResult.json +30 -0
  461. package/test-fixtures/remove-duplicate-datafields/f11/metadata.json +6 -0
  462. package/test-fixtures/remove-duplicate-datafields/f11/record.json +53 -0
  463. package/test-fixtures/remove-duplicate-datafields/v01/expectedResult.json +6 -0
  464. package/test-fixtures/remove-duplicate-datafields/v01/metadata.json +6 -0
  465. package/test-fixtures/remove-duplicate-datafields/v01/record.json +31 -0
  466. package/test-fixtures/remove-duplicate-datafields/v02/expectedResult.json +10 -0
  467. package/test-fixtures/remove-duplicate-datafields/v02/metadata.json +6 -0
  468. package/test-fixtures/remove-duplicate-datafields/v02/record.json +45 -0
  469. package/test-fixtures/remove-duplicate-datafields/v03/expectedResult.json +6 -0
  470. package/test-fixtures/remove-duplicate-datafields/v03/metadata.json +7 -0
  471. package/test-fixtures/remove-duplicate-datafields/v03/record.json +37 -0
  472. package/test-fixtures/remove-duplicate-datafields/v04/expectedResult.json +8 -0
  473. package/test-fixtures/remove-duplicate-datafields/v04/metadata.json +6 -0
  474. package/test-fixtures/remove-duplicate-datafields/v04/record.json +41 -0
  475. package/test-fixtures/remove-inferior-datafields/f01/expectedResult.json +21 -0
  476. package/test-fixtures/remove-inferior-datafields/f01/metadata.json +6 -0
  477. package/test-fixtures/remove-inferior-datafields/f01/record.json +31 -0
  478. package/test-fixtures/remove-inferior-datafields/f03/expectedResult.json +16 -0
  479. package/test-fixtures/remove-inferior-datafields/f03/metadata.json +6 -0
  480. package/test-fixtures/remove-inferior-datafields/f03/record.json +27 -0
  481. package/test-fixtures/remove-inferior-datafields/f04/expectedResult.json +31 -0
  482. package/test-fixtures/remove-inferior-datafields/f04/metadata.json +6 -0
  483. package/test-fixtures/remove-inferior-datafields/f04/record.json +38 -0
  484. package/test-fixtures/remove-inferior-datafields/f05/expectedResult.json +34 -0
  485. package/test-fixtures/remove-inferior-datafields/f05/metadata.json +6 -0
  486. package/test-fixtures/remove-inferior-datafields/f05/record.json +41 -0
  487. package/test-fixtures/remove-inferior-datafields/f06/expectedResult.json +16 -0
  488. package/test-fixtures/remove-inferior-datafields/f06/metadata.json +6 -0
  489. package/test-fixtures/remove-inferior-datafields/f06/record.json +20 -0
  490. package/test-fixtures/remove-inferior-datafields/v01/expectedResult.json +6 -0
  491. package/test-fixtures/remove-inferior-datafields/v01/metadata.json +6 -0
  492. package/test-fixtures/remove-inferior-datafields/v01/record.json +31 -0
  493. package/test-fixtures/remove-inferior-datafields/v02/expectedResult.json +6 -0
  494. package/test-fixtures/remove-inferior-datafields/v02/metadata.json +6 -0
  495. package/test-fixtures/remove-inferior-datafields/v02/record.json +21 -0
  496. package/test-fixtures/remove-orphanded-sf6s/f01/expectedResult.json +35 -0
  497. package/test-fixtures/remove-orphanded-sf6s/f01/metadata.json +6 -0
  498. package/test-fixtures/remove-orphanded-sf6s/f01/record.json +34 -0
  499. package/test-fixtures/remove-orphanded-sf6s/f02/expectedResult.json +40 -0
  500. package/test-fixtures/remove-orphanded-sf6s/f02/metadata.json +6 -0
  501. package/test-fixtures/remove-orphanded-sf6s/f02/record.json +43 -0
  502. package/test-fixtures/remove-orphanded-sf6s/v01/expectedResult.json +6 -0
  503. package/test-fixtures/remove-orphanded-sf6s/v01/metadata.json +6 -0
  504. package/test-fixtures/remove-orphanded-sf6s/v01/record.json +31 -0
  505. package/test-fixtures/remove-orphanded-sf6s/v02/expectedResult.json +6 -0
  506. package/test-fixtures/remove-orphanded-sf6s/v02/metadata.json +6 -0
  507. package/test-fixtures/remove-orphanded-sf6s/v02/record.json +31 -0
  508. package/test-fixtures/resolvable-ext-references-melinda.js +0 -27
  509. package/test-fixtures/sanitize-vocabulary-source-codes/f01/expectedResult.json +32 -0
  510. package/test-fixtures/sanitize-vocabulary-source-codes/f01/metadata.json +6 -0
  511. package/test-fixtures/sanitize-vocabulary-source-codes/f01/record.json +32 -0
  512. package/test-fixtures/sanitize-vocabulary-source-codes/f02/expectedResult.json +24 -0
  513. package/test-fixtures/sanitize-vocabulary-source-codes/f02/metadata.json +6 -0
  514. package/test-fixtures/sanitize-vocabulary-source-codes/f02/record.json +24 -0
  515. package/test-fixtures/sanitize-vocabulary-source-codes/v01/expectedResult.json +12 -0
  516. package/test-fixtures/sanitize-vocabulary-source-codes/v01/metadata.json +6 -0
  517. package/test-fixtures/sanitize-vocabulary-source-codes/v01/record.json +24 -0
  518. package/test-fixtures/sort-relator-terms/f01/expectedResult.json +23 -0
  519. package/test-fixtures/sort-relator-terms/f01/metadata.json +6 -0
  520. package/test-fixtures/sort-relator-terms/f01/record.json +22 -0
  521. package/test-fixtures/sort-relator-terms/f02/expectedResult.json +26 -0
  522. package/test-fixtures/sort-relator-terms/f02/metadata.json +6 -0
  523. package/test-fixtures/sort-relator-terms/f02/record.json +22 -0
  524. package/test-fixtures/sort-relator-terms/v01/expectedResult.json +5 -0
  525. package/test-fixtures/sort-relator-terms/v01/metadata.json +6 -0
  526. package/test-fixtures/sort-relator-terms/v01/record.json +22 -0
  527. package/test-fixtures/sort-relator-terms/v02/expectedResult.json +6 -0
  528. package/test-fixtures/sort-relator-terms/v02/metadata.json +6 -0
  529. package/test-fixtures/sort-relator-terms/v02/record.json +14 -0
  530. package/test-fixtures/sort-subfields/f01/expectedResult.json +24 -0
  531. package/test-fixtures/sort-subfields/f01/metadata.json +6 -0
  532. package/test-fixtures/sort-subfields/f01/record.json +20 -0
  533. package/test-fixtures/sort-subfields/v01/expectedResult.json +5 -0
  534. package/test-fixtures/sort-subfields/v01/metadata.json +6 -0
  535. package/test-fixtures/sort-subfields/v01/record.json +24 -0
  536. package/test-fixtures/sort-subfields/v02/expectedResult.json +6 -0
  537. package/test-fixtures/sort-subfields/v02/metadata.json +6 -0
  538. package/test-fixtures/sort-subfields/v02/record.json +8 -0
  539. package/test-fixtures/strip-punctuation/01/expectedResult.json +12 -0
  540. package/test-fixtures/strip-punctuation/01/metadata.json +6 -0
  541. package/test-fixtures/strip-punctuation/01/record.json +37 -0
  542. package/test-fixtures/strip-punctuation/02/expectedResult.json +4 -0
  543. package/test-fixtures/strip-punctuation/02/metadata.json +6 -0
  544. package/test-fixtures/strip-punctuation/02/record.json +14 -0
  545. package/test-fixtures/strip-punctuation/04/expectedResult.json +6 -0
  546. package/test-fixtures/strip-punctuation/04/metadata.json +6 -0
  547. package/test-fixtures/strip-punctuation/04/record.json +22 -0
  548. package/test-fixtures/strip-punctuation/05/expectedResult.json +6 -0
  549. package/test-fixtures/strip-punctuation/05/metadata.json +6 -0
  550. package/test-fixtures/strip-punctuation/05/record.json +12 -0
  551. package/test-fixtures/strip-punctuation/98/expectedResult.json +44 -0
  552. package/test-fixtures/strip-punctuation/98/metadata.json +6 -0
  553. package/test-fixtures/strip-punctuation/98/record.json +45 -0
  554. package/test-fixtures/strip-punctuation/99/expectedResult.json +16 -0
  555. package/test-fixtures/strip-punctuation/99/metadata.json +6 -0
  556. package/test-fixtures/strip-punctuation/99/record.json +16 -0
  557. package/test-fixtures/subfield0/f01/expectedResult.json +25 -0
  558. package/test-fixtures/subfield0/f01/metadata.json +6 -0
  559. package/test-fixtures/subfield0/f01/record.json +23 -0
  560. package/test-fixtures/subfield0/f02/expectedResult.json +35 -0
  561. package/test-fixtures/subfield0/f02/metadata.json +6 -0
  562. package/test-fixtures/subfield0/f02/record.json +41 -0
  563. package/test-fixtures/subfield0/f03/expectedResult.json +21 -0
  564. package/test-fixtures/subfield0/f03/metadata.json +7 -0
  565. package/test-fixtures/subfield0/f03/record.json +24 -0
  566. package/test-fixtures/subfield0/v01/expectedResult.json +4 -0
  567. package/test-fixtures/subfield0/v01/metadata.json +6 -0
  568. package/test-fixtures/subfield0/v01/record.json +23 -0
  569. package/test-fixtures/subfield0/v02/expectedResult.json +9 -0
  570. package/test-fixtures/subfield0/v02/metadata.json +6 -0
  571. package/test-fixtures/subfield0/v02/record.json +38 -0
  572. package/test-fixtures/typeOfDate-008/01/expectedResult.json +3 -0
  573. package/test-fixtures/typeOfDate-008/01/metadata.json +4 -0
  574. package/test-fixtures/typeOfDate-008/01/record.json +14 -0
  575. package/test-fixtures/typeOfDate-008/02/expectedResult.json +4 -0
  576. package/test-fixtures/typeOfDate-008/02/metadata.json +4 -0
  577. package/test-fixtures/typeOfDate-008/02/record.json +14 -0
  578. package/test-fixtures/typeOfDate-008/03/expectedResult.json +14 -0
  579. package/test-fixtures/typeOfDate-008/03/metadata.json +5 -0
  580. package/test-fixtures/typeOfDate-008/03/record.json +14 -0
  581. package/test-fixtures/typeOfDate-008/04/expectedResult.json +14 -0
  582. package/test-fixtures/typeOfDate-008/04/metadata.json +5 -0
  583. package/test-fixtures/typeOfDate-008/04/record.json +14 -0
  584. package/test-fixtures/typeOfDate-008/05/expectedResult.json +14 -0
  585. package/test-fixtures/typeOfDate-008/05/metadata.json +5 -0
  586. package/test-fixtures/typeOfDate-008/05/record.json +14 -0
  587. package/test-fixtures/update-field-540/f01/expectedResult.json +23 -0
  588. package/test-fixtures/update-field-540/f01/metadata.json +6 -0
  589. package/test-fixtures/update-field-540/f01/record.json +23 -0
  590. package/test-fixtures/update-field-540/v01/expectedResult.json +7 -0
  591. package/test-fixtures/update-field-540/v01/metadata.json +6 -0
  592. package/test-fixtures/update-field-540/v01/record.json +23 -0
  593. package/.travis.yml +0 -10
@@ -1,35 +1,3 @@
1
- /**
2
- *
3
- * @licstart The following is the entire license notice for the JavaScript code in this file.
4
- *
5
- * MARC record validators used in Melinda
6
- *
7
- * Copyright (C) 2014-2018 University Of Helsinki (The National Library Of Finland)
8
- *
9
- * This file is part of marc-record-validators-melinda
10
- *
11
- * marc-record-validators-melinda program is free software: you can redistribute it and/or modify
12
- * it under the terms of the GNU Affero 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-validators-melinda 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 Affero General Public License for more details.
20
- *
21
- * You should have received a copy of the GNU Affero 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
- /* eslint-disable no-undef, max-nested-callbacks, no-unused-expressions */
30
-
31
- 'use strict';
32
-
33
1
  import chai from 'chai';
34
2
  import chaiAsPromised from 'chai-as-promised';
35
3
  import {MarcRecord} from '@natlibfi/marc-record';
@@ -40,2294 +8,2549 @@ chai.use(chaiAsPromised);
40
8
 
41
9
  // Factory validation
42
10
  describe('ending-punctuation', () => {
43
- // Indicators and subfields validation
44
- describe('#validate: Indicators and subfields', () => {
45
- const recordValid = new MarcRecord({leader: '',
46
- fields: [{
47
- tag: '245',
48
- ind1: ' ',
49
- ind2: ' ',
50
- subfields: [
51
- {code: 'a', value: 'Elämäni ja tutkimusretkeni / '},
52
- {code: 'c', value: 'Roald Amundsen ; suomentanut Sulo Veikko Pekkola.'},
53
- {code: '6', value: 'FOO'}
54
- ]
55
- }, {
56
- tag: '337', // Range 336-338
57
- ind1: ' ',
58
- ind2: ' ',
59
- subfields: [
60
- {code: 'a', value: 'käytettävissä ilman laitetta'},
61
- {code: 'b', value: 'n'},
62
- {code: '2', value: 'rdamedia'}
63
- ]
64
- }, {
65
- tag: '500', // Range 500-509
66
- ind1: ' ',
67
- ind2: ' ',
68
- subfields: [
69
- {code: 'a', value: 'FOO (Bar)'}
70
- ]
71
- }]
72
- });
73
-
74
- const recordInvalid = new MarcRecord({leader: '',
75
- fields: [{
76
- tag: '245',
77
- ind1: ' ',
78
- ind2: ' ',
79
- subfields: [
80
- {code: 'a', value: 'Elämäni ja tutkimusretkeni / '},
81
- {code: 'c', value: 'Roald Amundsen ; suomentanut Sulo Veikko Pekkola'},
82
- {code: '6', value: 'FOO'}
83
- ]
84
- }, {
85
- tag: '337',
86
- ind1: ' ',
87
- ind2: ' ',
88
- subfields: [
89
- {code: 'a', value: 'käytettävissä ilman laitetta'},
90
- {code: 'b', value: 'n.'}, // This can be abbreviation -> does not generate error
91
- {code: '2', value: 'rdamedia'}
92
- ]
93
- }, {
94
- tag: '500',
95
- ind1: ' ',
96
- ind2: ' ',
97
- subfields: [
98
- {code: 'a', value: 'FOO (Bar).'}
99
- ]
100
- }]
101
- });
102
- const recordBroken = new MarcRecord({leader: '',
103
- fields: [{
104
- tag: '245',
105
- ind1: ' ',
106
- ind2: ' ',
107
- subfields: [
108
- {code: 'a', value: 'Elämäni ja tutkimusretkeni / '},
109
- {code: 'c', value: 'Roald Amundsen ; suomentanut Sulo Veikko Pekkola'},
110
- {code: '6', value: 'FOO'}
111
- ]
112
- }, {
113
- tag: '337',
114
- ind1: ' ',
115
- ind2: ' ',
116
- subfields: [
117
- {code: 'a', value: 'käytettävissä ilman laitetta'},
118
- {code: 'b', value: 'n'}, // Dot removed from possible abbreviation as it cannot be removed in fixing
119
- {code: '2', value: 'rdamedia'}
120
- ]
121
- }, {
122
- tag: '500',
123
- ind1: ' ',
124
- ind2: ' ',
125
- subfields: [
126
- {code: 'a', value: 'FOO (Bar).'}
127
- ]
128
- }]
129
- });
130
-
131
- it('Finds the record valid', async () => {
132
- const validator = await validatorFactory();
133
- const result = await validator.validate(recordValid);
134
- expect(result.valid).to.eql(true);
135
- });
136
-
137
- it('Finds the record invalid', async () => {
138
- const validator = await validatorFactory();
139
- const result = await validator.validate(recordInvalid);
140
- expect(result).to.eql({
141
- message: ['Field 245 has invalid ending punctuation', 'Field 500 has invalid ending punctuation'],
142
- valid: false
143
- });
144
- });
145
-
146
- it('Repairs the invalid record', async () => {
147
- const validator = await validatorFactory();
148
- const result = await validator.fix(recordBroken);
149
- expect(recordBroken.equalsTo(recordValid)).to.eql(true);
150
- expect(result).to.eql({
151
- message: ['Field 245 has invalid ending punctuation', 'Field 500 has invalid ending punctuation'],
152
- fix: ['Field 245 - Added punctuation to $c', 'Field 500 - Removed double punctuation from $a'],
153
- valid: false
154
- });
155
- });
156
- });
157
-
158
- describe('#specials', () => {
159
- // "036 KYLLÄ vain osakentän $b jälkeen"
160
- // Can have subfields a and b, dot only after b
161
- describe('#036 TRUE - only after subfield $b', () => {
162
- // Valid tests
163
- const recordValid = new MarcRecord({leader: '',
164
- fields: [{
165
- tag: '036',
166
- ind1: ' ',
167
- ind2: ' ',
168
- subfields: [
169
- {code: 'a', value: 'CNRS 84115'},
170
- {code: 'b', value: 'Centre national de la recherche scientifique.'}
171
- ]
172
- }]
173
- });
174
-
175
- const recordValidOnlyA = new MarcRecord({leader: '',
176
- fields: [{
177
- tag: '036',
178
- ind1: ' ',
179
- ind2: ' ',
180
- subfields: [
181
- {code: 'a', value: 'CNRS 84115'}
182
- ]
183
- }]
184
- });
185
-
186
- it('Finds record valid - Punc $b', async () => {
187
- const validator = await validatorFactory();
188
- const result = await validator.validate(recordValid);
189
- expect(result.valid).to.eql(true);
190
- });
191
-
192
- it('Finds record valid - Only $a without punc', async () => {
193
- const validator = await validatorFactory();
194
- const result = await validator.validate(recordValidOnlyA);
195
- expect(result.valid).to.eql(true);
196
- });
197
-
198
- // Invalid tests
199
- const recordInvalid = new MarcRecord({leader: '',
200
- fields: [{
201
- tag: '036',
202
- ind1: ' ',
203
- ind2: ' ',
204
- subfields: [
205
- {code: 'a', value: 'CNRS 84115'},
206
- {code: 'b', value: 'Centre national de la recherche scientifique'}
207
- ]
208
- }]
209
- });
210
-
211
- const recordInvalidOnlyA = new MarcRecord({leader: '',
212
- fields: [{
213
- tag: '036',
214
- ind1: ' ',
215
- ind2: ' ',
216
- subfields: [
217
- {code: 'a', value: 'CNRS 84115.'} // $a is register number, no change for abbreviation
218
- ]
219
- }]
220
- });
221
-
222
- it('Finds record invalid - No punc $b', async () => {
223
- const validator = await validatorFactory();
224
- const result = await validator.validate(recordInvalid);
225
- expect(result).to.eql({
226
- message: ['Field 036 has invalid ending punctuation'],
227
- valid: false
228
- });
229
- });
230
-
231
- it('Finds record invalid - Only $a with punc', async () => {
232
- const validator = await validatorFactory();
233
- const result = await validator.validate(recordInvalidOnlyA);
234
- expect(result).to.eql({
235
- message: ['Field 036 has invalid ending punctuation'],
236
- valid: false
237
- });
238
- });
239
-
240
- // Fix tests; invalid->valid
241
- it('Repairs the invalid record - Add punc $b', async () => {
242
- const validator = await validatorFactory();
243
- const result = await validator.fix(recordInvalid);
244
- expect(recordInvalid.equalsTo(recordValid)).to.eql(true);
245
- expect(result).to.eql({
246
- message: ['Field 036 has invalid ending punctuation'],
247
- fix: ['Field 036 - Added punctuation to $b'],
248
- valid: false
249
- });
250
- });
251
-
252
- it('Repairs the invalid record - Removes punc $a (register)', async () => {
253
- const validator = await validatorFactory();
254
- const result = await validator.fix(recordInvalidOnlyA);
255
- expect(recordInvalidOnlyA.equalsTo(recordValidOnlyA)).to.eql(true);
256
- expect(result).to.eql({
257
- message: ['Field 036 has invalid ending punctuation'],
258
- fix: ['Field 036 - Removed punctuation from $a'],
259
- valid: false
260
- });
261
- });
262
- });
263
-
264
- // "242 KYLLÄ Jos viimeinen osakenttä on $y, piste on ennen sitä" - Eli siis ei kentässä y (ennen sitä)
265
- describe('#242 TRUE - if last subfield $y, punc before it', () => {
266
- // Valid tests
267
- const recordValidOnlyA = new MarcRecord({leader: '',
268
- fields: [{
269
- tag: '242',
270
- ind1: ' ',
271
- ind2: ' ',
272
- subfields: [
273
- {code: 'a', value: 'World of art.'},
274
- {code: 'y', value: 'eng'}
275
- ]
276
- }]
277
- });
278
-
279
- const recordValidMultiple = new MarcRecord({leader: '',
280
- fields: [{
281
- tag: '242',
282
- ind1: ' ',
283
- ind2: ' ',
284
- subfields: [
285
- {code: 'a', value: 'Annals of chemistry.'},
286
- {code: 'n', value: 'Series C,'},
287
- {code: 'p', value: 'Organic chemistry and biochemistry.'},
288
- {code: 'y', value: 'eng'}
289
- ]
290
- }]
291
- });
292
-
293
- // "Suositellaan käytettäväksi myös osakenttää ‡y (käännöksen kielikoodi)." https://www.kiwi.fi/pages/viewpage.action?pageId=51282044
294
- const recordValidWithoutY = new MarcRecord({leader: '',
295
- fields: [{
296
- tag: '242',
297
- ind1: ' ',
298
- ind2: ' ',
299
- subfields: [
300
- {code: 'a', value: 'World of art.'}
301
- ]
302
- }]
303
- });
304
-
305
- it('Finds record valid - Punc $a', async () => {
306
- const validator = await validatorFactory();
307
- const result = await validator.validate(recordValidOnlyA);
308
- expect(result.valid).to.eql(true);
309
- });
310
-
311
- it('Finds record valid - Punc $p', async () => {
312
- const validator = await validatorFactory();
313
- const result = await validator.validate(recordValidMultiple);
314
- expect(result.valid).to.eql(true);
315
- });
316
-
317
- it('Finds record valid - Punc $a without $y', async () => {
318
- const validator = await validatorFactory();
319
- const result = await validator.validate(recordValidWithoutY);
320
- expect(result.valid).to.eql(true);
321
- });
322
-
323
- // Invalid tests
324
- const recordInvalidOnlyAMissingA = new MarcRecord({leader: '',
325
- fields: [{
326
- tag: '242',
327
- ind1: ' ',
328
- ind2: ' ',
329
- subfields: [
330
- {code: 'a', value: 'World of art'},
331
- {code: 'y', value: 'eng'}
332
- ]
333
- }]
334
- });
335
-
336
- const recordInvalidOnlyAPuncY = new MarcRecord({leader: '',
337
- fields: [{
338
- tag: '242',
339
- ind1: ' ',
340
- ind2: ' ',
341
- subfields: [
342
- {code: 'a', value: 'World of art.'},
343
- {code: 'y', value: 'eng.'} // $y is also checked as rule is explicit
344
- ]
345
- }]
346
- });
347
-
348
- const recordInvalidOnlyAMissingAPuncY = new MarcRecord({leader: '',
349
- fields: [{
350
- tag: '242',
351
- ind1: ' ',
352
- ind2: ' ',
353
- subfields: [
354
- {code: 'a', value: 'World of art'},
355
- {code: 'y', value: 'eng.'} // $y is also checked as rule is explicit
356
- ]
357
- }]
358
- });
359
-
360
- const recordValidMultipleMissingP = new MarcRecord({leader: '',
361
- fields: [{
362
- tag: '242',
363
- ind1: ' ',
364
- ind2: ' ',
365
- subfields: [
366
- {code: 'a', value: 'Annals of chemistry.'},
367
- {code: 'n', value: 'Series C,'},
368
- {code: 'p', value: 'Organic chemistry and biochemistry'},
369
- {code: 'y', value: 'eng'}
370
- ]
371
- }]
372
- });
373
-
374
- // "Suositellaan käytettäväksi myös osakenttää ‡y (käännöksen kielikoodi)." https://www.kiwi.fi/pages/viewpage.action?pageId=51282044
375
- const recordValidWithoutYMissingA = new MarcRecord({leader: '',
376
- fields: [{
377
- tag: '242',
378
- ind1: ' ',
379
- ind2: ' ',
380
- subfields: [
381
- {code: 'a', value: 'World of art'}
382
- ]
383
- }]
384
- });
385
-
386
- it('Finds record invalid - No punc at $a (only before $y)', async () => {
387
- const validator = await validatorFactory();
388
- const result = await validator.validate(recordInvalidOnlyAMissingA);
389
- expect(result).to.eql({
390
- message: ['Field 242 has invalid ending punctuation'],
391
- valid: false
392
- });
393
- });
394
-
395
- it('Finds record invalid - Punc at $y (Language field)', async () => { // $y is also checked as rule is explicit
396
- const validator = await validatorFactory();
397
- const result = await validator.validate(recordInvalidOnlyAPuncY);
398
- expect(result).to.eql({
399
- message: ['Field 242 has invalid ending punctuation'],
400
- valid: false
401
- });
402
- });
403
-
404
- it('Finds record invalid - No punc at $a & punc $y', async () => { // $y is also checked as rule is explicit
405
- const validator = await validatorFactory();
406
- const result = await validator.validate(recordInvalidOnlyAMissingAPuncY);
407
- expect(result).to.eql({
408
- message: ['Field 242 has invalid ending punctuation', 'Field 242 has invalid ending punctuation'],
409
- valid: false
410
- });
411
- });
412
-
413
- it('Finds record invalid - No punc $p (last before $y)', async () => {
414
- const validator = await validatorFactory();
415
- const result = await validator.validate(recordValidMultipleMissingP);
416
- expect(result).to.eql({
417
- message: ['Field 242 has invalid ending punctuation'],
418
- valid: false
419
- });
420
- });
421
-
422
- it('Finds record invalid - No punc $a (only)', async () => {
423
- const validator = await validatorFactory();
424
- const result = await validator.validate(recordValidWithoutYMissingA);
425
- expect(result).to.eql({
426
- message: ['Field 242 has invalid ending punctuation'],
427
- valid: false
428
- });
429
- });
430
-
431
- // Fix tests; invalid->valid
432
- it('Repairs the invalid record - Add punc $a', async () => {
433
- const validator = await validatorFactory();
434
- const result = await validator.fix(recordInvalidOnlyAMissingA);
435
- expect(recordInvalidOnlyAMissingA.equalsTo(recordValidOnlyA)).to.eql(true);
436
- expect(result).to.eql({
437
- message: ['Field 242 has invalid ending punctuation'],
438
- fix: ['Field 242 - Added punctuation to $a'],
439
- valid: false
440
- });
441
- });
442
-
443
- it('Repairs the invalid record - Remove punc $y (Language field)', async () => {
444
- const validator = await validatorFactory();
445
- const result = await validator.fix(recordInvalidOnlyAPuncY);
446
- expect(recordInvalidOnlyAPuncY.equalsTo(recordValidOnlyA)).to.eql(true);
447
- expect(result).to.eql({
448
- message: ['Field 242 has invalid ending punctuation'],
449
- fix: ['Field 242 - Removed punctuation from $y'],
450
- valid: false
451
- });
452
- });
453
-
454
- it('Repairs the invalid record - Add punc $a & remove punc $y (Language field)', async () => {
455
- const validator = await validatorFactory();
456
- const result = await validator.fix(recordInvalidOnlyAMissingAPuncY);
457
- expect(recordInvalidOnlyAMissingAPuncY.equalsTo(recordValidOnlyA)).to.eql(true);
458
- expect(result).to.eql({
459
- message: ['Field 242 has invalid ending punctuation', 'Field 242 has invalid ending punctuation'],
460
- fix: ['Field 242 - Removed punctuation from $y', 'Field 242 - Added punctuation to $a'],
461
- valid: false
462
- });
463
- });
464
-
465
- it('Repairs the invalid record - Add punc $p', async () => {
466
- const validator = await validatorFactory();
467
- const result = await validator.fix(recordValidMultipleMissingP);
468
- expect(recordValidMultipleMissingP.equalsTo(recordValidMultiple)).to.eql(true);
469
- expect(result).to.eql({
470
- message: ['Field 242 has invalid ending punctuation'],
471
- fix: ['Field 242 - Added punctuation to $p'],
472
- valid: false
473
- });
474
- });
475
-
476
- it('Repairs the invalid record - Add punc $a', async () => {
477
- const validator = await validatorFactory();
478
- const result = await validator.fix(recordValidWithoutYMissingA);
479
- expect(recordValidWithoutYMissingA.equalsTo(recordValidWithoutY)).to.eql(true);
480
- expect(result).to.eql({
481
- message: ['Field 242 has invalid ending punctuation'],
482
- fix: ['Field 242 - Added punctuation to $a'],
483
- valid: false
484
- });
485
- });
486
- });
487
-
488
- // "260 KYLLÄ Pääsääntö: $a : $b, $c. Tarkista eri poikkeukset ja välimerkitys MARC 21 Full -versiosta"
489
- // Punc only if last subfield c
490
- describe('#260 TRUE - Punc only if last subfield c', () => {
491
- // Valid tests
492
- const recordValidEndC = new MarcRecord({leader: '',
493
- fields: [{
494
- tag: '260',
495
- ind1: ' ',
496
- ind2: ' ',
497
- subfields: [
498
- {code: 'a', value: 'Helsinki'},
499
- {code: 'b', value: 'Suomen atk-kustannus,'},
500
- {code: 'c', value: '1982.'}
501
- ]
502
- }]
503
- });
504
-
505
- const recordValidEndG = new MarcRecord({leader: '',
506
- fields: [{
507
- tag: '260',
508
- ind1: ' ',
509
- ind2: ' ',
510
- subfields: [
511
- {code: 'a', value: 'London'},
512
- {code: 'b', value: 'Macmillan,'},
513
- {code: 'c', value: '1971'},
514
- {code: 'g', value: '(1973 printing)'}
515
- ]
516
- }]
517
- });
518
-
519
- const recordValidEndB = new MarcRecord({leader: '',
520
- fields: [{
521
- tag: '260',
522
- ind1: ' ',
523
- ind2: ' ',
524
- subfields: [
525
- {code: '3', value: 'June 1993-'},
526
- {code: 'a', value: 'London'},
527
- {code: 'b', value: 'Elle'}
528
- ]
529
- }]
530
- });
531
-
532
- it('Finds record valid - Punc $c', async () => {
533
- const validator = await validatorFactory();
534
- const result = await validator.validate(recordValidEndC);
535
- expect(result.valid).to.eql(true);
536
- });
537
-
538
- it('Finds record valid - Punc char $g (after $c)', async () => {
539
- const validator = await validatorFactory();
540
- const result = await validator.validate(recordValidEndG);
541
- expect(result.valid).to.eql(true);
542
- });
543
-
544
- it('Finds record valid - No punc $b', async () => {
545
- const validator = await validatorFactory();
546
- const result = await validator.validate(recordValidEndB);
547
- expect(result.valid).to.eql(true);
548
- });
549
-
550
- // Invalid tests
551
- const recordInvalidEndC = new MarcRecord({leader: '',
552
- fields: [{
553
- tag: '260',
554
- ind1: ' ',
555
- ind2: ' ',
556
- subfields: [
557
- {code: 'a', value: 'Helsinki'},
558
- {code: 'b', value: 'Suomen atk-kustannus,'},
559
- {code: 'c', value: '1982'}
560
- ]
561
- }]
562
- });
563
-
564
- const recordInvalidEndGDouble = new MarcRecord({leader: '',
565
- fields: [{
566
- tag: '260',
567
- ind1: ' ',
568
- ind2: ' ',
569
- subfields: [
570
- {code: 'a', value: 'London'},
571
- {code: 'b', value: 'Macmillan,'},
572
- {code: 'c', value: '1971'},
573
- {code: 'g', value: '(1973 printing).'}
574
- ]
575
- }]
576
- });
577
-
578
- it('Finds record invalid', async () => {
579
- const validator = await validatorFactory();
580
- const result = await validator.validate(recordInvalidEndC);
581
- expect(result).to.eql({
582
- message: ['Field 260 has invalid ending punctuation'],
583
- valid: false
584
- });
585
- });
586
-
587
- it('Finds record invalid', async () => {
588
- const validator = await validatorFactory();
589
- const result = await validator.validate(recordInvalidEndGDouble);
590
- expect(result).to.eql({
591
- message: ['Field 260 has invalid ending punctuation'],
592
- valid: false
593
- });
594
- });
595
-
596
- // Fix tests; invalid->valid
597
- it('Repairs the invalid record - Add punc $c', async () => {
598
- const validator = await validatorFactory();
599
- const result = await validator.fix(recordInvalidEndC);
600
- expect(recordInvalidEndC.equalsTo(recordValidEndC)).to.eql(true);
601
- expect(result).to.eql({
602
- message: ['Field 260 has invalid ending punctuation'],
603
- fix: ['Field 260 - Added punctuation to $c'],
604
- valid: false
605
- });
606
- });
607
-
608
- it('Repairs the invalid record - Remove double punc $g', async () => {
609
- const validator = await validatorFactory();
610
- const result = await validator.fix(recordInvalidEndGDouble);
611
- expect(recordInvalidEndGDouble.equalsTo(recordValidEndG)).to.eql(true);
612
- expect(result).to.eql({
613
- message: ['Field 260 has invalid ending punctuation'],
614
- fix: ['Field 260 - Removed double punctuation from $g'],
615
- valid: false
616
- });
617
- });
618
- });
619
-
620
- // "264 KYLLÄ Tarkista poikkeukset MARC 21 -sovellusohjeesta"
621
- // Eli jos `ind2 === '4'` niin silloin loppupiste merkitä osakentän *b* loppuun
622
- describe('#264 TRUE - If ind2 === 4, punc at the end of $b', () => {
623
- // Valid tests
624
- const recordValid = new MarcRecord({leader: '',
625
- fields: [{
626
- tag: '264',
627
- ind1: ' ',
628
- ind2: ' ',
629
- subfields: [
630
- {code: 'a', value: 'Helsinki'},
631
- {code: 'b', value: 'Helsingin yliopisto'},
632
- {code: 'c', value: '1995-2006.'}
633
- ]
634
- }]
635
- });
636
-
637
- const recordValidInd = new MarcRecord({leader: '',
638
- fields: [{
639
- tag: '264',
640
- ind1: ' ',
641
- ind2: '4',
642
- subfields: [
643
- {code: 'a', value: 'Helsinki : '},
644
- {code: 'b', value: 'Suomen poliisikoirayhdistys.'},
645
- {code: 'c', value: 1974'}
646
- ]
647
- }]
648
- });
649
-
650
- it('Finds record valid', async () => {
651
- const validator = await validatorFactory();
652
- const result = await validator.validate(recordValid);
653
- expect(result.valid).to.eql(true);
654
- });
655
-
656
- it('Finds record valid - Ind, copyright', async () => {
657
- const validator = await validatorFactory();
658
- const result = await validator.validate(recordValidInd);
659
- expect(result.valid).to.eql(true);
660
- });
661
-
662
- // Invalid tests
663
- const recordInvalid = new MarcRecord({leader: '',
664
- fields: [{
665
- tag: '264',
666
- subfields: [
667
- {code: 'a', value: 'Helsinki'},
668
- {code: 'b', value: 'Helsingin yliopisto'},
669
- {code: 'c', value: '1995-2006'}
670
- ]
671
- }]
672
- });
673
-
674
- const recordInvalidIndBMissing = new MarcRecord({leader: '',
675
- fields: [{
676
- tag: '264',
677
- ind1: ' ',
678
- ind2: '4',
679
- subfields: [
680
- {code: 'a', value: 'Helsinki : '},
681
- {code: 'b', value: 'Suomen poliisikoirayhdistys'},
682
- {code: 'c', value: '© 1974'}
683
- ]
684
- }]
685
- });
686
-
687
- const recordInvalidIndCExtra = new MarcRecord({leader: '',
688
- fields: [{
689
- tag: '264',
690
- ind1: ' ',
691
- ind2: '4',
692
- subfields: [
693
- {code: 'a', value: 'Helsinki : '},
694
- {code: 'b', value: 'Suomen poliisikoirayhdistys.'},
695
- {code: 'c', value: '© 1974.'}
696
- ]
697
- }]
698
- });
699
-
700
- const recordInvalidIndBMissingCExtra = new MarcRecord({leader: '',
701
- fields: [{
702
- tag: '264',
703
- ind1: ' ',
704
- ind2: '4',
705
- subfields: [
706
- {code: 'a', value: 'Helsinki : '},
707
- {code: 'b', value: 'Suomen poliisikoirayhdistys'},
708
- {code: 'c', value: '© 1974.'}
709
- ]
710
- }]
711
- });
712
-
713
- it('Finds record invalid - No punc $c', async () => {
714
- const validator = await validatorFactory();
715
- const result = await validator.validate(recordInvalid);
716
- expect(result).to.eql({
717
- message: ['Field 264 has invalid ending punctuation'],
718
- valid: false
719
- });
720
- });
721
-
722
- it('Finds record invalid - Ind, copyright, no punc $b ', async () => {
723
- const validator = await validatorFactory();
724
- const result = await validator.validate(recordInvalidIndBMissing);
725
- expect(result).to.eql({
726
- message: ['Field 264 has invalid ending punctuation'],
727
- valid: false
728
- });
729
- });
730
-
731
- it('Finds record invalid - Ind, copyright, extra punc $c', async () => {
732
- const validator = await validatorFactory();
733
- const result = await validator.validate(recordInvalidIndCExtra);
734
- expect(result).to.eql({
735
- message: ['Field 264 has invalid ending punctuation'],
736
- valid: false
737
- });
738
- });
739
-
740
- it('Finds record invalid - Ind, copyright, extra punc $c, no punc $b', async () => {
741
- const validator = await validatorFactory();
742
- const result = await validator.validate(recordInvalidIndBMissingCExtra);
743
- expect(result).to.eql({
744
- message: ['Field 264 has invalid ending punctuation', 'Field 264 has invalid ending punctuation'],
745
- valid: false
746
- });
747
- });
748
-
749
- // Fix tests; invalid->valid
750
- it('Repairs the invalid record - Add punc $c', async () => {
751
- const validator = await validatorFactory();
752
- const result = await validator.fix(recordInvalid);
753
- expect(recordInvalid.equalsTo(recordValid)).to.eql(true);
754
- expect(result).to.eql({
755
- message: ['Field 264 has invalid ending punctuation'],
756
- fix: ['Field 264 - Added punctuation to $c'],
757
- valid: false
758
- });
759
- });
760
-
761
- it('Repairs the invalid record - Add punc $b (Last $c, but ind2 === 4) ', async () => {
762
- const validator = await validatorFactory();
763
- const result = await validator.fix(recordInvalidIndBMissing);
764
- expect(recordInvalidIndBMissing.equalsTo(recordValidInd)).to.eql(true);
765
- expect(result).to.eql({
766
- message: ['Field 264 has invalid ending punctuation'],
767
- fix: ['Field 264 - Added punctuation to $b'],
768
- valid: false
769
- });
770
- });
771
-
772
- it('Repairs the invalid record - Remove punc $c ($c has ©, should not have punc)', async () => {
773
- const validator = await validatorFactory();
774
- const result = await validator.fix(recordInvalidIndCExtra);
775
- expect(recordInvalidIndCExtra.equalsTo(recordValidInd)).to.eql(true);
776
- expect(result).to.eql({
777
- message: ['Field 264 has invalid ending punctuation'],
778
- fix: ['Field 264 - Removed punctuation from $c'],
779
- valid: false
780
- });
781
- });
782
-
783
- it('Repairs the invalid record - Add punc $b, remove punc $c', async () => {
784
- const validator = await validatorFactory();
785
- const result = await validator.fix(recordInvalidIndBMissingCExtra);
786
- expect(recordInvalidIndBMissingCExtra.equalsTo(recordValidInd)).to.eql(true);
787
- expect(result).to.eql({
788
- message: ['Field 264 has invalid ending punctuation', 'Field 264 has invalid ending punctuation'],
789
- fix: ['Field 264 - Removed punctuation from $c', 'Field 264 - Added punctuation to $b'],
790
- valid: false
791
- });
792
- });
793
- });
794
-
795
- // "340 KYLLÄ Vain joidenkin osakenttien jälkeen. Tarkista osakentät MARC 21 Full -versiosta
796
- // -b: Piste aina osakentän loppuun
797
- // - a, d, e, f, h, i: Piste näistä viimeisen osakentän loppuun"
798
- // This doesn't match spec at all, but these rules were provided (https://www.kansalliskirjasto.fi/extra/marc21/bib/3XX.htm#340)
799
- describe('#340 TRUE - Punc at $b always and to last of [$a, $d, $e, $f, $h, $i]', () => {
800
- // Valid tests
801
- const recordValidA = new MarcRecord({leader: '',
802
- fields: [{
803
- tag: '340',
804
- ind1: ' ',
805
- ind2: ' ',
806
- subfields: [
807
- {code: 'a', value: 'marble.'}
808
- ]
809
- }]
810
- });
811
-
812
- const recordValidAB = new MarcRecord({leader: '',
813
- fields: [{
814
- tag: '340',
815
- ind1: ' ',
816
- ind2: ' ',
817
- subfields: [
818
- {code: 'a', value: 'parchment.'}, // This punc doesn't match example: https://www.kansalliskirjasto.fi/extra/marc21/bib/3XX.htm#340
819
- {code: 'b', value: '20 cm. folded to 10 x 12 cm.'}
820
- ]
821
- }]
822
- });
823
-
824
- const recordValidDD = new MarcRecord({leader: '',
825
- fields: [{
826
- tag: '340',
827
- ind1: ' ',
828
- ind2: ' ',
829
- subfields: [
830
- {code: 'd', value: 'handwritten'},
831
- {code: 'd', value: 'typed.'}
832
- ]
833
- }]
834
- });
835
-
836
- const recordValidComplex = new MarcRecord({leader: '',
837
- fields: [{
838
- tag: '340',
839
- ind1: ' ',
840
- ind2: ' ',
841
- subfields: [
842
- {code: 'a', value: 'wove paper'},
843
- {code: 'c', value: 'ink'},
844
- {code: 'c', value: 'gouache'},
845
- {code: 'd', value: 'lithography'},
846
- {code: 'd', value: 'collage.'}, // This punc doesn't match example: https://www.kansalliskirjasto.fi/extra/marc21/bib/3XX.htm#340
847
- {code: 'g', value: 'polychrome'}
848
- ]
849
- }]
850
- });
851
-
852
- const recordValidJ2 = new MarcRecord({leader: '',
853
- fields: [{
854
- tag: '340',
855
- ind1: ' ',
856
- ind2: ' ',
857
- subfields: [
858
- {code: 'j', value: 'original'},
859
- {code: '2', value: 'rda'}
860
- ]
861
- }]
862
- });
863
-
864
- it('Finds record valid - Punc $a (only)', async () => {
865
- const validator = await validatorFactory();
866
- const result = await validator.validate(recordValidA);
867
- expect(result.valid).to.eql(true);
868
- });
869
-
870
- it('Finds record valid - Punc $a (last) & punc $b (mandatory)', async () => {
871
- const validator = await validatorFactory();
872
- const result = await validator.validate(recordValidAB);
873
- expect(result.valid).to.eql(true);
874
- });
875
-
876
- it('Finds record valid - Punc $d (last of two)', async () => {
877
- const validator = await validatorFactory();
878
- const result = await validator.validate(recordValidDD);
879
- expect(result.valid).to.eql(true);
880
- });
881
-
882
- it('Finds record valid - Punc $d (last of two) followed by $g', async () => {
883
- const validator = await validatorFactory();
884
- const result = await validator.validate(recordValidComplex);
885
- expect(result.valid).to.eql(true);
886
- });
887
-
888
- it('Finds record valid - No punc (not $b, nor from list)', async () => {
889
- const validator = await validatorFactory();
890
- const result = await validator.validate(recordValidJ2);
891
- expect(result.valid).to.eql(true);
892
- });
893
-
894
- // Invalid tests
895
- const recordInvalidA = new MarcRecord({leader: '',
896
- fields: [{
897
- tag: '340',
898
- ind1: ' ',
899
- ind2: ' ',
900
- subfields: [
901
- {code: 'a', value: 'marble'}
902
- ]
903
- }]
904
- });
905
-
906
- const recordInvalidAMissingB = new MarcRecord({leader: '',
907
- fields: [{
908
- tag: '340',
909
- ind1: ' ',
910
- ind2: ' ',
911
- subfields: [
912
- {code: 'a', value: 'parchment'}, // This punc doesn't match example: https://www.kansalliskirjasto.fi/extra/marc21/bib/3XX.htm#340
913
- {code: 'b', value: '20 cm. folded to 10 x 12 cm.'}
914
- ]
915
- }]
916
- });
917
-
918
- const recordInvalidABMissing = new MarcRecord({leader: '',
919
- fields: [{
920
- tag: '340',
921
- ind1: ' ',
922
- ind2: ' ',
923
- subfields: [
924
- {code: 'a', value: 'parchment.'}, // This punc doesn't match example: https://www.kansalliskirjasto.fi/extra/marc21/bib/3XX.htm#340
925
- {code: 'b', value: '20 cm. folded to 10 x 12 cm'}
926
- ]
927
- }]
928
- });
929
-
930
- const recordInvalidDDMissing = new MarcRecord({leader: '',
931
- fields: [{
932
- tag: '340',
933
- ind1: ' ',
934
- ind2: ' ',
935
- subfields: [
936
- {code: 'd', value: 'handwritten'},
937
- {code: 'd', value: 'typed'}
938
- ]
939
- }]
940
- });
941
-
942
- const recordInvalidComplexDMissing = new MarcRecord({leader: '',
943
- fields: [{
944
- tag: '340',
945
- ind1: ' ',
946
- ind2: ' ',
947
- subfields: [
948
- {code: 'a', value: 'wove paper'},
949
- {code: 'c', value: 'ink'},
950
- {code: 'c', value: 'gouache'},
951
- {code: 'd', value: 'lithography'},
952
- {code: 'd', value: 'collage'}, // This punc doesn't match example: https://www.kansalliskirjasto.fi/extra/marc21/bib/3XX.htm#340
953
- {code: 'g', value: 'polychrome'}
954
- ]
955
- }]
956
- });
957
-
958
- it('Finds record invalid - No punc $a (only)', async () => {
959
- const validator = await validatorFactory();
960
- const result = await validator.validate(recordInvalidA);
961
- expect(result).to.eql({
962
- message: ['Field 340 has invalid ending punctuation'],
963
- valid: false
964
- });
965
- });
966
-
967
- it('Finds record invalid - No punc $a (last)', async () => {
968
- const validator = await validatorFactory();
969
- const result = await validator.validate(recordInvalidAMissingB);
970
- expect(result).to.eql({
971
- message: ['Field 340 has invalid ending punctuation'],
972
- valid: false
973
- });
974
- });
975
-
976
- it('Finds record invalid - No punc $b (mandatory)', async () => {
977
- const validator = await validatorFactory();
978
- const result = await validator.validate(recordInvalidABMissing);
979
- expect(result).to.eql({
980
- message: ['Field 340 has invalid ending punctuation'],
981
- valid: false
982
- });
983
- });
984
-
985
- it('Finds record invalid - No punc $d (last of two)', async () => {
986
- const validator = await validatorFactory();
987
- const result = await validator.validate(recordInvalidDDMissing);
988
- expect(result).to.eql({
989
- message: ['Field 340 has invalid ending punctuation'],
990
- valid: false
991
- });
992
- });
993
-
994
- it('Finds record invalid - No punc $d (last of two) followed by $g', async () => {
995
- const validator = await validatorFactory();
996
- const result = await validator.validate(recordInvalidComplexDMissing);
997
- expect(result).to.eql({
998
- message: ['Field 340 has invalid ending punctuation'],
999
- valid: false
1000
- });
1001
- });
1002
-
1003
- // Fix tests; invalid->valid
1004
- it('Repairs the invalid record - Add punc $a (only)', async () => {
1005
- const validator = await validatorFactory();
1006
- const result = await validator.fix(recordInvalidA);
1007
- expect(recordInvalidA.equalsTo(recordInvalidA)).to.eql(true);
1008
- expect(result).to.eql({
1009
- message: ['Field 340 has invalid ending punctuation'],
1010
- fix: ['Field 340 - Added punctuation to $a'],
1011
- valid: false
1012
- });
1013
- });
1014
-
1015
- it('Repairs the invalid record - Add punc $a (last)', async () => {
1016
- const validator = await validatorFactory();
1017
- const result = await validator.fix(recordInvalidAMissingB);
1018
- expect(recordInvalidAMissingB.equalsTo(recordValidAB)).to.eql(true);
1019
- expect(result).to.eql({
1020
- message: ['Field 340 has invalid ending punctuation'],
1021
- fix: ['Field 340 - Added punctuation to $a'],
1022
- valid: false
1023
- });
1024
- });
1025
-
1026
- it('Repairs the invalid record - Add punc $b (mandatory)', async () => {
1027
- const validator = await validatorFactory();
1028
- const result = await validator.fix(recordInvalidABMissing);
1029
- expect(recordInvalidABMissing.equalsTo(recordValidAB)).to.eql(true);
1030
- expect(result).to.eql({
1031
- message: ['Field 340 has invalid ending punctuation'],
1032
- fix: ['Field 340 - Added punctuation to $b'],
1033
- valid: false
1034
- });
1035
- });
1036
-
1037
- it('Repairs the invalid record - Add punc $d (last of two)', async () => {
1038
- const validator = await validatorFactory();
1039
- const result = await validator.fix(recordInvalidDDMissing);
1040
- expect(recordInvalidDDMissing.equalsTo(recordValidDD)).to.eql(true);
1041
- expect(result).to.eql({
1042
- message: ['Field 340 has invalid ending punctuation'],
1043
- fix: ['Field 340 - Added punctuation to $d'],
1044
- valid: false
1045
- });
1046
- });
1047
-
1048
- it('Repairs the invalid record - Add punc $d (last of list)', async () => {
1049
- const validator = await validatorFactory();
1050
- const result = await validator.fix(recordInvalidComplexDMissing);
1051
- expect(recordInvalidComplexDMissing.equalsTo(recordInvalidComplexDMissing)).to.eql(true);
1052
- expect(result).to.eql({
1053
- message: ['Field 340 has invalid ending punctuation'],
1054
- fix: ['Field 340 - Added punctuation to $d'],
1055
- valid: false
1056
- });
1057
- });
1058
- });
1059
-
1060
- // "520 KYLLÄ Jos viimeinen osakenttä on $u, piste on ennen sitä" (Sama kuin 242, $y)
1061
- describe('#520 TRUE - If last subfield $u, punc before it', () => {
1062
- // Valid tests
1063
- const recordValid = new MarcRecord({leader: '',
1064
- fields: [{
1065
- tag: '520',
1066
- ind1: ' ',
1067
- ind2: ' ',
1068
- subfields: [
1069
- {code: 'a', value: 'Mediaväkivalta ja sen yleisö.'}
1070
- ]
1071
- }]
1072
- });
1073
-
1074
- const recordValidWithU = new MarcRecord({leader: '',
1075
- fields: [{
1076
- tag: '520',
1077
- ind1: ' ',
1078
- ind2: ' ',
1079
- subfields: [
1080
- {code: 'a', value: 'Abstrakti.'}, // This does not match example: https://www.kansalliskirjasto.fi/extra/marc21/bib/50X-53X.htm#520
1081
- {code: 'u', value: 'http://www.ojp.usdoj.gov/bjs/abstract/cchrie98.htm'}
1082
- ]
1083
- }]
1084
- });
1085
-
1086
- const recordValidU = new MarcRecord({leader: '',
1087
- fields: [{
1088
- tag: '520',
1089
- ind1: ' ',
1090
- ind2: ' ',
1091
- subfields: [
1092
- {code: 'a', value: 'Abstrakti.'}, // This does not match example: https://www.kansalliskirjasto.fi/extra/marc21/bib/50X-53X.htm#520
1093
- {code: 'u', value: 'http://www.ojp.usdoj.gov/bjs/abstract/cchrie98.htm.'}
1094
- ]
1095
- }]
1096
- });
1097
-
1098
- it('Finds record valid - Punc $a (without $u)', async () => {
1099
- const validator = await validatorFactory();
1100
- const result = await validator.validate(recordValid);
1101
- expect(result.valid).to.eql(true);
1102
- });
1103
-
1104
- it('Finds record valid - Punc $a (with $u) ', async () => {
1105
- const validator = await validatorFactory();
1106
- const result = await validator.validate(recordValidWithU);
1107
- expect(result.valid).to.eql(true);
1108
- });
1109
-
1110
- it('Finds record valid - Punc $a & $u (punc at $u should be ignored) ', async () => {
1111
- const validator = await validatorFactory();
1112
- const result = await validator.validate(recordValidU);
1113
- expect(result.valid).to.eql(true);
1114
- });
1115
-
1116
- // Invalid tests
1117
- const recordInvalid = new MarcRecord({leader: '',
1118
- fields: [{
1119
- tag: '520',
1120
- ind1: ' ',
1121
- ind2: ' ',
1122
- subfields: [
1123
- {code: 'a', value: 'Mediaväkivalta ja sen yleisö'}
1124
- ]
1125
- }]
1126
- });
1127
-
1128
- const recordInvalidWithU = new MarcRecord({leader: '',
1129
- fields: [{
1130
- tag: '520',
1131
- ind1: ' ',
1132
- ind2: ' ',
1133
- subfields: [
1134
- {code: 'a', value: 'Abstrakti'},
1135
- {code: 'u', value: 'http://www.ojp.usdoj.gov/bjs/abstract/cchrie98.htm'}
1136
- ]
1137
- }]
1138
- });
1139
-
1140
- it('Finds record invalid - No punc $a (without $u)', async () => {
1141
- const validator = await validatorFactory();
1142
- const result = await validator.validate(recordInvalid);
1143
- expect(result).to.eql({
1144
- message: ['Field 520 has invalid ending punctuation'],
1145
- valid: false
1146
- });
1147
- });
1148
-
1149
- it('Finds record invalid - No punc $a (with $u)', async () => {
1150
- const validator = await validatorFactory();
1151
- const result = await validator.validate(recordInvalidWithU);
1152
- expect(result).to.eql({
1153
- message: ['Field 520 has invalid ending punctuation'],
1154
- valid: false
1155
- });
1156
- });
1157
-
1158
- // Fix tests; invalid->valid
1159
- it('Repairs the invalid record - Add punc $a (only)', async () => {
1160
- const validator = await validatorFactory();
1161
- const result = await validator.fix(recordInvalid);
1162
- expect(recordInvalid.equalsTo(recordValid)).to.eql(true);
1163
- expect(result).to.eql({
1164
- message: ['Field 520 has invalid ending punctuation'],
1165
- fix: ['Field 520 - Added punctuation to $a'],
1166
- valid: false
1167
- });
1168
- });
1169
-
1170
- it('Repairs the invalid record - Add punc $a (last before $u)', async () => {
1171
- const validator = await validatorFactory();
1172
- const result = await validator.fix(recordInvalidWithU);
1173
- expect(recordInvalidWithU.equalsTo(recordValidWithU)).to.eql(true);
1174
- expect(result).to.eql({
1175
- message: ['Field 520 has invalid ending punctuation'],
1176
- fix: ['Field 520 - Added punctuation to $a'],
1177
- valid: false
1178
- });
1179
- });
1180
- });
1181
-
1182
- // "538 KYLLÄ Jos viimeinen osakenttä on $u, piste on ennen sitä" (Sama kuin 520)
1183
- // Eli piste merkitään vikaan osakenttään as usual, mutta ennen *y*-osakenttää
1184
- // (speksin mukaan y->u) https://www.kansalliskirjasto.fi/extra/marc21/bib/53X-58X.htm#538
1185
- describe('#538 TRUE - If last subfield $u, punc before it', () => {
1186
- // Valid tests
1187
- const recordValid = new MarcRecord({leader: '',
1188
- fields: [{
1189
- tag: '538',
1190
- ind1: ' ',
1191
- ind2: ' ',
1192
- subfields: [
1193
- {code: 'a', value: 'Project methodology for digital version'},
1194
- {code: 'i', value: 'Technical details.'}, // This ended to ':' in examples, but it doesn't match statet rules: https://www.kansalliskirjasto.fi/extra/marc21/bib/53X-58X.htm#538
1195
- {code: 'u', value: 'http://www.columbia.edu/dlc/linglung/methodology.html'}
1196
- ]
1197
- }]
1198
- });
1199
-
1200
- const recordValidPuncU = new MarcRecord({leader: '',
1201
- fields: [{
1202
- tag: '538',
1203
- ind1: ' ',
1204
- ind2: ' ',
1205
- subfields: [
1206
- {code: 'a', value: 'Project methodology for digital version'},
1207
- {code: 'i', value: 'Technical details.'},
1208
- {code: 'u', value: 'http://www.columbia.edu/dlc/linglung/methodology.html.'}
1209
- ]
1210
- }]
1211
- });
1212
-
1213
- const recordValidOnlyA = new MarcRecord({leader: '',
1214
- fields: [{
1215
- tag: '538',
1216
- ind1: ' ',
1217
- ind2: ' ',
1218
- subfields: [
1219
- {code: 'a', value: 'SECAM-videolaite.'}
1220
- ]
1221
- }]
1222
- });
1223
-
1224
- it('Finds record valid - Punc $i (last before $u)', async () => {
1225
- const validator = await validatorFactory();
1226
- const result = await validator.validate(recordValid);
1227
- expect(result.valid).to.eql(true);
1228
- });
1229
-
1230
- it('Finds record valid - Punc $i & punc $u ($u is URL, should pass)', async () => {
1231
- const validator = await validatorFactory();
1232
- const result = await validator.validate(recordValidPuncU);
1233
- expect(result.valid).to.eql(true);
1234
- });
1235
-
1236
- it('Finds record valid - Punc $a (only)', async () => {
1237
- const validator = await validatorFactory();
1238
- const result = await validator.validate(recordValidOnlyA);
1239
- expect(result.valid).to.eql(true);
1240
- });
1241
-
1242
- // Invalid tests
1243
- const recordInvalidMissingI = new MarcRecord({leader: '',
1244
- fields: [{
1245
- tag: '538',
1246
- ind1: ' ',
1247
- ind2: ' ',
1248
- subfields: [
1249
- {code: 'a', value: 'Project methodology for digital version'},
1250
- {code: 'i', value: 'Technical details'},
1251
- {code: 'u', value: 'http://www.columbia.edu/dlc/linglung/methodology.html'}
1252
- ]
1253
- }]
1254
- });
1255
-
1256
- const recordInvalidI = new MarcRecord({leader: '',
1257
- fields: [{
1258
- tag: '538',
1259
- ind1: ' ',
1260
- ind2: ' ',
1261
- subfields: [
1262
- {code: 'a', value: 'Project methodology for digital version'},
1263
- {code: 'i', value: 'Technical details:'}, // This is actually like in examples, but it doesn't match statet rules: https://www.kansalliskirjasto.fi/extra/marc21/bib/53X-58X.htm#538
1264
- {code: 'u', value: 'http://www.columbia.edu/dlc/linglung/methodology.html'}
1265
- ]
1266
- }]
1267
- });
1268
-
1269
- const recordInvalidOnlyA = new MarcRecord({leader: '',
1270
- fields: [{
1271
- tag: '538',
1272
- ind1: ' ',
1273
- ind2: ' ',
1274
- subfields: [
1275
- {code: 'a', value: 'SECAM-videolaite'}
1276
- ]
1277
- }]
1278
- });
1279
-
1280
- it('Finds record invalid - No punc $i (last before $u)', async () => {
1281
- const validator = await validatorFactory();
1282
- const result = await validator.validate(recordInvalidMissingI);
1283
- expect(result).to.eql({
1284
- message: ['Field 538 has invalid ending punctuation'],
1285
- valid: false
1286
- });
1287
- });
1288
-
1289
- it('Finds record invalid - Invalid punc $i (":" not valid punc mark, but this is according example...)', async () => {
1290
- const validator = await validatorFactory();
1291
- const result = await validator.validate(recordInvalidI);
1292
- expect(result).to.eql({
1293
- message: ['Field 538 has invalid ending punctuation'],
1294
- valid: false
1295
- });
1296
- });
1297
-
1298
- it('Finds record invalid - No punc $a (only)', async () => {
1299
- const validator = await validatorFactory();
1300
- const result = await validator.validate(recordInvalidOnlyA);
1301
- expect(result).to.eql({
1302
- message: ['Field 538 has invalid ending punctuation'],
1303
- valid: false
1304
- });
1305
- });
1306
-
1307
- // Fix tests; invalid->valid
1308
- it('Repairs the invalid record - Add punc $i (last)', async () => {
1309
- const validator = await validatorFactory();
1310
- const result = await validator.fix(recordInvalidMissingI);
1311
- expect(recordInvalidMissingI.equalsTo(recordValid)).to.eql(true);
1312
- expect(result).to.eql({
1313
- message: ['Field 538 has invalid ending punctuation'],
1314
- fix: ['Field 538 - Added punctuation to $i'],
1315
- valid: false
1316
- });
1317
- });
1318
-
1319
- it('Repairs the invalid record - Add punc $a (only)', async () => {
1320
- const validator = await validatorFactory();
1321
- const result = await validator.fix(recordInvalidOnlyA);
1322
- expect(recordInvalidOnlyA.equalsTo(recordValidOnlyA)).to.eql(true);
1323
- expect(result).to.eql({
1324
- message: ['Field 538 has invalid ending punctuation'],
1325
- fix: ['Field 538 - Added punctuation to $a'],
1326
- valid: false
1327
- });
1328
- });
1329
- });
1330
-
1331
- // "567 KYLLÄ osakentän $a jälkeen, EI muiden osakenttien jälkeen"
1332
- // Only if last subfield $a
1333
- describe('#567 TRUE - After subfield $a, FALSE after others', () => {
1334
- // Valid tests
1335
- const recordValid = new MarcRecord({leader: '',
1336
- fields: [{
1337
- tag: '567',
1338
- ind1: ' ',
1339
- ind2: ' ',
1340
- subfields: [
1341
- {code: 'a', value: 'Narratiivinen tutkimus.'}
1342
- ]
1343
- }]
1344
- });
1345
-
1346
- const recordValidWithoutA = new MarcRecord({leader: '',
1347
- fields: [{
1348
- tag: '567',
1349
- ind1: ' ',
1350
- ind2: ' ',
1351
- subfields: [
1352
- {code: 'b', value: 'Narrative inquiry'},
1353
- {code: '2', value: 'lcsh'}
1354
- ]
1355
- }]
1356
- });
1357
-
1358
- it('Finds record valid - Punc $a (only)', async () => {
1359
- const validator = await validatorFactory();
1360
- const result = await validator.validate(recordValid);
1361
- expect(result.valid).to.eql(true);
1362
- });
1363
-
1364
- it('Finds record valid - No punc $b (only data field)', async () => {
1365
- const validator = await validatorFactory();
1366
- const result = await validator.validate(recordValidWithoutA);
1367
- expect(result.valid).to.eql(true);
1368
- });
1369
-
1370
- // Invalid tests
1371
- const recordInvalid = new MarcRecord({leader: '',
1372
- fields: [{
1373
- tag: '567',
1374
- ind1: ' ',
1375
- ind2: ' ',
1376
- subfields: [
1377
- {code: 'a', value: 'Narratiivinen tutkimus'}
1378
- ]
1379
- }]
1380
- });
1381
-
1382
- const recordInvalidWithoutA = new MarcRecord({leader: '',
1383
- fields: [{
1384
- tag: '567',
1385
- ind1: ' ',
1386
- ind2: ' ',
1387
- subfields: [
1388
- {code: 'b', value: 'Narrative inquiry.'},
1389
- {code: '2', value: 'lcsh'}
1390
- ]
1391
- }]
1392
- });
1393
-
1394
- it('Finds record invalid - No punc $a (only)', async () => {
1395
- const validator = await validatorFactory();
1396
- const result = await validator.validate(recordInvalid);
1397
- expect(result).to.eql({
1398
- message: ['Field 567 has invalid ending punctuation'],
1399
- valid: false
1400
- });
1401
- });
1402
-
1403
- it('Finds record invalid - Punc $b (only data field)', async () => {
1404
- const validator = await validatorFactory();
1405
- const result = await validator.validate(recordInvalidWithoutA);
1406
- expect(result).to.eql({
1407
- message: ['Field 567 has invalid ending punctuation'],
1408
- valid: false
1409
- });
1410
- });
1411
-
1412
- // Fix tests; invalid->valid
1413
- it('Repairs the invalid record - Add punc $a (only)', async () => {
1414
- const validator = await validatorFactory();
1415
- const result = await validator.fix(recordInvalid);
1416
- expect(recordInvalid.equalsTo(recordValid)).to.eql(true);
1417
- expect(result).to.eql({
1418
- message: ['Field 567 has invalid ending punctuation'],
1419
- fix: ['Field 567 - Added punctuation to $a'],
1420
- valid: false
1421
- });
1422
- });
1423
-
1424
- it('Repairs the invalid record - Remove punc $b (only data field)', async () => {
1425
- const validator = await validatorFactory();
1426
- const result = await validator.fix(recordInvalidWithoutA);
1427
- expect(recordInvalidWithoutA.equalsTo(recordValidWithoutA)).to.eql(true);
1428
- expect(result).to.eql({
1429
- message: ['Field 567 has invalid ending punctuation'],
1430
- fix: ['Field 567 - Removed punctuation from $b'],
1431
- valid: false
1432
- });
1433
- });
1434
- });
1435
-
1436
- // "647-651 EI - EI suomalaisten sanastojen termeihin, muihin sanaston käytännön mukaan, yleensä KYLLÄ"
1437
- // Finnish terms at $2:['ysa', 'yso', 'kassu', 'seko', 'valo', 'kulo', 'puho', 'oiko', 'mero', 'liito', 'fast', 'allars']
1438
- // Default TRUE, until more special cases are added
1439
- describe('#647-651 FALSE - If finnish, else TRUE', () => {
1440
- // Valid tests
1441
- const recordValid647FastEndPunc = new MarcRecord({leader: '',
1442
- fields: [{
1443
- tag: '647',
1444
- ind1: ' ',
1445
- ind2: ' ',
1446
- subfields: [
1447
- {code: 'a', value: 'Hurricane Katrina'},
1448
- {code: 'd', value: '(2005)'},
1449
- {code: '2', value: 'fast'}
1450
- ]
1451
- }]
1452
- });
1453
-
1454
- const recordVali648dFinNo = new MarcRecord({leader: '',
1455
- fields: [{
1456
- tag: '648',
1457
- ind1: ' ',
1458
- ind2: ' ',
1459
- subfields: [
1460
- {code: 'a', value: '1900-luku'},
1461
- {code: '2', value: 'ysa'}
1462
- ]
1463
- }]
1464
- });
1465
-
1466
- const recordValid648FastNo = new MarcRecord({leader: '',
1467
- fields: [{
1468
- tag: '648',
1469
- ind1: ' ',
1470
- ind2: ' ',
1471
- subfields: [
1472
- {code: 'a', value: '1862'},
1473
- {code: '2', value: 'fast'} // https://www.kansalliskirjasto.fi/extra/marc21/bib/6XX.htm#648
1474
- ]
1475
- }]
1476
- });
1477
-
1478
- const recordValid650FinNo = new MarcRecord({leader: '',
1479
- fields: [{
1480
- tag: '650',
1481
- ind1: ' ',
1482
- ind2: ' ',
1483
- subfields: [
1484
- {code: 'a', value: 'kirjastot'},
1485
- {code: 'x', value: 'atk-järjestelmät'},
1486
- {code: '2', value: 'ysa'}
1487
- ]
1488
- }]
1489
- });
1490
-
1491
- const recordValid650EngNoControl = new MarcRecord({leader: '',
1492
- fields: [{
1493
- tag: '650',
1494
- ind1: ' ',
1495
- ind2: ' ',
1496
- subfields: [
1497
- {code: 'a', value: 'Flour industry'},
1498
- {code: 'v', value: 'Periodicals.'}
1499
- ]
1500
- }]
1501
- });
1502
-
1503
- const recordValid650EngControl = new MarcRecord({leader: '',
1504
- fields: [{
1505
- tag: '650',
1506
- ind1: ' ',
1507
- ind2: ' ',
1508
- subfields: [
1509
- {code: 'a', value: 'Career Exploration.'},
1510
- {code: '2', value: 'ericd'}
1511
- ]
1512
- }]
1513
- });
1514
-
1515
- it('Finds record valid - 647 Fast, punc char at end', async () => {
1516
- const validator = await validatorFactory();
1517
- const result = await validator.validate(recordValid647FastEndPunc);
1518
- expect(result.valid).to.eql(true);
1519
- });
1520
-
1521
- it('Finds record valid - 648 Finnish, without punc', async () => {
1522
- const validator = await validatorFactory();
1523
- const result = await validator.validate(recordVali648dFinNo);
1524
- expect(result.valid).to.eql(true);
1525
- });
1526
-
1527
- it('Finds record valid - 648 Fast, without punc', async () => {
1528
- const validator = await validatorFactory();
1529
- const result = await validator.validate(recordValid648FastNo);
1530
- expect(result.valid).to.eql(true);
1531
- });
1532
-
1533
- it('Finds record valid - 650 Finnish, without punc', async () => {
1534
- const validator = await validatorFactory();
1535
- const result = await validator.validate(recordValid650FinNo);
1536
- expect(result.valid).to.eql(true);
1537
- });
1538
-
1539
- it('Finds record valid - 650 English, punc (no control)', async () => {
1540
- const validator = await validatorFactory();
1541
- const result = await validator.validate(recordValid650EngNoControl);
1542
- expect(result.valid).to.eql(true);
1543
- });
1544
-
1545
- it('Finds record valid - 650 English, with punc', async () => {
1546
- const validator = await validatorFactory();
1547
- const result = await validator.validate(recordValid650EngControl);
1548
- expect(result.valid).to.eql(true);
1549
- });
1550
-
1551
- // Invalid tests
1552
- const recordInvalid647FastEndPunc = new MarcRecord({leader: '',
1553
- fields: [{
1554
- tag: '647',
1555
- ind1: ' ',
1556
- ind2: ' ',
1557
- subfields: [
1558
- {code: 'a', value: 'Hurricane Katrina'},
1559
- {code: 'd', value: '(2005).'},
1560
- {code: '2', value: 'fast'}
1561
- ]
1562
- }]
1563
- });
1564
-
1565
- const recordInvali648dFinYes = new MarcRecord({leader: '',
1566
- fields: [{
1567
- tag: '648',
1568
- ind1: ' ',
1569
- ind2: ' ',
1570
- subfields: [
1571
- {code: 'a', value: '1900-luku.'},
1572
- {code: '2', value: 'ysa'}
1573
- ]
1574
- }]
1575
- });
1576
-
1577
- const recordInvalid648FastYes = new MarcRecord({leader: '',
1578
- fields: [{
1579
- tag: '648',
1580
- ind1: ' ',
1581
- ind2: ' ',
1582
- subfields: [
1583
- {code: 'a', value: '1862.'},
1584
- {code: '2', value: 'fast'}
1585
- ]
1586
- }]
1587
- });
1588
-
1589
- const recordInvalid650FinYes = new MarcRecord({leader: '',
1590
- fields: [{
1591
- tag: '650',
1592
- ind1: ' ',
1593
- ind2: ' ',
1594
- subfields: [
1595
- {code: 'a', value: 'kirjastot'},
1596
- {code: 'x', value: 'atk-järjestelmät.'},
1597
- {code: '2', value: 'ysa'}
1598
- ]
1599
- }]
1600
- });
1601
-
1602
- const recordInvalid650EngNoControl = new MarcRecord({leader: '',
1603
- fields: [{
1604
- tag: '650',
1605
- ind1: ' ',
1606
- ind2: ' ',
1607
- subfields: [
1608
- {code: 'a', value: 'Flour industry'},
1609
- {code: 'v', value: 'Periodicals'}
1610
- ]
1611
- }]
1612
- });
1613
-
1614
- const recordInvalid650EngControl = new MarcRecord({leader: '',
1615
- fields: [{
1616
- tag: '650',
1617
- ind1: ' ',
1618
- ind2: ' ',
1619
- subfields: [
1620
- {code: 'a', value: 'Career Exploration'},
1621
- {code: '2', value: 'ericd'}
1622
- ]
1623
- }]
1624
- });
1625
-
1626
- it('Finds record invalid - 647 Fast, dot at end', async () => {
1627
- const validator = await validatorFactory();
1628
- const result = await validator.validate(recordInvalid647FastEndPunc);
1629
- expect(result).to.eql({
1630
- message: ['Field 647 has invalid ending punctuation'],
1631
- valid: false
1632
- });
1633
- });
1634
-
1635
- it('Finds record invalid - 648 Finnish, with punc', async () => {
1636
- const validator = await validatorFactory();
1637
- const result = await validator.validate(recordInvali648dFinYes);
1638
- expect(result).to.eql({
1639
- message: ['Field 648 has invalid ending punctuation'],
1640
- valid: false
1641
- });
1642
- });
1643
-
1644
- it('Finds record invalid - 648 Fast, with punc', async () => {
1645
- const validator = await validatorFactory();
1646
- const result = await validator.validate(recordInvalid648FastYes);
1647
- expect(result).to.eql({
1648
- message: ['Field 648 has invalid ending punctuation'],
1649
- valid: false
1650
- });
1651
- });
1652
-
1653
- it('Finds record invalid - 650 Finnish, with punc', async () => {
1654
- const validator = await validatorFactory();
1655
- const result = await validator.validate(recordInvalid650FinYes);
1656
- expect(result).to.eql({
1657
- message: ['Field 650 has invalid ending punctuation'],
1658
- valid: false
1659
- });
1660
- });
1661
-
1662
- it('Finds record invalid - 650 !Finnish, without punc (no control)', async () => {
1663
- const validator = await validatorFactory();
1664
- const result = await validator.validate(recordInvalid650EngNoControl);
1665
- expect(result).to.eql({
1666
- message: ['Field 650 has invalid ending punctuation'],
1667
- valid: false
1668
- });
1669
- });
1670
-
1671
- it('Finds record invalid - 650 !Finnish, without punc', async () => {
1672
- const validator = await validatorFactory();
1673
- const result = await validator.validate(recordInvalid650EngControl);
1674
- expect(result).to.eql({
1675
- message: ['Field 650 has invalid ending punctuation'],
1676
- valid: false
1677
- });
1678
- });
1679
-
1680
- // Fix tests; invalid->valid
1681
- it('Repairs the invalid record - 647 Fast, removes double punc $d', async () => {
1682
- const validator = await validatorFactory();
1683
- const result = await validator.fix(recordInvalid647FastEndPunc);
1684
- expect(recordInvalid647FastEndPunc.equalsTo(recordValid647FastEndPunc)).to.eql(true);
1685
- expect(result).to.eql({
1686
- message: ['Field 647 has invalid ending punctuation'],
1687
- fix: ['Field 647 - Removed double punctuation from $d'],
1688
- valid: false
1689
- });
1690
- });
1691
-
1692
- it('Repairs the invalid record - 648 Finnish, removes punc $a', async () => {
1693
- const validator = await validatorFactory();
1694
- const result = await validator.fix(recordInvali648dFinYes);
1695
- expect(recordInvali648dFinYes.equalsTo(recordVali648dFinNo)).to.eql(true);
1696
- expect(result).to.eql({
1697
- message: ['Field 648 has invalid ending punctuation'],
1698
- fix: ['Field 648 - Removed punctuation from $a'],
1699
- valid: false
1700
- });
1701
- });
1702
-
1703
- it('Repairs the invalid record - 648 Fast, removes punc $a', async () => {
1704
- const validator = await validatorFactory();
1705
- const result = await validator.fix(recordInvalid648FastYes);
1706
- expect(recordInvalid648FastYes.equalsTo(recordValid648FastNo)).to.eql(true);
1707
- expect(result).to.eql({
1708
- message: ['Field 648 has invalid ending punctuation'],
1709
- fix: ['Field 648 - Removed punctuation from $a'],
1710
- valid: false
1711
- });
1712
- });
1713
-
1714
- it('Repairs the invalid record - 650 Finnish, removes punc $x', async () => {
1715
- const validator = await validatorFactory();
1716
- const result = await validator.fix(recordInvalid650FinYes);
1717
- expect(recordInvalid650FinYes.equalsTo(recordValid650FinNo)).to.eql(true);
1718
- expect(result).to.eql({
1719
- message: ['Field 650 has invalid ending punctuation'],
1720
- fix: ['Field 650 - Removed punctuation from $x'],
1721
- valid: false
1722
- });
1723
- });
1724
-
1725
- it('Repairs the invalid record - 650 !Finnish, add punc $v (no control)', async () => {
1726
- const validator = await validatorFactory();
1727
- const result = await validator.fix(recordInvalid650EngNoControl);
1728
- expect(recordInvalid650EngNoControl.equalsTo(recordValid650EngNoControl)).to.eql(true);
1729
- expect(result).to.eql({
1730
- message: ['Field 650 has invalid ending punctuation'],
1731
- fix: ['Field 650 - Added punctuation to $v'],
1732
- valid: false
1733
- });
1734
- });
1735
-
1736
- it('Repairs the invalid record - 650 !Finnish, add punc $a', async () => {
1737
- const validator = await validatorFactory();
1738
- const result = await validator.fix(recordInvalid650EngControl);
1739
- expect(recordInvalid650EngControl.equalsTo(recordValid650EngControl)).to.eql(true);
1740
- expect(result).to.eql({
1741
- message: ['Field 650 has invalid ending punctuation'],
1742
- fix: ['Field 650 - Added punctuation to $a'],
1743
- valid: false
1744
- });
1745
- });
1746
- });
1747
-
1748
- // "654-662 EI - EI suomalaisten sanastojen termeihin, muihin sanaston käytännön mukaan, yleensä KYLLÄ"
1749
- // Finnish terms at $2:['ysa', 'yso', 'kassu', 'seko', 'valo', 'kulo', 'puho', 'oiko', 'mero', 'liito', 'fast', 'allars']
1750
- // Default TRUE, until more special cases are added
1751
- describe('#654-662 TRUE - If finnish, else TRUE', () => {
1752
- // Valid tests
1753
- const recordValid655FinNo = new MarcRecord({leader: '',
1754
- fields: [{
1755
- tag: '655',
1756
- ind1: ' ',
1757
- ind2: ' ',
1758
- subfields: [
1759
- {code: 'a', value: 'kausijulkaisut'},
1760
- {code: '2', value: 'ysa'}
1761
- ]
1762
- }]
1763
- });
1764
-
1765
- const recordValid655EngYes = new MarcRecord({leader: '',
1766
- fields: [{
1767
- tag: '655',
1768
- ind1: ' ',
1769
- ind2: ' ',
1770
- subfields: [
1771
- {code: 'a', value: 'Bird\'s-eye views'},
1772
- {code: 'y', value: '1874.'},
1773
- {code: '2', value: 'gmgpc'}
1774
- ]
1775
- }]
1776
- });
1777
-
1778
- const recordValid655EngYesNoControl = new MarcRecord({leader: '',
1779
- fields: [{
1780
- tag: '655',
1781
- ind1: ' ',
1782
- ind2: ' ',
1783
- subfields: [
1784
- {code: 'a', value: 'Diaries.'}
1785
- ]
1786
- }]
1787
- });
1788
-
1789
- const recordValid656FinNo = new MarcRecord({leader: '',
1790
- fields: [{
1791
- tag: '656',
1792
- ind1: ' ',
1793
- ind2: ' ',
1794
- subfields: [
1795
- {code: 'a', value: 'kuvaamataidonopettajat'},
1796
- {code: '2', value: 'ysa'}
1797
- ]
1798
- }]
1799
- });
1800
-
1801
- const recordValid657EngYes = new MarcRecord({leader: '',
1802
- fields: [{
1803
- tag: '657',
1804
- ind1: ' ',
1805
- ind2: ' ',
1806
- subfields: [
1807
- {code: 'a', value: 'Personnel benefits management'},
1808
- {code: 'x', value: 'Vital statistics'},
1809
- {code: 'z', value: 'Love Canal, New York.'},
1810
- {code: '2', value: 'New York State Management Functions Index'}
1811
- ]
1812
- }]
1813
- });
1814
-
1815
- const recordValid658EngYes = new MarcRecord({leader: '',
1816
- fields: [{
1817
- tag: '658',
1818
- ind1: ' ',
1819
- ind2: ' ',
1820
- subfields: [
1821
- {code: 'a', value: 'Math manipulatives'},
1822
- {code: 'd', value: 'highly correlated.'},
1823
- {code: '2', value: '[source code]'}
1824
- ]
1825
- }]
1826
- });
1827
-
1828
- const recordValid662EngYes = new MarcRecord({leader: '',
1829
- fields: [{
1830
- tag: '662',
1831
- ind1: ' ',
1832
- ind2: ' ',
1833
- subfields: [
1834
- {code: 'a', value: 'Antarctica.'},
1835
- {code: '2', value: 'lcsh/naf'}
1836
- ]
1837
- }]
1838
- });
1839
-
1840
- it('Finds record valid - 655 Finnish, no punc $a', async () => {
1841
- const validator = await validatorFactory();
1842
- const result = await validator.validate(recordValid655FinNo);
1843
- expect(result.valid).to.eql(true);
1844
- });
1845
-
1846
- it('Finds record valid - 655 English, with punc $y', async () => {
1847
- const validator = await validatorFactory();
1848
- const result = await validator.validate(recordValid655EngYes);
1849
- expect(result.valid).to.eql(true);
1850
- });
1851
-
1852
- it('Finds record valid - 655 English, with punc $a (no control)', async () => {
1853
- const validator = await validatorFactory();
1854
- const result = await validator.validate(recordValid655EngYesNoControl);
1855
- expect(result.valid).to.eql(true);
1856
- });
1857
-
1858
- it('Finds record valid - 656 Finnish, without punc $a', async () => {
1859
- const validator = await validatorFactory();
1860
- const result = await validator.validate(recordValid656FinNo);
1861
- expect(result.valid).to.eql(true);
1862
- });
1863
-
1864
- it('Finds record valid - 657 English, with punc $z', async () => {
1865
- const validator = await validatorFactory();
1866
- const result = await validator.validate(recordValid657EngYes);
1867
- expect(result.valid).to.eql(true);
1868
- });
1869
-
1870
- it('Finds record valid - 658 English, with punc $d', async () => {
1871
- const validator = await validatorFactory();
1872
- const result = await validator.validate(recordValid658EngYes);
1873
- expect(result.valid).to.eql(true);
1874
- });
1875
-
1876
- it('Finds record valid - 662 English, with punc $a', async () => {
1877
- const validator = await validatorFactory();
1878
- const result = await validator.validate(recordValid662EngYes);
1879
- expect(result.valid).to.eql(true);
1880
- });
1881
-
1882
- // Invalid tests
1883
- const recordInvalid655FinYes = new MarcRecord({leader: '',
1884
- fields: [{
1885
- tag: '655',
1886
- ind1: ' ',
1887
- ind2: ' ',
1888
- subfields: [
1889
- {code: 'a', value: 'kausijulkaisut.'},
1890
- {code: '2', value: 'ysa'}
1891
- ]
1892
- }]
1893
- });
1894
-
1895
- const recordInvalid655EngNo = new MarcRecord({leader: '',
1896
- fields: [{
1897
- tag: '655',
1898
- ind1: ' ',
1899
- ind2: ' ',
1900
- subfields: [
1901
- {code: 'a', value: 'Bird\'s-eye views'},
1902
- {code: 'y', value: '1874'},
1903
- {code: '2', value: 'gmgpc'}
1904
- ]
1905
- }]
1906
- });
1907
-
1908
- const recordInvalid655EngNoNoControl = new MarcRecord({leader: '',
1909
- fields: [{
1910
- tag: '655',
1911
- ind1: ' ',
1912
- ind2: ' ',
1913
- subfields: [
1914
- {code: 'a', value: 'Diaries'}
1915
- ]
1916
- }]
1917
- });
1918
-
1919
- const recordInvalid656FinYes = new MarcRecord({leader: '',
1920
- fields: [{
1921
- tag: '656',
1922
- ind1: ' ',
1923
- ind2: ' ',
1924
- subfields: [
1925
- {code: 'a', value: 'kuvaamataidonopettajat.'},
1926
- {code: '2', value: 'ysa'}
1927
- ]
1928
- }]
1929
- });
1930
-
1931
- const recordInvalid657EngNo = new MarcRecord({leader: '',
1932
- fields: [{
1933
- tag: '657',
1934
- ind1: ' ',
1935
- ind2: ' ',
1936
- subfields: [
1937
- {code: 'a', value: 'Personnel benefits management'},
1938
- {code: 'x', value: 'Vital statistics'},
1939
- {code: 'z', value: 'Love Canal, New York'},
1940
- {code: '2', value: 'New York State Management Functions Index'}
1941
- ]
1942
- }]
1943
- });
1944
-
1945
- const recordInvalid658EngNo = new MarcRecord({leader: '',
1946
- fields: [{
1947
- tag: '658',
1948
- ind1: ' ',
1949
- ind2: ' ',
1950
- subfields: [
1951
- {code: 'a', value: 'Math manipulatives'},
1952
- {code: 'd', value: 'highly correlated'},
1953
- {code: '2', value: '[source code]'}
1954
- ]
1955
- }]
1956
- });
1957
-
1958
- const recordInvalid662EngNo = new MarcRecord({leader: '',
1959
- fields: [{
1960
- tag: '662',
1961
- ind1: ' ',
1962
- ind2: ' ',
1963
- subfields: [
1964
- {code: 'a', value: 'Antarctica'},
1965
- {code: '2', value: 'lcsh/naf'}
1966
- ]
1967
- }]
1968
- });
1969
-
1970
- it('Finds record invalid - 655 Finnish, punc $a', async () => {
1971
- const validator = await validatorFactory();
1972
- const result = await validator.validate(recordInvalid655FinYes);
1973
- expect(result).to.eql({
1974
- message: ['Field 655 has invalid ending punctuation'],
1975
- valid: false
1976
- });
1977
- });
1978
-
1979
- it('Finds record invalid - 655 !Finnish, without punc $y', async () => {
1980
- const validator = await validatorFactory();
1981
- const result = await validator.validate(recordInvalid655EngNo);
1982
- expect(result).to.eql({
1983
- message: ['Field 655 has invalid ending punctuation'],
1984
- valid: false
1985
- });
1986
- });
1987
-
1988
- it('Finds record invalid - 655 !Finnish, without punc $a (no control)', async () => {
1989
- const validator = await validatorFactory();
1990
- const result = await validator.validate(recordInvalid655EngNoNoControl);
1991
- expect(result).to.eql({
1992
- message: ['Field 655 has invalid ending punctuation'],
1993
- valid: false
1994
- });
1995
- });
1996
-
1997
- it('Finds record invalid - 656 Finnish, with punc $a', async () => {
1998
- const validator = await validatorFactory();
1999
- const result = await validator.validate(recordInvalid656FinYes);
2000
- expect(result).to.eql({
2001
- message: ['Field 656 has invalid ending punctuation'],
2002
- valid: false
2003
- });
2004
- });
2005
-
2006
- it('Finds record invalid - 657 !Finnish, without punc $z', async () => {
2007
- const validator = await validatorFactory();
2008
- const result = await validator.validate(recordInvalid657EngNo);
2009
- expect(result).to.eql({
2010
- message: ['Field 657 has invalid ending punctuation'],
2011
- valid: false
2012
- });
2013
- });
2014
-
2015
- it('Finds record invalid - 658 !Finnish, without punc $d', async () => {
2016
- const validator = await validatorFactory();
2017
- const result = await validator.validate(recordInvalid658EngNo);
2018
- expect(result).to.eql({
2019
- message: ['Field 658 has invalid ending punctuation'],
2020
- valid: false
2021
- });
2022
- });
2023
-
2024
- it('Finds record invalid - 662 !Finnish, without punc $a', async () => {
2025
- const validator = await validatorFactory();
2026
- const result = await validator.validate(recordInvalid662EngNo);
2027
- expect(result).to.eql({
2028
- message: ['Field 662 has invalid ending punctuation'],
2029
- valid: false
2030
- });
2031
- });
2032
-
2033
- // Fix tests; invalid->valid
2034
- it('Repairs the invalid record - 655 Finnish, remove punc $a', async () => {
2035
- const validator = await validatorFactory();
2036
- const result = await validator.fix(recordInvalid655FinYes);
2037
- expect(recordInvalid655FinYes.equalsTo(recordValid655FinNo)).to.eql(true);
2038
- expect(result).to.eql({
2039
- message: ['Field 655 has invalid ending punctuation'],
2040
- fix: ['Field 655 - Removed punctuation from $a'],
2041
- valid: false
2042
- });
2043
- });
2044
-
2045
- it('Repairs the invalid record - 655 !Finnish, add punc $y', async () => {
2046
- const validator = await validatorFactory();
2047
- const result = await validator.fix(recordInvalid655EngNo);
2048
- expect(recordInvalid655EngNo.equalsTo(recordValid655EngYes)).to.eql(true);
2049
- expect(result).to.eql({
2050
- message: ['Field 655 has invalid ending punctuation'],
2051
- fix: ['Field 655 - Added punctuation to $y'],
2052
- valid: false
2053
- });
2054
- });
2055
-
2056
- it('Repairs the invalid record - 655 !Finnish, add punc $a (no control)', async () => {
2057
- const validator = await validatorFactory();
2058
- const result = await validator.fix(recordInvalid655EngNoNoControl);
2059
- expect(recordInvalid655EngNoNoControl.equalsTo(recordValid655EngYesNoControl)).to.eql(true);
2060
- expect(result).to.eql({
2061
- message: ['Field 655 has invalid ending punctuation'],
2062
- fix: ['Field 655 - Added punctuation to $a'],
2063
- valid: false
2064
- });
2065
- });
2066
-
2067
- it('Repairs the invalid record - 656 Finnish, remove punc $a', async () => {
2068
- const validator = await validatorFactory();
2069
- const result = await validator.fix(recordInvalid656FinYes);
2070
- expect(recordInvalid656FinYes.equalsTo(recordValid656FinNo)).to.eql(true);
2071
- expect(result).to.eql({
2072
- message: ['Field 656 has invalid ending punctuation'],
2073
- fix: ['Field 656 - Removed punctuation from $a'],
2074
- valid: false
2075
- });
2076
- });
2077
-
2078
- it('Repairs the invalid record - 657 !Finnish, add punc $z', async () => {
2079
- const validator = await validatorFactory();
2080
- const result = await validator.fix(recordInvalid657EngNo);
2081
- expect(recordInvalid657EngNo.equalsTo(recordValid657EngYes)).to.eql(true);
2082
- expect(result).to.eql({
2083
- message: ['Field 657 has invalid ending punctuation'],
2084
- fix: ['Field 657 - Added punctuation to $z'],
2085
- valid: false
2086
- });
2087
- });
2088
-
2089
- it('Repairs the invalid record - 658 !Finnish, add punc $d', async () => {
2090
- const validator = await validatorFactory();
2091
- const result = await validator.fix(recordInvalid658EngNo);
2092
- expect(recordInvalid658EngNo.equalsTo(recordValid658EngYes)).to.eql(true);
2093
- expect(result).to.eql({
2094
- message: ['Field 658 has invalid ending punctuation'],
2095
- fix: ['Field 658 - Added punctuation to $d'],
2096
- valid: false
2097
- });
2098
- });
2099
-
2100
- it('Repairs the invalid record - 662 !Finnish, add pun $a', async () => {
2101
- const validator = await validatorFactory();
2102
- const result = await validator.fix(recordInvalid662EngNo);
2103
- expect(recordInvalid662EngNo.equalsTo(recordValid662EngYes)).to.eql(true);
2104
- expect(result).to.eql({
2105
- message: ['Field 662 has invalid ending punctuation'],
2106
- fix: ['Field 662 - Added punctuation to $a'],
2107
- valid: false
2108
- });
2109
- });
2110
- });
2111
-
2112
- // "760-787 KYLLÄ osakentän $a jälkeen, EI muiden osakenttien jälkeen" (kuten 567)
2113
- // Only if last subfield $a
2114
- describe('#760-787 TRUE - After subfield $a, FALSE after others', () => {
2115
- // Valid tests
2116
- const recordValid = new MarcRecord({leader: '',
2117
- fields: [{
2118
- tag: '760',
2119
- ind1: ' ',
2120
- ind2: ' ',
2121
- subfields: [
2122
- {code: 'a', value: 'Mellor, Alec.'},
2123
- {code: 't', value: 'Strange masonic stories'},
2124
- {code: 'e', value: 'eng'}
2125
- ]
2126
- }]
2127
- });
2128
-
2129
- const recordValidOnlyA = new MarcRecord({leader: '',
2130
- fields: [{
2131
- tag: '760',
2132
- ind1: ' ',
2133
- ind2: ' ',
2134
- subfields: [
2135
- {code: 'a', value: 'Mellor, Alec.'}
2136
- ]
2137
- }]
2138
- });
2139
-
2140
- it('Finds record valid - Punc $a, but following fields, $e no punc (last)', async () => {
2141
- const validator = await validatorFactory();
2142
- const result = await validator.validate(recordValid);
2143
- expect(result.valid).to.eql(true);
2144
- });
2145
-
2146
- it('Finds record valid - Punc $a (only)', async () => {
2147
- const validator = await validatorFactory();
2148
- const result = await validator.validate(recordValidOnlyA);
2149
- expect(result.valid).to.eql(true);
2150
- });
2151
-
2152
- // Invalid tests
2153
- const recordInvalid = new MarcRecord({leader: '',
2154
- fields: [{
2155
- tag: '760',
2156
- ind1: ' ',
2157
- ind2: ' ',
2158
- subfields: [
2159
- {code: 'a', value: 'Mellor, Alec.'},
2160
- {code: 't', value: 'Strange masonic stories'},
2161
- {code: 'e', value: 'eng.'}
2162
- ]
2163
- }]
2164
- });
2165
-
2166
- const recordInvalidOnlyA = new MarcRecord({leader: '',
2167
- fields: [{
2168
- tag: '760',
2169
- ind1: ' ',
2170
- ind2: ' ',
2171
- subfields: [
2172
- {code: 'a', value: 'Mellor, Alec'}
2173
- ]
2174
- }]
2175
- });
2176
-
2177
- it('Finds record invalid - Punc $e (language field, strict)', async () => {
2178
- const validator = await validatorFactory();
2179
- const result = await validator.validate(recordInvalid);
2180
- expect(result).to.eql({
2181
- message: ['Field 760 has invalid ending punctuation'],
2182
- valid: false
2183
- });
2184
- });
2185
-
2186
- it('Finds record invalid - No punc $a (only)', async () => {
2187
- const validator = await validatorFactory();
2188
- const result = await validator.validate(recordInvalidOnlyA);
2189
- expect(result).to.eql({
2190
- message: ['Field 760 has invalid ending punctuation'],
2191
- valid: false
2192
- });
2193
- });
2194
-
2195
- // Fix tests; invalid->valid
2196
- it('Repairs the invalid record - Remove punc $e (language field, strict)', async () => {
2197
- const validator = await validatorFactory();
2198
- const result = await validator.fix(recordInvalid);
2199
- expect(recordInvalid.equalsTo(recordValid)).to.eql(true);
2200
- expect(result).to.eql({
2201
- message: ['Field 760 has invalid ending punctuation'],
2202
- fix: ['Field 760 - Removed punctuation from $e'],
2203
- valid: false
2204
- });
2205
- });
2206
-
2207
- it('Repairs the invalid record - Add punc $a (only)', async () => {
2208
- const validator = await validatorFactory();
2209
- const result = await validator.fix(recordInvalidOnlyA);
2210
- expect(recordInvalidOnlyA.equalsTo(recordValidOnlyA)).to.eql(true);
2211
- expect(result).to.eql({
2212
- message: ['Field 760 has invalid ending punctuation'],
2213
- fix: ['Field 760 - Added punctuation to $a'],
2214
- valid: false
2215
- });
2216
- });
2217
- });
2218
-
2219
- // "`880`-kenttä: https://www.kansalliskirjasto.fi/extra/marc21/bib/841-88X.htm#880 Eli tää on se Loppupisteohjeen `Samoin kuin vastaavat kentät` -keissi
2220
- // Spex on siinä, mutta lyhkäsesti: `880`-kentässä on muiden kenttien translitteroidut versiot (Data eri kirjaimistolla). 880-kentän osakentästä `6` selviää mihin kenttää se linkkaa."
2221
- // 880 Samoin kuin vastaavat kentät - Siis tarkistetaan kontrollikentän $6 säännön
2222
- describe('#880 - Like linked fields', () => {
2223
- // Valid tests
2224
- const recordValidSimple = new MarcRecord({leader: '',
2225
- fields: [{
2226
- tag: '880',
2227
- ind1: ' ',
2228
- ind2: ' ',
2229
- subfields: [
2230
- {code: 'a', value: '平田 篤胤'},
2231
- {code: 'b', value: '1776-1843.'},
2232
- {code: '6', value: '100-01/$1'} // Tag 100 has value TRUE -> last data subfield should have punc
2233
- ]
2234
- }]
2235
- });
2236
-
2237
- const recordValidComplex = new MarcRecord({leader: '',
2238
- fields: [{
2239
- tag: '880',
2240
- ind1: ' ',
2241
- ind2: ' ',
2242
- subfields: [
2243
- {code: 'b', value: 'ידיעות אחרונות'},
2244
- {code: 'b', value: 'ספרי חמד'},
2245
- {code: 'c', value: '2006.'},
2246
- {code: '6', value: '260-02/(2/r ‡a תל-אביב'} // Tag 260 has value TRUE -> last data subfield should have punc
2247
- ]
2248
- }]
2249
- });
2250
-
2251
- it('Finds record valid - Punc $b', async () => {
2252
- const validator = await validatorFactory();
2253
- const result = await validator.validate(recordValidSimple);
2254
- expect(result.valid).to.eql(true);
2255
- });
2256
-
2257
- it('Finds record valid - Punc $c', async () => {
2258
- const validator = await validatorFactory();
2259
- const result = await validator.validate(recordValidComplex);
2260
- expect(result.valid).to.eql(true);
2261
- });
2262
-
2263
- // Invalid tests
2264
- const recordInvalidSimple = new MarcRecord({leader: '',
2265
- fields: [{
2266
- tag: '880',
2267
- ind1: ' ',
2268
- ind2: ' ',
2269
- subfields: [
2270
- {code: 'a', value: '平田 篤胤'},
2271
- {code: 'b', value: '1776-1843'},
2272
- {code: '6', value: '100-01/$1'} // Tag 100 has value TRUE -> last data subfield should have punc
2273
- ]
2274
- }]
2275
- });
2276
-
2277
- const recordInvalidComplex = new MarcRecord({leader: '',
2278
- fields: [{
2279
- tag: '880',
2280
- ind1: ' ',
2281
- ind2: ' ',
2282
- subfields: [
2283
- {code: 'b', value: 'ידיעות אחרונות'},
2284
- {code: 'b', value: 'ספרי חמד'},
2285
- {code: 'c', value: '2006'},
2286
- {code: '6', value: '260-02/(2/r ‡a תל-אביב'} // Tag 260 has value TRUE -> last data subfield should have punc
2287
- ]
2288
- }]
2289
- });
2290
-
2291
- it('Finds record invalid - No punc $b', async () => {
2292
- const validator = await validatorFactory();
2293
- const result = await validator.validate(recordInvalidSimple);
2294
- expect(result).to.eql({
2295
- message: ['Field 880 has invalid ending punctuation'],
2296
- valid: false
2297
- });
2298
- });
2299
-
2300
- it('Finds record invalid - No punc $c', async () => {
2301
- const validator = await validatorFactory();
2302
- const result = await validator.validate(recordInvalidComplex);
2303
- expect(result).to.eql({
2304
- message: ['Field 880 has invalid ending punctuation'],
2305
- valid: false
2306
- });
2307
- });
2308
-
2309
- // Fix tests; invalid->valid
2310
- it('Repairs the invalid record - Add punc $b', async () => {
2311
- const validator = await validatorFactory();
2312
- const result = await validator.fix(recordInvalidSimple);
2313
- expect(recordInvalidSimple.equalsTo(recordValidSimple)).to.eql(true);
2314
- expect(result).to.eql({
2315
- message: ['Field 880 has invalid ending punctuation'],
2316
- fix: ['Field 880 - Added punctuation to $b'],
2317
- valid: false
2318
- });
2319
- });
2320
-
2321
- it('Repairs the invalid record - Add punc $c', async () => {
2322
- const validator = await validatorFactory();
2323
- const result = await validator.fix(recordInvalidComplex);
2324
- expect(recordInvalidComplex.equalsTo(recordValidComplex)).to.eql(true);
2325
- expect(result).to.eql({
2326
- message: ['Field 880 has invalid ending punctuation'],
2327
- fix: ['Field 880 - Added punctuation to $c'],
2328
- valid: false
2329
- });
2330
- });
2331
- });
2332
- });
11
+ // Indicators and subfields validation
12
+ describe('#validate: Indicators and subfields', () => {
13
+ const recordValid = new MarcRecord({
14
+ leader: '',
15
+ fields: [
16
+ {
17
+ tag: '245',
18
+ ind1: ' ',
19
+ ind2: ' ',
20
+ subfields: [
21
+ {code: 'a', value: 'Elämäni ja tutkimusretkeni / '},
22
+ {code: 'c', value: 'Roald Amundsen ; suomentanut Sulo Veikko Pekkola.'},
23
+ {code: '6', value: 'FOO'}
24
+ ]
25
+ }, {
26
+ tag: '337', // Range 336-338
27
+ ind1: ' ',
28
+ ind2: ' ',
29
+ subfields: [
30
+ {code: 'a', value: 'käytettävissä ilman laitetta'},
31
+ {code: 'b', value: 'n'},
32
+ {code: '2', value: 'rdamedia'}
33
+ ]
34
+ }, {
35
+ tag: '500', // Range 500-509
36
+ ind1: ' ',
37
+ ind2: ' ',
38
+ subfields: [{code: 'a', value: 'FOO (Bar)'}]
39
+ }
40
+ ]
41
+ });
42
+
43
+ const recordInvalid = new MarcRecord({
44
+ leader: '',
45
+ fields: [
46
+ {
47
+ tag: '245',
48
+ ind1: ' ',
49
+ ind2: ' ',
50
+ subfields: [
51
+ {code: 'a', value: 'Elämäni ja tutkimusretkeni / '},
52
+ {code: 'c', value: 'Roald Amundsen ; suomentanut Sulo Veikko Pekkola'},
53
+ {code: '6', value: 'FOO'}
54
+ ]
55
+ }, {
56
+ tag: '337',
57
+ ind1: ' ',
58
+ ind2: ' ',
59
+ subfields: [
60
+ {code: 'a', value: 'käytettävissä ilman laitetta'},
61
+ {code: 'b', value: 'n.'}, // This can be abbreviation -> does not generate error
62
+ {code: '2', value: 'rdamedia'}
63
+ ]
64
+ }, {
65
+ tag: '500',
66
+ ind1: ' ',
67
+ ind2: ' ',
68
+ subfields: [{code: 'a', value: 'FOO (Bar).'}]
69
+ }
70
+ ]
71
+ });
72
+ const recordBroken = new MarcRecord({
73
+ leader: '',
74
+ fields: [
75
+ {
76
+ tag: '245',
77
+ ind1: ' ',
78
+ ind2: ' ',
79
+ subfields: [
80
+ {code: 'a', value: 'Elämäni ja tutkimusretkeni / '},
81
+ {code: 'c', value: 'Roald Amundsen ; suomentanut Sulo Veikko Pekkola'},
82
+ {code: '6', value: 'FOO'}
83
+ ]
84
+ }, {
85
+ tag: '337',
86
+ ind1: ' ',
87
+ ind2: ' ',
88
+ subfields: [
89
+ {code: 'a', value: 'käytettävissä ilman laitetta'},
90
+ {code: 'b', value: 'n'}, // Dot removed from possible abbreviation as it cannot be removed in fixing
91
+ {code: '2', value: 'rdamedia'}
92
+ ]
93
+ }, {
94
+ tag: '500',
95
+ ind1: ' ',
96
+ ind2: ' ',
97
+ subfields: [{code: 'a', value: 'FOO (Bar).'}]
98
+ }
99
+ ]
100
+ });
101
+
102
+ it('Finds the record valid', async () => {
103
+ const validator = await validatorFactory();
104
+ const result = await validator.validate(recordValid);
105
+ expect(result.valid).to.eql(true);
106
+ });
107
+
108
+ it('Finds the record invalid', async () => {
109
+ const validator = await validatorFactory();
110
+ const result = await validator.validate(recordInvalid);
111
+ expect(result).to.eql({
112
+ message: ['Field 245 has invalid ending punctuation', 'Field 500 has invalid ending punctuation'],
113
+ valid: false
114
+ });
115
+ });
116
+
117
+ it('Repairs the invalid record', async () => {
118
+ const validator = await validatorFactory();
119
+ const result = await validator.fix(recordBroken);
120
+ expect(recordBroken.equalsTo(recordValid)).to.eql(true);
121
+ expect(result).to.eql({
122
+ message: ['Field 245 has invalid ending punctuation', 'Field 500 has invalid ending punctuation'],
123
+ fix: ['Field 245 - Added punctuation to $c', 'Field 500 - Removed double punctuation from $a'],
124
+ valid: false
125
+ });
126
+ });
127
+ });
128
+
129
+ describe('#specials', () => {
130
+ // "036 KYLLÄ vain osakentän $b jälkeen"
131
+ // Can have subfields a and b, dot only after b
132
+ describe('#036 TRUE - only after subfield $b', () => {
133
+ // Valid tests
134
+ const recordValid = new MarcRecord({
135
+ leader: '',
136
+ fields: [
137
+ {
138
+ tag: '036',
139
+ ind1: ' ',
140
+ ind2: ' ',
141
+ subfields: [
142
+ {code: 'a', value: 'CNRS 84115'},
143
+ {code: 'b', value: 'Centre national de la recherche scientifique.'}
144
+ ]
145
+ }
146
+ ]
147
+ });
148
+
149
+ const recordValidOnlyA = new MarcRecord({
150
+ leader: '',
151
+ fields: [
152
+ {
153
+ tag: '036',
154
+ ind1: ' ',
155
+ ind2: ' ',
156
+ subfields: [{code: 'a', value: 'CNRS 84115'}]
157
+ }
158
+ ]
159
+ });
160
+
161
+ it('Finds record valid - Punc $b', async () => {
162
+ const validator = await validatorFactory();
163
+ const result = await validator.validate(recordValid);
164
+ expect(result.valid).to.eql(true);
165
+ });
166
+
167
+ it('Finds record valid - Only $a without punc', async () => {
168
+ const validator = await validatorFactory();
169
+ const result = await validator.validate(recordValidOnlyA);
170
+ expect(result.valid).to.eql(true);
171
+ });
172
+
173
+ // Invalid tests
174
+ const recordInvalid = new MarcRecord({
175
+ leader: '',
176
+ fields: [
177
+ {
178
+ tag: '036',
179
+ ind1: ' ',
180
+ ind2: ' ',
181
+ subfields: [
182
+ {code: 'a', value: 'CNRS 84115'},
183
+ {code: 'b', value: 'Centre national de la recherche scientifique'}
184
+ ]
185
+ }
186
+ ]
187
+ });
188
+
189
+ const recordInvalidOnlyA = new MarcRecord({
190
+ leader: '',
191
+ fields: [
192
+ {
193
+ tag: '036',
194
+ ind1: ' ',
195
+ ind2: ' ',
196
+ subfields: [{code: 'a', value: 'CNRS 84115.'}] // $a is register number, no change for abbreviation
197
+ }
198
+ ]
199
+ });
200
+
201
+ it('Finds record invalid - No punc $b', async () => {
202
+ const validator = await validatorFactory();
203
+ const result = await validator.validate(recordInvalid);
204
+ expect(result).to.eql({
205
+ message: ['Field 036 has invalid ending punctuation'],
206
+ valid: false
207
+ });
208
+ });
209
+
210
+ it('Finds record invalid - Only $a with punc', async () => {
211
+ const validator = await validatorFactory();
212
+ const result = await validator.validate(recordInvalidOnlyA);
213
+ expect(result).to.eql({
214
+ message: ['Field 036 has invalid ending punctuation'],
215
+ valid: false
216
+ });
217
+ });
218
+
219
+ // Fix tests; invalid->valid
220
+ it('Repairs the invalid record - Add punc $b', async () => {
221
+ const validator = await validatorFactory();
222
+ const result = await validator.fix(recordInvalid);
223
+ expect(recordInvalid.equalsTo(recordValid)).to.eql(true);
224
+ expect(result).to.eql({
225
+ message: ['Field 036 has invalid ending punctuation'],
226
+ fix: ['Field 036 - Added punctuation to $b'],
227
+ valid: false
228
+ });
229
+ });
230
+
231
+ it('Repairs the invalid record - Removes punc $a (register)', async () => {
232
+ const validator = await validatorFactory();
233
+ const result = await validator.fix(recordInvalidOnlyA);
234
+ expect(recordInvalidOnlyA.equalsTo(recordValidOnlyA)).to.eql(true);
235
+ expect(result).to.eql({
236
+ message: ['Field 036 has invalid ending punctuation'],
237
+ fix: ['Field 036 - Removed punctuation from $a'],
238
+ valid: false
239
+ });
240
+ });
241
+ });
242
+
243
+ // "242 KYLLÄ Jos viimeinen osakenttä on $y, piste on ennen sitä" - Eli siis ei kentässä y (ennen sitä)
244
+ describe('#242 TRUE - if last subfield $y, punc before it', () => {
245
+ // Valid tests
246
+ const recordValidOnlyA = new MarcRecord({
247
+ leader: '',
248
+ fields: [
249
+ {
250
+ tag: '242',
251
+ ind1: ' ',
252
+ ind2: ' ',
253
+ subfields: [
254
+ {code: 'a', value: 'World of art.'},
255
+ {code: 'y', value: 'eng'}
256
+ ]
257
+ }
258
+ ]
259
+ });
260
+
261
+ const recordValidMultiple = new MarcRecord({
262
+ leader: '',
263
+ fields: [
264
+ {
265
+ tag: '242',
266
+ ind1: ' ',
267
+ ind2: ' ',
268
+ subfields: [
269
+ {code: 'a', value: 'Annals of chemistry.'},
270
+ {code: 'n', value: 'Series C,'},
271
+ {code: 'p', value: 'Organic chemistry and biochemistry.'},
272
+ {code: 'y', value: 'eng'}
273
+ ]
274
+ }
275
+ ]
276
+ });
277
+
278
+ // "Suositellaan käytettäväksi myös osakenttää ‡y (käännöksen kielikoodi)." https://www.kiwi.fi/pages/viewpage.action?pageId=51282044
279
+ const recordValidWithoutY = new MarcRecord({
280
+ leader: '',
281
+ fields: [
282
+ {
283
+ tag: '242',
284
+ ind1: ' ',
285
+ ind2: ' ',
286
+ subfields: [{code: 'a', value: 'World of art.'}]
287
+ }
288
+ ]
289
+ });
290
+
291
+ it('Finds record valid - Punc $a', async () => {
292
+ const validator = await validatorFactory();
293
+ const result = await validator.validate(recordValidOnlyA);
294
+ expect(result.valid).to.eql(true);
295
+ });
296
+
297
+ it('Finds record valid - Punc $p', async () => {
298
+ const validator = await validatorFactory();
299
+ const result = await validator.validate(recordValidMultiple);
300
+ expect(result.valid).to.eql(true);
301
+ });
302
+
303
+ it('Finds record valid - Punc $a without $y', async () => {
304
+ const validator = await validatorFactory();
305
+ const result = await validator.validate(recordValidWithoutY);
306
+ expect(result.valid).to.eql(true);
307
+ });
308
+
309
+ // Invalid tests
310
+ const recordInvalidOnlyAMissingA = new MarcRecord({
311
+ leader: '',
312
+ fields: [
313
+ {
314
+ tag: '242',
315
+ ind1: ' ',
316
+ ind2: ' ',
317
+ subfields: [
318
+ {code: 'a', value: 'World of art'},
319
+ {code: 'y', value: 'eng'}
320
+ ]
321
+ }
322
+ ]
323
+ });
324
+
325
+ const recordInvalidOnlyAPuncY = new MarcRecord({
326
+ leader: '',
327
+ fields: [
328
+ {
329
+ tag: '242',
330
+ ind1: ' ',
331
+ ind2: ' ',
332
+ subfields: [
333
+ {code: 'a', value: 'World of art.'},
334
+ {code: 'y', value: 'eng.'} // $y is also checked as rule is explicit
335
+ ]
336
+ }
337
+ ]
338
+ });
339
+
340
+ const recordInvalidOnlyAMissingAPuncY = new MarcRecord({
341
+ leader: '',
342
+ fields: [
343
+ {
344
+ tag: '242',
345
+ ind1: ' ',
346
+ ind2: ' ',
347
+ subfields: [
348
+ {code: 'a', value: 'World of art'},
349
+ {code: 'y', value: 'eng.'} // $y is also checked as rule is explicit
350
+ ]
351
+ }
352
+ ]
353
+ });
354
+
355
+ const recordValidMultipleMissingP = new MarcRecord({
356
+ leader: '',
357
+ fields: [
358
+ {
359
+ tag: '242',
360
+ ind1: ' ',
361
+ ind2: ' ',
362
+ subfields: [
363
+ {code: 'a', value: 'Annals of chemistry.'},
364
+ {code: 'n', value: 'Series C,'},
365
+ {code: 'p', value: 'Organic chemistry and biochemistry'},
366
+ {code: 'y', value: 'eng'}
367
+ ]
368
+ }
369
+ ]
370
+ });
371
+
372
+ // "Suositellaan käytettäväksi myös osakenttää y (käännöksen kielikoodi)." https://www.kiwi.fi/pages/viewpage.action?pageId=51282044
373
+ const recordValidWithoutYMissingA = new MarcRecord({
374
+ leader: '',
375
+ fields: [
376
+ {
377
+ tag: '242',
378
+ ind1: ' ',
379
+ ind2: ' ',
380
+ subfields: [{code: 'a', value: 'World of art'}]
381
+ }
382
+ ]
383
+ });
384
+
385
+ it('Finds record invalid - No punc at $a (only before $y)', async () => {
386
+ const validator = await validatorFactory();
387
+ const result = await validator.validate(recordInvalidOnlyAMissingA);
388
+ expect(result).to.eql({
389
+ message: ['Field 242 has invalid ending punctuation'],
390
+ valid: false
391
+ });
392
+ });
393
+
394
+ it('Finds record invalid - Punc at $y (Language field)', async () => { // $y is also checked as rule is explicit
395
+ const validator = await validatorFactory();
396
+ const result = await validator.validate(recordInvalidOnlyAPuncY);
397
+ expect(result).to.eql({
398
+ message: ['Field 242 has invalid ending punctuation'],
399
+ valid: false
400
+ });
401
+ });
402
+
403
+ it('Finds record invalid - No punc at $a & punc $y', async () => { // $y is also checked as rule is explicit
404
+ const validator = await validatorFactory();
405
+ const result = await validator.validate(recordInvalidOnlyAMissingAPuncY);
406
+ expect(result).to.eql({
407
+ message: ['Field 242 has invalid ending punctuation', 'Field 242 has invalid ending punctuation'],
408
+ valid: false
409
+ });
410
+ });
411
+
412
+ it('Finds record invalid - No punc $p (last before $y)', async () => {
413
+ const validator = await validatorFactory();
414
+ const result = await validator.validate(recordValidMultipleMissingP);
415
+ expect(result).to.eql({
416
+ message: ['Field 242 has invalid ending punctuation'],
417
+ valid: false
418
+ });
419
+ });
420
+
421
+ it('Finds record invalid - No punc $a (only)', async () => {
422
+ const validator = await validatorFactory();
423
+ const result = await validator.validate(recordValidWithoutYMissingA);
424
+ expect(result).to.eql({
425
+ message: ['Field 242 has invalid ending punctuation'],
426
+ valid: false
427
+ });
428
+ });
429
+
430
+ // Fix tests; invalid->valid
431
+ it('Repairs the invalid record - Add punc $a', async () => {
432
+ const validator = await validatorFactory();
433
+ const result = await validator.fix(recordInvalidOnlyAMissingA);
434
+ expect(recordInvalidOnlyAMissingA.equalsTo(recordValidOnlyA)).to.eql(true);
435
+ expect(result).to.eql({
436
+ message: ['Field 242 has invalid ending punctuation'],
437
+ fix: ['Field 242 - Added punctuation to $a'],
438
+ valid: false
439
+ });
440
+ });
441
+
442
+ it('Repairs the invalid record - Remove punc $y (Language field)', async () => {
443
+ const validator = await validatorFactory();
444
+ const result = await validator.fix(recordInvalidOnlyAPuncY);
445
+ expect(recordInvalidOnlyAPuncY.equalsTo(recordValidOnlyA)).to.eql(true);
446
+ expect(result).to.eql({
447
+ message: ['Field 242 has invalid ending punctuation'],
448
+ fix: ['Field 242 - Removed punctuation from $y'],
449
+ valid: false
450
+ });
451
+ });
452
+
453
+ it('Repairs the invalid record - Add punc $a & remove punc $y (Language field)', async () => {
454
+ const validator = await validatorFactory();
455
+ const result = await validator.fix(recordInvalidOnlyAMissingAPuncY);
456
+ expect(recordInvalidOnlyAMissingAPuncY.equalsTo(recordValidOnlyA)).to.eql(true);
457
+ expect(result).to.eql({
458
+ message: ['Field 242 has invalid ending punctuation', 'Field 242 has invalid ending punctuation'],
459
+ fix: ['Field 242 - Removed punctuation from $y', 'Field 242 - Added punctuation to $a'],
460
+ valid: false
461
+ });
462
+ });
463
+
464
+ it('Repairs the invalid record - Add punc $p', async () => {
465
+ const validator = await validatorFactory();
466
+ const result = await validator.fix(recordValidMultipleMissingP);
467
+ expect(recordValidMultipleMissingP.equalsTo(recordValidMultiple)).to.eql(true);
468
+ expect(result).to.eql({
469
+ message: ['Field 242 has invalid ending punctuation'],
470
+ fix: ['Field 242 - Added punctuation to $p'],
471
+ valid: false
472
+ });
473
+ });
474
+
475
+ it('Repairs the invalid record - Add punc $a', async () => {
476
+ const validator = await validatorFactory();
477
+ const result = await validator.fix(recordValidWithoutYMissingA);
478
+ expect(recordValidWithoutYMissingA.equalsTo(recordValidWithoutY)).to.eql(true);
479
+ expect(result).to.eql({
480
+ message: ['Field 242 has invalid ending punctuation'],
481
+ fix: ['Field 242 - Added punctuation to $a'],
482
+ valid: false
483
+ });
484
+ });
485
+ });
486
+
487
+ // "260 KYLLÄ Pääsääntö: $a : $b, $c. Tarkista eri poikkeukset ja välimerkitys MARC 21 Full -versiosta"
488
+ // Punc only if last subfield c
489
+ describe('#260 TRUE - Punc only if last subfield c', () => {
490
+ // Valid tests
491
+ const recordValidEndC = new MarcRecord({
492
+ leader: '',
493
+ fields: [
494
+ {
495
+ tag: '260',
496
+ ind1: ' ',
497
+ ind2: ' ',
498
+ subfields: [
499
+ {code: 'a', value: 'Helsinki'},
500
+ {code: 'b', value: 'Suomen atk-kustannus,'},
501
+ {code: 'c', value: '1982.'}
502
+ ]
503
+ }
504
+ ]
505
+ });
506
+
507
+ const recordValidEndG = new MarcRecord({
508
+ leader: '',
509
+ fields: [
510
+ {
511
+ tag: '260',
512
+ ind1: ' ',
513
+ ind2: ' ',
514
+ subfields: [
515
+ {code: 'a', value: 'London'},
516
+ {code: 'b', value: 'Macmillan,'},
517
+ {code: 'c', value: '1971'},
518
+ {code: 'g', value: '(1973 printing)'}
519
+ ]
520
+ }
521
+ ]
522
+ });
523
+
524
+ const recordValidEndB = new MarcRecord({
525
+ leader: '',
526
+ fields: [
527
+ {
528
+ tag: '260',
529
+ ind1: ' ',
530
+ ind2: ' ',
531
+ subfields: [
532
+ {code: '3', value: 'June 1993-'},
533
+ {code: 'a', value: 'London'},
534
+ {code: 'b', value: 'Elle'}
535
+ ]
536
+ }
537
+ ]
538
+ });
539
+
540
+ it('Finds record valid - Punc $c', async () => {
541
+ const validator = await validatorFactory();
542
+ const result = await validator.validate(recordValidEndC);
543
+ expect(result.valid).to.eql(true);
544
+ });
545
+
546
+ it('Finds record valid - Punc char $g (after $c)', async () => {
547
+ const validator = await validatorFactory();
548
+ const result = await validator.validate(recordValidEndG);
549
+ expect(result.valid).to.eql(true);
550
+ });
551
+
552
+ it('Finds record valid - No punc $b', async () => {
553
+ const validator = await validatorFactory();
554
+ const result = await validator.validate(recordValidEndB);
555
+ expect(result.valid).to.eql(true);
556
+ });
557
+
558
+ // Invalid tests
559
+ const recordInvalidEndC = new MarcRecord({
560
+ leader: '',
561
+ fields: [
562
+ {
563
+ tag: '260',
564
+ ind1: ' ',
565
+ ind2: ' ',
566
+ subfields: [
567
+ {code: 'a', value: 'Helsinki'},
568
+ {code: 'b', value: 'Suomen atk-kustannus,'},
569
+ {code: 'c', value: '1982'}
570
+ ]
571
+ }
572
+ ]
573
+ });
574
+
575
+ const recordInvalidEndGDouble = new MarcRecord({
576
+ leader: '',
577
+ fields: [
578
+ {
579
+ tag: '260',
580
+ ind1: ' ',
581
+ ind2: ' ',
582
+ subfields: [
583
+ {code: 'a', value: 'London'},
584
+ {code: 'b', value: 'Macmillan,'},
585
+ {code: 'c', value: '1971'},
586
+ {code: 'g', value: '(1973 printing).'}
587
+ ]
588
+ }
589
+ ]
590
+ });
591
+
592
+ it('Finds record invalid', async () => {
593
+ const validator = await validatorFactory();
594
+ const result = await validator.validate(recordInvalidEndC);
595
+ expect(result).to.eql({
596
+ message: ['Field 260 has invalid ending punctuation'],
597
+ valid: false
598
+ });
599
+ });
600
+
601
+ it('Finds record invalid', async () => {
602
+ const validator = await validatorFactory();
603
+ const result = await validator.validate(recordInvalidEndGDouble);
604
+ expect(result).to.eql({
605
+ message: ['Field 260 has invalid ending punctuation'],
606
+ valid: false
607
+ });
608
+ });
609
+
610
+ // Fix tests; invalid->valid
611
+ it('Repairs the invalid record - Add punc $c', async () => {
612
+ const validator = await validatorFactory();
613
+ const result = await validator.fix(recordInvalidEndC);
614
+ expect(recordInvalidEndC.equalsTo(recordValidEndC)).to.eql(true);
615
+ expect(result).to.eql({
616
+ message: ['Field 260 has invalid ending punctuation'],
617
+ fix: ['Field 260 - Added punctuation to $c'],
618
+ valid: false
619
+ });
620
+ });
621
+
622
+ it('Repairs the invalid record - Remove double punc $g', async () => {
623
+ const validator = await validatorFactory();
624
+ const result = await validator.fix(recordInvalidEndGDouble);
625
+ expect(recordInvalidEndGDouble.equalsTo(recordValidEndG)).to.eql(true);
626
+ expect(result).to.eql({
627
+ message: ['Field 260 has invalid ending punctuation'],
628
+ fix: ['Field 260 - Removed double punctuation from $g'],
629
+ valid: false
630
+ });
631
+ });
632
+ });
633
+
634
+ // 264-kenttään tulee loppupiste, JOS on käytetty osakenttää ‡c tuotantoajan, julkaisuajan,
635
+ // jakeluajan tai valmistusajan ilmaisemiseen (2. indikaattori = 0, 1, 2 tai 3) JA osakenttä ‡c
636
+ // ei pääty hakasulkuun ']' tai tavuviivaan '-' tai kaarisulkuun ')' tai kysymysmerkkiin '?'
637
+
638
+ // Copyright-vuoden kanssa ei käytetä loppupistettä (2. indikaattori = 4).
639
+
640
+ // Esimerkit
641
+ // 264 #0 ‡a [Vantaa?] : ‡b [Olli Kela], ‡c [2011?]
642
+ // 264 #1 ‡a Helsinki : ‡b Helsingin yliopisto, ‡c 1992-
643
+ // 264 #1 ‡a Helsinki : ‡b Helsingin yliopisto, ‡c 1995-2006. ← loppupiste
644
+ // 264 #2 ‡a Kouvola : ‡b Nuorisovirasto
645
+ // 264 #3 ‡a Lahti : ‡b Valtion monistuskeskus, ‡c 1965. ← loppupiste
646
+ describe('#264 TRUE - If ind2 === 0, 1, 2 or 3, punc at the end', () => {
647
+ // Valid tests
648
+ const recordValidInd2v1 = new MarcRecord({
649
+ leader: '',
650
+ fields: [
651
+ {
652
+ tag: '264',
653
+ ind1: '#',
654
+ ind2: '1',
655
+ subfields: [
656
+ {code: 'a', value: 'Helsinki'},
657
+ {code: 'b', value: 'Helsingin yliopisto'},
658
+ {code: 'c', value: '1995-2006.'}
659
+ ]
660
+ }
661
+ ]
662
+ });
663
+
664
+ const recordValidInd2v1Short = new MarcRecord({
665
+ leader: '',
666
+ fields: [
667
+ {
668
+ tag: '264',
669
+ ind1: '#',
670
+ ind2: '1',
671
+ subfields: [
672
+ {code: 'a', value: 'Helsinki'},
673
+ {code: 'b', value: 'Helsingin yliopisto'},
674
+ {code: 'c', value: '1995-'}
675
+ ]
676
+ }
677
+ ]
678
+ });
679
+
680
+ const recordValidInd2v2WithoutC = new MarcRecord({
681
+ leader: '',
682
+ fields: [
683
+ {
684
+ tag: '264',
685
+ ind1: '#',
686
+ ind2: '2',
687
+ subfields: [
688
+ {code: 'a', value: 'Kouvola'},
689
+ {code: 'b', value: 'Nuorisovirasto'}
690
+ ]
691
+ }
692
+ ]
693
+ });
694
+
695
+ const recordValidCopyright = new MarcRecord({
696
+ leader: '',
697
+ fields: [
698
+ {
699
+ tag: '264',
700
+ ind1: ' ',
701
+ ind2: '4',
702
+ subfields: [
703
+ {code: 'a', value: 'Helsinki : '},
704
+ {code: 'b', value: 'Suomen poliisikoirayhdistys.'},
705
+ {code: 'c', value: '© 1974'}
706
+ ]
707
+ }
708
+ ]
709
+ });
710
+
711
+ it('Finds record valid - Ind2 = 1, $c 1995-2006.', async () => {
712
+ const validator = await validatorFactory();
713
+ const result = await validator.validate(recordValidInd2v1);
714
+ expect(result.valid).to.eql(true);
715
+ });
716
+
717
+ it('Finds record valid - Ind2 = 1, $c 1995-', async () => {
718
+ const validator = await validatorFactory();
719
+ const result = await validator.validate(recordValidInd2v1Short);
720
+ expect(result.valid).to.eql(true);
721
+ });
722
+
723
+ it('Finds record valid - Ind2 = 2, no $c', async () => {
724
+ const validator = await validatorFactory();
725
+ const result = await validator.validate(recordValidInd2v2WithoutC);
726
+ expect(result.valid).to.eql(true);
727
+ });
728
+
729
+ it('Finds record valid - Ind2 = 4, copyright', async () => {
730
+ const validator = await validatorFactory();
731
+ const result = await validator.validate(recordValidCopyright);
732
+ expect(result.valid).to.eql(true);
733
+ });
734
+
735
+ const recordInvalidInd2v1 = new MarcRecord({
736
+ leader: '',
737
+ fields: [
738
+ {
739
+ tag: '264',
740
+ ind1: '#',
741
+ ind2: '1',
742
+ subfields: [
743
+ {code: 'a', value: 'Helsinki'},
744
+ {code: 'b', value: 'Helsingin yliopisto'},
745
+ {code: 'c', value: '1995-2006'}
746
+ ]
747
+ }
748
+ ]
749
+ });
750
+
751
+ const recordInvalidCopyrightCExtra = new MarcRecord({
752
+ leader: '',
753
+ fields: [
754
+ {
755
+ tag: '264',
756
+ ind1: ' ',
757
+ ind2: '4',
758
+ subfields: [
759
+ {code: 'a', value: 'Helsinki : '},
760
+ {code: 'b', value: 'Suomen poliisikoirayhdistys.'},
761
+ {code: 'c', value: '© 1974.'}
762
+ ]
763
+ }
764
+ ]
765
+ });
766
+
767
+ it('Finds record invalid - No punc $c', async () => {
768
+ const validator = await validatorFactory();
769
+ const result = await validator.validate(recordInvalidInd2v1);
770
+ expect(result).to.eql({
771
+ message: ['Field 264 has invalid ending punctuation'],
772
+ valid: false
773
+ });
774
+ });
775
+
776
+ it('Finds record invalid - Ind2 = 4, copyright, extra punc $c', async () => {
777
+ const validator = await validatorFactory();
778
+ const result = await validator.validate(recordInvalidCopyrightCExtra);
779
+ expect(result).to.eql({
780
+ message: ['Field 264 has invalid ending punctuation'],
781
+ valid: false
782
+ });
783
+ });
784
+
785
+ // Fix tests; invalid->valid
786
+ it('Repairs the invalid record - Add punc $c', async () => {
787
+ const validator = await validatorFactory();
788
+ const result = await validator.fix(recordInvalidInd2v1);
789
+ expect(recordInvalidInd2v1.equalsTo(recordValidInd2v1)).to.eql(true);
790
+ expect(result).to.eql({
791
+ message: ['Field 264 has invalid ending punctuation'],
792
+ fix: ['Field 264 - Added punctuation to $c'],
793
+ valid: false
794
+ });
795
+ });
796
+
797
+ it('Repairs the invalid record - Remove punc $c ($c has ©, should not have punc)', async () => {
798
+ const validator = await validatorFactory();
799
+ const result = await validator.fix(recordInvalidCopyrightCExtra);
800
+ expect(recordInvalidCopyrightCExtra.equalsTo(recordValidCopyright)).to.eql(true);
801
+ expect(result).to.eql({
802
+ message: ['Field 264 has invalid ending punctuation'],
803
+ fix: ['Field 264 - Removed punctuation from $c'],
804
+ valid: false
805
+ });
806
+ });
807
+ });
808
+
809
+ // "340 KYLLÄ Vain joidenkin osakenttien jälkeen. Tarkista osakentät MARC 21 Full -versiosta
810
+ // -b: Piste aina osakentän loppuun
811
+ // - a, d, e, f, h, i: Piste näistä viimeisen osakentän loppuun"
812
+ // This doesn't match spec at all, but these rules were provided (https://www.kansalliskirjasto.fi/extra/marc21/bib/3XX.htm#340)
813
+ describe('#340 TRUE - Punc at $b always and to last of [$a, $d, $e, $f, $h, $i]', () => {
814
+ // Valid tests
815
+ const recordValidA = new MarcRecord({
816
+ leader: '',
817
+ fields: [
818
+ {
819
+ tag: '340',
820
+ ind1: ' ',
821
+ ind2: ' ',
822
+ subfields: [{code: 'a', value: 'marble.'}]
823
+ }
824
+ ]
825
+ });
826
+
827
+ const recordValidAB = new MarcRecord({
828
+ leader: '',
829
+ fields: [
830
+ {
831
+ tag: '340',
832
+ ind1: ' ',
833
+ ind2: ' ',
834
+ subfields: [
835
+ {code: 'a', value: 'parchment.'}, // This punc doesn't match example: https://www.kansalliskirjasto.fi/extra/marc21/bib/3XX.htm#340
836
+ {code: 'b', value: '20 cm. folded to 10 x 12 cm.'}
837
+ ]
838
+ }
839
+ ]
840
+ });
841
+
842
+ const recordValidDD = new MarcRecord({
843
+ leader: '',
844
+ fields: [
845
+ {
846
+ tag: '340',
847
+ ind1: ' ',
848
+ ind2: ' ',
849
+ subfields: [
850
+ {code: 'd', value: 'handwritten'},
851
+ {code: 'd', value: 'typed.'}
852
+ ]
853
+ }
854
+ ]
855
+ });
856
+
857
+ const recordValidComplex = new MarcRecord({
858
+ leader: '',
859
+ fields: [
860
+ {
861
+ tag: '340',
862
+ ind1: ' ',
863
+ ind2: ' ',
864
+ subfields: [
865
+ {code: 'a', value: 'wove paper'},
866
+ {code: 'c', value: 'ink'},
867
+ {code: 'c', value: 'gouache'},
868
+ {code: 'd', value: 'lithography'},
869
+ {code: 'd', value: 'collage.'}, // This punc doesn't match example: https://www.kansalliskirjasto.fi/extra/marc21/bib/3XX.htm#340
870
+ {code: 'g', value: 'polychrome'}
871
+ ]
872
+ }
873
+ ]
874
+ });
875
+
876
+ const recordValidJ2 = new MarcRecord({
877
+ leader: '',
878
+ fields: [
879
+ {
880
+ tag: '340',
881
+ ind1: ' ',
882
+ ind2: ' ',
883
+ subfields: [
884
+ {code: 'j', value: 'original'},
885
+ {code: '2', value: 'rda'}
886
+ ]
887
+ }
888
+ ]
889
+ });
890
+
891
+ it('Finds record valid - Punc $a (only)', async () => {
892
+ const validator = await validatorFactory();
893
+ const result = await validator.validate(recordValidA);
894
+ expect(result.valid).to.eql(true);
895
+ });
896
+
897
+ it('Finds record valid - Punc $a (last) & punc $b (mandatory)', async () => {
898
+ const validator = await validatorFactory();
899
+ const result = await validator.validate(recordValidAB);
900
+ expect(result.valid).to.eql(true);
901
+ });
902
+
903
+ it('Finds record valid - Punc $d (last of two)', async () => {
904
+ const validator = await validatorFactory();
905
+ const result = await validator.validate(recordValidDD);
906
+ expect(result.valid).to.eql(true);
907
+ });
908
+
909
+ it('Finds record valid - Punc $d (last of two) followed by $g', async () => {
910
+ const validator = await validatorFactory();
911
+ const result = await validator.validate(recordValidComplex);
912
+ expect(result.valid).to.eql(true);
913
+ });
914
+
915
+ it('Finds record valid - No punc (not $b, nor from list)', async () => {
916
+ const validator = await validatorFactory();
917
+ const result = await validator.validate(recordValidJ2);
918
+ expect(result.valid).to.eql(true);
919
+ });
920
+
921
+ // Invalid tests
922
+ const recordInvalidA = new MarcRecord({
923
+ leader: '',
924
+ fields: [
925
+ {
926
+ tag: '340',
927
+ ind1: ' ',
928
+ ind2: ' ',
929
+ subfields: [{code: 'a', value: 'marble'}]
930
+ }
931
+ ]
932
+ });
933
+
934
+ const recordInvalidAMissingB = new MarcRecord({
935
+ leader: '',
936
+ fields: [
937
+ {
938
+ tag: '340',
939
+ ind1: ' ',
940
+ ind2: ' ',
941
+ subfields: [
942
+ {code: 'a', value: 'parchment'}, // This punc doesn't match example: https://www.kansalliskirjasto.fi/extra/marc21/bib/3XX.htm#340
943
+ {code: 'b', value: '20 cm. folded to 10 x 12 cm.'}
944
+ ]
945
+ }
946
+ ]
947
+ });
948
+
949
+ const recordInvalidABMissing = new MarcRecord({
950
+ leader: '',
951
+ fields: [
952
+ {
953
+ tag: '340',
954
+ ind1: ' ',
955
+ ind2: ' ',
956
+ subfields: [
957
+ {code: 'a', value: 'parchment.'}, // This punc doesn't match example: https://www.kansalliskirjasto.fi/extra/marc21/bib/3XX.htm#340
958
+ {code: 'b', value: '20 cm. folded to 10 x 12 cm'}
959
+ ]
960
+ }
961
+ ]
962
+ });
963
+
964
+ const recordInvalidDDMissing = new MarcRecord({
965
+ leader: '',
966
+ fields: [
967
+ {
968
+ tag: '340',
969
+ ind1: ' ',
970
+ ind2: ' ',
971
+ subfields: [
972
+ {code: 'd', value: 'handwritten'},
973
+ {code: 'd', value: 'typed'}
974
+ ]
975
+ }
976
+ ]
977
+ });
978
+
979
+ const recordInvalidComplexDMissing = new MarcRecord({
980
+ leader: '',
981
+ fields: [
982
+ {
983
+ tag: '340',
984
+ ind1: ' ',
985
+ ind2: ' ',
986
+ subfields: [
987
+ {code: 'a', value: 'wove paper'},
988
+ {code: 'c', value: 'ink'},
989
+ {code: 'c', value: 'gouache'},
990
+ {code: 'd', value: 'lithography'},
991
+ {code: 'd', value: 'collage'}, // This punc doesn't match example: https://www.kansalliskirjasto.fi/extra/marc21/bib/3XX.htm#340
992
+ {code: 'g', value: 'polychrome'}
993
+ ]
994
+ }
995
+ ]
996
+ });
997
+
998
+ it('Finds record invalid - No punc $a (only)', async () => {
999
+ const validator = await validatorFactory();
1000
+ const result = await validator.validate(recordInvalidA);
1001
+ expect(result).to.eql({
1002
+ message: ['Field 340 has invalid ending punctuation'],
1003
+ valid: false
1004
+ });
1005
+ });
1006
+
1007
+ it('Finds record invalid - No punc $a (last)', async () => {
1008
+ const validator = await validatorFactory();
1009
+ const result = await validator.validate(recordInvalidAMissingB);
1010
+ expect(result).to.eql({
1011
+ message: ['Field 340 has invalid ending punctuation'],
1012
+ valid: false
1013
+ });
1014
+ });
1015
+
1016
+ it('Finds record invalid - No punc $b (mandatory)', async () => {
1017
+ const validator = await validatorFactory();
1018
+ const result = await validator.validate(recordInvalidABMissing);
1019
+ expect(result).to.eql({
1020
+ message: ['Field 340 has invalid ending punctuation'],
1021
+ valid: false
1022
+ });
1023
+ });
1024
+
1025
+ it('Finds record invalid - No punc $d (last of two)', async () => {
1026
+ const validator = await validatorFactory();
1027
+ const result = await validator.validate(recordInvalidDDMissing);
1028
+ expect(result).to.eql({
1029
+ message: ['Field 340 has invalid ending punctuation'],
1030
+ valid: false
1031
+ });
1032
+ });
1033
+
1034
+ it('Finds record invalid - No punc $d (last of two) followed by $g', async () => {
1035
+ const validator = await validatorFactory();
1036
+ const result = await validator.validate(recordInvalidComplexDMissing);
1037
+ expect(result).to.eql({
1038
+ message: ['Field 340 has invalid ending punctuation'],
1039
+ valid: false
1040
+ });
1041
+ });
1042
+
1043
+ // Fix tests; invalid->valid
1044
+ it('Repairs the invalid record - Add punc $a (only)', async () => {
1045
+ const validator = await validatorFactory();
1046
+ const result = await validator.fix(recordInvalidA);
1047
+ expect(recordInvalidA.equalsTo(recordInvalidA)).to.eql(true);
1048
+ expect(result).to.eql({
1049
+ message: ['Field 340 has invalid ending punctuation'],
1050
+ fix: ['Field 340 - Added punctuation to $a'],
1051
+ valid: false
1052
+ });
1053
+ });
1054
+
1055
+ it('Repairs the invalid record - Add punc $a (last)', async () => {
1056
+ const validator = await validatorFactory();
1057
+ const result = await validator.fix(recordInvalidAMissingB);
1058
+ expect(recordInvalidAMissingB.equalsTo(recordValidAB)).to.eql(true);
1059
+ expect(result).to.eql({
1060
+ message: ['Field 340 has invalid ending punctuation'],
1061
+ fix: ['Field 340 - Added punctuation to $a'],
1062
+ valid: false
1063
+ });
1064
+ });
1065
+
1066
+ it('Repairs the invalid record - Add punc $b (mandatory)', async () => {
1067
+ const validator = await validatorFactory();
1068
+ const result = await validator.fix(recordInvalidABMissing);
1069
+ expect(recordInvalidABMissing.equalsTo(recordValidAB)).to.eql(true);
1070
+ expect(result).to.eql({
1071
+ message: ['Field 340 has invalid ending punctuation'],
1072
+ fix: ['Field 340 - Added punctuation to $b'],
1073
+ valid: false
1074
+ });
1075
+ });
1076
+
1077
+ it('Repairs the invalid record - Add punc $d (last of two)', async () => {
1078
+ const validator = await validatorFactory();
1079
+ const result = await validator.fix(recordInvalidDDMissing);
1080
+ expect(recordInvalidDDMissing.equalsTo(recordValidDD)).to.eql(true);
1081
+ expect(result).to.eql({
1082
+ message: ['Field 340 has invalid ending punctuation'],
1083
+ fix: ['Field 340 - Added punctuation to $d'],
1084
+ valid: false
1085
+ });
1086
+ });
1087
+
1088
+ it('Repairs the invalid record - Add punc $d (last of list)', async () => {
1089
+ const validator = await validatorFactory();
1090
+ const result = await validator.fix(recordInvalidComplexDMissing);
1091
+ expect(recordInvalidComplexDMissing.equalsTo(recordInvalidComplexDMissing)).to.eql(true);
1092
+ expect(result).to.eql({
1093
+ message: ['Field 340 has invalid ending punctuation'],
1094
+ fix: ['Field 340 - Added punctuation to $d'],
1095
+ valid: false
1096
+ });
1097
+ });
1098
+ });
1099
+
1100
+ // "520 KYLLÄ Jos viimeinen osakenttä on $u, piste on ennen sitä" (Sama kuin 242, $y)
1101
+ describe('#520 TRUE - If last subfield $u, punc before it', () => {
1102
+ // Valid tests
1103
+ const recordValid = new MarcRecord({
1104
+ leader: '',
1105
+ fields: [
1106
+ {
1107
+ tag: '520',
1108
+ ind1: ' ',
1109
+ ind2: ' ',
1110
+ subfields: [{code: 'a', value: 'Mediaväkivalta ja sen yleisö.'}]
1111
+ }
1112
+ ]
1113
+ });
1114
+
1115
+ const recordValidWithU = new MarcRecord({
1116
+ leader: '',
1117
+ fields: [
1118
+ {
1119
+ tag: '520',
1120
+ ind1: ' ',
1121
+ ind2: ' ',
1122
+ subfields: [
1123
+ {code: 'a', value: 'Abstrakti.'}, // This does not match example: https://www.kansalliskirjasto.fi/extra/marc21/bib/50X-53X.htm#520
1124
+ {code: 'u', value: 'http://www.ojp.usdoj.gov/bjs/abstract/cchrie98.htm'}
1125
+ ]
1126
+ }
1127
+ ]
1128
+ });
1129
+
1130
+ const recordValidU = new MarcRecord({
1131
+ leader: '',
1132
+ fields: [
1133
+ {
1134
+ tag: '520',
1135
+ ind1: ' ',
1136
+ ind2: ' ',
1137
+ subfields: [
1138
+ {code: 'a', value: 'Abstrakti.'}, // This does not match example: https://www.kansalliskirjasto.fi/extra/marc21/bib/50X-53X.htm#520
1139
+ {code: 'u', value: 'http://www.ojp.usdoj.gov/bjs/abstract/cchrie98.htm.'}
1140
+ ]
1141
+ }
1142
+ ]
1143
+ });
1144
+
1145
+ it('Finds record valid - Punc $a (without $u)', async () => {
1146
+ const validator = await validatorFactory();
1147
+ const result = await validator.validate(recordValid);
1148
+ expect(result.valid).to.eql(true);
1149
+ });
1150
+
1151
+ it('Finds record valid - Punc $a (with $u) ', async () => {
1152
+ const validator = await validatorFactory();
1153
+ const result = await validator.validate(recordValidWithU);
1154
+ expect(result.valid).to.eql(true);
1155
+ });
1156
+
1157
+ it('Finds record valid - Punc $a & $u (punc at $u should be ignored) ', async () => {
1158
+ const validator = await validatorFactory();
1159
+ const result = await validator.validate(recordValidU);
1160
+ expect(result.valid).to.eql(true);
1161
+ });
1162
+
1163
+ // Invalid tests
1164
+ const recordInvalid = new MarcRecord({
1165
+ leader: '',
1166
+ fields: [
1167
+ {
1168
+ tag: '520',
1169
+ ind1: ' ',
1170
+ ind2: ' ',
1171
+ subfields: [{code: 'a', value: 'Mediaväkivalta ja sen yleisö'}]
1172
+ }
1173
+ ]
1174
+ });
1175
+
1176
+ const recordInvalidWithU = new MarcRecord({
1177
+ leader: '',
1178
+ fields: [
1179
+ {
1180
+ tag: '520',
1181
+ ind1: ' ',
1182
+ ind2: ' ',
1183
+ subfields: [
1184
+ {code: 'a', value: 'Abstrakti'},
1185
+ {code: 'u', value: 'http://www.ojp.usdoj.gov/bjs/abstract/cchrie98.htm'}
1186
+ ]
1187
+ }
1188
+ ]
1189
+ });
1190
+
1191
+ it('Finds record invalid - No punc $a (without $u)', async () => {
1192
+ const validator = await validatorFactory();
1193
+ const result = await validator.validate(recordInvalid);
1194
+ expect(result).to.eql({
1195
+ message: ['Field 520 has invalid ending punctuation'],
1196
+ valid: false
1197
+ });
1198
+ });
1199
+
1200
+ it('Finds record invalid - No punc $a (with $u)', async () => {
1201
+ const validator = await validatorFactory();
1202
+ const result = await validator.validate(recordInvalidWithU);
1203
+ expect(result).to.eql({
1204
+ message: ['Field 520 has invalid ending punctuation'],
1205
+ valid: false
1206
+ });
1207
+ });
1208
+
1209
+ // Fix tests; invalid->valid
1210
+ it('Repairs the invalid record - Add punc $a (only)', async () => {
1211
+ const validator = await validatorFactory();
1212
+ const result = await validator.fix(recordInvalid);
1213
+ expect(recordInvalid.equalsTo(recordValid)).to.eql(true);
1214
+ expect(result).to.eql({
1215
+ message: ['Field 520 has invalid ending punctuation'],
1216
+ fix: ['Field 520 - Added punctuation to $a'],
1217
+ valid: false
1218
+ });
1219
+ });
1220
+
1221
+ it('Repairs the invalid record - Add punc $a (last before $u)', async () => {
1222
+ const validator = await validatorFactory();
1223
+ const result = await validator.fix(recordInvalidWithU);
1224
+ expect(recordInvalidWithU.equalsTo(recordValidWithU)).to.eql(true);
1225
+ expect(result).to.eql({
1226
+ message: ['Field 520 has invalid ending punctuation'],
1227
+ fix: ['Field 520 - Added punctuation to $a'],
1228
+ valid: false
1229
+ });
1230
+ });
1231
+ });
1232
+
1233
+ // "538 KYLLÄ Jos viimeinen osakenttä on $u, piste on ennen sitä" (Sama kuin 520)
1234
+ // Eli piste merkitään vikaan osakenttään as usual, mutta ennen *y*-osakenttää
1235
+ // (speksin mukaan y->u) https://www.kansalliskirjasto.fi/extra/marc21/bib/53X-58X.htm#538
1236
+ describe('#538 TRUE - If last subfield $u, punc before it', () => {
1237
+ // Valid tests
1238
+ const recordValid = new MarcRecord({
1239
+ leader: '',
1240
+ fields: [
1241
+ {
1242
+ tag: '538',
1243
+ ind1: ' ',
1244
+ ind2: ' ',
1245
+ subfields: [
1246
+ {code: 'a', value: 'Project methodology for digital version'},
1247
+ {code: 'i', value: 'Technical details.'}, // This ended to ':' in examples, but it doesn't match statet rules: https://www.kansalliskirjasto.fi/extra/marc21/bib/53X-58X.htm#538
1248
+ {code: 'u', value: 'http://www.columbia.edu/dlc/linglung/methodology.html'}
1249
+ ]
1250
+ }
1251
+ ]
1252
+ });
1253
+
1254
+ const recordValidPuncU = new MarcRecord({
1255
+ leader: '',
1256
+ fields: [
1257
+ {
1258
+ tag: '538',
1259
+ ind1: ' ',
1260
+ ind2: ' ',
1261
+ subfields: [
1262
+ {code: 'a', value: 'Project methodology for digital version'},
1263
+ {code: 'i', value: 'Technical details.'},
1264
+ {code: 'u', value: 'http://www.columbia.edu/dlc/linglung/methodology.html.'}
1265
+ ]
1266
+ }
1267
+ ]
1268
+ });
1269
+
1270
+ const recordValidOnlyA = new MarcRecord({
1271
+ leader: '',
1272
+ fields: [
1273
+ {
1274
+ tag: '538',
1275
+ ind1: ' ',
1276
+ ind2: ' ',
1277
+ subfields: [{code: 'a', value: 'SECAM-videolaite.'}]
1278
+ }
1279
+ ]
1280
+ });
1281
+
1282
+ it('Finds record valid - Punc $i (last before $u)', async () => {
1283
+ const validator = await validatorFactory();
1284
+ const result = await validator.validate(recordValid);
1285
+ expect(result.valid).to.eql(true);
1286
+ });
1287
+
1288
+ it('Finds record valid - Punc $i & punc $u ($u is URL, should pass)', async () => {
1289
+ const validator = await validatorFactory();
1290
+ const result = await validator.validate(recordValidPuncU);
1291
+ expect(result.valid).to.eql(true);
1292
+ });
1293
+
1294
+ it('Finds record valid - Punc $a (only)', async () => {
1295
+ const validator = await validatorFactory();
1296
+ const result = await validator.validate(recordValidOnlyA);
1297
+ expect(result.valid).to.eql(true);
1298
+ });
1299
+
1300
+ // Invalid tests
1301
+ const recordInvalidMissingI = new MarcRecord({
1302
+ leader: '',
1303
+ fields: [
1304
+ {
1305
+ tag: '538',
1306
+ ind1: ' ',
1307
+ ind2: ' ',
1308
+ subfields: [
1309
+ {code: 'a', value: 'Project methodology for digital version'},
1310
+ {code: 'i', value: 'Technical details'},
1311
+ {code: 'u', value: 'http://www.columbia.edu/dlc/linglung/methodology.html'}
1312
+ ]
1313
+ }
1314
+ ]
1315
+ });
1316
+
1317
+ const recordInvalidI = new MarcRecord({
1318
+ leader: '',
1319
+ fields: [
1320
+ {
1321
+ tag: '538',
1322
+ ind1: ' ',
1323
+ ind2: ' ',
1324
+ subfields: [
1325
+ {code: 'a', value: 'Project methodology for digital version'},
1326
+ {code: 'i', value: 'Technical details:'}, // This is actually like in examples, but it doesn't match statet rules: https://www.kansalliskirjasto.fi/extra/marc21/bib/53X-58X.htm#538
1327
+ {code: 'u', value: 'http://www.columbia.edu/dlc/linglung/methodology.html'}
1328
+ ]
1329
+ }
1330
+ ]
1331
+ });
1332
+
1333
+ const recordInvalidOnlyA = new MarcRecord({
1334
+ leader: '',
1335
+ fields: [
1336
+ {
1337
+ tag: '538',
1338
+ ind1: ' ',
1339
+ ind2: ' ',
1340
+ subfields: [{code: 'a', value: 'SECAM-videolaite'}]
1341
+ }
1342
+ ]
1343
+ });
1344
+
1345
+ it('Finds record invalid - No punc $i (last before $u)', async () => {
1346
+ const validator = await validatorFactory();
1347
+ const result = await validator.validate(recordInvalidMissingI);
1348
+ expect(result).to.eql({
1349
+ message: ['Field 538 has invalid ending punctuation'],
1350
+ valid: false
1351
+ });
1352
+ });
1353
+
1354
+ it('Finds record invalid - Invalid punc $i (":" not valid punc mark, but this is according example...)', async () => {
1355
+ const validator = await validatorFactory();
1356
+ const result = await validator.validate(recordInvalidI);
1357
+ expect(result).to.eql({
1358
+ message: ['Field 538 has invalid ending punctuation'],
1359
+ valid: false
1360
+ });
1361
+ });
1362
+
1363
+ it('Finds record invalid - No punc $a (only)', async () => {
1364
+ const validator = await validatorFactory();
1365
+ const result = await validator.validate(recordInvalidOnlyA);
1366
+ expect(result).to.eql({
1367
+ message: ['Field 538 has invalid ending punctuation'],
1368
+ valid: false
1369
+ });
1370
+ });
1371
+
1372
+ // Fix tests; invalid->valid
1373
+ it('Repairs the invalid record - Add punc $i (last)', async () => {
1374
+ const validator = await validatorFactory();
1375
+ const result = await validator.fix(recordInvalidMissingI);
1376
+ expect(recordInvalidMissingI.equalsTo(recordValid)).to.eql(true);
1377
+ expect(result).to.eql({
1378
+ message: ['Field 538 has invalid ending punctuation'],
1379
+ fix: ['Field 538 - Added punctuation to $i'],
1380
+ valid: false
1381
+ });
1382
+ });
1383
+
1384
+ it('Repairs the invalid record - Add punc $a (only)', async () => {
1385
+ const validator = await validatorFactory();
1386
+ const result = await validator.fix(recordInvalidOnlyA);
1387
+ expect(recordInvalidOnlyA.equalsTo(recordValidOnlyA)).to.eql(true);
1388
+ expect(result).to.eql({
1389
+ message: ['Field 538 has invalid ending punctuation'],
1390
+ fix: ['Field 538 - Added punctuation to $a'],
1391
+ valid: false
1392
+ });
1393
+ });
1394
+ });
1395
+
1396
+ // "567 KYLLÄ osakentän $a jälkeen, EI muiden osakenttien jälkeen"
1397
+ // Only if last subfield $a
1398
+ describe('#567 TRUE - After subfield $a, FALSE after others', () => {
1399
+ // Valid tests
1400
+ const recordValid = new MarcRecord({
1401
+ leader: '',
1402
+ fields: [
1403
+ {
1404
+ tag: '567',
1405
+ ind1: ' ',
1406
+ ind2: ' ',
1407
+ subfields: [{code: 'a', value: 'Narratiivinen tutkimus.'}]
1408
+ }
1409
+ ]
1410
+ });
1411
+
1412
+ const recordValidWithoutA = new MarcRecord({
1413
+ leader: '',
1414
+ fields: [
1415
+ {
1416
+ tag: '567',
1417
+ ind1: ' ',
1418
+ ind2: ' ',
1419
+ subfields: [
1420
+ {code: 'b', value: 'Narrative inquiry'},
1421
+ {code: '2', value: 'lcsh'}
1422
+ ]
1423
+ }
1424
+ ]
1425
+ });
1426
+
1427
+ it('Finds record valid - Punc $a (only)', async () => {
1428
+ const validator = await validatorFactory();
1429
+ const result = await validator.validate(recordValid);
1430
+ expect(result.valid).to.eql(true);
1431
+ });
1432
+
1433
+ it('Finds record valid - No punc $b (only data field)', async () => {
1434
+ const validator = await validatorFactory();
1435
+ const result = await validator.validate(recordValidWithoutA);
1436
+ expect(result.valid).to.eql(true);
1437
+ });
1438
+
1439
+ // Invalid tests
1440
+ const recordInvalid = new MarcRecord({
1441
+ leader: '',
1442
+ fields: [
1443
+ {
1444
+ tag: '567',
1445
+ ind1: ' ',
1446
+ ind2: ' ',
1447
+ subfields: [{code: 'a', value: 'Narratiivinen tutkimus'}]
1448
+ }
1449
+ ]
1450
+ });
1451
+
1452
+ const recordInvalidWithoutA = new MarcRecord({
1453
+ leader: '',
1454
+ fields: [
1455
+ {
1456
+ tag: '567',
1457
+ ind1: ' ',
1458
+ ind2: ' ',
1459
+ subfields: [
1460
+ {code: 'b', value: 'Narrative inquiry.'},
1461
+ {code: '2', value: 'lcsh'}
1462
+ ]
1463
+ }
1464
+ ]
1465
+ });
1466
+
1467
+ it('Finds record invalid - No punc $a (only)', async () => {
1468
+ const validator = await validatorFactory();
1469
+ const result = await validator.validate(recordInvalid);
1470
+ expect(result).to.eql({
1471
+ message: ['Field 567 has invalid ending punctuation'],
1472
+ valid: false
1473
+ });
1474
+ });
1475
+
1476
+ it('Finds record invalid - Punc $b (only data field)', async () => {
1477
+ const validator = await validatorFactory();
1478
+ const result = await validator.validate(recordInvalidWithoutA);
1479
+ expect(result).to.eql({
1480
+ message: ['Field 567 has invalid ending punctuation'],
1481
+ valid: false
1482
+ });
1483
+ });
1484
+
1485
+ // Fix tests; invalid->valid
1486
+ it('Repairs the invalid record - Add punc $a (only)', async () => {
1487
+ const validator = await validatorFactory();
1488
+ const result = await validator.fix(recordInvalid);
1489
+ expect(recordInvalid.equalsTo(recordValid)).to.eql(true);
1490
+ expect(result).to.eql({
1491
+ message: ['Field 567 has invalid ending punctuation'],
1492
+ fix: ['Field 567 - Added punctuation to $a'],
1493
+ valid: false
1494
+ });
1495
+ });
1496
+
1497
+ it('Repairs the invalid record - Remove punc $b (only data field)', async () => {
1498
+ const validator = await validatorFactory();
1499
+ const result = await validator.fix(recordInvalidWithoutA);
1500
+ expect(recordInvalidWithoutA.equalsTo(recordValidWithoutA)).to.eql(true);
1501
+ expect(result).to.eql({
1502
+ message: ['Field 567 has invalid ending punctuation'],
1503
+ fix: ['Field 567 - Removed punctuation from $b'],
1504
+ valid: false
1505
+ });
1506
+ });
1507
+ });
1508
+
1509
+ // "647-651 EI - EI suomalaisten sanastojen termeihin, muihin sanaston käytännön mukaan, yleensä KYLLÄ"
1510
+ // Finnish terms at $2:['ysa', 'yso', 'kassu', 'seko', 'valo', 'kulo', 'puho', 'oiko', 'mero', 'liito', 'fast', 'allars']
1511
+ // Default TRUE, until more special cases are added
1512
+ describe('#647-651 FALSE - If finnish, else TRUE', () => {
1513
+ // Valid tests
1514
+ const recordValid647FastEndPunc = new MarcRecord({
1515
+ leader: '',
1516
+ fields: [
1517
+ {
1518
+ tag: '647',
1519
+ ind1: ' ',
1520
+ ind2: ' ',
1521
+ subfields: [
1522
+ {code: 'a', value: 'Hurricane Katrina'},
1523
+ {code: 'd', value: '(2005)'},
1524
+ {code: '2', value: 'fast'}
1525
+ ]
1526
+ }
1527
+ ]
1528
+ });
1529
+
1530
+ const recordVali648dFinNo = new MarcRecord({
1531
+ leader: '',
1532
+ fields: [
1533
+ {
1534
+ tag: '648',
1535
+ ind1: ' ',
1536
+ ind2: ' ',
1537
+ subfields: [
1538
+ {code: 'a', value: '1900-luku'},
1539
+ {code: '2', value: 'yso/swe'}
1540
+ ]
1541
+ }
1542
+ ]
1543
+ });
1544
+
1545
+ const recordValid648FastNo = new MarcRecord({
1546
+ leader: '',
1547
+ fields: [
1548
+ {
1549
+ tag: '648',
1550
+ ind1: ' ',
1551
+ ind2: ' ',
1552
+ subfields: [
1553
+ {code: 'a', value: '1862'},
1554
+ {code: '2', value: 'fast'} // https://www.kansalliskirjasto.fi/extra/marc21/bib/6XX.htm#648
1555
+ ]
1556
+ }
1557
+ ]
1558
+ });
1559
+
1560
+ const recordValid650FinNo = new MarcRecord({
1561
+ leader: '',
1562
+ fields: [
1563
+ {
1564
+ tag: '650',
1565
+ ind1: ' ',
1566
+ ind2: ' ',
1567
+ subfields: [
1568
+ {code: 'a', value: 'kirjastot'},
1569
+ {code: 'x', value: 'atk-järjestelmät'},
1570
+ {code: '2', value: 'kauno/fin'}
1571
+ ]
1572
+ }
1573
+ ]
1574
+ });
1575
+
1576
+ const recordValid650EngNoControl = new MarcRecord({
1577
+ leader: '',
1578
+ fields: [
1579
+ {
1580
+ tag: '650',
1581
+ ind1: ' ',
1582
+ ind2: ' ',
1583
+ subfields: [
1584
+ {code: 'a', value: 'Flour industry'},
1585
+ {code: 'v', value: 'Periodicals.'}
1586
+ ]
1587
+ }
1588
+ ]
1589
+ });
1590
+
1591
+ const recordValid650EngControl = new MarcRecord({
1592
+ leader: '',
1593
+ fields: [
1594
+ {
1595
+ tag: '650',
1596
+ ind1: ' ',
1597
+ ind2: ' ',
1598
+ subfields: [
1599
+ {code: 'a', value: 'Career Exploration.'},
1600
+ {code: '2', value: 'ericd'}
1601
+ ]
1602
+ }
1603
+ ]
1604
+ });
1605
+
1606
+ it('Finds record valid - 647 Fast, punc char at end', async () => {
1607
+ const validator = await validatorFactory();
1608
+ const result = await validator.validate(recordValid647FastEndPunc);
1609
+ expect(result.valid).to.eql(true);
1610
+ });
1611
+
1612
+ it('Finds record valid - 648 Finnish, without punc', async () => {
1613
+ const validator = await validatorFactory();
1614
+ const result = await validator.validate(recordVali648dFinNo);
1615
+ expect(result.valid).to.eql(true);
1616
+ });
1617
+
1618
+ it('Finds record valid - 648 Fast, without punc', async () => {
1619
+ const validator = await validatorFactory();
1620
+ const result = await validator.validate(recordValid648FastNo);
1621
+ expect(result.valid).to.eql(true);
1622
+ });
1623
+
1624
+ it('Finds record valid - 650 Finnish, without punc', async () => {
1625
+ const validator = await validatorFactory();
1626
+ const result = await validator.validate(recordValid650FinNo);
1627
+ expect(result.valid).to.eql(true);
1628
+ });
1629
+
1630
+ it('Finds record valid - 650 English, punc (no control)', async () => {
1631
+ const validator = await validatorFactory();
1632
+ const result = await validator.validate(recordValid650EngNoControl);
1633
+ expect(result.valid).to.eql(true);
1634
+ });
1635
+
1636
+ it('Finds record valid - 650 English, with punc', async () => {
1637
+ const validator = await validatorFactory();
1638
+ const result = await validator.validate(recordValid650EngControl);
1639
+ expect(result.valid).to.eql(true);
1640
+ });
1641
+
1642
+ // Invalid tests
1643
+ const recordInvalid647FastEndPunc = new MarcRecord({
1644
+ leader: '',
1645
+ fields: [
1646
+ {
1647
+ tag: '647',
1648
+ ind1: ' ',
1649
+ ind2: ' ',
1650
+ subfields: [
1651
+ {code: 'a', value: 'Hurricane Katrina'},
1652
+ {code: 'd', value: '(2005).'},
1653
+ {code: '2', value: 'fast'}
1654
+ ]
1655
+ }
1656
+ ]
1657
+ });
1658
+
1659
+ const recordInvali648dFinYes = new MarcRecord({
1660
+ leader: '',
1661
+ fields: [
1662
+ {
1663
+ tag: '648',
1664
+ ind1: ' ',
1665
+ ind2: ' ',
1666
+ subfields: [
1667
+ {code: 'a', value: '1900-luku.'},
1668
+ {code: '2', value: 'yso/swe'}
1669
+ ]
1670
+ }
1671
+ ]
1672
+ });
1673
+
1674
+ const recordInvalid648FastYes = new MarcRecord({
1675
+ leader: '',
1676
+ fields: [
1677
+ {
1678
+ tag: '648',
1679
+ ind1: ' ',
1680
+ ind2: ' ',
1681
+ subfields: [
1682
+ {code: 'a', value: '1862.'},
1683
+ {code: '2', value: 'fast'}
1684
+ ]
1685
+ }
1686
+ ]
1687
+ });
1688
+
1689
+ const recordInvalid650FinYes = new MarcRecord({
1690
+ leader: '',
1691
+ fields: [
1692
+ {
1693
+ tag: '650',
1694
+ ind1: ' ',
1695
+ ind2: ' ',
1696
+ subfields: [
1697
+ {code: 'a', value: 'kirjastot'},
1698
+ {code: 'x', value: 'atk-järjestelmät.'},
1699
+ {code: '2', value: 'kauno/fin'}
1700
+ ]
1701
+ }
1702
+ ]
1703
+ });
1704
+
1705
+ const recordInvalid650EngNoControl = new MarcRecord({
1706
+ leader: '',
1707
+ fields: [
1708
+ {
1709
+ tag: '650',
1710
+ ind1: ' ',
1711
+ ind2: ' ',
1712
+ subfields: [
1713
+ {code: 'a', value: 'Flour industry'},
1714
+ {code: 'v', value: 'Periodicals'}
1715
+ ]
1716
+ }
1717
+ ]
1718
+ });
1719
+
1720
+ const recordInvalid650EngControl = new MarcRecord({
1721
+ leader: '',
1722
+ fields: [
1723
+ {
1724
+ tag: '650',
1725
+ ind1: ' ',
1726
+ ind2: ' ',
1727
+ subfields: [
1728
+ {code: 'a', value: 'Career Exploration'},
1729
+ {code: '2', value: 'ericd'}
1730
+ ]
1731
+ }
1732
+ ]
1733
+ });
1734
+
1735
+ it('Finds record invalid - 647 Fast, dot at end', async () => {
1736
+ const validator = await validatorFactory();
1737
+ const result = await validator.validate(recordInvalid647FastEndPunc);
1738
+ expect(result).to.eql({
1739
+ message: ['Field 647 has invalid ending punctuation'],
1740
+ valid: false
1741
+ });
1742
+ });
1743
+
1744
+ it('Finds record invalid - 648 Finnish, with punc', async () => {
1745
+ const validator = await validatorFactory();
1746
+ const result = await validator.validate(recordInvali648dFinYes);
1747
+ expect(result).to.eql({
1748
+ message: ['Field 648 has invalid ending punctuation'],
1749
+ valid: false
1750
+ });
1751
+ });
1752
+
1753
+ it('Finds record invalid - 648 Fast, with punc', async () => {
1754
+ const validator = await validatorFactory();
1755
+ const result = await validator.validate(recordInvalid648FastYes);
1756
+ expect(result).to.eql({
1757
+ message: ['Field 648 has invalid ending punctuation'],
1758
+ valid: false
1759
+ });
1760
+ });
1761
+
1762
+ it('Finds record invalid - 650 Finnish, with punc', async () => {
1763
+ const validator = await validatorFactory();
1764
+ const result = await validator.validate(recordInvalid650FinYes);
1765
+ expect(result).to.eql({
1766
+ message: ['Field 650 has invalid ending punctuation'],
1767
+ valid: false
1768
+ });
1769
+ });
1770
+
1771
+ it('Finds record invalid - 650 !Finnish, without punc (no control)', async () => {
1772
+ const validator = await validatorFactory();
1773
+ const result = await validator.validate(recordInvalid650EngNoControl);
1774
+ expect(result).to.eql({
1775
+ message: ['Field 650 has invalid ending punctuation'],
1776
+ valid: false
1777
+ });
1778
+ });
1779
+
1780
+ it('Finds record invalid - 650 !Finnish, without punc', async () => {
1781
+ const validator = await validatorFactory();
1782
+ const result = await validator.validate(recordInvalid650EngControl);
1783
+ expect(result).to.eql({
1784
+ message: ['Field 650 has invalid ending punctuation'],
1785
+ valid: false
1786
+ });
1787
+ });
1788
+
1789
+ // Fix tests; invalid->valid
1790
+ it('Repairs the invalid record - 647 Fast, removes double punc $d', async () => {
1791
+ const validator = await validatorFactory();
1792
+ const result = await validator.fix(recordInvalid647FastEndPunc);
1793
+ expect(recordInvalid647FastEndPunc.equalsTo(recordValid647FastEndPunc)).to.eql(true);
1794
+ expect(result).to.eql({
1795
+ message: ['Field 647 has invalid ending punctuation'],
1796
+ fix: ['Field 647 - Removed double punctuation from $d'],
1797
+ valid: false
1798
+ });
1799
+ });
1800
+
1801
+ it('Repairs the invalid record - 648 Finnish, removes punc $a', async () => {
1802
+ const validator = await validatorFactory();
1803
+ const result = await validator.fix(recordInvali648dFinYes);
1804
+ expect(recordInvali648dFinYes.equalsTo(recordVali648dFinNo)).to.eql(true);
1805
+ expect(result).to.eql({
1806
+ message: ['Field 648 has invalid ending punctuation'],
1807
+ fix: ['Field 648 - Removed punctuation from $a'],
1808
+ valid: false
1809
+ });
1810
+ });
1811
+
1812
+ it('Repairs the invalid record - 648 Fast, removes punc $a', async () => {
1813
+ const validator = await validatorFactory();
1814
+ const result = await validator.fix(recordInvalid648FastYes);
1815
+ expect(recordInvalid648FastYes.equalsTo(recordValid648FastNo)).to.eql(true);
1816
+ expect(result).to.eql({
1817
+ message: ['Field 648 has invalid ending punctuation'],
1818
+ fix: ['Field 648 - Removed punctuation from $a'],
1819
+ valid: false
1820
+ });
1821
+ });
1822
+
1823
+ it('Repairs the invalid record - 650 Finnish, removes punc $x', async () => {
1824
+ const validator = await validatorFactory();
1825
+ const result = await validator.fix(recordInvalid650FinYes);
1826
+ expect(recordInvalid650FinYes.equalsTo(recordValid650FinNo)).to.eql(true);
1827
+ expect(result).to.eql({
1828
+ message: ['Field 650 has invalid ending punctuation'],
1829
+ fix: ['Field 650 - Removed punctuation from $x'],
1830
+ valid: false
1831
+ });
1832
+ });
1833
+
1834
+ it('Repairs the invalid record - 650 !Finnish, add punc $v (no control)', async () => {
1835
+ const validator = await validatorFactory();
1836
+ const result = await validator.fix(recordInvalid650EngNoControl);
1837
+ expect(recordInvalid650EngNoControl.equalsTo(recordValid650EngNoControl)).to.eql(true);
1838
+ expect(result).to.eql({
1839
+ message: ['Field 650 has invalid ending punctuation'],
1840
+ fix: ['Field 650 - Added punctuation to $v'],
1841
+ valid: false
1842
+ });
1843
+ });
1844
+
1845
+ it('Repairs the invalid record - 650 !Finnish, add punc $a', async () => {
1846
+ const validator = await validatorFactory();
1847
+ const result = await validator.fix(recordInvalid650EngControl);
1848
+ expect(recordInvalid650EngControl.equalsTo(recordValid650EngControl)).to.eql(true);
1849
+ expect(result).to.eql({
1850
+ message: ['Field 650 has invalid ending punctuation'],
1851
+ fix: ['Field 650 - Added punctuation to $a'],
1852
+ valid: false
1853
+ });
1854
+ });
1855
+ });
1856
+
1857
+ // "654-662 EI - EI suomalaisten sanastojen termeihin, muihin sanaston käytännön mukaan, yleensä KYLLÄ"
1858
+ // Finnish terms at $2:['ysa', 'yso', 'kassu', 'seko', 'valo', 'kulo', 'puho', 'oiko', 'mero', 'liito', 'fast', 'allars']
1859
+ // Default TRUE, until more special cases are added
1860
+ describe('#654-662 TRUE - If finnish, else TRUE', () => {
1861
+ // Valid tests
1862
+ const recordValid655FinNo = new MarcRecord({
1863
+ leader: '',
1864
+ fields: [
1865
+ {
1866
+ tag: '655',
1867
+ ind1: ' ',
1868
+ ind2: ' ',
1869
+ subfields: [
1870
+ {code: 'a', value: 'kausijulkaisut'},
1871
+ {code: '2', value: 'yso/eng'}
1872
+ ]
1873
+ }
1874
+ ]
1875
+ });
1876
+
1877
+ const recordValid655FinNo2 = new MarcRecord({
1878
+ leader: '',
1879
+ fields: [
1880
+ {
1881
+ tag: '655',
1882
+ ind1: ' ',
1883
+ ind2: ' ',
1884
+ subfields: [
1885
+ {code: 'a', value: 'vironkielinen kirjallisuus'},
1886
+ {code: '2', value: 'local'}
1887
+ ]
1888
+ }
1889
+ ]
1890
+ });
1891
+
1892
+ const recordValid655EngYes = new MarcRecord({
1893
+ leader: '',
1894
+ fields: [
1895
+ {
1896
+ tag: '655',
1897
+ ind1: ' ',
1898
+ ind2: ' ',
1899
+ subfields: [
1900
+ {code: 'a', value: 'Bird\'s-eye views'},
1901
+ {code: 'y', value: '1874.'},
1902
+ {code: '2', value: 'gmgpc'}
1903
+ ]
1904
+ }
1905
+ ]
1906
+ });
1907
+
1908
+ const recordValid655EngYesNoControl = new MarcRecord({
1909
+ leader: '',
1910
+ fields: [
1911
+ {
1912
+ tag: '655',
1913
+ ind1: ' ',
1914
+ ind2: ' ',
1915
+ subfields: [{code: 'a', value: 'Diaries.'}]
1916
+ }
1917
+ ]
1918
+ });
1919
+
1920
+ const recordValid656FinNo = new MarcRecord({
1921
+ leader: '',
1922
+ fields: [
1923
+ {
1924
+ tag: '656',
1925
+ ind1: ' ',
1926
+ ind2: ' ',
1927
+ subfields: [
1928
+ {code: 'a', value: 'kuvaamataidonopettajat'},
1929
+ {code: '2', value: 'slm/eng'}
1930
+ ]
1931
+ }
1932
+ ]
1933
+ });
1934
+
1935
+ const recordValid657EngYes = new MarcRecord({
1936
+ leader: '',
1937
+ fields: [
1938
+ {
1939
+ tag: '657',
1940
+ ind1: ' ',
1941
+ ind2: ' ',
1942
+ subfields: [
1943
+ {code: 'a', value: 'Personnel benefits management'},
1944
+ {code: 'x', value: 'Vital statistics'},
1945
+ {code: 'z', value: 'Love Canal, New York.'},
1946
+ {code: '2', value: 'New York State Management Functions Index'}
1947
+ ]
1948
+ }
1949
+ ]
1950
+ });
1951
+
1952
+ const recordValid658EngYes = new MarcRecord({
1953
+ leader: '',
1954
+ fields: [
1955
+ {
1956
+ tag: '658',
1957
+ ind1: ' ',
1958
+ ind2: ' ',
1959
+ subfields: [
1960
+ {code: 'a', value: 'Math manipulatives'},
1961
+ {code: 'd', value: 'highly correlated.'},
1962
+ {code: '2', value: '[source code]'}
1963
+ ]
1964
+ }
1965
+ ]
1966
+ });
1967
+
1968
+ const recordValid662EngYes = new MarcRecord({
1969
+ leader: '',
1970
+ fields: [
1971
+ {
1972
+ tag: '662',
1973
+ ind1: ' ',
1974
+ ind2: ' ',
1975
+ subfields: [
1976
+ {code: 'a', value: 'Antarctica.'},
1977
+ {code: '2', value: 'lcsh/naf'}
1978
+ ]
1979
+ }
1980
+ ]
1981
+ });
1982
+
1983
+ it('Finds record valid - 655 Finnish, no punc $a', async () => {
1984
+ const validator = await validatorFactory();
1985
+ const result = await validator.validate(recordValid655FinNo);
1986
+ expect(result.valid).to.eql(true);
1987
+ });
1988
+
1989
+ it('Finds record valid - 655 Finnish, without punc', async () => {
1990
+ const validator = await validatorFactory();
1991
+ const result = await validator.validate(recordValid655FinNo2);
1992
+ expect(result.valid).to.eql(true);
1993
+ });
1994
+
1995
+ it('Finds record valid - 655 English, with punc $y', async () => {
1996
+ const validator = await validatorFactory();
1997
+ const result = await validator.validate(recordValid655EngYes);
1998
+ expect(result.valid).to.eql(true);
1999
+ });
2000
+
2001
+ it('Finds record valid - 655 English, with punc $a (no control)', async () => {
2002
+ const validator = await validatorFactory();
2003
+ const result = await validator.validate(recordValid655EngYesNoControl);
2004
+ expect(result.valid).to.eql(true);
2005
+ });
2006
+
2007
+ it('Finds record valid - 656 Finnish, without punc $a', async () => {
2008
+ const validator = await validatorFactory();
2009
+ const result = await validator.validate(recordValid656FinNo);
2010
+ expect(result.valid).to.eql(true);
2011
+ });
2012
+
2013
+ it('Finds record valid - 657 English, with punc $z', async () => {
2014
+ const validator = await validatorFactory();
2015
+ const result = await validator.validate(recordValid657EngYes);
2016
+ expect(result.valid).to.eql(true);
2017
+ });
2018
+
2019
+ it('Finds record valid - 658 English, with punc $d', async () => {
2020
+ const validator = await validatorFactory();
2021
+ const result = await validator.validate(recordValid658EngYes);
2022
+ expect(result.valid).to.eql(true);
2023
+ });
2024
+
2025
+ it('Finds record valid - 662 English, with punc $a', async () => {
2026
+ const validator = await validatorFactory();
2027
+ const result = await validator.validate(recordValid662EngYes);
2028
+ expect(result.valid).to.eql(true);
2029
+ });
2030
+
2031
+ // Invalid tests
2032
+ const recordInvalid655FinYes = new MarcRecord({
2033
+ leader: '',
2034
+ fields: [
2035
+ {
2036
+ tag: '655',
2037
+ ind1: ' ',
2038
+ ind2: ' ',
2039
+ subfields: [
2040
+ {code: 'a', value: 'kausijulkaisut.'},
2041
+ {code: '2', value: 'yso/eng'}
2042
+ ]
2043
+ }
2044
+ ]
2045
+ });
2046
+
2047
+ const recordInvalid655FinYes2 = new MarcRecord({
2048
+ leader: '',
2049
+ fields: [
2050
+ {
2051
+ tag: '655',
2052
+ ind1: ' ',
2053
+ ind2: ' ',
2054
+ subfields: [
2055
+ {code: 'a', value: 'vironkielinen kirjallisuus.'},
2056
+ {code: '2', value: 'local'}
2057
+ ]
2058
+ }
2059
+ ]
2060
+ });
2061
+
2062
+ const recordInvalid655EngNo = new MarcRecord({
2063
+ leader: '',
2064
+ fields: [
2065
+ {
2066
+ tag: '655',
2067
+ ind1: ' ',
2068
+ ind2: ' ',
2069
+ subfields: [
2070
+ {code: 'a', value: 'Bird\'s-eye views'},
2071
+ {code: 'y', value: '1874'},
2072
+ {code: '2', value: 'gmgpc'}
2073
+ ]
2074
+ }
2075
+ ]
2076
+ });
2077
+
2078
+ const recordInvalid655EngNoNoControl = new MarcRecord({
2079
+ leader: '',
2080
+ fields: [
2081
+ {
2082
+ tag: '655',
2083
+ ind1: ' ',
2084
+ ind2: ' ',
2085
+ subfields: [{code: 'a', value: 'Diaries'}]
2086
+ }
2087
+ ]
2088
+ });
2089
+
2090
+ const recordInvalid656FinYes = new MarcRecord({
2091
+ leader: '',
2092
+ fields: [
2093
+ {
2094
+ tag: '656',
2095
+ ind1: ' ',
2096
+ ind2: ' ',
2097
+ subfields: [
2098
+ {code: 'a', value: 'kuvaamataidonopettajat.'},
2099
+ {code: '2', value: 'slm/eng'}
2100
+ ]
2101
+ }
2102
+ ]
2103
+ });
2104
+
2105
+ const recordInvalid657EngNo = new MarcRecord({
2106
+ leader: '',
2107
+ fields: [
2108
+ {
2109
+ tag: '657',
2110
+ ind1: ' ',
2111
+ ind2: ' ',
2112
+ subfields: [
2113
+ {code: 'a', value: 'Personnel benefits management'},
2114
+ {code: 'x', value: 'Vital statistics'},
2115
+ {code: 'z', value: 'Love Canal, New York'},
2116
+ {code: '2', value: 'New York State Management Functions Index'}
2117
+ ]
2118
+ }
2119
+ ]
2120
+ });
2121
+
2122
+ const recordInvalid658EngNo = new MarcRecord({
2123
+ leader: '',
2124
+ fields: [
2125
+ {
2126
+ tag: '658',
2127
+ ind1: ' ',
2128
+ ind2: ' ',
2129
+ subfields: [
2130
+ {code: 'a', value: 'Math manipulatives'},
2131
+ {code: 'd', value: 'highly correlated'},
2132
+ {code: '2', value: '[source code]'}
2133
+ ]
2134
+ }
2135
+ ]
2136
+ });
2137
+
2138
+ const recordInvalid662EngNo = new MarcRecord({
2139
+ leader: '',
2140
+ fields: [
2141
+ {
2142
+ tag: '662',
2143
+ ind1: ' ',
2144
+ ind2: ' ',
2145
+ subfields: [
2146
+ {code: 'a', value: 'Antarctica'},
2147
+ {code: '2', value: 'lcsh/naf'}
2148
+ ]
2149
+ }
2150
+ ]
2151
+ });
2152
+
2153
+ it('Finds record invalid - 655 Finnish, punc $a', async () => {
2154
+ const validator = await validatorFactory();
2155
+ const result = await validator.validate(recordInvalid655FinYes);
2156
+ expect(result).to.eql({
2157
+ message: ['Field 655 has invalid ending punctuation'],
2158
+ valid: false
2159
+ });
2160
+ });
2161
+
2162
+ it('Finds record invalid - 655 Finnish, with punc', async () => {
2163
+ const validator = await validatorFactory();
2164
+ const result = await validator.validate(recordInvalid655FinYes2);
2165
+ expect(result).to.eql({
2166
+ message: ['Field 655 has invalid ending punctuation'],
2167
+ valid: false
2168
+ });
2169
+ });
2170
+
2171
+ it('Finds record invalid - 655 !Finnish, without punc $y', async () => {
2172
+ const validator = await validatorFactory();
2173
+ const result = await validator.validate(recordInvalid655EngNo);
2174
+ expect(result).to.eql({
2175
+ message: ['Field 655 has invalid ending punctuation'],
2176
+ valid: false
2177
+ });
2178
+ });
2179
+
2180
+ it('Finds record invalid - 655 !Finnish, without punc $a (no control)', async () => {
2181
+ const validator = await validatorFactory();
2182
+ const result = await validator.validate(recordInvalid655EngNoNoControl);
2183
+ expect(result).to.eql({
2184
+ message: ['Field 655 has invalid ending punctuation'],
2185
+ valid: false
2186
+ });
2187
+ });
2188
+
2189
+ it('Finds record invalid - 656 Finnish, with punc $a', async () => {
2190
+ const validator = await validatorFactory();
2191
+ const result = await validator.validate(recordInvalid656FinYes);
2192
+ expect(result).to.eql({
2193
+ message: ['Field 656 has invalid ending punctuation'],
2194
+ valid: false
2195
+ });
2196
+ });
2197
+
2198
+ it('Finds record invalid - 657 !Finnish, without punc $z', async () => {
2199
+ const validator = await validatorFactory();
2200
+ const result = await validator.validate(recordInvalid657EngNo);
2201
+ expect(result).to.eql({
2202
+ message: ['Field 657 has invalid ending punctuation'],
2203
+ valid: false
2204
+ });
2205
+ });
2206
+
2207
+ it('Finds record invalid - 658 !Finnish, without punc $d', async () => {
2208
+ const validator = await validatorFactory();
2209
+ const result = await validator.validate(recordInvalid658EngNo);
2210
+ expect(result).to.eql({
2211
+ message: ['Field 658 has invalid ending punctuation'],
2212
+ valid: false
2213
+ });
2214
+ });
2215
+
2216
+ it('Finds record invalid - 662 !Finnish, without punc $a', async () => {
2217
+ const validator = await validatorFactory();
2218
+ const result = await validator.validate(recordInvalid662EngNo);
2219
+ expect(result).to.eql({
2220
+ message: ['Field 662 has invalid ending punctuation'],
2221
+ valid: false
2222
+ });
2223
+ });
2224
+
2225
+ // Fix tests; invalid->valid
2226
+ it('Repairs the invalid record - 655 Finnish, remove punc $a', async () => {
2227
+ const validator = await validatorFactory();
2228
+ const result = await validator.fix(recordInvalid655FinYes);
2229
+ expect(recordInvalid655FinYes.equalsTo(recordValid655FinNo)).to.eql(true);
2230
+ expect(result).to.eql({
2231
+ message: ['Field 655 has invalid ending punctuation'],
2232
+ fix: ['Field 655 - Removed punctuation from $a'],
2233
+ valid: false
2234
+ });
2235
+ });
2236
+
2237
+ it('Repairs the invalid record - 655 Finnish, removes punc $a 2', async () => {
2238
+ const validator = await validatorFactory();
2239
+ const result = await validator.fix(recordInvalid655FinYes2);
2240
+ expect(recordInvalid655FinYes2.equalsTo(recordValid655FinNo2)).to.eql(true);
2241
+ expect(result).to.eql({
2242
+ message: ['Field 655 has invalid ending punctuation'],
2243
+ fix: ['Field 655 - Removed punctuation from $a'],
2244
+ valid: false
2245
+ });
2246
+ });
2247
+
2248
+ it('Repairs the invalid record - 655 !Finnish, add punc $y', async () => {
2249
+ const validator = await validatorFactory();
2250
+ const result = await validator.fix(recordInvalid655EngNo);
2251
+ expect(recordInvalid655EngNo.equalsTo(recordValid655EngYes)).to.eql(true);
2252
+ expect(result).to.eql({
2253
+ message: ['Field 655 has invalid ending punctuation'],
2254
+ fix: ['Field 655 - Added punctuation to $y'],
2255
+ valid: false
2256
+ });
2257
+ });
2258
+
2259
+ it('Repairs the invalid record - 655 !Finnish, add punc $a (no control)', async () => {
2260
+ const validator = await validatorFactory();
2261
+ const result = await validator.fix(recordInvalid655EngNoNoControl);
2262
+ expect(recordInvalid655EngNoNoControl.equalsTo(recordValid655EngYesNoControl)).to.eql(true);
2263
+ expect(result).to.eql({
2264
+ message: ['Field 655 has invalid ending punctuation'],
2265
+ fix: ['Field 655 - Added punctuation to $a'],
2266
+ valid: false
2267
+ });
2268
+ });
2269
+
2270
+ it('Repairs the invalid record - 656 Finnish, remove punc $a', async () => {
2271
+ const validator = await validatorFactory();
2272
+ const result = await validator.fix(recordInvalid656FinYes);
2273
+ expect(recordInvalid656FinYes.equalsTo(recordValid656FinNo)).to.eql(true);
2274
+ expect(result).to.eql({
2275
+ message: ['Field 656 has invalid ending punctuation'],
2276
+ fix: ['Field 656 - Removed punctuation from $a'],
2277
+ valid: false
2278
+ });
2279
+ });
2280
+
2281
+ it('Repairs the invalid record - 657 !Finnish, add punc $z', async () => {
2282
+ const validator = await validatorFactory();
2283
+ const result = await validator.fix(recordInvalid657EngNo);
2284
+ expect(recordInvalid657EngNo.equalsTo(recordValid657EngYes)).to.eql(true);
2285
+ expect(result).to.eql({
2286
+ message: ['Field 657 has invalid ending punctuation'],
2287
+ fix: ['Field 657 - Added punctuation to $z'],
2288
+ valid: false
2289
+ });
2290
+ });
2291
+
2292
+ it('Repairs the invalid record - 658 !Finnish, add punc $d', async () => {
2293
+ const validator = await validatorFactory();
2294
+ const result = await validator.fix(recordInvalid658EngNo);
2295
+ expect(recordInvalid658EngNo.equalsTo(recordValid658EngYes)).to.eql(true);
2296
+ expect(result).to.eql({
2297
+ message: ['Field 658 has invalid ending punctuation'],
2298
+ fix: ['Field 658 - Added punctuation to $d'],
2299
+ valid: false
2300
+ });
2301
+ });
2302
+
2303
+ it('Repairs the invalid record - 662 !Finnish, add pun $a', async () => {
2304
+ const validator = await validatorFactory();
2305
+ const result = await validator.fix(recordInvalid662EngNo);
2306
+ expect(recordInvalid662EngNo.equalsTo(recordValid662EngYes)).to.eql(true);
2307
+ expect(result).to.eql({
2308
+ message: ['Field 662 has invalid ending punctuation'],
2309
+ fix: ['Field 662 - Added punctuation to $a'],
2310
+ valid: false
2311
+ });
2312
+ });
2313
+ });
2314
+
2315
+ // "760-787 KYLLÄ osakentän $a jälkeen, EI muiden osakenttien jälkeen" (kuten 567)
2316
+ // Only if last subfield $a
2317
+ describe('#760-787 TRUE - After subfield $a, FALSE after others', () => {
2318
+ // Valid tests
2319
+ const recordValid = new MarcRecord({
2320
+ leader: '',
2321
+ fields: [
2322
+ {
2323
+ tag: '760',
2324
+ ind1: ' ',
2325
+ ind2: ' ',
2326
+ subfields: [
2327
+ {code: 'a', value: 'Mellor, Alec.'},
2328
+ {code: 't', value: 'Strange masonic stories'},
2329
+ {code: 'e', value: 'eng'}
2330
+ ]
2331
+ }
2332
+ ]
2333
+ });
2334
+
2335
+ const recordValidOnlyA = new MarcRecord({
2336
+ leader: '',
2337
+ fields: [
2338
+ {
2339
+ tag: '760',
2340
+ ind1: ' ',
2341
+ ind2: ' ',
2342
+ subfields: [{code: 'a', value: 'Mellor, Alec.'}]
2343
+ }
2344
+ ]
2345
+ });
2346
+
2347
+ it('Finds record valid - Punc $a, but following fields, $e no punc (last)', async () => {
2348
+ const validator = await validatorFactory();
2349
+ const result = await validator.validate(recordValid);
2350
+ expect(result.valid).to.eql(true);
2351
+ });
2352
+
2353
+ it('Finds record valid - Punc $a (only)', async () => {
2354
+ const validator = await validatorFactory();
2355
+ const result = await validator.validate(recordValidOnlyA);
2356
+ expect(result.valid).to.eql(true);
2357
+ });
2358
+
2359
+ // Invalid tests
2360
+ const recordInvalid = new MarcRecord({
2361
+ leader: '',
2362
+ fields: [
2363
+ {
2364
+ tag: '760',
2365
+ ind1: ' ',
2366
+ ind2: ' ',
2367
+ subfields: [
2368
+ {code: 'a', value: 'Mellor, Alec.'},
2369
+ {code: 't', value: 'Strange masonic stories'},
2370
+ {code: 'e', value: 'eng.'}
2371
+ ]
2372
+ }
2373
+ ]
2374
+ });
2375
+
2376
+ const recordInvalidOnlyA = new MarcRecord({
2377
+ leader: '',
2378
+ fields: [
2379
+ {
2380
+ tag: '760',
2381
+ ind1: ' ',
2382
+ ind2: ' ',
2383
+ subfields: [{code: 'a', value: 'Mellor, Alec'}]
2384
+ }
2385
+ ]
2386
+ });
2387
+
2388
+ it('Finds record invalid - Punc $e (language field, strict)', async () => {
2389
+ const validator = await validatorFactory();
2390
+ const result = await validator.validate(recordInvalid);
2391
+ expect(result).to.eql({
2392
+ message: ['Field 760 has invalid ending punctuation'],
2393
+ valid: false
2394
+ });
2395
+ });
2396
+
2397
+ it('Finds record invalid - No punc $a (only)', async () => {
2398
+ const validator = await validatorFactory();
2399
+ const result = await validator.validate(recordInvalidOnlyA);
2400
+ expect(result).to.eql({
2401
+ message: ['Field 760 has invalid ending punctuation'],
2402
+ valid: false
2403
+ });
2404
+ });
2405
+
2406
+ // Fix tests; invalid->valid
2407
+ it('Repairs the invalid record - Remove punc $e (language field, strict)', async () => {
2408
+ const validator = await validatorFactory();
2409
+ const result = await validator.fix(recordInvalid);
2410
+ expect(recordInvalid.equalsTo(recordValid)).to.eql(true);
2411
+ expect(result).to.eql({
2412
+ message: ['Field 760 has invalid ending punctuation'],
2413
+ fix: ['Field 760 - Removed punctuation from $e'],
2414
+ valid: false
2415
+ });
2416
+ });
2417
+
2418
+ it('Repairs the invalid record - Add punc $a (only)', async () => {
2419
+ const validator = await validatorFactory();
2420
+ const result = await validator.fix(recordInvalidOnlyA);
2421
+ expect(recordInvalidOnlyA.equalsTo(recordValidOnlyA)).to.eql(true);
2422
+ expect(result).to.eql({
2423
+ message: ['Field 760 has invalid ending punctuation'],
2424
+ fix: ['Field 760 - Added punctuation to $a'],
2425
+ valid: false
2426
+ });
2427
+ });
2428
+ });
2429
+
2430
+ // "`880`-kenttä: https://www.kansalliskirjasto.fi/extra/marc21/bib/841-88X.htm#880 Eli tää on se Loppupisteohjeen `Samoin kuin vastaavat kentät` -keissi
2431
+ // Spex on siinä, mutta lyhkäsesti: `880`-kentässä on muiden kenttien translitteroidut versiot (Data eri kirjaimistolla). 880-kentän osakentästä `6` selviää mihin kenttää se linkkaa."
2432
+ // 880 Samoin kuin vastaavat kentät - Siis tarkistetaan kontrollikentän $6 säännön
2433
+ describe('#880 - Like linked fields', () => {
2434
+ // Valid tests
2435
+ const recordValidSimple = new MarcRecord({
2436
+ leader: '',
2437
+ fields: [
2438
+ {
2439
+ tag: '880',
2440
+ ind1: ' ',
2441
+ ind2: ' ',
2442
+ subfields: [
2443
+ {code: 'a', value: '平田 篤胤'},
2444
+ {code: 'b', value: '1776-1843.'},
2445
+ {code: '6', value: '100-01/$1'} // Tag 100 has value TRUE -> last data subfield should have punc
2446
+ ]
2447
+ }
2448
+ ]
2449
+ });
2450
+
2451
+ const recordValidComplex = new MarcRecord({
2452
+ leader: '',
2453
+ fields: [
2454
+ {
2455
+ tag: '880',
2456
+ ind1: ' ',
2457
+ ind2: ' ',
2458
+ subfields: [
2459
+ {code: 'b', value: 'ידיעות אחרונות'},
2460
+ {code: 'b', value: 'ספרי חמד'},
2461
+ {code: 'c', value: '2006.'},
2462
+ {code: '6', value: '260-02/(2/r ‡a תל-אביב'} // Tag 260 has value TRUE -> last data subfield should have punc
2463
+ ]
2464
+ }
2465
+ ]
2466
+ });
2467
+
2468
+ it('Finds record valid - Punc $b', async () => {
2469
+ const validator = await validatorFactory();
2470
+ const result = await validator.validate(recordValidSimple);
2471
+ expect(result.valid).to.eql(true);
2472
+ });
2473
+
2474
+ it('Finds record valid - Punc $c', async () => {
2475
+ const validator = await validatorFactory();
2476
+ const result = await validator.validate(recordValidComplex);
2477
+ expect(result.valid).to.eql(true);
2478
+ });
2479
+
2480
+ // Invalid tests
2481
+ const recordInvalidSimple = new MarcRecord({
2482
+ leader: '',
2483
+ fields: [
2484
+ {
2485
+ tag: '880',
2486
+ ind1: ' ',
2487
+ ind2: ' ',
2488
+ subfields: [
2489
+ {code: 'a', value: '平田 篤胤'},
2490
+ {code: 'b', value: '1776-1843'},
2491
+ {code: '6', value: '100-01/$1'} // Tag 100 has value TRUE -> last data subfield should have punc
2492
+ ]
2493
+ }
2494
+ ]
2495
+ });
2496
+
2497
+ const recordInvalidComplex = new MarcRecord({
2498
+ leader: '',
2499
+ fields: [
2500
+ {
2501
+ tag: '880',
2502
+ ind1: ' ',
2503
+ ind2: ' ',
2504
+ subfields: [
2505
+ {code: 'b', value: 'ידיעות אחרונות'},
2506
+ {code: 'b', value: 'ספרי חמד'},
2507
+ {code: 'c', value: '2006'},
2508
+ {code: '6', value: '260-02/(2/r ‡a תל-אביב'} // Tag 260 has value TRUE -> last data subfield should have punc
2509
+ ]
2510
+ }
2511
+ ]
2512
+ });
2513
+
2514
+ it('Finds record invalid - No punc $b', async () => {
2515
+ const validator = await validatorFactory();
2516
+ const result = await validator.validate(recordInvalidSimple);
2517
+ expect(result).to.eql({
2518
+ message: ['Field 880 has invalid ending punctuation'],
2519
+ valid: false
2520
+ });
2521
+ });
2522
+
2523
+ it('Finds record invalid - No punc $c', async () => {
2524
+ const validator = await validatorFactory();
2525
+ const result = await validator.validate(recordInvalidComplex);
2526
+ expect(result).to.eql({
2527
+ message: ['Field 880 has invalid ending punctuation'],
2528
+ valid: false
2529
+ });
2530
+ });
2531
+
2532
+ // Fix tests; invalid->valid
2533
+ it('Repairs the invalid record - Add punc $b', async () => {
2534
+ const validator = await validatorFactory();
2535
+ const result = await validator.fix(recordInvalidSimple);
2536
+ expect(recordInvalidSimple.equalsTo(recordValidSimple)).to.eql(true);
2537
+ expect(result).to.eql({
2538
+ message: ['Field 880 has invalid ending punctuation'],
2539
+ fix: ['Field 880 - Added punctuation to $b'],
2540
+ valid: false
2541
+ });
2542
+ });
2543
+
2544
+ it('Repairs the invalid record - Add punc $c', async () => {
2545
+ const validator = await validatorFactory();
2546
+ const result = await validator.fix(recordInvalidComplex);
2547
+ expect(recordInvalidComplex.equalsTo(recordValidComplex)).to.eql(true);
2548
+ expect(result).to.eql({
2549
+ message: ['Field 880 has invalid ending punctuation'],
2550
+ fix: ['Field 880 - Added punctuation to $c'],
2551
+ valid: false
2552
+ });
2553
+ });
2554
+ });
2555
+ });
2333
2556
  });