Skip to content

Commit

Permalink
Filter out broken matches which are no challenges
Browse files Browse the repository at this point in the history
  • Loading branch information
bkimminich committed Sep 15, 2021
1 parent 69059a3 commit 8e1395d
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 10 deletions.
2 changes: 1 addition & 1 deletion routes/vulnCodeSnippet.ts
Original file line number Diff line number Diff line change
Expand Up @@ -141,7 +141,7 @@ exports.serveCodeSnippet = () => async (req: Request<SnippetRequestBody, {}, {}>
exports.challengesWithCodeSnippet = () => async (req: Request, res: Response, next: NextFunction) => { // TODO Split off function for actual detection and reuse in codingChallengeFixesSpec
const match = /vuln-code-snippet start .*/
const matches = await fileSniff(SNIPPET_PATHS, match)
const challenges = matches.map(m => m.match.trim().substr(26).trim()).join(' ').split(' ')
const challenges = matches.map(m => m.match.trim().substr(26).trim()).join(' ').split(' ').filter(c => c.endsWith('Challenge'))
res.json({ challenges })
}

Expand Down
14 changes: 5 additions & 9 deletions test/server/codingChallengeFixesSpec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,24 +15,20 @@ describe('codingChallengeFixes', () => {
before(async () => {
const match = /vuln-code-snippet start .*/
const matches = await fileSniff(SNIPPET_PATHS, match)
codingChallenges = matches.map(m => m.match.trim().substr(26).trim()).join(' ').split(' ')
codingChallenges = matches.map(m => m.match.trim().substr(26).trim()).join(' ').split(' ').filter(c => c.endsWith('Challenge'))
})

it('should have a correct fix for each coding challenge', async () => {
for (const challenge of codingChallenges) {
if (challenge.endsWith('Challenge')) {
const fixes = readFixes(challenge)
expect(fixes.correct, `Coding challenge ${challenge} does not have a correct fix file`).to.be.greaterThan(-1)
}
const fixes = readFixes(challenge)
expect(fixes.correct, `Coding challenge ${challenge} does not have a correct fix file`).to.be.greaterThan(-1)
}
})

it('should have a total of three or more fix options for each coding challenge', async () => {
for (const challenge of codingChallenges) {
if (challenge.endsWith('Challenge')) {
const fixes = readFixes(challenge)
expect(fixes.fixes.length, `Coding challenge ${challenge} does not have enough fix option files`).to.be.greaterThanOrEqual(3)
}
const fixes = readFixes(challenge)
expect(fixes.fixes.length, `Coding challenge ${challenge} does not have enough fix option files`).to.be.greaterThanOrEqual(3)
}
})
})

0 comments on commit 8e1395d

Please sign in to comment.