refactor: simplify is-audited logic (#57346)

This commit is contained in:
Oliver Eyton-Williams
2024-12-06 18:24:47 +01:00
committed by GitHub
parent 3c48b8dd3f
commit ce8b971073
8 changed files with 26 additions and 55 deletions
+4 -6
View File
@@ -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
});
+9 -12
View File
@@ -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 =>
+1 -10
View File
@@ -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);