fix(seed): Simplify Unique Titles Test (#17056)

Originally the test would check for the index of a title in an array of
unique challenge titles. However, the index of the title within the
array isn't important for this test, so I simplified the code using
@Bouncey's suggestion in PR #17035.

Also changed grammar for the error that's thrown when a challenge
title isn't a valid string.

BREAKING CHANGE: None
pull/17059/head
Kristofer Koishigawa 2018-04-13 23:15:40 +09:00 committed by Stuart Taylor
parent bcd31aa499
commit d6f217c1b9
1 changed files with 3 additions and 3 deletions

View File

@ -6,13 +6,13 @@ class ChallengeTitles {
}
check(title) {
if (typeof title !== 'string') {
throw new Error(`Expected a valid string for ${title}, got ${typeof title}`);
throw new Error(`Expected a valid string for ${title}, but got a(n) ${typeof title}`);
} else if (title.length === 0) {
throw new Error(`Expected a title length greater than 0`);
}
const titleToCheck = title.toLowerCase().replace(/\s+/g, '');
const titleIndex = _.findIndex(this.knownTitles, existing => titleToCheck === existing);
if (titleIndex !== -1) {
const isKnown = this.knownTitles.includes(titleToCheck);
if (isKnown) {
throw new Error(`
All challenges must have a unique title.