Skip to content

Commit ac09fc0

Browse files
fix(tools): ensure module name is available in external curricula data (freeCodeCamp#60610)
1 parent 85bda9c commit ac09fc0

2 files changed

Lines changed: 55 additions & 18 deletions

File tree

client/i18n/locales/english/intro.json

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1787,6 +1787,7 @@
17871787
"css-variables": "Variables",
17881788
"css-grid": "Grid",
17891789
"css-animations": "Animations",
1790+
"review-css": "CSS Review",
17901791
"exam-css": "CSS Exam",
17911792
"code-editors": "Code Editors",
17921793
"javascript-variables-and-strings": "Variables and Strings",
@@ -1809,6 +1810,7 @@
18091810
"recursion": "Recursion",
18101811
"functional-programming": "Functional Programming",
18111812
"asynchronous-javascript": "Asynchronous JavaScript",
1813+
"review-javascript": "JavaScript Review",
18121814
"exam-javascript": "JavaScript Exam",
18131815
"react-fundamentals": "React Fundamentals",
18141816
"react-state-hooks-and-routing": "React State, Hooks, and Routing",

tools/scripts/build/build-external-curricula-data-v2.test.ts

Lines changed: 53 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -74,18 +74,25 @@ ${result.error.message}`
7474
});
7575

7676
test('the super block files generated should have the correct schema', async () => {
77+
const superBlocks = Object.values(SuperBlocks);
78+
7779
const fileArray = (
7880
await readdirp.promise(`${clientStaticPath}/curriculum-data/${VERSION}`, {
7981
directoryFilter: ['!challenges'],
8082
fileFilter: entry => {
8183
// The directory contains super block files and other curriculum-related files.
8284
// We're only interested in super block ones.
83-
const superBlocks = Object.values(SuperBlocks);
84-
return superBlocks.includes(entry.basename);
85+
const isSuperBlock = superBlocks.some(superBlock =>
86+
entry.basename.includes(superBlock)
87+
);
88+
89+
return isSuperBlock;
8590
}
8691
})
8792
).map(file => file.path);
8893

94+
expect(fileArray.length).toBeGreaterThan(0);
95+
8996
fileArray.forEach(fileInArray => {
9097
const fileContent = fs.readFileSync(
9198
`${clientStaticPath}/curriculum-data/${VERSION}/${fileInArray}`,
@@ -102,21 +109,30 @@ ${result.error.message}`);
102109
});
103110

