proskomma-core 0.9.12 → 0.9.13

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 (167) hide show
  1. package/esm/wrapper.mjs +1 -1
  2. package/{index.js → index.cjs} +1 -1
  3. package/package.json +2 -2
  4. package/babel.config.js +0 -18
  5. package/test/code/main/bad.cjs +0 -79
  6. package/test/code/main/basics.cjs +0 -534
  7. package/test/code/main/block.cjs +0 -586
  8. package/test/code/main/block_scope_numbers.cjs +0 -31
  9. package/test/code/main/blocks_with_atts.cjs +0 -150
  10. package/test/code/main/blocks_with_cv.cjs +0 -250
  11. package/test/code/main/break.cjs +0 -73
  12. package/test/code/main/checksum.cjs +0 -36
  13. package/test/code/main/cl_global.cjs +0 -35
  14. package/test/code/main/class_for_fragment.cjs +0 -18
  15. package/test/code/main/clean_usfm.cjs +0 -46
  16. package/test/code/main/cp_vp.cjs +0 -158
  17. package/test/code/main/custom.cjs +0 -124
  18. package/test/code/main/cv.cjs +0 -249
  19. package/test/code/main/cvMatching.cjs +0 -155
  20. package/test/code/main/cv_indexes.cjs +0 -189
  21. package/test/code/main/cv_navigation.cjs +0 -124
  22. package/test/code/main/document.cjs +0 -382
  23. package/test/code/main/empty_blocks.cjs +0 -71
  24. package/test/code/main/entries.cjs +0 -402
  25. package/test/code/main/export_lexing_regexes.cjs +0 -19
  26. package/test/code/main/fig.cjs +0 -67
  27. package/test/code/main/filter.cjs +0 -222
  28. package/test/code/main/glossary.cjs +0 -36
  29. package/test/code/main/graft_headings.cjs +0 -36
  30. package/test/code/main/graft_introduction.cjs +0 -96
  31. package/test/code/main/graft_note.cjs +0 -104
  32. package/test/code/main/graft_rems.cjs +0 -34
  33. package/test/code/main/graft_sidebars.cjs +0 -62
  34. package/test/code/main/graft_title.cjs +0 -36
  35. package/test/code/main/hello.cjs +0 -105
  36. package/test/code/main/import_document.cjs +0 -22
  37. package/test/code/main/import_usfm_int.cjs +0 -48
  38. package/test/code/main/item_groups.cjs +0 -133
  39. package/test/code/main/items_with_cv.cjs +0 -311
  40. package/test/code/main/milestone_attributes.cjs +0 -163
  41. package/test/code/main/mixed_sequence_documents.cjs +0 -137
  42. package/test/code/main/mixed_sequences.cjs +0 -217
  43. package/test/code/main/modify_sequence.cjs +0 -29
  44. package/test/code/main/multiple_chapters.cjs +0 -58
  45. package/test/code/main/multiple_content.cjs +0 -105
  46. package/test/code/main/mutate_add.cjs +0 -180
  47. package/test/code/main/mutate_delete.cjs +0 -236
  48. package/test/code/main/mutate_rehash.cjs +0 -68
  49. package/test/code/main/mutate_tags.cjs +0 -90
  50. package/test/code/main/mutate_update.cjs +0 -538
  51. package/test/code/main/selectors.cjs +0 -289
  52. package/test/code/main/sequence.cjs +0 -361
  53. package/test/code/main/serialize.cjs +0 -104
  54. package/test/code/main/spans.cjs +0 -51
  55. package/test/code/main/split_long_tokens.cjs +0 -30
  56. package/test/code/main/standard_vrs.cjs +0 -76
  57. package/test/code/main/subclass.cjs +0 -25
  58. package/test/code/main/table.cjs +0 -119
  59. package/test/code/main/tags.cjs +0 -248
  60. package/test/code/main/token_alignment.cjs +0 -84
  61. package/test/code/main/trees.cjs +0 -211
  62. package/test/code/main/tribos.cjs +0 -865
  63. package/test/code/main/tsv.cjs +0 -385
  64. package/test/code/main/usx_ref.cjs +0 -65
  65. package/test/code/main/verse_mapping.cjs +0 -252
  66. package/test/code/main/verse_range.cjs +0 -31
  67. package/test/code/main/word_likes.cjs +0 -41
  68. package/test/code/utils/byte_array.cjs +0 -271
  69. package/test/code/utils/canons.cjs +0 -20
  70. package/test/code/utils/generate_id.cjs +0 -17
  71. package/test/code/utils/graft_defs.cjs +0 -16
  72. package/test/code/utils/inspect.cjs +0 -130
  73. package/test/code/utils/items.cjs +0 -56
  74. package/test/code/utils/push_succinct.cjs +0 -69
  75. package/test/code/utils/scope_defs.cjs +0 -79
  76. package/test/code/utils/serialize.cjs +0 -28
  77. package/test/code/utils/splice.cjs +0 -67
  78. package/test/code/utils/tags.cjs +0 -69
  79. package/test/code/utils/versification.cjs +0 -249
  80. package/test/lib/load.js +0 -110
  81. package/test/skipped_code/diff.js +0 -53
  82. package/test/test_data/inputBlockSpec/dodson.json +0 -1654
  83. package/test/test_data/inputBlockSpec/kv.json +0 -326
  84. package/test/test_data/inputBlockSpec/mk1.json +0 -1019
  85. package/test/test_data/inputBlockSpec/table.json +0 -170
  86. package/test/test_data/tree/genealogy.json +0 -55
  87. package/test/test_data/tree/jude.json +0 -15965
  88. package/test/test_data/tsv/en_tn_66-JUD.tsv +0 -75
  89. package/test/test_data/tsv/twl_JUD.tsv +0 -144
  90. package/test/test_data/usfm/1pe_webbe.usfm +0 -13
  91. package/test/test_data/usfm/66-JUD-ust.usfm +0 -1089
  92. package/test/test_data/usfm/78-GALspavbl.usfm +0 -10
  93. package/test/test_data/usfm/add_test.usfm +0 -15
  94. package/test/test_data/usfm/backslash.usfm +0 -4
  95. package/test/test_data/usfm/cl.usfm +0 -14
  96. package/test/test_data/usfm/cp_vp.usfm +0 -8
  97. package/test/test_data/usfm/custom.usfm +0 -13
  98. package/test/test_data/usfm/en_ust_oba.usfm +0 -875
  99. package/test/test_data/usfm/en_ust_psa_1.usfm +0 -20
  100. package/test/test_data/usfm/fig.usfm +0 -3
  101. package/test/test_data/usfm/filter.usfm +0 -7
  102. package/test/test_data/usfm/footnote.usfm +0 -11
  103. package/test/test_data/usfm/frt.usfm +0 -4
  104. package/test/test_data/usfm/headings.usfm +0 -7
  105. package/test/test_data/usfm/hello.usfm +0 -8
  106. package/test/test_data/usfm/int.usfm +0 -7
  107. package/test/test_data/usfm/milestone_attributes.usfm +0 -7
  108. package/test/test_data/usfm/milestone_attributes_default.usfm +0 -7
  109. package/test/test_data/usfm/no_break_space.usfm +0 -4
  110. package/test/test_data/usfm/no_mt.usfm +0 -6
  111. package/test/test_data/usfm/rems.usfm +0 -6
  112. package/test/test_data/usfm/section_intros.usfm +0 -26
  113. package/test/test_data/usfm/sidebars.usfm +0 -25
  114. package/test/test_data/usfm/slash_in_att.usfm +0 -6
  115. package/test/test_data/usfm/soft_line_break.usfm +0 -4
  116. package/test/test_data/usfm/spans.usfm +0 -5
  117. package/test/test_data/usfm/split_long_tokens.usfm +0 -6
  118. package/test/test_data/usfm/table.usfm +0 -18
  119. package/test/test_data/usfm/table_at_end.usfm +0 -11
  120. package/test/test_data/usfm/table_in_intro.usfm +0 -22
  121. package/test/test_data/usfm/table_no_end_cells.usfm +0 -18
  122. package/test/test_data/usfm/tit_kitchen_sink.usfm +0 -73
  123. package/test/test_data/usfm/titus_template.usfm +0 -58
  124. package/test/test_data/usfm/ugnt_3jn.usfm +0 -265
  125. package/test/test_data/usfm/ult_3jn.usfm +0 -335
  126. package/test/test_data/usfm/unknown.usfm +0 -5
  127. package/test/test_data/usfm/ust_psa.usfm +0 -29
  128. package/test/test_data/usfm/ust_psa_verse_ranges.usfm +0 -24
  129. package/test/test_data/usfm/ust_psa_with_ts.usfm +0 -29
  130. package/test/test_data/usfm/verse_breaks_in_blocks.usfm +0 -20
  131. package/test/test_data/usfm/verse_range.usfm +0 -7
  132. package/test/test_data/usfm/web_ecc.usfm +0 -391
  133. package/test/test_data/usfm/web_psa51.usfm +0 -71
  134. package/test/test_data/usfm/whitespace.usfm +0 -12
  135. package/test/test_data/usfm/xref.usfm +0 -11
  136. package/test/test_data/usx/bad_element.usx +0 -2
  137. package/test/test_data/usx/cp_vp.usx +0 -12
  138. package/test/test_data/usx/diff1.usx +0 -59
  139. package/test/test_data/usx/diff2.usx +0 -74
  140. package/test/test_data/usx/douay_rheims_ecc.usx +0 -58
  141. package/test/test_data/usx/douay_rheims_psa.usx +0 -5366
  142. package/test/test_data/usx/douay_rheims_psa_40_60.usx +0 -666
  143. package/test/test_data/usx/douay_rheims_rut.usx +0 -26
  144. package/test/test_data/usx/esg3.usx +0 -47
  145. package/test/test_data/usx/fig.usx +0 -6
  146. package/test/test_data/usx/milestone_attributes.usx +0 -11
  147. package/test/test_data/usx/not_nfc18_glo.usx +0 -9
  148. package/test/test_data/usx/not_nfc18_phm.usx +0 -24
  149. package/test/test_data/usx/opt_break.usx +0 -10
  150. package/test/test_data/usx/sidebars.usx +0 -29
  151. package/test/test_data/usx/table.usx +0 -23
  152. package/test/test_data/usx/web_psa.usx +0 -8489
  153. package/test/test_data/usx/web_psa150.usx +0 -33
  154. package/test/test_data/usx/web_psa_40_60.usx +0 -1079
  155. package/test/test_data/usx/web_rut.usx +0 -95
  156. package/test/test_data/usx/web_rut_1.usx +0 -17
  157. package/test/test_data/utils/douay_rheims.vrs +0 -520
  158. package/test/test_data/utils/douay_rheims_PSA.usx +0 -5366
  159. package/test/test_data/utils/serialize_example.json +0 -91
  160. package/test/test_data/utils/truncated_versification.vrs +0 -29
  161. package/test/test_data/utils/web_rut_items.json +0 -2977
  162. package/test/test_data/utils/webbe.vrs +0 -395
  163. package/test/test_data/utils/webbe_PSA.usx +0 -8489
  164. package/test/test_data/vrs/douay_rheims.vrs +0 -520
  165. package/test/test_data/vrs/truncated_versification.vrs +0 -27
  166. package/test/test_data/vrs/webbe.vrs +0 -397
  167. package/webpack.prod.js +0 -50
