Skip to content

Commit 993239f

Browse files
committed
test: fix validateXMLBoilerplate tests
1 parent 682678c commit 993239f

File tree

1 file changed

+14
-57
lines changed

1 file changed

+14
-57
lines changed

tests/xml.test.js

Lines changed: 14 additions & 57 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
import { afterAll, afterEach, beforeAll, describe, expect, test } from 'vitest'
22
import { MODES } from '../lib/config/modes.mjs'
33
import { toContainError, ValidationError, ValidationWarning, ValidationComment } from '../lib/helpers/error.mjs'
4-
import { detectDeprecatedElements, validateCodeBlocks, validateTextLikeRefs, validateIprAttribute, validatePreptimeAttribute, validateSubmissionType, validateIETFTLPBoilerplateXML, validateIPRAutogeneratedBoilerplate } from '../lib/modules/xml.mjs'
4+
import { detectDeprecatedElements, validateCodeBlocks, validateTextLikeRefs, validateIprAttribute, validatePreptimeAttribute, validateSubmissionType, validateIPRAutogeneratedBoilerplate, validateXMLBoilerplate } from '../lib/modules/xml.mjs'
55
import { baseXMLDoc } from './fixtures/base-doc.mjs'
66
import { cloneDeep, set } from 'lodash-es'
77
import { setupServer } from 'msw/node'
@@ -216,19 +216,19 @@ describe('Validate IETF-TLP boilerplate for XML documents', () => {
216216
test('Valid IETF-TLP boilerplate and ipr attribute', async () => {
217217
const doc = cloneDeep(baseXMLDoc)
218218
set(doc, 'data.rfc._attr.ipr', 'trust200902')
219-
await expect(validateIETFTLPBoilerplateXML(doc)).resolves.toHaveLength(0)
219+
await expect(validateXMLBoilerplate(doc)).resolves.toHaveLength(0)
220220
})
221221

222222
test('Unnecessary boilerplate text detected', async () => {
223223
const doc = cloneDeep(baseXMLDoc)
224224
set(doc, 'data.rfc.front.t', 'This Internet-Draft is submitted in full conformance with the provisions of BCP 78 and BCP 79.')
225-
await expect(validateIETFTLPBoilerplateXML(doc)).resolves.toContainError('UNNECESSARY_BOILERPLATE_TEXT', ValidationWarning)
225+
await expect(validateXMLBoilerplate(doc)).resolves.toContainError('UNNECESSARY_BOILERPLATE_TEXT', ValidationWarning)
226226
})
227227

228228
test('Multiple boilerplate texts detected', async () => {
229229
const doc = cloneDeep(baseXMLDoc)
230230
set(doc, 'data.rfc.front.t', 'This Internet-Draft is submitted in full conformance with the provisions of BCP 78 and BCP 79. Copyright (c) 2025 IETF Trust and the persons identified as the document authors. All rights reserved.')
231-
await expect(validateIETFTLPBoilerplateXML(doc)).resolves.toEqual(
231+
await expect(validateXMLBoilerplate(doc)).resolves.toEqual(
232232
expect.arrayContaining([
233233
expect.objectContaining({ name: 'UNNECESSARY_BOILERPLATE_TEXT' }),
234234
expect.objectContaining({ name: 'UNNECESSARY_BOILERPLATE_TEXT' })
@@ -240,14 +240,14 @@ describe('Validate IETF-TLP boilerplate for XML documents', () => {
240240
const doc = cloneDeep(baseXMLDoc)
241241
set(doc, 'data.rfc._attr.ipr', 'trust200902')
242242
set(doc, 'data.rfc.front.t', 'This is a clean document without boilerplate.')
243-
await expect(validateIETFTLPBoilerplateXML(doc)).resolves.toHaveLength(0)
243+
await expect(validateXMLBoilerplate(doc)).resolves.toHaveLength(0)
244244
})
245245
})
246246

247247
describe('Test ipr and ipr autogenerated boilerplate', () => {
248248
test('should report error if ipr attribute is missing', async () => {
249249
const doc = cloneDeep(baseXMLDoc)
250-
const result = await validateIPRAutogeneratedBoilerplate(doc)
250+
const result = await validateXMLBoilerplate(doc)
251251
expect(result).toContainEqual(
252252
expect.objectContaining({
253253
name: 'MISSING_IPR_ATTRIBUTE',
@@ -259,7 +259,7 @@ describe('Test ipr and ipr autogenerated boilerplate', () => {
259259
test('should warn if ipr attribute is invalid', async () => {
260260
const doc = cloneDeep(baseXMLDoc)
261261
set(doc, 'data.rfc._attr.ipr', 'somethingInvalid')
262-
const result = await validateIPRAutogeneratedBoilerplate(doc)
262+
const result = await validateXMLBoilerplate(doc)
263263
expect(result).toContainEqual(
264264
expect.objectContaining({
265265
name: 'INVALID_IPR_VALUE'
@@ -278,19 +278,6 @@ describe('Test ipr and ipr autogenerated boilerplate', () => {
278278
expect(result).toHaveLength(0)
279279
})
280280

281-
test('trust200902 - missing required text', async () => {
282-
const doc = cloneDeep(baseXMLDoc)
283-
set(doc, 'data.rfc._attr.ipr', 'trust200902')
284-
set(doc, 'data.rfc.boilerplate', 'Some incomplete or random text')
285-
286-
const result = await validateIPRAutogeneratedBoilerplate(doc)
287-
expect(result).toContainEqual(
288-
expect.objectContaining({
289-
name: 'MISSING_EXPECTED_BOILERPLATE'
290-
})
291-
)
292-
})
293-
294281
test('trust200902 - has unexpected "noModification"', async () => {
295282
const doc = cloneDeep(baseXMLDoc)
296283
set(doc, 'data.rfc._attr.ipr', 'trust200902')
@@ -319,21 +306,6 @@ describe('Test ipr and ipr autogenerated boilerplate', () => {
319306
expect(result).toHaveLength(0)
320307
})
321308

322-
test('noModificationTrust200902 - missing noModification', async () => {
323-
const doc = cloneDeep(baseXMLDoc)
324-
set(doc, 'data.rfc._attr.ipr', 'noModificationTrust200902')
325-
set(doc, 'data.rfc.boilerplate',
326-
'This Internet-Draft is submitted in full conformance ' +
327-
'with the provisions of BCP 78 and BCP 79.'
328-
)
329-
const result = await validateIPRAutogeneratedBoilerplate(doc)
330-
expect(result).toContainEqual(
331-
expect.objectContaining({
332-
name: 'MISSING_EXPECTED_BOILERPLATE'
333-
})
334-
)
335-
})
336-
337309
test('noDerivativesTrust200902 - has correct texts', async () => {
338310
const doc = cloneDeep(baseXMLDoc)
339311
set(doc, 'data.rfc._attr.ipr', 'noDerivativesTrust200902')
@@ -368,53 +340,38 @@ describe('Test ipr and ipr autogenerated boilerplate', () => {
368340
const result = await validateIPRAutogeneratedBoilerplate(doc)
369341
expect(result).toHaveLength(0)
370342
})
371-
372-
test('pre5378Trust200902 - missing the pre5378 text', async () => {
373-
const doc = cloneDeep(baseXMLDoc)
374-
set(doc, 'data.rfc._attr.ipr', 'pre5378Trust200902')
375-
set(doc, 'data.rfc.boilerplate',
376-
'This Internet-Draft is submitted in full conformance ' +
377-
'with the provisions of BCP 78 and BCP 79.'
378-
)
379-
const result = await validateIPRAutogeneratedBoilerplate(doc)
380-
expect(result).toContainEqual(
381-
expect.objectContaining({
382-
name: 'MISSING_EXPECTED_BOILERPLATE'
383-
})
384-
)
385-
})
386343
})
387344

388345
describe('Validate IETF-TLP boilerplate for XML documents', () => {
389346
test('Valid IETF-TLP boilerplate and ipr attribute', async () => {
390347
const doc = cloneDeep(baseXMLDoc)
391348
set(doc, 'data.rfc._attr.ipr', 'trust200902')
392-
await expect(validateIETFTLPBoilerplateXML(doc)).resolves.toHaveLength(0)
349+
await expect(validateXMLBoilerplate(doc)).resolves.toHaveLength(0)
393350
})
394351

395352
test('Missing ipr attribute', async () => {
396353
const doc = cloneDeep(baseXMLDoc)
397354
set(doc, 'data.rfc._attr', {})
398-
await expect(validateIETFTLPBoilerplateXML(doc)).resolves.toContainError('MISSING_IPR_ATTRIBUTE', ValidationError)
355+
await expect(validateXMLBoilerplate(doc)).resolves.toContainError('MISSING_IPR_ATTRIBUTE', ValidationError)
399356
})
400357

401358
test('Invalid ipr attribute value', async () => {
402359
const doc = cloneDeep(baseXMLDoc)
403360
set(doc, 'data.rfc._attr.ipr', 'invalidValue')
404-
await expect(validateIETFTLPBoilerplateXML(doc)).resolves.toContainError('INVALID_IPR_VALUE', ValidationWarning)
361+
await expect(validateXMLBoilerplate(doc)).resolves.toContainError('INVALID_IPR_VALUE', ValidationWarning)
405362
})
406363

407364
test('Unnecessary boilerplate text detected', async () => {
408365
const doc = cloneDeep(baseXMLDoc)
409366
set(doc, 'data.rfc.front.t', 'This Internet-Draft is submitted in full conformance with the provisions of BCP 78 and BCP 79.')
410-
await expect(validateIETFTLPBoilerplateXML(doc)).resolves.toContainError('UNNECESSARY_BOILERPLATE_TEXT', ValidationWarning)
411-
await expect(validateIETFTLPBoilerplateXML(doc)).resolves.toContainError('MISSING_IPR_ATTRIBUTE', ValidationError)
367+
await expect(validateXMLBoilerplate(doc)).resolves.toContainError('UNNECESSARY_BOILERPLATE_TEXT', ValidationWarning)
368+
await expect(validateXMLBoilerplate(doc)).resolves.toContainError('MISSING_IPR_ATTRIBUTE', ValidationError)
412369
})
413370

414371
test('Multiple boilerplate texts detected', async () => {
415372
const doc = cloneDeep(baseXMLDoc)
416373
set(doc, 'data.rfc.front.t', 'This Internet-Draft is submitted in full conformance with the provisions of BCP 78 and BCP 79. Copyright (c) 2025 IETF Trust and the persons identified as the document authors. All rights reserved.')
417-
await expect(validateIETFTLPBoilerplateXML(doc)).resolves.toEqual(
374+
await expect(validateXMLBoilerplate(doc)).resolves.toEqual(
418375
expect.arrayContaining([
419376
expect.objectContaining({ name: 'UNNECESSARY_BOILERPLATE_TEXT' }),
420377
expect.objectContaining({ name: 'UNNECESSARY_BOILERPLATE_TEXT' })
@@ -426,6 +383,6 @@ describe('Validate IETF-TLP boilerplate for XML documents', () => {
426383
const doc = cloneDeep(baseXMLDoc)
427384
set(doc, 'data.rfc._attr.ipr', 'trust200902')
428385
set(doc, 'data.rfc.front.t', 'This is a clean document without boilerplate.')
429-
await expect(validateIETFTLPBoilerplateXML(doc)).resolves.toHaveLength(0)
386+
await expect(validateXMLBoilerplate(doc)).resolves.toHaveLength(0)
430387
})
431388
})

0 commit comments

Comments
 (0)