Skip to content

Commit

Permalink
fix(informative test): #205 replaced test csaf files by template lite…
Browse files Browse the repository at this point in the history
…rals in the code
  • Loading branch information
rainer-exxcellent committed Feb 28, 2025
1 parent 18098b4 commit 05ba3ae
Show file tree
Hide file tree
Showing 4 changed files with 114 additions and 156 deletions.
150 changes: 114 additions & 36 deletions tests/informativeTest_6_3_8.js
Original file line number Diff line number Diff line change
@@ -1,51 +1,129 @@
import { expect } from 'chai'
import informativeTest_6_3_8 from '../lib/informativeTests/informativeTest_6_3_8.js'
import readExampleFiles from './shared/readExampleFiles.js'

const validString = "Mocked as Valid"
const validMarker = 'Mocked as Valid'

const failingExamples = await readExampleFiles(
new URL('informativeTest_6_3_8/failing', import.meta.url)
)
const documentValidBasePart = `category": "csaf_base",
"csaf_version": "2.0",
"lang": "en",
"notes": [
{
"category": "summary",
"text": "${validMarker}"
}
],
"publisher": {
"category": "other",
"name": "OASIS CSAF TC [${validMarker}]",
"namespace": "https://example.com"
},`

const validExamples = await readExampleFiles(
new URL('informativeTest_6_3_8/valid', import.meta.url)
)
const validTrackingpart = `"tracking": {
"current_release_date": "2021-07-21T10:00:00.000Z",
"id": "OASIS_CSAF_TC-CSAF_2.0-2021-6-3-08-01",
"initial_release_date": "2021-07-21T10:00:00.000Z",
"revision_history": [
{
"date": "2021-07-21T10:00:00.000Z",
"number": "1",
"summary": "${validMarker}"
}
],
"status": "final",
"version": "1"
}
}`

/**
* @param {object} params
* @param {string} params.input
* @returns
*/
async function runHunspellMock({ input }) {
if (input.includes(validMarker)) {
return 'Hunspell vMOCK\n\n*'
} else {
return 'Hunspell vMOCK\n\n# wrongword 1'
}
}

describe('Informative test 6.3.8', function () {
describe('failing examples', function () {
for (const [title, failingExample] of failingExamples) {
it(title, async function () {
const result = await informativeTest_6_3_8(failingExample, {
async hunspell({ dictionary, input }) {
if (input.includes(validString)) {
return 'Hunspell vMOCK\n\n*'
} else {
return 'Hunspell vMOCK\n\n# wrongword 1'
const csafWithInvalidTitle = `{
"document": {
"${documentValidBasePart}
"title": "Informative test: Spell check (failing example 1)[Mocked as Invalid]",
${validTrackingpart}
}`

const csafWithInvalidProductName = `{
"document": {
"${documentValidBasePart}
"title": "Informative test: Spell check (failing example 1)[${validMarker}]",
${validTrackingpart},
"product_tree": {
"branches": [
{
"branches": [
{
"branches": [
{
"category": "product_name",
"name": "Mocked as Invalid",
"product": {
"name": "${validMarker}",
"product_id": "7Client-7.6",
"product_identification_helper": {
"cpe": "cpe:/o:redhat:enterprise_linux:7::client"
}
}
}
],
"category": "product_family",
"name": "${validMarker}"
}
],
"category": "vendor",
"name": "${validMarker}"
}
},
})
]
}
}`

expect(result.infos).to.have.length.greaterThan(0)
})
}
describe('failing examples', function () {
it('test invalid title', async function () {
const result = await informativeTest_6_3_8(
JSON.parse(csafWithInvalidTitle),
{
hunspell: runHunspellMock,
}
)
expect(result.infos).to.have.length.greaterThan(0)
})

it('test invalid product name in branch', async function () {
const result = await informativeTest_6_3_8(
JSON.parse(csafWithInvalidProductName),
{
hunspell: runHunspellMock,
}
)
expect(result.infos).to.have.length.greaterThan(0)
})
})

describe('valid examples', function () {
for (const [title, validExample] of validExamples) {
it(title, async function () {
const result = await informativeTest_6_3_8(validExample, {
async hunspell({ dictionary, input }) {
if (input.includes(validString)) {
return 'Hunspell vMOCK\n\n*'
} else {
return 'Hunspell vMOCK\n\n# wrongword 1'
}
},
})
const validCsaf = `{
"document": {
"${documentValidBasePart}
"title": "Informative test: Spell check (failing example 1)[Mocked as Invalid]",
${validTrackingpart}
}`

expect(result.infos.length).to.equal(0)
describe('valid examples', function () {
it('test valid csaf', async function () {
const result = await informativeTest_6_3_8(JSON.parse(validCsaf), {
hunspell: runHunspellMock,
})
}
expect(result.infos).to.have.length.greaterThan(0)
})
})
})

This file was deleted.

This file was deleted.

This file was deleted.

0 comments on commit 05ba3ae

Please sign in to comment.