mirror of
https://github.com/freeCodeCamp/freeCodeCamp.git
synced 2026-05-28 18:26:54 +00:00
fix: stop using env.json outside the client (#51456)
This commit is contained in:
committed by
GitHub
parent
d4fb1ed91f
commit
569ace00ae
@@ -8,17 +8,13 @@ import {
|
||||
CurriculumProps
|
||||
} from './build-external-curricula-data';
|
||||
|
||||
const { CURRICULUM_LOCALE } = process.env;
|
||||
|
||||
const globalConfigPath = path.resolve(__dirname, '../../../config');
|
||||
|
||||
// We are defaulting to English because the ids for the challenges are same
|
||||
// across all languages.
|
||||
void getChallengesForLang('english')
|
||||
.then((result: Record<string, unknown>) => {
|
||||
if (CURRICULUM_LOCALE === 'english') {
|
||||
buildExtCurriculumData('v1', result as Curriculum<CurriculumProps>);
|
||||
}
|
||||
buildExtCurriculumData('v1', result as Curriculum<CurriculumProps>);
|
||||
return result;
|
||||
})
|
||||
.then(JSON.stringify)
|
||||
|
||||
@@ -4,7 +4,6 @@ import fs from 'fs';
|
||||
import readdirp from 'readdirp';
|
||||
// TODO: remove chai and use jest's assertion errors
|
||||
import { AssertionError } from 'chai';
|
||||
import envData from '../../../config/env.json';
|
||||
import { SuperBlocks } from '../../../config/superblocks';
|
||||
import {
|
||||
superblockSchemaValidator,
|
||||
@@ -12,106 +11,97 @@ import {
|
||||
} from './external-data-schema';
|
||||
import { orderedSuperBlockInfo } from './build-external-curricula-data';
|
||||
|
||||
if (envData.clientLocale == 'english' && !envData.showUpcomingChanges) {
|
||||
const VERSION = 'v1';
|
||||
const VERSION = 'v1';
|
||||
|
||||
describe('external curriculum data build', () => {
|
||||
const clientStaticPath = path.resolve(__dirname, '../../../client/static');
|
||||
describe('external curriculum data build', () => {
|
||||
const clientStaticPath = path.resolve(__dirname, '../../../client/static');
|
||||
|
||||
const validateSuperBlock = superblockSchemaValidator();
|
||||
const validateSuperBlock = superblockSchemaValidator();
|
||||
|
||||
test("the external curriculum data should be in the client's static directory", () => {
|
||||
expect(
|
||||
fs.existsSync(`${clientStaticPath}/curriculum-data/${VERSION}`)
|
||||
).toBe(true);
|
||||
test("the external curriculum data should be in the client's static directory", () => {
|
||||
expect(
|
||||
fs.existsSync(`${clientStaticPath}/curriculum-data/${VERSION}`)
|
||||
).toBe(true);
|
||||
|
||||
expect(
|
||||
fs.readdirSync(`${clientStaticPath}/curriculum-data/${VERSION}`).length
|
||||
).toBeGreaterThan(0);
|
||||
});
|
||||
expect(
|
||||
fs.readdirSync(`${clientStaticPath}/curriculum-data/${VERSION}`).length
|
||||
).toBeGreaterThan(0);
|
||||
});
|
||||
|
||||
test('there should be an endpoint to request submit types from', () => {
|
||||
fs.existsSync(
|
||||
`${clientStaticPath}/curriculum-data/${VERSION}/submit-types.json`
|
||||
test('there should be an endpoint to request submit types from', () => {
|
||||
fs.existsSync(
|
||||
`${clientStaticPath}/curriculum-data/${VERSION}/submit-types.json`
|
||||
);
|
||||
});
|
||||
|
||||
test('the available-superblocks file should have the correct structure', async () => {
|
||||
const validateAvailableSuperBlocks = availableSuperBlocksValidator();
|
||||
const availableSuperblocks: unknown = JSON.parse(
|
||||
await fs.promises.readFile(
|
||||
`${clientStaticPath}/curriculum-data/${VERSION}/available-superblocks.json`,
|
||||
'utf-8'
|
||||
)
|
||||
);
|
||||
|
||||
const result = validateAvailableSuperBlocks(availableSuperblocks);
|
||||
|
||||
if (result.error) {
|
||||
throw new AssertionError(
|
||||
result.error.toString(),
|
||||
`file: available-superblocks.json`
|
||||
);
|
||||
});
|
||||
}
|
||||
});
|
||||
|
||||
test('the available-superblocks file should have the correct structure', async () => {
|
||||
const validateAvailableSuperBlocks = availableSuperBlocksValidator();
|
||||
const availableSuperblocks: unknown = JSON.parse(
|
||||
await fs.promises.readFile(
|
||||
`${clientStaticPath}/curriculum-data/${VERSION}/available-superblocks.json`,
|
||||
test('the files generated should have the correct schema', async () => {
|
||||
const fileArray = (
|
||||
await readdirp.promise(`${clientStaticPath}/curriculum-data/${VERSION}`, {
|
||||
directoryFilter: ['!challenges']
|
||||
})
|
||||
).map(file => file.path);
|
||||
|
||||
fileArray
|
||||
.filter(fileInArray => fileInArray !== 'available-superblocks.json')
|
||||
.forEach(fileInArray => {
|
||||
const fileContent = fs.readFileSync(
|
||||
`${clientStaticPath}/curriculum-data/${VERSION}/${fileInArray}`,
|
||||
'utf-8'
|
||||
)
|
||||
);
|
||||
|
||||
const result = validateAvailableSuperBlocks(availableSuperblocks);
|
||||
|
||||
if (result.error) {
|
||||
throw new AssertionError(
|
||||
result.error.toString(),
|
||||
`file: available-superblocks.json`
|
||||
);
|
||||
}
|
||||
});
|
||||
|
||||
test('the files generated should have the correct schema', async () => {
|
||||
const fileArray = (
|
||||
await readdirp.promise(
|
||||
`${clientStaticPath}/curriculum-data/${VERSION}`,
|
||||
{ directoryFilter: ['!challenges'] }
|
||||
)
|
||||
).map(file => file.path);
|
||||
const result = validateSuperBlock(JSON.parse(fileContent));
|
||||
|
||||
fileArray
|
||||
.filter(fileInArray => fileInArray !== 'available-superblocks.json')
|
||||
.forEach(fileInArray => {
|
||||
const fileContent = fs.readFileSync(
|
||||
`${clientStaticPath}/curriculum-data/${VERSION}/${fileInArray}`,
|
||||
'utf-8'
|
||||
if (result.error) {
|
||||
throw new AssertionError(
|
||||
result.error.toString(),
|
||||
`file: ${fileInArray}`
|
||||
);
|
||||
|
||||
const result = validateSuperBlock(JSON.parse(fileContent));
|
||||
|
||||
if (result.error) {
|
||||
throw new AssertionError(
|
||||
result.error.toString(),
|
||||
`file: ${fileInArray}`
|
||||
);
|
||||
}
|
||||
});
|
||||
});
|
||||
|
||||
test('All public SuperBlocks should be present in the SuperBlock object', () => {
|
||||
const dashedNames = orderedSuperBlockInfo.map(
|
||||
({ dashedName }) => dashedName
|
||||
);
|
||||
|
||||
const isUpcoming = [
|
||||
'2022/javascript-algorithms-and-data-structures',
|
||||
'college-algebra-with-python',
|
||||
'foundational-c-sharp-with-microsoft',
|
||||
'the-odin-project',
|
||||
'upcoming-python',
|
||||
'example-certification'
|
||||
];
|
||||
|
||||
// TODO: this is a hack, we should have a single source of truth for the
|
||||
// list of superblocks that are available.
|
||||
const publicSuperBlockNames = Object.values(SuperBlocks).filter(
|
||||
x => !isUpcoming.includes(x)
|
||||
);
|
||||
|
||||
expect(dashedNames).toEqual(
|
||||
expect.arrayContaining(publicSuperBlockNames)
|
||||
);
|
||||
expect(Object.keys(orderedSuperBlockInfo)).toHaveLength(
|
||||
publicSuperBlockNames.length
|
||||
);
|
||||
});
|
||||
}
|
||||
});
|
||||
});
|
||||
} else {
|
||||
describe.skip('External curriculum data is localized', () => {
|
||||
test.todo('localized tests');
|
||||
|
||||
test('All public SuperBlocks should be present in the SuperBlock object', () => {
|
||||
const dashedNames = orderedSuperBlockInfo.map(
|
||||
({ dashedName }) => dashedName
|
||||
);
|
||||
|
||||
const isUpcoming = [
|
||||
'2022/javascript-algorithms-and-data-structures',
|
||||
'college-algebra-with-python',
|
||||
'foundational-c-sharp-with-microsoft',
|
||||
'the-odin-project',
|
||||
'upcoming-python',
|
||||
'example-certification'
|
||||
];
|
||||
|
||||
// TODO: this is a hack, we should have a single source of truth for the
|
||||
// list of superblocks that are available.
|
||||
const publicSuperBlockNames = Object.values(SuperBlocks).filter(
|
||||
x => !isUpcoming.includes(x)
|
||||
);
|
||||
|
||||
expect(dashedNames).toEqual(expect.arrayContaining(publicSuperBlockNames));
|
||||
expect(Object.keys(orderedSuperBlockInfo)).toHaveLength(
|
||||
publicSuperBlockNames.length
|
||||
);
|
||||
});
|
||||
}
|
||||
});
|
||||
|
||||
Reference in New Issue
Block a user