@opentermsarchive/engine 0.26.0 → 0.27.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (64) hide show
  1. package/README.md +1 -469
  2. package/bin/ota-track.js +3 -3
  3. package/bin/ota-validate.js +2 -2
  4. package/bin/ota.js +1 -1
  5. package/config/default.json +1 -1
  6. package/config/test.json +2 -2
  7. package/package.json +6 -7
  8. package/scripts/dataset/export/index.js +4 -4
  9. package/scripts/dataset/export/index.test.js +11 -17
  10. package/scripts/dataset/export/test/fixtures/dataset/README.md +1 -1
  11. package/scripts/declarations/lint/index.mocha.js +1 -1
  12. package/scripts/declarations/utils/index.js +12 -12
  13. package/scripts/declarations/validate/definitions.js +1 -1
  14. package/scripts/declarations/validate/index.mocha.js +30 -34
  15. package/scripts/declarations/validate/service.history.schema.js +11 -11
  16. package/scripts/declarations/validate/service.schema.js +13 -13
  17. package/scripts/history/migrate-services.js +4 -4
  18. package/scripts/history/update-to-full-hash.js +2 -2
  19. package/scripts/import/index.js +14 -14
  20. package/scripts/rewrite/config/rewrite-snapshots.json +1 -1
  21. package/scripts/rewrite/config/rewrite-versions.json +1 -1
  22. package/scripts/rewrite/rewrite-snapshots.js +3 -3
  23. package/scripts/rewrite/rewrite-versions.js +14 -14
  24. package/scripts/utils/renamer/README.md +3 -3
  25. package/scripts/utils/renamer/index.js +13 -13
  26. package/src/archivist/errors.js +1 -1
  27. package/src/archivist/extract/exports.js +3 -0
  28. package/src/archivist/{filter → extract}/index.js +23 -27
  29. package/src/archivist/extract/index.test.js +516 -0
  30. package/src/archivist/index.js +101 -140
  31. package/src/archivist/index.test.js +178 -166
  32. package/src/archivist/recorder/index.js +11 -55
  33. package/src/archivist/recorder/index.test.js +310 -356
  34. package/src/archivist/recorder/record.js +18 -7
  35. package/src/archivist/recorder/repositories/git/dataMapper.js +41 -31
  36. package/src/archivist/recorder/repositories/git/index.js +11 -15
  37. package/src/archivist/recorder/repositories/git/index.test.js +1058 -463
  38. package/src/archivist/recorder/repositories/interface.js +8 -6
  39. package/src/archivist/recorder/repositories/mongo/dataMapper.js +21 -14
  40. package/src/archivist/recorder/repositories/mongo/index.js +8 -8
  41. package/src/archivist/recorder/repositories/mongo/index.test.js +898 -479
  42. package/src/archivist/recorder/snapshot.js +5 -0
  43. package/src/archivist/recorder/snapshot.test.js +65 -0
  44. package/src/archivist/recorder/version.js +14 -0
  45. package/src/archivist/recorder/version.test.js +65 -0
  46. package/src/archivist/services/index.js +60 -51
  47. package/src/archivist/services/index.test.js +63 -83
  48. package/src/archivist/services/service.js +26 -22
  49. package/src/archivist/services/service.test.js +46 -68
  50. package/src/archivist/services/{pageDeclaration.js → sourceDocument.js} +11 -9
  51. package/src/archivist/services/{pageDeclaration.test.js → sourceDocument.test.js} +21 -21
  52. package/src/archivist/services/terms.js +26 -0
  53. package/src/archivist/services/{documentDeclaration.test.js → terms.test.js} +15 -15
  54. package/src/exports.js +2 -2
  55. package/src/index.js +16 -13
  56. package/src/logger/index.js +35 -36
  57. package/src/notifier/index.js +8 -8
  58. package/src/tracker/index.js +6 -6
  59. package/src/archivist/filter/exports.js +0 -3
  60. package/src/archivist/filter/index.test.js +0 -564
  61. package/src/archivist/recorder/record.test.js +0 -91
  62. package/src/archivist/services/documentDeclaration.js +0 -26
  63. /package/scripts/utils/renamer/rules/{documentTypes.json → termsTypes.json} +0 -0
  64. /package/scripts/utils/renamer/rules/{documentTypesByService.json → termsTypesByService.json} +0 -0
