mirror of
https://github.com/freeCodeCamp/freeCodeCamp.git
synced 2025-12-25 02:14:11 -05:00
fix(tools): adjust create language block helper script (#62090)
This commit is contained in:
@@ -70,6 +70,26 @@ describe('updateSimpleSuperblockStructure', () => {
|
||||
}
|
||||
);
|
||||
});
|
||||
|
||||
it('should insert the block into the blocks array at the end when no order is given', async () => {
|
||||
const existingBlocks = ['block1', 'block2'];
|
||||
const superblockFilename = 'test-superblock';
|
||||
const newBlock = 'block3';
|
||||
|
||||
mockGetSuperblockStructure.mockReturnValue({
|
||||
blocks: existingBlocks
|
||||
});
|
||||
|
||||
await updateSimpleSuperblockStructure(newBlock, {}, superblockFilename);
|
||||
|
||||
expect(mockGetSuperblockStructure).toHaveBeenCalledWith(superblockFilename);
|
||||
expect(mockWriteSuperblockStructure).toHaveBeenCalledWith(
|
||||
superblockFilename,
|
||||
{
|
||||
blocks: ['block1', 'block2', 'block3']
|
||||
}
|
||||
);
|
||||
});
|
||||
});
|
||||
|
||||
describe('updateChapterModuleSuperblockStructure', () => {
|
||||
|
||||
@@ -8,14 +8,20 @@ import { insertInto } from './utils';
|
||||
|
||||
export async function updateSimpleSuperblockStructure(
|
||||
block: string,
|
||||
position: { order: number },
|
||||
position: { order?: number },
|
||||
superblockFilename: string
|
||||
) {
|
||||
const existing = getSuperblockStructure(superblockFilename) as {
|
||||
blocks: string[];
|
||||
};
|
||||
|
||||
const order =
|
||||
typeof position.order === 'number'
|
||||
? position.order
|
||||
: existing.blocks.length;
|
||||
|
||||
const updated = {
|
||||
blocks: insertInto(existing.blocks, position.order, block)
|
||||
blocks: insertInto(existing.blocks, order, block)
|
||||
};
|
||||
await writeSuperblockStructure(superblockFilename, updated);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user