Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 7 additions & 11 deletions lib/generators/rtb.ts
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ async function createRtbExport (
}

interface FlagElement {
ele: (name: string, attributes?: Record<string, any>) => any
ele: (name: string, attributesOrText?: Record<string, any> | string | number) => any
att: (name: string, value: string) => any
}

Expand All @@ -75,7 +75,7 @@ async function createRtbExport (
}

interface BoxesElement {
ele: (name: string, attributes?: Record<string, any>) => any
ele: (name: string, attributesOrText?: Record<string, any> | string | number) => any
}

interface ChallengeWithCategory {
Expand Down Expand Up @@ -114,10 +114,6 @@ async function createRtbExport (
return difficulty
}

interface FlagElement {
ele: (name: string, attributes?: Record<string, any>) => any
}

function insertFlag (
challenge: Challenge,
flags: FlagElement,
Expand All @@ -143,7 +139,7 @@ async function createRtbExport (
}

interface XmlElement {
ele: (name: string, attributes?: Record<string, any>) => XmlElement
ele: (name: string, attributesOrText?: Record<string, any> | string | number) => XmlElement
up: () => XmlElement
}

Expand All @@ -158,24 +154,24 @@ async function createRtbExport (
if (categories.size > 0) {
const categoriesXml = xmlRTB.ele('categories', { count: categories.size })
Array.from(categories).forEach(category => {
categoriesXml.ele('category').ele('category', { name: category })
categoriesXml.ele('category').ele('category', category)
})
categoriesXml.up()
}
return categories
}

interface XmlRTBElement {
ele: (name: string, attributes?: Record<string, any>) => XmlRTBElement
ele: (name: string, attributesOrText?: Record<string, any> | string | number) => XmlRTBElement
up: () => XmlRTBElement
}

interface CorporationElement {
ele: (name: string, attributes?: Record<string, any>) => CorporationElement
ele: (name: string, attributesOrText?: Record<string, any> | string | number) => CorporationElement
}

interface BoxesElementReturn {
ele: (name: string, attributes?: Record<string, any>) => BoxesElementReturn
ele: (name: string, attributesOrText?: Record<string, any> | string | number) => BoxesElementReturn
}

function insertCorporation (
Expand Down
9 changes: 9 additions & 0 deletions test/unit/generateRtbData.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,15 @@ describe('Generated RTB data', () => {
assert.match(result, /<categories count="3">/)
})

it('should generate categories with text content not attributes (RootTheBox import format)', async () => {
const result = await generateData(challenges, [], defaultOptions)
assert.ok(typeof result === 'string')
assert.match(result, /<category>\s*<category>1<\/category>\s*<\/category>/)
assert.match(result, /<category>\s*<category>2<\/category>\s*<\/category>/)
assert.match(result, /<category>\s*<category>3<\/category>\s*<\/category>/)
assert.doesNotMatch(result, /<category name="/)
})

it('should put each given challenge as a <flag> into the matching category <box>', async () => {
const result = await generateData(challenges, [], defaultOptions)
assert.ok(typeof result === 'string')
Expand Down