(
foundChallenges: Challenge[],
meta: { challengeOrder: Challenge[]; dashedName: string },
throwOnError?: boolean
)
| 50 | * @throws {Error} If validation fails (missing challenges, duplicates, etc.) |
| 51 | */ |
| 52 | export function validateChallenges( |
| 53 | foundChallenges: Challenge[], |
| 54 | meta: { challengeOrder: Challenge[]; dashedName: string }, |
| 55 | throwOnError?: boolean |
| 56 | ) { |
| 57 | const metaChallengeIds = new Set(meta.challengeOrder.map(c => c.id)); |
| 58 | const foundChallengeIds = new Set(foundChallenges.map(c => c.id)); |
| 59 | |
| 60 | const throwOrLog = createValidator(throwOnError); |
| 61 | |
| 62 | throwOrLog(() => { |
| 63 | const missingFromMeta = Array.from(foundChallengeIds).filter( |
| 64 | id => !metaChallengeIds.has(id) |
| 65 | ); |
| 66 | if (missingFromMeta.length > 0) |
| 67 | throw Error( |
| 68 | `Challenges found in directory but missing from meta: ${missingFromMeta.join(', ')}` |
| 69 | ); |
| 70 | }); |
| 71 | |
| 72 | throwOrLog(() => { |
| 73 | const missingFromFiles = Array.from(metaChallengeIds).filter( |
| 74 | id => !foundChallengeIds.has(id) |
| 75 | ); |
| 76 | if (missingFromFiles.length > 0) |
| 77 | throw Error( |
| 78 | `Challenges in meta but missing files with id(s): ${missingFromFiles.join(', ')}` |
| 79 | ); |
| 80 | }); |
| 81 | |
| 82 | throwOrLog(() => { |
| 83 | const duplicateIds = duplicates(foundChallenges.map(c => c.id)); |
| 84 | if (duplicateIds.length > 0) |
| 85 | throw Error( |
| 86 | `Duplicate challenges found in found challenges with id(s): ${duplicateIds.join(', ')}` |
| 87 | ); |
| 88 | }); |
| 89 | |
| 90 | throwOrLog(() => { |
| 91 | const duplicateMetaIds = duplicates(meta.challengeOrder.map(c => c.id)); |
| 92 | if (duplicateMetaIds.length > 0) |
| 93 | throw Error( |
| 94 | `Duplicate challenges found in meta with id(s): ${duplicateMetaIds.join(', ')}` |
| 95 | ); |
| 96 | }); |
| 97 | |
| 98 | throwOrLog(() => { |
| 99 | const duplicateTitles = duplicates(foundChallenges.map(c => c.title)); |
| 100 | if (duplicateTitles.length > 0) |
| 101 | throw Error( |
| 102 | `Duplicate titles found in found challenges with title(s): ${duplicateTitles.join(', ')} in block ${meta.dashedName}` |
| 103 | ); |
| 104 | }); |
| 105 | |
| 106 | throwOrLog(() => { |
| 107 | const duplicateMetaTitles = duplicates( |
| 108 | meta.challengeOrder.map(c => c.title) |
| 109 | ); |
no test coverage detected