@opentermsarchive/engine 0.26.1 → 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 (59) hide show
  1. package/bin/ota-track.js +3 -3
  2. package/bin/ota-validate.js +2 -2
  3. package/bin/ota.js +1 -1
  4. package/config/default.json +1 -1
  5. package/package.json +3 -4
  6. package/scripts/dataset/export/index.js +4 -4
  7. package/scripts/dataset/export/index.test.js +11 -17
  8. package/scripts/declarations/lint/index.mocha.js +1 -1
  9. package/scripts/declarations/utils/index.js +12 -12
  10. package/scripts/declarations/validate/definitions.js +1 -1
  11. package/scripts/declarations/validate/index.mocha.js +30 -34
  12. package/scripts/declarations/validate/service.history.schema.js +11 -11
  13. package/scripts/declarations/validate/service.schema.js +13 -13
  14. package/scripts/history/migrate-services.js +4 -4
  15. package/scripts/history/update-to-full-hash.js +2 -2
  16. package/scripts/import/index.js +14 -14
  17. package/scripts/rewrite/rewrite-snapshots.js +3 -3
  18. package/scripts/rewrite/rewrite-versions.js +14 -14
  19. package/scripts/utils/renamer/README.md +3 -3
  20. package/scripts/utils/renamer/index.js +13 -13
  21. package/src/archivist/errors.js +1 -1
  22. package/src/archivist/extract/exports.js +3 -0
  23. package/src/archivist/{filter → extract}/index.js +23 -27
  24. package/src/archivist/extract/index.test.js +516 -0
  25. package/src/archivist/index.js +101 -140
  26. package/src/archivist/index.test.js +178 -166
  27. package/src/archivist/recorder/index.js +11 -55
  28. package/src/archivist/recorder/index.test.js +310 -356
  29. package/src/archivist/recorder/record.js +18 -7
  30. package/src/archivist/recorder/repositories/git/dataMapper.js +41 -31
  31. package/src/archivist/recorder/repositories/git/index.js +11 -15
  32. package/src/archivist/recorder/repositories/git/index.test.js +1058 -463
  33. package/src/archivist/recorder/repositories/interface.js +8 -6
  34. package/src/archivist/recorder/repositories/mongo/dataMapper.js +21 -14
  35. package/src/archivist/recorder/repositories/mongo/index.js +8 -8
  36. package/src/archivist/recorder/repositories/mongo/index.test.js +898 -479
  37. package/src/archivist/recorder/snapshot.js +5 -0
  38. package/src/archivist/recorder/snapshot.test.js +65 -0
  39. package/src/archivist/recorder/version.js +14 -0
  40. package/src/archivist/recorder/version.test.js +65 -0
  41. package/src/archivist/services/index.js +60 -51
  42. package/src/archivist/services/index.test.js +63 -83
  43. package/src/archivist/services/service.js +26 -22
  44. package/src/archivist/services/service.test.js +46 -68
  45. package/src/archivist/services/{pageDeclaration.js → sourceDocument.js} +11 -9
  46. package/src/archivist/services/{pageDeclaration.test.js → sourceDocument.test.js} +21 -21
  47. package/src/archivist/services/terms.js +26 -0
  48. package/src/archivist/services/{documentDeclaration.test.js → terms.test.js} +15 -15
  49. package/src/exports.js +2 -2
  50. package/src/index.js +16 -13
  51. package/src/logger/index.js +35 -36
  52. package/src/notifier/index.js +8 -8
  53. package/src/tracker/index.js +6 -6
  54. package/src/archivist/filter/exports.js +0 -3
  55. package/src/archivist/filter/index.test.js +0 -564
  56. package/src/archivist/recorder/record.test.js +0 -91
  57. package/src/archivist/services/documentDeclaration.js +0 -26
  58. /package/scripts/utils/renamer/rules/{documentTypes.json → termsTypes.json} +0 -0
  59. /package/scripts/utils/renamer/rules/{documentTypesByService.json → termsTypesByService.json} +0 -0
@@ -1,6 +1,9 @@
1
1
  import chai from 'chai';
2
2
  import config from 'config';
3
3
 
4
+ import Snapshot from './snapshot.js';
5
+ import Version from './version.js';
6
+
4
7
  import Recorder from './index.js';