@@ -1,538 +0,0 @@
1
- /* eslint-disable no-unused-vars */
2
- const path = require('path');
3
- const fse = require('fs-extra');
4
- const test = require('tape');
5
- const deepCopy = require('deep-copy-all');
6
- const { pkWithDoc } = require('../../lib/load.js');
7
- const {
8
- blocksSpec2Query, object2Query, oneObject2Query,
9
- } = require('../../../src/util/scriptlike/blocksSpec.cjs');
10
-
11
- const testGroup = 'Mutate Update Operations';
12
-
13
- const cleanPk = pkWithDoc('../test_data/usx/web_rut.usx', {
14
- lang: 'eng',
15
- abbr: 'ust',
16
- }, {}, {}, [], [])[0];
17
-
18
- const cleanPk2 = pkWithDoc('../test_data/usfm/ust_psa.usfm', {
19
- lang: 'eng',
20
- abbr: 'ust',
21
- }, {}, {}, [], [])[0];
22
-
23
- const cleanPk3 = pkWithDoc('../test_data/usfm/milestone_attributes.usfm', {
24
- lang: 'eng',
25
- abbr: 'ust',
26
- }, {}, {}, [], [])[0];
27
-
28
- const blockSetup = async t => {
29
- const pk = deepCopy(cleanPk);
30
- let query = '{docSets { id documents { id nSequences sequences { id type } mainSequence { id blocks(positions: [0]) { bs { payload } text items { type subType payload } } } } } }';
31
- let result = await pk.gqlQuery(query);
32
- t.equal(result.errors, undefined);
33
- t.equal(result.data.docSets.length, 1);
34
- const docSet = result.data.docSets[0];
35
- const document = docSet.documents[0];
36
- const sequence = document.mainSequence;
37
- let block = sequence.blocks[0];
38
- const items = block.items;
39
- return [pk, docSet, document, sequence, block, items];
40
- };
41
-
42
- const perfSetup = async t => {
43
- const pk = deepCopy(cleanPk3);
44
- let query = '{docSets { id documents { id perf mainSequence { id } } } }';
45
- let result = await pk.gqlQuery(query);
46
- t.equal(result.errors, undefined);
47
- t.equal(result.data.docSets.length, 1);
48
- const docSetId = result.data.docSets[0].id;
49
- const documentId = result.data.docSets[0].documents[0].id;
50
- const sequenceId = result.data.docSets[0].documents[0].mainSequence.id;
51
- const perf = JSON.parse(result.data.docSets[0].documents[0].perf);
52
- const perfSequence = JSON.stringify(perf.sequences[perf.main_sequence_id]);
53
- return [pk, docSetId, documentId, sequenceId, perfSequence];
54
- };
55
-
56
- const searchScopes = (items, searchStr) => items.filter(i => i.type === 'scope' && i.payload.includes(searchStr));
57
- const searchGrafts = (items, searchStr) => items.filter(i => i.type === 'graft' && i.subType.includes(searchStr));
58
-
59
- const blocksSpec = fse.readJSONSync(path.resolve(__dirname, '../../test_data/inputBlockSpec/mk1.json'));
60
-
61
- test(
62
- `updateItems args exceptions (${testGroup})`,
63
- async function (t) {
64
- try {
65
- t.plan(6);
66
- let [pk, docSet, document, sequence, block, items] = await blockSetup(t);
67
- let query = `mutation { updateItems(` +
68
- `docSetId: "1234"` +
69
- ` documentId: "${document.id}"` +
70
- ` sequenceId: "${sequence.id}"` +
71
- ` blockPosition: 0` +
72
- ` items: ${object2Query(items)}) }`;
73
- let result = await pk.gqlQuery(query);
74
- t.equal(result.errors[0].message, 'DocSet \'1234\' not found');
75
- query = `mutation { updateItems(` +
76
- `docSetId: "${docSet.id}"` +
77
- ` documentId: "5678"` +
78
- ` sequenceId: "${sequence.id}"` +
79
- ` blockPosition: 0` +
80
- ` items: ${object2Query(items)}) }`;
81
- result = await pk.gqlQuery(query);
82
- t.equal(result.errors[0].message, 'Document \'5678\' not found');
83
- query = `mutation { updateItems(` +
84
- `docSetId: "${docSet.id}"` +
85
- ` documentId: "${document.id}"` +
86
- ` sequenceId: "9012"` +
87
- ` blockPosition: 0` +
88
- ` items: ${object2Query(items)}) }`;
89
- result = await pk.gqlQuery(query);
90
- t.equal(result.errors[0].message, 'Sequence \'9012\' not found');
91
- query = `mutation { updateItems(` +
92
- `docSetId: "${docSet.id}"` +
93
- ` documentId: "${document.id}"` +
94
- ` sequenceId: "${sequence.id}"` +
95
- ` blockPosition: 1000` +
96
- ` items: ${object2Query(items)}) }`;
97
- result = await pk.gqlQuery(query);
98
- t.equal(result.errors[0].message, 'Could not find block 1000 (length=42)');
99
- } catch (err) {
100
- console.log(err);
101
- }
102
- },
103
- );
104
-
105
- test(
106
- `updateItems, existing token enums (${testGroup})`,
107
- async function (t) {
108
- try {
109
- t.plan(10);
110
- let [pk, docSet, document, sequence, block, items] = await blockSetup(t);
111
- t.ok(block.text.includes('country'));
112
- t.ok(block.text.includes('land'));
113
-
114
- const newItems = items
115
- .map(i => (
116
- {
117
- type: i.type,
118
- subType: i.subType,
119
- payload: i.payload.replace('country', 'land'),
120
- }
121
- ));
122
-
123
- let query = `mutation { updateItems(` +
124
- `docSetId: "${docSet.id}"` +
125
- ` documentId: "${document.id}"` +
126
- ` sequenceId: "${sequence.id}"` +
127
- ` blockPosition: 0` +
128
- ` items: ${object2Query(newItems)}) }`;
129
- let result = await pk.gqlQuery(query);
130
- t.equal(result.errors, undefined);
131
- t.equal(result.data.updateItems, true);
132
- query = '{docSets { id documents { id mainSequence { id blocks(positions: [0]) { text } } } } }';
133
- result = await pk.gqlQuery(query);
134
- t.equal(result.errors, undefined);
135
- t.equal(result.data.docSets.length, 1);
136
- block = result.data.docSets[0].documents[0].mainSequence.blocks[0];
137
- t.ok(!block.text.includes('country'));
138
- t.ok(block.text.includes('land'));
139
- } catch (err) {
140
- console.log(err);
141
- }
142
- },
143
- );
144
-
145
- test(
146
- `updateItems, new token enum (${testGroup})`,
147
- async function (t) {
148
- try {
149
- t.plan(10);
150
- let [pk, docSet, document, sequence, block, items] = await blockSetup(t);
151
- t.ok(block.text.includes('country'));
152
- t.ok(!block.text.includes('nation'));
153
-
154
- const newItemObjects = items
155
- .map(i => (
156
- {
157
- type: i.type,
158
- subType: i.subType,
159
- payload: i.payload.replace('country', 'nation'),
160
- }
161
- ));
162
-
163
- let query = `mutation { updateItems(` +
164
- `docSetId: "${docSet.id}"` +
165
- ` documentId: "${document.id}"` +
166
- ` sequenceId: "${sequence.id}"` +
167
- ` blockPosition: 0` +
168
- ` items: ${object2Query(newItemObjects)}) }`;
169
- let result = await pk.gqlQuery(query);
170
- t.equal(result.errors, undefined);
171
- t.equal(result.data.updateItems, true);
172
- query = '{docSets { id documents { id mainSequence { id blocks(positions: [0]) { text } } } } }';
173
- result = await pk.gqlQuery(query);
174
- t.equal(result.errors, undefined);
175
- t.equal(result.data.docSets.length, 1);
176
- block = result.data.docSets[0].documents[0].mainSequence.blocks[0];
177
- t.ok(!block.text.includes('country'));
178
- t.ok(block.text.includes('nation'));
179
- } catch (err) {
180
- console.log(err);
181
- }
182
- },
183
- );
184
-
185
- test(
186
- `updateItems - add blockGraft (${testGroup})`,
187
- async function (t) {
188
- try {
189
- t.plan(9);
190
- let [pk, docSet, document, sequence, block, items] = await blockSetup(t);
191
- const titleId = document.sequences.filter(s => s.type === 'title')[0].id;
192
- let query = `mutation { updateItems(` +
193
- `docSetId: "${docSet.id}"` +
194
- ` documentId: "${document.id}"` +
195
- ` sequenceId: "${sequence.id}"` +
196
- ` blockPosition: 0` +
197
- ` items: ${object2Query(items)}` +
198
- ` blockGrafts: ${object2Query([{
199
- type: 'graft',
200
- subType: 'title',
201
- payload: titleId,
202
- }])}` +
203
- `) }`;
204
- let result = await pk.gqlQuery(query);
205
- t.equal(result.errors, undefined);
206
- t.equal(result.data.updateItems, true);
207
- query = '{docSets { id documents { id mainSequence { id blocks(positions: [0]) { bg { subType payload } text } } } } }';
208
- result = await pk.gqlQuery(query);
209
- t.equal(result.errors, undefined);
210
- t.equal(result.data.docSets.length, 1);
211
- block = result.data.docSets[0].documents[0].mainSequence.blocks[0];
212
- t.equal(block.bg.length, 1);
213
- t.equal(block.bg[0].subType, 'title');
214
- t.equal(block.bg[0].payload, titleId);
215
- } catch (err) {
216
- console.log(err);
217
- }
218
- },
219
- );
220
-
221
- test(
222
- `updateItems - change BlockScope (${testGroup})`,
223
- async function (t) {
224
- try {
225
- t.plan(8);
226
- let [pk, docSet, document, sequence, block, items] = await blockSetup(t);
227
- const bs = block.bs.payload;
228
- t.equal(bs, 'blockTag/p');
229
- let query = `mutation { updateItems(` +
230
- `docSetId: "${docSet.id}"` +
231
- ` documentId: "${document.id}"` +
232
- ` sequenceId: "${sequence.id}"` +
233
- ` blockPosition: 0` +
234
- ` items: ${object2Query(items)}` +
235
- ` blockScope: ${oneObject2Query({
236
- type: 'scope',
237
- subType: 'start',
238
- payload: 'blockTag/q',
239
- })}` +
240
- `) }`;
241
- let result = await pk.gqlQuery(query);
242
- t.equal(result.errors, undefined);
243
- t.equal(result.data.updateItems, true);
244
- query = '{docSets { id documents { id mainSequence { id blocks(positions: [0]) { bs { payload } text } } } } }';
245
- result = await pk.gqlQuery(query);
246
- t.equal(result.errors, undefined);
247
- t.equal(result.data.docSets.length, 1);
248
- block = result.data.docSets[0].documents[0].mainSequence.blocks[0];
249
- t.equal(block.bs.payload, 'blockTag/q');
250
- } catch (err) {
251
- console.log(err);
252
- }
253
- },
254
- );
255
-
256
- test(
257
- `updateItems, new scope enum (${testGroup})`,
258
- async function (t) {
259
- try {
260
- t.plan(10);
261
- let [pk, docSet, document, sequence, block, items] = await blockSetup(t);
262
- t.equal(searchScopes(items, '/1').length, 5);
263
- t.equal(searchScopes(items, '/23').length, 0);
264
-
265
- const newItemObjects = items
266
- .map(i => (
267
- {
268
- type: i.type,
269
- subType: i.subType,
270
- payload: i.payload.replace(/1$/g, '23'),
271
- }
272
- ));
273
-
274
- let query = `mutation { updateItems(` +
275
- `docSetId: "${docSet.id}"` +
276
- ` documentId: "${document.id}"` +
277
- ` sequenceId: "${sequence.id}"` +
278
- ` blockPosition: 0` +
279
- ` items: ${object2Query(newItemObjects)}) }`;
280
- let result = await pk.gqlQuery(query);
281
- t.equal(result.errors, undefined);
282
- t.equal(result.data.updateItems, true);
283
- query = '{docSets { id documents { id mainSequence { id blocks(positions: [0]) { text items { type subType payload } } } } } }';
284
- result = await pk.gqlQuery(query);
285
- t.equal(result.errors, undefined);
286
- t.equal(result.data.docSets.length, 1);
287
- block = result.data.docSets[0].documents[0].mainSequence.blocks[0];
288
- t.equal(searchScopes(block.items, '/1').length, 0);
289
- t.equal(searchScopes(block.items, '/23').length, 5);
290
- } catch (err) {
291
- console.log(err);
292
- }
293
- },
294
- );
295
-
296
- test(
297
- `updateItems, new open-and-closed scope (${testGroup})`,
298
- async function (t) {
299
- try {
300
- t.plan(8);
301
- let [pk, docSet, document, sequence, block, items] = await blockSetup(t);
302
- t.ok(!block.text.includes('banana'));
303
-
304
- const newItems = items.concat([
305
- {
306
- type: 'scope',
307
- subType: 'start',
308
- payload: 'span/bd',
309
- },
310
- {
311
- type: 'token',
312
- subType: 'wordLike',
313
- payload: 'banana',
314
- },
315
- {
316
- type: 'scope',
317
- subType: 'end',
318
- payload: 'span/bd',
319
- },
320
- ]);
321
- let query = `mutation { updateItems(` +
322
- `docSetId: "${docSet.id}"` +
323
- ` documentId: "${document.id}"` +
324
- ` sequenceId: "${sequence.id}"` +
325
- ` blockPosition: 0` +
326
- ` items: ${object2Query(newItems)}) }`;
327
- let result = await pk.gqlQuery(query);
328
- t.equal(result.errors, undefined);
329
- t.equal(result.data.updateItems, true);
330
- query = '{docSets { id documents { id mainSequence { id blocks(positions: [0]) { text } } } } }';
331
- result = await pk.gqlQuery(query);
332
- t.equal(result.errors, undefined);
333
- t.equal(result.data.docSets.length, 1);
334
- block = result.data.docSets[0].documents[0].mainSequence.blocks[0];
335
- t.ok(block.text.includes('banana'));
336
- } catch (err) {
337
- console.log(err);
338
- }
339
- },
340
- );
341
-
342
- test(
343
- `updateItems, scope type exception (${testGroup})`,
344
- async function (t) {
345
- try {
346
- t.plan(4);
347
- let [pk, docSet, document, sequence, block, items] = await blockSetup(t);
348
-
349
- const newItemObjects = items
350
- .map(i => (
351
- {
352
- type: i.type,
353
- subType: i.subType,
354
- payload: i.payload.replace(/chapter/g, 'BANANA'),
355
- }
356
- ));
357
-
358
- let query = `mutation { updateItems(` +
359
- `docSetId: "${docSet.id}"` +
360
- ` documentId: "${document.id}"` +
361
- ` blockPosition: 0` +
362
- ` items: ${object2Query(newItemObjects)}) }`;
363
- let result = await pk.gqlQuery(query);
364
- t.equal(result.errors.length, 1);
365
- t.ok(result.errors[0].message.includes('BANANA'));
366
- } catch (err) {
367
- console.log(err);
368
- }
369
- },
370
- );
371
-
372
- test(
373
- `updateItems, new graft enum (${testGroup})`,
374
- async function (t) {
375
- try {
376
- t.plan(10);
377
- let [pk, docSet, document, sequence, block, items] = await blockSetup(t);
378
- t.equal(searchGrafts(items, 'footnote').length, 1);
379
- t.equal(searchGrafts(items, 'BANANA').length, 0);
380
-
381
- const newItemObjects = items
382
- .map(i => (
383
- {
384
- type: i.type,
385
- subType: i.subType.replace(/footnote/g, 'BANANA'),
386
- payload: i.payload,
387
- }
388
- ));
389
-
390
- let query = `mutation { updateItems(` +
391
- `docSetId: "${docSet.id}"` +
392
- ` documentId: "${document.id}"` +
393
- ` sequenceId: "${sequence.id}"` +
394
- ` blockPosition: 0` +
395
- ` items: ${object2Query(newItemObjects)}) }`;
396
- let result = await pk.gqlQuery(query);
397
- t.equal(result.errors, undefined);
398
- t.equal(result.data.updateItems, true);
399
- query = '{docSets { id documents { id mainSequence { id blocks(positions: [0]) { text items { type subType payload } } } } } }';
400
- result = await pk.gqlQuery(query);
401
- t.equal(result.errors, undefined);
402
- t.equal(result.data.docSets.length, 1);
403
- block = result.data.docSets[0].documents[0].mainSequence.blocks[0];
404
- t.equal(searchGrafts(block.items, 'footnote').length, 0);
405
- t.equal(searchGrafts(block.items, 'BANANA').length, 1);
406
- } catch (err) {
407
- console.log(err);
408
- }
409
- },
410
- );
411
-
412
- test(
413
- `updateBlocks (${testGroup})`,
414
- async function (t) {
415
- try {
416
- t.plan(16);
417
- let [pk, docSet, document, sequence, block, items] = await blockSetup(t);
418
- const blockQuery = blocksSpec2Query(blocksSpec);
419
- let query = `mutation { updateAllBlocks(` +
420
- `docSetId: "${docSet.id}"` +
421
- ` documentId: "${document.id}"` +
422
- ` sequenceId: "${sequence.id}"` +
423
- ` blocksSpec: ${blockQuery}) }`;
424
- let result = await pk.gqlQuery(query);
425
- t.equal(result.errors, undefined);
426
- t.equal(result.data.updateAllBlocks, true);
427
- query = '{documents { mainSequence { id blocks { text bs {payload} bg {subType payload} } } } }';
428
- result = await pk.gqlQuery(query);
429
- t.equal(result.errors, undefined);
430
- const mainSequence = result.data.documents[0].mainSequence;
431
- t.equal(mainSequence.blocks.length, 7);
432
- t.ok(mainSequence.blocks[0].text.startsWith('Start of'));
433
- t.equal(mainSequence.blocks[0].bs.payload, 'blockTag/m');
434
- t.equal(mainSequence.blocks[0].bg.length, 1);
435
- t.equal(mainSequence.blocks[0].bg[0].subType, 'title');
436
- query = '{documents { mainSequence { id blocks { is {payload} os {payload} tokens { type subType payload } } } } }';
437
- result = await pk.gqlQuery(query);
438
- t.equal(result.errors, undefined);
439
- t.equal(result.data.documents[0].mainSequence.blocks[0].tokens[0].payload, 'Start');
440
- t.ok(result.data.documents[0].mainSequence.blocks[0].is.map(s => s.payload).includes('chapter/1'));
441
- t.ok(result.data.documents[0].mainSequence.blocks[1].os.map(s => s.payload).includes('chapter/1'));
442
- t.ok(result.data.documents[0].mainSequence.blocks[0].is.map(s => s.payload).includes('verse/1'));
443
- t.ok(result.data.documents[0].mainSequence.blocks[4].is.map(s => s.payload).includes('verses/3'));
444
- } catch (err) {
445
- console.log(err);
446
- }
447
- },
448
- );
449
-
450
- test(
451
- `Roundtrip (non-)update from PERF (${testGroup})`,
452
- async function (t) {
453
- try {
454
- t.plan(6);
455
- let [pk, docSetId, documentId, sequenceId, perf] = await perfSetup(t);
456
- let query = `mutation { updateSequenceFromPerf(` +
457
- `docSetId: "${docSetId}"` +
458
- ` documentId: "${documentId}"` +
459
- ` sequenceId: "${sequenceId}"` +
460
- ` perf: """${perf}""") }`;
461
- let result = await pk.gqlQuery(query);
462
- t.equal(result.errors, undefined);
463
- t.equal(result.data.updateSequenceFromPerf, true);
464
- query = '{documents { perf } }';
465
- result = await pk.gqlQuery(query);
466
- t.equal(result.errors, undefined);
467
- const newPerf = Object.values(JSON.parse(result.data.documents[0].perf).sequences).filter(s => s.type === 'main')[0];
468
- t.equal(perf, JSON.stringify(newPerf));
469
- } catch (err) {
470
- console.log(err);
471
- }
472
- },
473
- );
474
-
475
- test(
476
- `Update from PERF (${testGroup})`,
477
- async function (t) {
478
- try {
479
- t.plan(7);
480
- let [pk, docSetId, documentId, sequenceId, perf] = await perfSetup(t);
481
- perf = perf.replace(/Obadiah/g, 'OBADIAH');
482
- let query = `mutation { updateSequenceFromPerf(` +
483
- `docSetId: "${docSetId}"` +
484
- ` documentId: "${documentId}"` +
485
- ` sequenceId: "${sequenceId}"` +
486
- ` perf: """${perf}""") }`;
487
- let result = await pk.gqlQuery(query);
488
- t.equal(result.errors, undefined);
489
- t.equal(result.data.updateSequenceFromPerf, true);
490
- query = '{documents { perf } }';
491
- result = await pk.gqlQuery(query);
492
- t.equal(result.errors, undefined);
493
- const newPerf = JSON.stringify(Object.values(JSON.parse(result.data.documents[0].perf).sequences).filter(s => s.type === 'main')[0]);
494
- t.notOk(newPerf.includes('Obadiah'));
495
- t.ok(newPerf.includes('OBADIAH'));
496
- } catch (err) {
497
- console.log(err);
498
- }
499
- },
500
- );
501
-
502
- test(
503
- `gcSequences (${testGroup})`,
504
- async function (t) {
505
- try {
506
- t.plan(10);
507
- let [pk, docSet, document, sequence, block, items] = await blockSetup(t);
508
- const nSequences = document.nSequences;
509
- const newItemObjects = items.filter(i => i.type !== 'graft');
510
- let query = `mutation { updateItems(` +
511
- `docSetId: "${docSet.id}"` +
512
- ` documentId: "${document.id}"` +
513
- ` sequenceId: "${sequence.id}"` +
514
- ` blockPosition: 0` +
515
- ` items: ${object2Query(newItemObjects)}) }`;
516
- let result = await pk.gqlQuery(query);
517
- t.equal(result.errors, undefined);
518
- t.equal(result.data.updateItems, true);
519
- query = '{docSets { documents { nSequences } } }';
520
- result = await pk.gqlQuery(query);
521
- t.equal(result.errors, undefined);
522
- t.equal(result.data.docSets[0].documents[0].nSequences, nSequences);
523
- query = `mutation { gcSequences(` +
524
- `docSetId: "${docSet.id}"` +
525
- ` documentId: "${document.id}"` +
526
- `) }`;
527
- result = await pk.gqlQuery(query);
528
- t.equal(result.errors, undefined);
529
- t.equal(result.data.gcSequences, true);
530
- query = '{docSets { documents { nSequences } } }';
531
- result = await pk.gqlQuery(query);
532
- t.equal(result.errors, undefined);
533
- t.equal(result.data.docSets[0].documents[0].nSequences, nSequences - 2);
534
- } catch (err) {
535
- console.log(err);
536
- }
537
- },
538
- );