Files
freeCodeCamp/tools/scripts/build/mobile-curriculum.test.ts
2022-06-03 10:47:35 +05:30

82 lines
2.7 KiB
TypeScript

import path from 'path';
import fs from 'fs';
import { AssertionError } from 'chai';
import envData from '../../../config/env.json';
import { SuperBlocks } from '../../../config/certification-settings';
import { mobileSchemaValidator } from './mobileSchema';
import { superBlockMobileAppOrder } from './build-external-curricula-data';
if (envData.clientLocale == 'english' && !envData.showUpcomingChanges) {
const VERSION = 'v1';
describe('mobile curriculum build', () => {
const mobileStaticPath = path.resolve(__dirname, '../../../client/static');
const blockIntroPath = path.resolve(
__dirname,
'../../../client/i18n/locales/english/intro.json'
);
const validateMobileSuperBlock = mobileSchemaValidator();
test('the mobile curriculum should have a static folder with multiple files', () => {
expect(
fs.existsSync(`${mobileStaticPath}/curriculum-data/${VERSION}`)
).toBe(true);
expect(
fs.readdirSync(`${mobileStaticPath}/curriculum-data/${VERSION}`).length
).toBeGreaterThan(0);
});
test('the mobile curriculum should have access to the intro.json file', () => {
expect(fs.existsSync(blockIntroPath)).toBe(true);
});
test('the files generated should have the correct schema', () => {
const fileArray = fs.readdirSync(
`${mobileStaticPath}/curriculum-data/${VERSION}`
);
fileArray
.filter(fileInArray => fileInArray !== 'available-superblocks.json')
.forEach(fileInArray => {
const fileContent = fs.readFileSync(
`${mobileStaticPath}/curriculum-data/${VERSION}/${fileInArray}`,
'utf-8'
);
const result = validateMobileSuperBlock(JSON.parse(fileContent));
if (result.error) {
throw new AssertionError(
result.error.toString(),
`file: ${fileInArray}`
);
}
});
});
test('All SuperBlocks should be present in the mobile SuperBlock object', () => {
const dashedNames = superBlockMobileAppOrder.map(
({ dashedName }) => dashedName
);
// 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 => x !== '2022/javascript-algorithms-and-data-structures'
);
expect(dashedNames).toEqual(
expect.arrayContaining(publicSuperBlockNames)
);
expect(Object.keys(superBlockMobileAppOrder)).toHaveLength(
publicSuperBlockNames.length
);
});
});
} else {
describe.skip('Mobile curriculum is not localized', () => {
test.todo('localized tests');
});
}