5
8
 
6
9
  const { expect } = chai;
@@ -29,432 +32,383 @@ describe('Recorder', () => {
29
32
 
30
33
  after(async () => recorder.finalize());
31
34
 
32
- describe('#recordSnapshot', () => {
33
- const CONTENT = '<html><h1>ToS fixture data with UTF-8 çhãràčtęrs</h1></html>';
34
-
35
- let id;
36
- let isFirstRecord;
37
- let record;
38
-
39
- context('when a required param is missing', () => {
40
- after(async () => recorder.snapshotsRepository.removeAll());
41
-
42
- const validParams = {
43
- serviceId: SERVICE_ID,
44
- documentType: TYPE,
45
- content: CONTENT,
46
- fetchDate: FETCH_DATE,
47
- mimeType: MIME_TYPE,
48
- };
49
-
50
- const paramsNameToExpectedTextInError = {
51
- serviceId: 'service ID',
52
- documentType: 'terms type',
53
- fetchDate: 'fetch date',
54
- content: 'content',
55
- mimeType: 'mime type',
56
- };
57
-
58
- Object.entries(validParams).forEach(([testedRequiredParam]) => {
59
- context(`when "${testedRequiredParam}" is missing`, () => {
60
- it('throws an error', async () => {
61
- try {
62
- const validParamsExceptTheOneTested = Object.fromEntries(Object.entries(validParams).filter(([paramName]) => paramName != testedRequiredParam));
63
-
64
- await recorder.recordSnapshot(validParamsExceptTheOneTested);
65
- } catch (e) {
66
- expect(e).to.be.an('error');
67
- expect(e.message).to.contain(paramsNameToExpectedTextInError[testedRequiredParam]);
68
-
69
- return;
70
- }
71
- expect.fail('No error was thrown');
35
+ context('Snapshot', () => {
36
+ describe('#record', () => {
37
+ const CONTENT = '<html><h1>ToS fixture data with UTF-8 çhãràčtęrs</h1></html>';
38
+
39
+ let id;
40
+ let isFirstRecord;
41
+ let record;
42
+
43
+ context('when a required param is missing', () => {
44
+ after(async () => recorder.snapshotsRepository.removeAll());
45
+
46
+ Snapshot.REQUIRED_PARAMS.forEach(testedRequiredParam => {
47
+ context(`when "${testedRequiredParam}" is missing`, () => {
48
+ it('throws an error', async () => {
49
+ try {
50
+ const validParamsExceptTheOneTested = Snapshot.REQUIRED_PARAMS.filter(paramName => paramName != testedRequiredParam).reduce(
51
+ (accumulator, currentValue) => {
52
+ accumulator[currentValue] = 'non null value';
53
+
54
+ return accumulator;
55
+ },
56
+ {},
57
+ );
58
+
59
+ await recorder.record(new Snapshot({ ...validParamsExceptTheOneTested }));
60
+ } catch (e) {
61
+ expect(e).to.be.an('error');
62
+ expect(e.message).to.contain(testedRequiredParam);
63
+
64
+ return;
65
+ }
66
+ expect.fail('No error was thrown');
67
+ });
72
68
  });
73
69
  });
74
70
  });
75
- });
76
-
77
- context('when it is the first record', () => {
78
- before(async () => {
79
- ({ id, isFirstRecord } = await recorder.recordSnapshot({
80
- serviceId: SERVICE_ID,
81
- documentType: TYPE,
82
- content: CONTENT,
83
- mimeType: MIME_TYPE,
84
- fetchDate: FETCH_DATE,
85
- }));
86
-
87
- record = await recorder.snapshotsRepository.findLatest(SERVICE_ID, TYPE);
88
- });
89
-
90
- after(async () => recorder.snapshotsRepository.removeAll());
91
-
92
- it('records the document with the proper content', async () => {
93
- expect(await record.content).to.equal(CONTENT);
94
- });
95
71
 
96
- it('returns the record id', async () => {
97
- expect(record.id).to.include(id);
98
- });
72
+ context('when it is the first record', () => {
73
+ before(async () => {
74
+ ({ id, isFirstRecord } = await recorder.record(new Snapshot({
75
+ serviceId: SERVICE_ID,
76
+ termsType: TYPE,
77
+ content: CONTENT,
78
+ mimeType: MIME_TYPE,
79
+ fetchDate: FETCH_DATE,
80
+ })));
99
81
 
100
- it('returns a boolean to know if it is the first record', async () => {
101
- expect(isFirstRecord).to.be.true;
102
- });
103
- });
82
+ record = await recorder.snapshotsRepository.findLatest(SERVICE_ID, TYPE);
83
+ });
104
84
 
105
- context('when it is not the first record', () => {
106
- const UPDATED_CONTENT = '<html><h1>ToS fixture data with UTF-8 çhãràčtęrs</h1><h2>Updated!</h2></html>';
85
+ after(async () => recorder.snapshotsRepository.removeAll());
107
86
 
108
- before(async () => {
109
- await recorder.recordSnapshot({
110
- serviceId: SERVICE_ID,
111
- documentType: TYPE,
112
- content: CONTENT,
113
- mimeType: MIME_TYPE,
114
- fetchDate: FETCH_DATE,
87
+ it('records the snapshot with the proper content', async () => {
88
+ expect(await record.content).to.equal(CONTENT);
115
89
  });
116
90
 
117
- ({ id, isFirstRecord } = await recorder.recordSnapshot({
118
- serviceId: SERVICE_ID,
119
- documentType: TYPE,
120
- content: UPDATED_CONTENT,
121
- mimeType: MIME_TYPE,
122
- fetchDate: FETCH_DATE_LATER,
123
- }));
91
+ it('returns the record id', async () => {
92
+ expect(record.id).to.include(id);
93
+ });
124
94
 
125
- record = await recorder.snapshotsRepository.findLatest(SERVICE_ID, TYPE);
95
+ it('states that it is the first record', async () => {
96
+ expect(isFirstRecord).to.be.true;
97
+ });
126
98
  });
127
99
 
128
- after(async () => recorder.snapshotsRepository.removeAll());
100
+ context('when it is not the first record', () => {
101
+ const UPDATED_CONTENT = '<html><h1>ToS fixture data with UTF-8 çhãràčtęrs</h1><h2>Updated!</h2></html>';
129
102
 
130
- it('records the document with the proper content', async () => {
131
- expect(await record.content).to.equal(UPDATED_CONTENT);
132
- });
103
+ before(async () => {
104
+ await recorder.record(new Snapshot({
105
+ serviceId: SERVICE_ID,
106
+ termsType: TYPE,
107
+ content: CONTENT,
108
+ mimeType: MIME_TYPE,
109
+ fetchDate: FETCH_DATE,
110
+ }));
133
111
 
134
- it('returns the record id', async () => {
135
- expect(record.id).to.include(id);
136
- });
112
+ ({ id, isFirstRecord } = await recorder.record(new Snapshot({
113
+ serviceId: SERVICE_ID,
114
+ termsType: TYPE,
115
+ content: UPDATED_CONTENT,
116
+ mimeType: MIME_TYPE,
117
+ fetchDate: FETCH_DATE_LATER,
118
+ })));
137
119
 
138
- it('returns a boolean to know if it is the first record', async () => {
139
- expect(isFirstRecord).to.be.false;
140
- });
141
- });
120
+ record = await recorder.snapshotsRepository.findLatest(SERVICE_ID, TYPE);
121
+ });
142
122
 
143
- context('when the content has not changed', () => {
144
- before(async () => {
145
- await recorder.recordSnapshot({
146
- serviceId: SERVICE_ID,
147
- documentType: TYPE,
148
- content: CONTENT,
149
- mimeType: MIME_TYPE,
150
- fetchDate: FETCH_DATE,
123
+ after(async () => recorder.snapshotsRepository.removeAll());
124
+
125
+ it('records the snapshot with the proper content', async () => {
126
+ expect(await record.content).to.equal(UPDATED_CONTENT);
151
127
  });
152
128
 
153
- ({ id, isFirstRecord } = await recorder.recordSnapshot({
154
- serviceId: SERVICE_ID,
155
- documentType: TYPE,
156
- content: CONTENT,
157
- mimeType: MIME_TYPE,
158
- fetchDate: FETCH_DATE_LATER,
159
- }));
129
+ it('returns the record id', async () => {
130
+ expect(record.id).to.include(id);
131
+ });
160
132
 
161
- record = await recorder.snapshotsRepository.findLatest(SERVICE_ID, TYPE);
133
+ it('states that it is not the first record', async () => {
134
+ expect(isFirstRecord).to.be.false;
135
+ });
162
136
  });
163
137
 
164
- after(async () => recorder.snapshotsRepository.removeAll());
138
+ context('when the content has not changed', () => {
139
+ before(async () => {
140
+ await recorder.record(new Snapshot({
141
+ serviceId: SERVICE_ID,
142
+ termsType: TYPE,
143
+ content: CONTENT,
144
+ mimeType: MIME_TYPE,
145
+ fetchDate: FETCH_DATE,
146
+ }));
147
+
148
+ ({ id, isFirstRecord } = await recorder.record(new Snapshot({
149
+ serviceId: SERVICE_ID,
150
+ termsType: TYPE,
151
+ content: CONTENT,
152
+ mimeType: MIME_TYPE,
153
+ fetchDate: FETCH_DATE_LATER,
154
+ })));
155
+
156
+ record = await recorder.snapshotsRepository.findLatest(SERVICE_ID, TYPE);
157
+ });
158
+
159
+ after(async () => recorder.snapshotsRepository.removeAll());
165
160
 
166
- it('does not record the document', async () => {
167
- expect(id).to.not.be.ok;
161
+ it('does not record the snapshot', async () => {
162
+ expect(id).to.not.be.ok;
163
+ });
168
164
  });
169
165
  });
170
166
  });
171
167
 
172
- describe('#recordVersion', () => {
173
- const CONTENT = '# ToS fixture data with UTF-8 çhãràčtęrs';
174
- const SNAPSHOT_ID = '61af86dc5ff5caa74ae926ad';
175
-
176
- let id;
177
- let isFirstRecord;
178
- let record;
179
-
180
- context('when a required param is missing', () => {
181
- after(async () => recorder.versionsRepository.removeAll());
182
-
183
- const validParams = {
184
- serviceId: SERVICE_ID,
185
- documentType: TYPE,
186
- content: CONTENT,
187
- snapshotIds: [SNAPSHOT_ID],
188
- fetchDate: FETCH_DATE,
189
- };
190
-
191
- const paramsNameToExpectedTextInError = {
192
- serviceId: 'service ID',
193
- documentType: 'terms type',
194
- snapshotIds: 'snapshot ID',
195
- fetchDate: 'fetch date',
196
- content: 'content',
197
- };
198
-
199
- Object.entries(validParams).forEach(([testedRequiredParam]) => {
200
- context(`when "${testedRequiredParam}" is missing`, () => {
201
- it('throws an error', async () => {
202
- try {
203
- const validParamsExceptTheOneTested = Object.fromEntries(Object.entries(validParams).filter(([paramName]) => paramName != testedRequiredParam));
204
-
205
- await recorder.recordVersion(validParamsExceptTheOneTested);
206
- } catch (e) {
207
- expect(e).to.be.an('error');
208
- expect(e.message).to.contain(paramsNameToExpectedTextInError[testedRequiredParam]);
209
-
210
- return;
211
- }
212
- expect.fail('No error was thrown');
168
+ context('Version', () => {
169
+ describe('#record', () => {
170
+ const CONTENT = '# ToS fixture data with UTF-8 çhãràčtęrs';
171
+ const SNAPSHOT_ID = '61af86dc5ff5caa74ae926ad';
172
+
173
+ let id;
174
+ let isFirstRecord;
175
+ let record;
176
+
177
+ context('when a required param is missing', () => {
178
+ after(async () => recorder.versionsRepository.removeAll());
179
+
180
+ Version.REQUIRED_PARAMS.forEach(testedRequiredParam => {
181
+ context(`when "${testedRequiredParam}" is missing`, () => {
182
+ it('throws an error', async () => {
183
+ try {
184
+ const validParamsExceptTheOneTested = Version.REQUIRED_PARAMS.filter(paramName => paramName != testedRequiredParam).reduce(
185
+ (accumulator, currentValue) => {
186
+ accumulator[currentValue] = 'no null value';
187
+
188
+ return accumulator;
189
+ },
190
+ {},
191
+ );
192
+
193
+ await recorder.record(new Version({ ...validParamsExceptTheOneTested }));
194
+ } catch (e) {
195
+ expect(e).to.be.an('error');
196
+ expect(e.message).to.contain(testedRequiredParam);
197
+
198
+ return;
199
+ }
200
+ expect.fail('No error was thrown');
201
+ });
213
202
  });
214
203
  });
215
204
  });
216
- });
217
-
218
- context('when it is the first record', () => {
219
- before(async () => {
220
- ({ id, isFirstRecord } = await recorder.recordVersion({
221
- serviceId: SERVICE_ID,
222
- documentType: TYPE,
223
- content: CONTENT,
224
- snapshotIds: [SNAPSHOT_ID],
225
- fetchDate: FETCH_DATE,
226
- }));
227
-
228
- record = await recorder.versionsRepository.findLatest(SERVICE_ID, TYPE);
229
- });
230
-
231
- after(async () => recorder.versionsRepository.removeAll());
232
-
233
- it('records the document with the proper content', async () => {
234
- expect(await record.content).to.equal(CONTENT);
235
- });
236
205
 
237
- it('returns the record id', async () => {
238
- expect(record.id).to.include(id);
239
- });
206
+ context('when it is the first record', () => {
207
+ before(async () => {
208
+ ({ id, isFirstRecord } = await recorder.record(new Version({
209
+ serviceId: SERVICE_ID,
210
+ termsType: TYPE,
211
+ content: CONTENT,
212
+ snapshotIds: [SNAPSHOT_ID],
213
+ fetchDate: FETCH_DATE,
214
+ })));
240
215
 
241
- it('returns a boolean to know if it is the first record', async () => {
242
- expect(isFirstRecord).to.be.true;
243
- });
244
- });
216
+ record = await recorder.versionsRepository.findLatest(SERVICE_ID, TYPE);
217
+ });
245
218
 
246
- context('when it is not the first record', () => {
247
- const UPDATED_CONTENT = '<html><h1>ToS fixture data with UTF-8 çhãràčtęrs</h1><h2>Updated!</h2></html>';
219
+ after(async () => recorder.versionsRepository.removeAll());
248
220
 
249
- before(async () => {
250
- await recorder.recordVersion({
251
- serviceId: SERVICE_ID,
252
- documentType: TYPE,
253
- content: CONTENT,
254
- snapshotIds: [SNAPSHOT_ID],
255
- fetchDate: FETCH_DATE,
221
+ it('records the version with the proper content', async () => {
222
+ expect(await record.content).to.equal(CONTENT);
256
223
  });
257
224
 
258
- ({ id, isFirstRecord } = await recorder.recordVersion({
259
- serviceId: SERVICE_ID,
260
- documentType: TYPE,
261
- content: UPDATED_CONTENT,
262
- snapshotIds: [SNAPSHOT_ID],
263
- fetchDate: FETCH_DATE_LATER,
264
- }));
225
+ it('returns the record id', async () => {
226
+ expect(record.id).to.include(id);
227
+ });
265
228
 
266
- record = await recorder.versionsRepository.findLatest(SERVICE_ID, TYPE);
229
+ it('states that it is the first record', async () => {
230
+ expect(isFirstRecord).to.be.true;
231
+ });
267
232
  });
268
233
 
269
- after(async () => recorder.versionsRepository.removeAll());
234
+ context('when it is not the first record', () => {
235
+ const UPDATED_CONTENT = '<html><h1>ToS fixture data with UTF-8 çhãràčtęrs</h1><h2>Updated!</h2></html>';
270
236
 
271
- it('records the document with the proper content', async () => {
272
- expect(await record.content).to.equal(UPDATED_CONTENT);
273
- });
237
+ before(async () => {
238
+ await recorder.record(new Version({
239
+ serviceId: SERVICE_ID,
240
+ termsType: TYPE,
241
+ content: CONTENT,
242
+ snapshotIds: [SNAPSHOT_ID],
243
+ fetchDate: FETCH_DATE,
244
+ }));
274
245
 
275
- it('records in the document that it is not a refilter', async () => {
276
- expect(record.isRefilter).to.equal(false);
277
- });
246
+ ({ id, isFirstRecord } = await recorder.record(new Version({
247
+ serviceId: SERVICE_ID,
248
+ termsType: TYPE,
249
+ content: UPDATED_CONTENT,
250
+ snapshotIds: [SNAPSHOT_ID],
251
+ fetchDate: FETCH_DATE_LATER,
252
+ })));
278
253
 
279
- it('returns the record id', async () => {
280
- expect(record.id).to.include(id);
281
- });
254
+ record = await recorder.versionsRepository.findLatest(SERVICE_ID, TYPE);
255
+ });
282
256
 
283
- it('returns a boolean to know if it is the first record', async () => {
284
- expect(isFirstRecord).to.be.false;
285
- });
286
- });
257
+ after(async () => recorder.versionsRepository.removeAll());
287
258
 
288
- context('when the content has not changed', () => {
289
- before(async () => {
290
- await recorder.recordVersion({
291
- serviceId: SERVICE_ID,
292
- documentType: TYPE,
293
- content: CONTENT,
294
- snapshotIds: [SNAPSHOT_ID],
295
- fetchDate: FETCH_DATE,
259
+ it('records the version with the proper content', async () => {
260
+ expect(await record.content).to.equal(UPDATED_CONTENT);
296
261
  });
297
262
 
298
- ({ id, isFirstRecord } = await recorder.recordVersion({
299
- serviceId: SERVICE_ID,
300
- documentType: TYPE,
301
- content: CONTENT,
302
- snapshotIds: [SNAPSHOT_ID],
303
- fetchDate: FETCH_DATE_LATER,
304
- }));
305
-
306
- record = await recorder.versionsRepository.findLatest(SERVICE_ID, TYPE);
307
- });
263
+ it('records in the version that it is not an extracted only version', async () => {
264
+ expect(record.isExtractOnly).to.equal(false);
265
+ });
308
266
 
309
- after(async () => recorder.versionsRepository.removeAll());
267
+ it('returns the record id', async () => {
268
+ expect(record.id).to.include(id);
269
+ });
310
270
 
311
- it('does not record the document', async () => {
312
- expect(id).to.not.be.ok;
271
+ it('states that it is not the first record', async () => {
272
+ expect(isFirstRecord).to.be.false;
273
+ });
313
274
  });
314
- });
315
- });
316
275
 
317
- describe('#recordRefilter', () => {
318
- const CONTENT = '# ToS fixture data with UTF-8 çhãràčtęrs';
319
- const SNAPSHOT_ID = '61af86dc5ff5caa74ae926ad';
320
-
321
- let id;
322
- let isFirstRecord;
323
- let record;
324
-
325
- context('when a required param is missing', () => {
326
- after(async () => recorder.versionsRepository.removeAll());
327
-
328
- const validParams = {
329
- serviceId: SERVICE_ID,
330
- documentType: TYPE,
331
- content: CONTENT,
332
- snapshotIds: [SNAPSHOT_ID],
333
- fetchDate: FETCH_DATE,
334
- };
335
-
336
- const paramsNameToExpectedTextInError = {
337
- serviceId: 'service ID',
338
- documentType: 'terms type',
339
- snapshotIds: 'snapshot ID',
340
- fetchDate: 'fetch date',
341
- content: 'content',
342
- };
343
-
344
- Object.entries(validParams).forEach(([testedRequiredParam]) => {
345
- context(`when "${testedRequiredParam}" is missing`, () => {
346
- it('throws an error', async () => {
347
- try {
348
- const validParamsExceptTheOneTested = Object.fromEntries(Object.entries(validParams).filter(([paramName]) => paramName != testedRequiredParam));
349
-
350
- await recorder.recordRefilter(validParamsExceptTheOneTested);
351
- } catch (e) {
352
- expect(e).to.be.an('error');
353
- expect(e.message).to.contain(paramsNameToExpectedTextInError[testedRequiredParam]);
354
-
355
- return;
356
- }
357
- expect.fail('No error was thrown');
358
- });
276
+ context('when the content has not changed', () => {
277
+ before(async () => {
278
+ await recorder.record(new Version({
279
+ serviceId: SERVICE_ID,
280
+ termsType: TYPE,
281
+ content: CONTENT,
282
+ snapshotIds: [SNAPSHOT_ID],
283
+ fetchDate: FETCH_DATE,
284
+ }));
285
+
286
+ ({ id, isFirstRecord } = await recorder.record(new Version({
287
+ serviceId: SERVICE_ID,
288
+ termsType: TYPE,
289
+ content: CONTENT,
290
+ snapshotIds: [SNAPSHOT_ID],
291
+ fetchDate: FETCH_DATE_LATER,
292
+ })));
293
+
294
+ record = await recorder.versionsRepository.findLatest(SERVICE_ID, TYPE);
359
295
  });
360
- });
361
- });
362
296
 
363
- context('when it is the first record', () => {
364
- before(async () => {
365
- ({ id, isFirstRecord } = await recorder.recordRefilter({
366
- serviceId: SERVICE_ID,
367
- documentType: TYPE,
368
- content: CONTENT,
369
- snapshotIds: [SNAPSHOT_ID],
370
- fetchDate: FETCH_DATE,
371
- }));
372
-
373
- record = await recorder.versionsRepository.findLatest(SERVICE_ID, TYPE);
297
+ after(async () => recorder.versionsRepository.removeAll());
298
+
299
+ it('does not record any version', async () => {
300
+ expect(id).to.not.be.ok;
301
+ });
374
302
  });
375
303
 
376
- after(async () => recorder.versionsRepository.removeAll()); after(async () => recorder.versionsRepository.removeAll());
304
+ context('when it is an extraction only', () => {
305
+ const CONTENT = '# ToS fixture data with UTF-8 çhãràčtęrs';
306
+ const SNAPSHOT_ID = '61af86dc5ff5caa74ae926ad';
377
307
 
378
- it('records the document with the proper content', async () => {
379
- expect(await record.content).to.equal(CONTENT);
380
- });
308
+ let id;
309
+ let isFirstRecord;
310
+ let record;
381
311
 
382
- it('returns the record id', async () => {
383
- expect(record.id).to.include(id);
384
- });
312
+ context('when it is the first record', () => {
313
+ before(async () => {
314
+ ({ id, isFirstRecord } = await recorder.record(new Version({
315
+ serviceId: SERVICE_ID,
316
+ termsType: TYPE,
317
+ content: CONTENT,
318
+ snapshotIds: [SNAPSHOT_ID],
319
+ fetchDate: FETCH_DATE,
320
+ isExtractOnly: true,
321
+ })));
385
322
 
386
- it('returns a boolean to know if it is the first record', async () => {
387
- expect(isFirstRecord).to.be.true;
388
- });
389
- });
323
+ record = await recorder.versionsRepository.findLatest(SERVICE_ID, TYPE);
324
+ });
390
325
 
391
- context('when it is not the first record', () => {
392
- const UPDATED_CONTENT = '<html><h1>ToS fixture data with UTF-8 çhãràčtęrs</h1><h2>Updated!</h2></html>';
326
+ after(async () => recorder.versionsRepository.removeAll()); after(async () => recorder.versionsRepository.removeAll());
393
327
 
394
- before(async () => {
395
- await recorder.recordRefilter({
396
- serviceId: SERVICE_ID,
397
- documentType: TYPE,
398
- content: CONTENT,
399
- snapshotIds: [SNAPSHOT_ID],
400
- fetchDate: FETCH_DATE,
401
- });
328
+ it('records the version with the proper content', async () => {
329
+ expect(await record.content).to.equal(CONTENT);
330
+ });
402
331
 
403
- ({ id, isFirstRecord } = await recorder.recordRefilter({
404
- serviceId: SERVICE_ID,
405
- documentType: TYPE,
406
- content: UPDATED_CONTENT,
407
- snapshotIds: [SNAPSHOT_ID],
408
- fetchDate: FETCH_DATE_LATER,
409
- }));
332
+ it('returns the record id', async () => {
333
+ expect(record.id).to.include(id);
334
+ });
410
335
 
411
- record = await recorder.versionsRepository.findLatest(SERVICE_ID, TYPE);
412
- });
336
+ it('states that it is the first record', async () => {
337
+ expect(isFirstRecord).to.be.true;
338
+ });
339
+ });
413
340
 
414
- after(async () => recorder.versionsRepository.removeAll());
341
+ context('when it is not the first record', () => {
342
+ const UPDATED_CONTENT = '<html><h1>ToS fixture data with UTF-8 çhãràčtęrs</h1><h2>Updated!</h2></html>';
343
+
344
+ before(async () => {
345
+ await recorder.record(new Version({
346
+ serviceId: SERVICE_ID,
347
+ termsType: TYPE,
348
+ content: CONTENT,
349
+ snapshotIds: [SNAPSHOT_ID],
350
+ fetchDate: FETCH_DATE,
351
+ }));
352
+
353
+ ({ id, isFirstRecord } = await recorder.record(new Version({
354
+ serviceId: SERVICE_ID,
355
+ termsType: TYPE,
356
+ content: UPDATED_CONTENT,
357
+ snapshotIds: [SNAPSHOT_ID],
358
+ fetchDate: FETCH_DATE_LATER,
359
+ isExtractOnly: true,
360
+ })));
361
+
362
+ record = await recorder.versionsRepository.findLatest(SERVICE_ID, TYPE);
363
+ });
415
364
 
416
- it('records the document with the proper content', async () => {
417
- expect(await record.content).to.equal(UPDATED_CONTENT);
418
- });
365
+ after(async () => recorder.versionsRepository.removeAll());
419
366
 
420
- it('records in the document that it is a refilter', async () => {
421
- expect(record.isRefilter).to.equal(true);
422
- });
367
+ it('records the version with the proper content', async () => {
368
+ expect(await record.content).to.equal(UPDATED_CONTENT);
369
+ });
423
370
 
424
- it('returns the record id', async () => {
425
- expect(record.id).to.include(id);
426
- });
371
+ it('records in the version that it is an extracted only version', async () => {
372
+ expect(record.isExtractOnly).to.equal(true);
373
+ });
427
374
 
428
- it('returns a boolean to know if it is the first record', async () => {
429
- expect(isFirstRecord).to.be.false;
430
- });
431
- });
375
+ it('returns the record id', async () => {
376
+ expect(record.id).to.include(id);
377
+ });
432
378
 
433
- context('when the content has not changed', () => {
434
- before(async () => {
435
- await recorder.recordRefilter({
436
- serviceId: SERVICE_ID,
437
- documentType: TYPE,
438
- content: CONTENT,
439
- snapshotIds: [SNAPSHOT_ID],
440
- fetchDate: FETCH_DATE,
379
+ it('states that it is not the first record', async () => {
380
+ expect(isFirstRecord).to.be.false;
381
+ });
441
382
  });
442
383
 
443
- ({ id, isFirstRecord } = await recorder.recordRefilter({
444
- serviceId: SERVICE_ID,
445
- documentType: TYPE,
446
- content: CONTENT,
447
- snapshotIds: [SNAPSHOT_ID],
448
- fetchDate: FETCH_DATE_LATER,
449
- }));
450
-
451
- record = await recorder.versionsRepository.findLatest(SERVICE_ID, TYPE);
452
- });
384
+ context('when the content has not changed', () => {
385
+ before(async () => {
386
+ await recorder.record(new Version({
387
+ serviceId: SERVICE_ID,
388
+ termsType: TYPE,
389
+ content: CONTENT,
390
+ snapshotIds: [SNAPSHOT_ID],
391
+ fetchDate: FETCH_DATE,
392
+ }));
393
+
394
+ ({ id, isFirstRecord } = await recorder.record(new Version({
395
+ serviceId: SERVICE_ID,
396
+ termsType: TYPE,
397
+ content: CONTENT,
398
+ snapshotIds: [SNAPSHOT_ID],
399
+ fetchDate: FETCH_DATE_LATER,
400
+ isExtractOnly: true,
401
+ })));
402
+
403
+ record = await recorder.versionsRepository.findLatest(SERVICE_ID, TYPE);
404
+ });
453
405
 
454
- after(async () => recorder.versionsRepository.removeAll());
406
+ after(async () => recorder.versionsRepository.removeAll());
455
407
 
456
- it('does not record the document', async () => {
457
- expect(id).to.not.be.ok;
408
+ it('does not record any version', async () => {
409
+ expect(id).to.not.be.ok;
410
+ });
411
+ });
458
412
  });
459
413
  });
460
414
  });