104111
test('block-based super blocks and blocks should have the correct data', async () => {
112+
const superBlocks = Object.values(SuperBlocks);
113+
105114
const superBlockFiles = (
106115
await readdirp.promise(`${clientStaticPath}/curriculum-data/${VERSION}`, {
107116
directoryFilter: ['!challenges'],
108117
fileFilter: entry => {
109118
// The directory contains super block files and other curriculum-related files.
110119
// We're only interested in super block ones.
111-
const superBlocks = Object.values(SuperBlocks);
112-
return (
113-
superBlocks.includes(entry.basename) &&
114-
!chapterBasedSuperBlocks.includes(entry.basename)
120+
const isSuperBlock = superBlocks.some(superBlock =>
121+
entry.basename.includes(superBlock)
115122
);
123+
124+
const isChapterBasedSuperBlock = chapterBasedSuperBlocks.some(
125+
chapterBasedSuperBlock =>
126+
entry.basename.includes(chapterBasedSuperBlock)
127+
);
128+
129+
return isSuperBlock && !isChapterBasedSuperBlock;
116130
}
117131
})
118132
).map(file => file.path);
119133

134+
expect(superBlockFiles.length).toBeGreaterThan(0);
135+
120136
superBlockFiles.forEach(file => {
121137
const fileContentJson = fs.readFileSync(
122138
`${clientStaticPath}/curriculum-data/${VERSION}/${file}`,
@@ -135,33 +151,43 @@ ${result.error.message}`);
135151
// Randomly pick a block to check its data.
136152
const blocks = superBlockData.blocks;
137153
const randomBlockIndex = Math.floor(Math.random() * blocks.length);
154+
const randomBlock = blocks[randomBlockIndex];
138155

139156
expect(superBlockData.intro).toEqual(intros[superBlock].intro);
140157
expect(superBlockData.blocks[randomBlockIndex].intro).toEqual(
141-
intros[superBlock].blocks[randomBlockIndex].intro
158+
intros[superBlock].blocks[randomBlock.meta.dashedName as string].intro
142159
);
143160
expect(superBlockData.blocks[randomBlockIndex].meta.name).toEqual(
144-
intros[superBlock].blocks[randomBlockIndex].title
161+
intros[superBlock].blocks[randomBlock.meta.dashedName as string].title
145162
);
146163
});
147164
});
148165

149166
test('chapter-based super blocks and blocks should have the correct data', async () => {
167+
const superBlocks = Object.values(SuperBlocks);
168+
150169
const superBlockFiles = (
151170
await readdirp.promise(`${clientStaticPath}/curriculum-data/${VERSION}`, {
152171
directoryFilter: ['!challenges'],
153172
fileFilter: entry => {
154173
// The directory contains super block files and other curriculum-related files.
155174
// We're only interested in super block ones.
156-
const superBlocks = Object.values(SuperBlocks);
157-
return (
158-
superBlocks.includes(entry.basename) &&
159-
chapterBasedSuperBlocks.includes(entry.basename)
175+
const isSuperBlock = superBlocks.some(superBlock =>
176+
entry.basename.includes(superBlock)
177+
);
178+
179+
const isChapterBasedSuperBlock = chapterBasedSuperBlocks.some(
180+
chapterBasedSuperBlock =>
181+
entry.basename.includes(chapterBasedSuperBlock)
160182
);
183+
184+
return isSuperBlock && isChapterBasedSuperBlock;
161185
}
162186
})
163187
).map(file => file.path);
164188

189+
expect(superBlockFiles.length).toBeGreaterThan(0);
190+
165191
superBlockFiles.forEach(file => {
166192
const fileContentJson = fs.readFileSync(
167193
`${clientStaticPath}/curriculum-data/${VERSION}/${file}`,
@@ -182,42 +208,51 @@ ${result.error.message}`);
182208
] as ChapterBasedCurriculumIntros[SuperBlocks];
183209

184210
// Randomly pick a chapter.
185-
const chapters = superBlockData.chapters;
211+
const chapters = superBlockData.chapters.filter(
212+
({ comingSoon }) => !comingSoon
213+
);
186214
const randomChapterIndex = Math.floor(Math.random() * chapters.length);
187215
const randomChapter = chapters[randomChapterIndex];
188216

189217
// Randomly pick a module.
190-
const modules = randomChapter.modules;
218+
const modules = randomChapter.modules.filter(
219+
({ comingSoon }) => !comingSoon
220+
);
191221
const randomModuleIndex = Math.floor(Math.random() * modules.length);
192222
const randomModule = modules[randomModuleIndex];
193223

194224
// Randomly pick a block.
195225
const blocks = randomModule.blocks;
196226
const randomBlockIndex = Math.floor(Math.random() * blocks.length);
227+
const randomBlock = blocks[randomBlockIndex];
197228

198229
// Check super block data
199230
expect(superBlockData.intro).toEqual(superBlockIntros.intro);
200231

201232
// Check chapter data
202233
expect(superBlockData.chapters[randomChapterIndex].name).toEqual(
203-
superBlockIntros.chapters[randomChapterIndex]
234+
superBlockIntros.chapters[randomChapter.dashedName]
204235
);
205236

206237
// Check module data
207238
expect(
208239
superBlockData.chapters[randomChapterIndex].modules[randomModuleIndex]
209240
.name
210-
).toEqual(superBlockIntros.modules[randomModuleIndex]);
241+
).toEqual(superBlockIntros.modules[randomModule.dashedName]);
211242

212243
// Check block data
213244
expect(
214245
superBlockData.chapters[randomChapterIndex].modules[randomModuleIndex]
215246
.blocks[randomBlockIndex].intro
216-
).toEqual(superBlockIntros.blocks[randomBlockIndex].intro);
247+
).toEqual(
248+
superBlockIntros.blocks[randomBlock.meta.dashedName as string].intro
249+
);
217250
expect(
218251
superBlockData.chapters[randomChapterIndex].modules[randomModuleIndex]
219252
.blocks[randomBlockIndex].meta.name
220-
).toEqual(superBlockIntros.blocks[randomBlockIndex].title);
253+
).toEqual(
254+
superBlockIntros.blocks[randomBlock.meta.dashedName as string].title
255+
);
221256
});
222257
});
223258

0 commit comments

Comments
 (0)