@@ -1,564 +0,0 @@
1
- import fsApi from 'fs';
2
- import path from 'path';
3
- import { fileURLToPath } from 'url';
4
-
5
- import chai from 'chai';
6
- import jsdom from 'jsdom';
7
-
8
- import { InaccessibleContentError } from '../errors.js';
9
- import PageDeclaration from '../services/pageDeclaration.js';
10
-
11
- import { convertRelativeURLsToAbsolute, filterHTML, filterPDF } from './index.js';
12
-
13
- const __dirname = path.dirname(fileURLToPath(import.meta.url));
14
- const fs = fsApi.promises;
15
- const { JSDOM } = jsdom;
16
- const { expect } = chai;
17
-
18
- const virtualLocation = 'https://exemple.com/main';
19
- const rawHTML = `
20
- <!DOCTYPE html>
21
- <html>
22
- <head>
23
- <meta charset="UTF-8">
24
- <title>TOS</title>
25
- </head>
26
- <body>
27
- <h1>Title</h1>
28
- <p><a id="link1" href="/relative/link">link 1</a></p>
29
- <p><a id="link2" href="#anchor">link 2</a></p>
30
- <p><a id="link3" href="http://absolute.url/link">link 3</a></p>
31
- <div id="empty"></div>
32
- <div id="whitespaceOnly"> </div>
33
- </body>
34
- </html>`;
35
-
36
- const expectedFiltered = `Title
37
- =====
38
-
39
- [link 1](https://exemple.com/relative/link)
40
-
41
- [link 2](#anchor)
42
-
43
- [link 3](http://absolute.url/link)`;
44
-
45
- const expectedFilteredWithAdditional = `Title
46
- =====`;
47
-
48
- const rawHTMLWithCommonChangingItems = `
49
- <!DOCTYPE html>
50
- <html>
51
- <head>
52
- <meta charset="UTF-8">
53
- <title>TOS</title>
54
- <style>body { background: red }</style>
55
- <script>console.log("test")</script>
56
- </head>
57
- <body>
58
- <style>body { background: blue }</style>
59
- <script>console.log("test")</script>
60
- <h1>Title</h1>
61
- <p><a id="link1" href="/relative/link">link 1</a></p>
62
- <p><a id="link2" href="#anchor">link 2</a></p>
63
- <p><a id="link3" href="http://absolute.url/link">link 3</a></p>
64
- <p><a id="link4" href="">link 4</a></p>
65
- <a href="/cdn-cgi/l/email-protection#3b4c52555f484f495e5a56154b49524d5a584215484f5a4f5e565e554f7b4c52555f484f495e5a5615585456">[email&#160;protected]</a>
66
- <p><a href="/cdn-cgi/l/email-protection#2d4e4243594c4e596d4e4459545e4e424259034858">conta<span>[email&#160;protected]</span></a></p>
67
- </body>
68
- </html>`;
69
-
70
- /* eslint-disable no-irregular-whitespace */
71
- const expectedFilteredWithCommonChangingItems = `Title
72
- =====
73
-
74
- [link 1](https://exemple.com/relative/link)
75
-
76
- [link 2](#anchor)
77
-
78
- [link 3](http://absolute.url/link)
79
-
80
- link 4
81
-
82
- [\\[email protected\\]](https://exemple.com/cdn-cgi/l/email-protection)
83
-
84
- [\\[email protected\\]](https://exemple.com/cdn-cgi/l/email-protection)`;
85
- /* eslint-enable no-irregular-whitespace */
86
-
87
- const additionalFilter = {
88
- removeLinks: function removeLinks(document) {
89
- const links = document.querySelectorAll('a');
90
-
91
- links.forEach(link => {
92
- link.remove();
93
- });
94
- },
95
- removeLinksAsync: async function removeLinksAsync(document) {
96
- return new Promise(resolve => {
97
- setTimeout(() => {
98
- const links = document.querySelectorAll('a');
99
-
100
- links.forEach(link => {
101
- link.remove();
102
- });
103
- resolve();
104
- }, 300);
105
- });
106
- },
107
- };
108
-
109
- describe('Filter', () => {
110
- describe('#convertRelativeURLsToAbsolute', () => {
111
- let subject;
112
-
113
- before(() => {
114
- const { document: webPageDOM } = new JSDOM(rawHTML).window;
115
-
116
- convertRelativeURLsToAbsolute(webPageDOM, virtualLocation);
117
- subject = Array.from(webPageDOM.querySelectorAll('a[href]')).map(el => el.href);
118
- });
119
-
120
- it('converts relative urls', async () => {
121
- expect(subject).to.include('https://exemple.com/relative/link');
122
- });
123
-
124
- it('leaves absolute urls untouched', async () => {
125
- expect(subject).to.include('http://absolute.url/link');
126
- });
127
- });
128
-
129
- describe('#filterHTML', () => {
130
- context('with string selector', () => {
131
- it('filters the given HTML content with common changing items', async () => {
132
- const result = await filterHTML({
133
- content: rawHTMLWithCommonChangingItems,
134
- pageDeclaration: new PageDeclaration({
135
- location: virtualLocation,
136
- contentSelectors: 'body',
137
- }),
138
- });
139
-
140
- expect(result).to.equal(expectedFilteredWithCommonChangingItems);
141
- });
142
-
143
- it('filters the given HTML content', async () => {
144
- const result = await filterHTML({
145
- content: rawHTML,
146
- pageDeclaration: new PageDeclaration({
147
- location: virtualLocation,
148
- contentSelectors: 'body',
149
- }),
150
- });
151
-
152
- expect(result).to.equal(expectedFiltered);
153
- });
154
-
155
- context('with no match for the given selector', () => {
156
- it('throws an InaccessibleContentError error', async () => {
157
- await expect(filterHTML({
158
- content: rawHTML,
159
- pageDeclaration: new PageDeclaration({
160
- location: virtualLocation,
161
- contentSelectors: '#thisAnchorDoesNotExist',
162
- }),
163
- })).to.be.rejectedWith(InaccessibleContentError, /#thisAnchorDoesNotExist/);
164
- });
165
- });
166
-
167
- context('with no content for the matching given selector', () => {
168
- it('throws an InaccessibleContentError error', async () => {
169
- await expect(filterHTML({
170
- content: rawHTML,
171
- pageDeclaration: new PageDeclaration({
172
- location: virtualLocation,
173
- contentSelectors: '#empty',
174
- }),
175
- })).to.be.rejectedWith(InaccessibleContentError, /empty content/);
176
- });
177
- });
178
-
179
- context('with a whitespace only content for the corresponding given selector', () => {
180
- it('throws an InaccessibleContentError error', async () => {
181
- await expect(filterHTML({
182
- content: rawHTML,
183
- pageDeclaration: new PageDeclaration({
184
- location: virtualLocation,
185
- contentSelectors: '#whitespaceOnly',
186
- }),
187
- })).to.be.rejectedWith(InaccessibleContentError, /empty content/);
188
- });
189
- });
190
-
191
- context('with an additional filter', () => {
192
- it('filters the given HTML content also with given additional filter', async () => {
193
- const result = await filterHTML({
194
- content: rawHTML,
195
- pageDeclaration: new PageDeclaration({
196
- location: virtualLocation,
197
- contentSelectors: 'body',
198
- filters: [additionalFilter.removeLinks],
199
- }),
200
- });
201
-
202
- expect(result).to.equal(expectedFilteredWithAdditional);
203
- });
204
- });
205
-
206
- context('with an additional async filter', () => {
207
- it('filters the given HTML content also with given additional filter', async () => {
208
- const result = await filterHTML({
209
- content: rawHTML,
210
- pageDeclaration: new PageDeclaration({
211
- location: virtualLocation,
212
- contentSelectors: 'body',
213
- filters: [additionalFilter.removeLinksAsync],
214
- }),
215
- });
216
-
217
- expect(result).to.equal(expectedFilteredWithAdditional);
218
- });
219
- });
220
-
221
- context('with multiple selectors in one string', () => {
222
- it('filters the given HTML content', async () => {
223
- const result = await filterHTML({
224
- content: rawHTML,
225
- pageDeclaration: new PageDeclaration({
226
- location: virtualLocation,
227
- contentSelectors: 'h1, #link2',
228
- }),
229
- });
230
-
231
- expect(result).to.equal('Title\n=====\n\n[link 2](#anchor)');
232
- });
233
- });
234
- });
235
-
236
- context('with an array of selectors', () => {
237
- it('filters the given HTML content', async () => {
238
- const result = await filterHTML({
239
- content: rawHTML,
240
- pageDeclaration: new PageDeclaration({
241
- location: virtualLocation,
242
- contentSelectors: [ 'h1', '#link2' ],
243
- }),
244
- });
245
-
246
- expect(result).to.equal('Title\n=====\n\n[link 2](#anchor)');
247
- });
248
-
249
- context('when one selector is dependent on another', () => {
250
- it('filters the given HTML content', async () => {
251
- const result = await filterHTML({
252
- content: rawHTML,
253
- pageDeclaration: new PageDeclaration({
254
- location: virtualLocation,
255
- contentSelectors: [ 'h1', 'h1 ~ p' ],
256
- }),
257
- });
258
-
259
- expect(result).to.equal('Title\n=====\n\n[link 1](https://exemple.com/relative/link)\n\n[link 2](#anchor)\n\n[link 3](http://absolute.url/link)');
260
- });
261
- });
262
- });
263
-
264
- context('with range selector', () => {
265
- context('with startBefore and endBefore', () => {
266
- it('filters the given HTML content', async () => {
267
- const result = await filterHTML({
268
- content: rawHTML,
269
- pageDeclaration: new PageDeclaration({
270
- location: virtualLocation,
271
- contentSelectors: {
272
- startBefore: '#link1',
273
- endBefore: '#link2',
274
- },
275
- }),
276
- });
277
-
278
- expect(result).to.equal('[link 1](https://exemple.com/relative/link)');
279
- });
280
- });
281
- context('with startBefore and endAfter', () => {
282
- it('filters the given HTML content', async () => {
283
- const result = await filterHTML({
284
- content: rawHTML,
285
- pageDeclaration: new PageDeclaration({
286
- location: virtualLocation,
287
- contentSelectors: {
288
- startBefore: '#link2',
289
- endAfter: '#link2',
290
- },
291
- }),
292
- });
293
-
294
- expect(result).to.equal('[link 2](#anchor)');
295
- });
296
- });
297
- context('with startAfter and endBefore', () => {
298
- it('filters the given HTML content', async () => {
299
- const result = await filterHTML({
300
- content: rawHTML,
301
- pageDeclaration: new PageDeclaration({
302
- location: virtualLocation,
303
- contentSelectors: {
304
- startAfter: '#link1',
305
- endBefore: '#link3',
306
- },
307
- }),
308
- });
309
-
310
- expect(result).to.equal('[link 2](#anchor)');
311
- });
312
- });
313
- context('with startAfter and endAfter', () => {
314
- it('filters the given HTML content', async () => {
315
- const result = await filterHTML({
316
- content: rawHTML,
317
- pageDeclaration: new PageDeclaration({
318
- location: virtualLocation,
319
- contentSelectors: {
320
- startAfter: '#link2',
321
- endAfter: '#link3',
322
- },
323
- }),
324
- });
325
-
326
- expect(result).to.equal('[link 3](http://absolute.url/link)');
327
- });
328
- });
329
- context('with a "start" selector that has no match', () => {
330
- it('throws an InaccessibleContentError error', async () => {
331
- await expect(filterHTML({
332
- content: rawHTML,
333
- pageDeclaration: new PageDeclaration({
334
- location: virtualLocation,
335
- contentSelectors: {
336
- startAfter: '#paragraph1',
337
- endAfter: '#link2',
338
- },
339
- }),
340
- })).to.be.rejectedWith(InaccessibleContentError, /"start" selector has no match/);
341
- });
342
- });
343
- context('with an "end" selector that has no match', () => {
344
- it('throws an InaccessibleContentError error', async () => {
345
- await expect(filterHTML({
346
- content: rawHTML,
347
- pageDeclaration: new PageDeclaration({
348
- location: virtualLocation,
349
- contentSelectors: {
350
- startAfter: '#link2',
351
- endAfter: '#paragraph1',
352
- },
353
- }),
354
- })).to.be.rejectedWith(InaccessibleContentError, /"end" selector has no match/);
355
- });
356
- });
357
- });
358
-
359
- context('with an array of range selectors', () => {
360
- it('filters the given HTML content', async () => {
361
- const result = await filterHTML({
362
- content: rawHTML,
363
- pageDeclaration: new PageDeclaration({
364
- location: virtualLocation,
365
- contentSelectors: [
366
- {
367
- startAfter: '#link1',
368
- endAfter: '#link2',
369
- },
370
- {
371
- startAfter: '#link2',
372
- endAfter: '#link3',
373
- },
374
- ],
375
- }),
376
- });
377
-
378
- expect(result).to.equal('[link 2](#anchor)\n\n[link 3](http://absolute.url/link)');
379
- });
380
- });
381
-
382
- context('with an array of mixed string selectors and range selectors', () => {
383
- it('filters the given HTML content', async () => {
384
- const result = await filterHTML({
385
- content: rawHTML,
386
- pageDeclaration: new PageDeclaration({
387
- location: virtualLocation,
388
- contentSelectors: [
389
- 'h1',
390
- {
391
- startAfter: '#link2',
392
- endAfter: '#link3',
393
- },
394
- ],
395
- }),
396
- });
397
-
398
- expect(result).to.equal('Title\n=====\n\n[link 3](http://absolute.url/link)');
399
- });
400
- });
401
-
402
- describe('Remove elements', () => {
403
- context('with a simple selector', () => {
404
- it('removes the specified elements', async () => {
405
- const result = await filterHTML({
406
- content: rawHTML,
407
- pageDeclaration: new PageDeclaration({
408
- location: virtualLocation,
409
- contentSelectors: 'body',
410
- noiseSelectors: 'h1',
411
- }),
412
- });
413
-
414
- expect(result).to.equal('[link 1](https://exemple.com/relative/link)\n\n[link 2](#anchor)\n\n[link 3](http://absolute.url/link)');
415
- });
416
- });
417
-
418
- context('with an array of string selectors', () => {
419
- it('removes the specified elements', async () => {
420
- const result = await filterHTML({
421
- content: rawHTML,
422
- pageDeclaration: new PageDeclaration({
423
- location: virtualLocation,
424
- contentSelectors: 'body',
425
- noiseSelectors: [ 'h1', '#link3' ],
426
- }),
427
- });
428
-
429
- expect(result).to.equal('[link 1](https://exemple.com/relative/link)\n\n[link 2](#anchor)');
430
- });
431
- });
432
-
433
- context('with a simple range selector', () => {
434
- it('removes the specified elements', async () => {
435
- const result = await filterHTML({
436
- content: rawHTML,
437
- pageDeclaration: new PageDeclaration({
438
- location: virtualLocation,
439
- contentSelectors: 'body',
440
- noiseSelectors: {
441
- startBefore: '#link1',
442
- endAfter: '#link3',
443
- },
444
- }),
445
- });
446
-
447
- expect(result).to.equal('Title\n=====');
448
- });
449
- context('with a "start" selector that has no match', () => {
450
- it('throws an InaccessibleContentError error', async () => {
451
- await expect(filterHTML({
452
- content: rawHTML,
453
- pageDeclaration: new PageDeclaration({
454
- location: virtualLocation,
455
- contentSelectors: 'body',
456
- noiseSelectors: {
457
- startAfter: '#paragraph1',
458
- endAfter: '#link2',
459
- },
460
- }),
461
- })).to.be.rejectedWith(InaccessibleContentError, /"start" selector has no match/);
462
- });
463
- });
464
- context('with an "end" selector that has no match', () => {
465
- it('throws an InaccessibleContentError error', async () => {
466
- await expect(filterHTML({
467
- content: rawHTML,
468
- pageDeclaration: new PageDeclaration({
469
- location: virtualLocation,
470
- contentSelectors: 'body',
471
- noiseSelectors: {
472
- startAfter: '#link2',
473
- endAfter: '#paragraph1',
474
- },
475
- }),
476
- })).to.be.rejectedWith(InaccessibleContentError, /"end" selector has no match/);
477
- });
478
- });
479
- });
480
- context('with an array of range selectors', () => {
481
- it('removes all the selections', async () => {
482
- const result = await filterHTML({
483
- content: rawHTML,
484
- pageDeclaration: new PageDeclaration({
485
- location: virtualLocation,
486
- contentSelectors: 'body',
487
- noiseSelectors: [
488
- {
489
- startBefore: 'h1',
490
- endBefore: '#link1',
491
- },
492
- {
493
- startBefore: '#link3',
494
- endAfter: '#link3',
495
- },
496
- ],
497
- }),
498
- });
499
-
500
- expect(result).to.equal('[link 1](https://exemple.com/relative/link)\n\n[link 2](#anchor)');
501
- });
502
- });
503
-
504
- context('with an array of mixed selectors and range selectors', () => {
505
- it('removes all the selections', async () => {
506
- const result = await filterHTML({
507
- content: rawHTML,
508
- pageDeclaration: new PageDeclaration({
509
- location: virtualLocation,
510
- contentSelectors: 'body',
511
- noiseSelectors: [
512
- 'h1',
513
- {
514
- startBefore: '#link3',
515
- endAfter: '#link3',
516
- },
517
- ],
518
- }),
519
- });
520
-
521
- expect(result).to.equal('[link 1](https://exemple.com/relative/link)\n\n[link 2](#anchor)');
522
- });
523
-
524
- context('where one selector is dependent on another', () => {
525
- it('removes all the selections', async () => {
526
- const result = await filterHTML({
527
- content: rawHTML,
528
- pageDeclaration: new PageDeclaration({
529
- location: virtualLocation,
530
- contentSelectors: 'body',
531
- noiseSelectors: [
532
- 'h1',
533
- {
534
- startAfter: 'h1',
535
- endBefore: '#link2',
536
- },
537
- ],
538
- }),
539
- });
540
-
541
- expect(result).to.equal('[link 2](#anchor)\n\n[link 3](http://absolute.url/link)');
542
- });
543
- });
544
- });
545
- });
546
- });
547
-
548
- describe('#filterPDF', () => {
549
- let pdfContent;
550
- let expectedFilteredContent;
551
-
552
- before(async () => {
553
- pdfContent = await fs.readFile(path.resolve(__dirname, '../../../test/fixtures/terms.pdf'));
554
- expectedFilteredContent = await fs.readFile(
555
- path.resolve(__dirname, '../../../test/fixtures/termsFromPDF.md'),
556
- { encoding: 'utf8' },
557
- );
558
- });
559
-
560
- it('filters the given PDF', async () => {
561
- expect(await filterPDF({ content: pdfContent })).to.equal(expectedFilteredContent);
562
- });
563
- });
564
- });
@@ -1,91 +0,0 @@
1
- import chai from 'chai';
2
- import config from 'config';
3
-
4
- import Record from './record.js';
5
- import RepositoryFactory from './repositories/factory.js';
6
-
7
- const { expect } = chai;
8
-
9
- describe('Record', () => {
10
- let repository;
11
- let subject;
12
- const REQUIRED_PARAMS = [ 'serviceId', 'documentType', 'mimeType', 'fetchDate' ];
13
- const recordParams = {
14
- serviceId: 'ServiceA',
15
- documentType: 'Terms of Service',
16
- mimeType: 'text/html',
17
- fetchDate: new Date('2000-01-01T12:00:00.000Z'),
18
- };
19
-
20
- describe('Validation', () => {
21
- describe('Required paramaters', () => {
22
- REQUIRED_PARAMS.forEach(requiredParam => {
23
- describe(`"${requiredParam}"`, () => {
24
- context('when it is missing', () => {
25
- it('throws an error', async () => {
26
- try {
27
- const params = {};
28
-
29
- Object.keys(recordParams).filter(param => param != requiredParam).forEach(param => {
30
- params[param] = recordParams[param];
31
- });
32
-
33
- subject = new Record({ ...params });
34
- } catch (e) {
35
- expect(e).to.be.an('error');
36
- expect(e.message).to.have.string(`"${requiredParam}" is required`);
37
-
38
- return;
39
- }
40
- expect.fail('No error was thrown');
41
- });
42
- });
43
-
44
- context('when it is null', () => {
45
- it('throws an error', async () => {
46
- try {
47
- subject = new Record({ ...recordParams, [requiredParam]: null });
48
- } catch (e) {
49
- expect(e).to.be.an('error');
50
- expect(e.message).to.have.string(`"${requiredParam}" is required`);
51
-
52
- return;
53
- }
54
- expect.fail('No error was thrown');
55
- });
56
- });
57
- });
58
- });
59
- });
60
- });
61
-
62
- describe('Content access', () => {
63
- before(async () => {
64
- repository = await RepositoryFactory.create(config.get('recorder.versions.storage')).initialize();
65
- await repository.save(new Record({
66
- ...recordParams,
67
- content: 'content',
68
- }));
69
- ([subject] = await repository.findAll());
70
- });
71
-
72
- after(async () => {
73
- await repository.removeAll();
74
- await repository.finalize();
75
- });
76
-
77
- context('when it is neither defined nor loaded', () => {
78
- it('throws an error explaining how to recover', async () => {
79
- try {
80
- console.log(subject.content);
81
- } catch (e) {
82
- expect(e).to.be.an('error');
83
- expect(e.message).to.have.string('set the content or use Repository#loadRecordContent');
84
-
85
- return;
86
- }
87
- expect.fail('No error was thrown');
88
- });
89
- });
90
- });
91
- });
@@ -1,26 +0,0 @@
1
- export default class DocumentDeclaration {
2
- constructor({ service, type, pages, validUntil }) {
3
- this.service = service;
4
- this.type = type;
5
- this.pages = pages;
6
-
7
- if (validUntil) {
8
- this.validUntil = validUntil;
9
- }
10
- }
11
-
12
- get isMultiPage() {
13
- return this.pages.length > 1;
14
- }
15
-
16
- toPersistence() {
17
- return {
18
- name: this.service.name,
19
- documents: {
20
- [this.type]: this.isMultiPage
21
- ? { combine: this.pages.map(page => page.toPersistence()) }
22
- : this.pages[0].toPersistence(),
23
- },
24
- };
25
- }
26
- }