fix(tools): use ObjectId filename in create-next-challenge and insert-challenge scripts (#66355)

This commit is contained in:
Ragini Pandey
2026-03-13 00:07:34 +05:30
committed by GitHub
parent a135c4589b
commit b5b35d02c2
3 changed files with 7 additions and 6 deletions

View File

@@ -14,7 +14,7 @@ const createNextChallenge = async () => {
const challengeId = new ObjectId();
const challengeText = template({ ...options, challengeId });
createChallengeFile(options.dashedName, challengeText, path);
createChallengeFile(challengeId.toString(), challengeText, path);
const meta = getMetaData();
meta.challengeOrder.push({

View File

@@ -27,7 +27,7 @@ const insertChallenge = async () => {
const template = getTemplate(options.challengeType);
const challengeId = new ObjectId();
const challengeText = template({ ...options, challengeId });
createChallengeFile(options.dashedName, challengeText, path);
createChallengeFile(challengeId.toString(), challengeText, path);
const meta = getMetaData();
meta.challengeOrder.splice(indexToInsert, 0, {

View File

@@ -119,14 +119,15 @@ describe('Challenge utils helper scripts', () => {
});
describe('createChallengeFile util', () => {
it('should create the challenge', () => {
it('should create the challenge using an ObjectId string as the filename', () => {
process.env.INIT_CWD = projectPath;
const template = 'pretend this is a template';
const challengeId = new ObjectId();
createChallengeFile('hi', template);
// - Should write a file with a given name and template
createChallengeFile(challengeId.toString(), template);
// - Should write a file named after the ObjectId with the given template
expect(fs.writeFileSync).toHaveBeenCalledWith(
`${projectPath}/hi.md`,
`${projectPath}/${challengeId.toString()}.md`,
template
);
});