mirror of
https://github.com/freeCodeCamp/freeCodeCamp.git
synced 2026-05-28 18:26:54 +00:00
refactor: simplify is-audited logic (#57346)
This commit is contained in:
committed by
GitHub
parent
3c48b8dd3f
commit
ce8b971073
@@ -4,7 +4,7 @@ import {
|
||||
SuperBlockStage,
|
||||
superBlockStages,
|
||||
notAuditedSuperBlocks,
|
||||
createFlatSuperBlockMap,
|
||||
generateSuperBlockList,
|
||||
getAuditedSuperBlocks
|
||||
} from './curriculum';
|
||||
|
||||
@@ -19,9 +19,9 @@ describe('superBlockOrder', () => {
|
||||
});
|
||||
});
|
||||
|
||||
describe('createFlatSuperBlockMap', () => {
|
||||
describe('generateSuperBlockList', () => {
|
||||
it('should return an array of SuperBlocks object with New and Upcoming when { showNewCurriculum: true, showUpcomingChanges: true }', () => {
|
||||
const result = createFlatSuperBlockMap({
|
||||
const result = generateSuperBlockList({
|
||||
showNewCurriculum: true,
|
||||
showUpcomingChanges: true
|
||||
});
|
||||
@@ -29,7 +29,7 @@ describe('createFlatSuperBlockMap', () => {
|
||||
});
|
||||
|
||||
it('should return an array of SuperBlocks without New and Upcoming when { showNewCurriculum: false, showUpcomingChanges: false }', () => {
|
||||
const result = createFlatSuperBlockMap({
|
||||
const result = generateSuperBlockList({
|
||||
showNewCurriculum: false,
|
||||
showUpcomingChanges: false
|
||||
});
|
||||
@@ -64,8 +64,6 @@ describe('getAuditedSuperBlocks', () => {
|
||||
Object.keys(notAuditedSuperBlocks).forEach(language => {
|
||||
it(`should return only audited SuperBlocks for ${language}`, () => {
|
||||
const auditedSuperBlocks = getAuditedSuperBlocks({
|
||||
showNewCurriculum: true,
|
||||
showUpcomingChanges: true,
|
||||
language
|
||||
});
|
||||
|
||||
|
||||
@@ -248,28 +248,25 @@ type Config = {
|
||||
showUpcomingChanges: boolean;
|
||||
};
|
||||
|
||||
type LanguagesConfig = Config & {
|
||||
language: string;
|
||||
};
|
||||
|
||||
export function createFlatSuperBlockMap(config: Config): SuperBlocks[] {
|
||||
export function generateSuperBlockList(config: Config): SuperBlocks[] {
|
||||
return getStageOrder(config)
|
||||
.map(stage => superBlockStages[stage])
|
||||
.flat();
|
||||
}
|
||||
|
||||
export function getAuditedSuperBlocks({
|
||||
language = 'english',
|
||||
showNewCurriculum,
|
||||
showUpcomingChanges
|
||||
}: LanguagesConfig): SuperBlocks[] {
|
||||
language = 'english'
|
||||
}: {
|
||||
language: string;
|
||||
}): SuperBlocks[] {
|
||||
if (!Object.prototype.hasOwnProperty.call(notAuditedSuperBlocks, language)) {
|
||||
throw Error(`'${language}' key not found in 'notAuditedSuperBlocks'`);
|
||||
}
|
||||
|
||||
const flatSuperBlockMap = createFlatSuperBlockMap({
|
||||
showNewCurriculum,
|
||||
showUpcomingChanges
|
||||
// To find the audited superblocks, we need to start with all superblocks.
|
||||
const flatSuperBlockMap = generateSuperBlockList({
|
||||
showNewCurriculum: true,
|
||||
showUpcomingChanges: true
|
||||
});
|
||||
const auditedSuperBlocks = flatSuperBlockMap.filter(
|
||||
superBlock =>
|
||||
|
||||
@@ -3,22 +3,13 @@ import {
|
||||
getAuditedSuperBlocks
|
||||
} from '../../shared/config/curriculum';
|
||||
|
||||
export function isAuditedSuperBlock(
|
||||
language: string,
|
||||
superblock: SuperBlocks,
|
||||
{
|
||||
showNewCurriculum,
|
||||
showUpcomingChanges
|
||||
}: { showNewCurriculum: boolean; showUpcomingChanges: boolean }
|
||||
) {
|
||||
export function isAuditedSuperBlock(language: string, superblock: SuperBlocks) {
|
||||
// TODO: when all the consumers of this function use TypeScript we can remove
|
||||
// this check
|
||||
if (!language || !superblock)
|
||||
throw Error('Both arguments must be provided for auditing');
|
||||
|
||||
const auditedSuperBlocks = getAuditedSuperBlocks({
|
||||
showNewCurriculum,
|
||||
showUpcomingChanges,
|
||||
language
|
||||
});
|
||||
return auditedSuperBlocks.includes(superblock);
|
||||
|
||||
Reference in New Issue
Block a user