|
1 | 1 | const test = require('node:test'); |
2 | 2 | const assert = require('node:assert/strict'); |
3 | | -const { readRegistry, flipDraft, documentScope, publicationChanges, registryChanges } = require('../scripts/review/documents'); |
| 3 | +const { readRegistry, flipDraft, documentScope, publicationChanges, registryChanges, validLocation } = require('../scripts/review/documents'); |
4 | 4 | const source = `const docs = [{doc_location:'a/manual', active:true, draft:true},{doc_location:'b/manual',active:true,draft:true}]; module.exports={docs};`; |
| 5 | +test('actual registry supports PDF-only tiles while detecting document changes', () => { |
| 6 | + const registry = require('node:fs').readFileSync(require('node:path').join(__dirname, '../src/docConfig.js'), 'utf8'); |
| 7 | + assert.deepEqual(registryChanges(registry, registry), []); |
| 8 | + const changed = registry.replace('const docs = [', "const docs = [{doc_location:'regression/manual',active:true,draft:true},"); |
| 9 | + assert.deepEqual(registryChanges(registry, changed), ['regression/manual']); |
| 10 | +}); |
| 11 | + |
| 12 | +test('PDF-only tiles need no document path but malformed document entries are rejected', () => { |
| 13 | + const pdf = `const docs=[{downloadUrl:'/report.pdf',doc_name:'Report'}];`; |
| 14 | + assert.deepEqual(registryChanges(pdf, pdf), []); |
| 15 | + for (const entry of ['{}', "{downloadUrl:''}", "{doc_location:null,downloadUrl:'/report.pdf'}"]) { |
| 16 | + assert.throws(() => registryChanges(`const docs=[${entry}];`, source), /Invalid document location/); |
| 17 | + } |
| 18 | +}); |
| 19 | + |
| 20 | +test('document locations reject non-string values with a validation error', () => { |
| 21 | + for (const value of [undefined, null, 123, true, {}, '']) { |
| 22 | + assert.throws(() => validLocation(value), /Invalid document location/); |
| 23 | + } |
| 24 | +}); |
5 | 25 | test('only the explicitly selected registry flag changes', () => { |
6 | 26 | const result = flipDraft(source, 'a/manual'); |
7 | 27 | assert.equal(readRegistry(result)[0].draft, false); |
|
0 commit comments