fix(client): modified test suite to not throw errors (#37894)

modified challenge test suite so it does not throw an error if two steps for the project based curriculum have the same title
This commit is contained in:
Kristofer Koishigawa
2019-12-09 19:36:32 +09:00
committed by Mrugesh Mohapatra
parent 2fbafda167
commit 869b4f479e

View File

@ -2,7 +2,7 @@ class ChallengeTitles {
constructor() { constructor() {
this.knownTitles = []; this.knownTitles = [];
} }
check(title) { check(title, pathAndTitle) {
if (typeof title !== 'string') { if (typeof title !== 'string') {
throw new Error( throw new Error(
`Expected a valid string for ${title}, but got a(n) ${typeof title}` `Expected a valid string for ${title}, but got a(n) ${typeof title}`
@ -12,15 +12,19 @@ class ChallengeTitles {
if (titleToCheck.length === 0) { if (titleToCheck.length === 0) {
throw new Error('Expected a title length greater than 0'); throw new Error('Expected a title length greater than 0');
} }
const isKnown = this.knownTitles.includes(titleToCheck); const isProjectCurriculumChallenge = title.match(/^Part\s*\d+/);
const titleToAdd = isProjectCurriculumChallenge
? pathAndTitle
: titleToCheck;
const isKnown = this.knownTitles.includes(titleToAdd);
if (isKnown) { if (isKnown) {
throw new Error(` throw new Error(`
All challenges must have a unique title. All current curriculum challenges must have a unique title.
The title ${title} is already assigned The title ${title} (at ${pathAndTitle}) is already assigned
`); `);
} }
this.knownTitles = [...this.knownTitles, titleToCheck]; this.knownTitles = [...this.knownTitles, titleToAdd];
} }
} }