mirror of
https://github.com/freeCodeCamp/freeCodeCamp.git
synced 2026-03-24 20:00:39 -04:00
fix(tools): use ObjectId filename in create-next-challenge and insert-challenge scripts (#66355)
This commit is contained in:
@@ -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({
|
||||
|
||||
@@ -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, {
|
||||
|
||||
@@ -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
|
||||
);
|
||||
});
|
||||
|
||||
Reference in New Issue
Block a user