From 001f884e214da144da7913049db478cc7afee071 Mon Sep 17 00:00:00 2001 From: Oliver Eyton-Williams Date: Mon, 15 Dec 2025 12:22:19 +0100 Subject: [PATCH] fix(api): always use the same logic when saving challenges (#64553) --- api/src/routes/protected/challenge.test.ts | 16 ++++++++++++++-- api/src/routes/protected/challenge.ts | 7 ++----- api/src/utils/common-challenge-functions.ts | 5 +---- 3 files changed, 17 insertions(+), 11 deletions(-) diff --git a/api/src/routes/protected/challenge.test.ts b/api/src/routes/protected/challenge.test.ts index b78eb875cee..2f30bd0480a 100644 --- a/api/src/routes/protected/challenge.test.ts +++ b/api/src/routes/protected/challenge.test.ts @@ -901,7 +901,13 @@ describe('challengeRoutes', () => { alreadyCompleted: false, points: 1, completedDate, - savedChallenges: [] + savedChallenges: [ + { + files: jsFiles, + id: JsProjectId, + lastSavedDate: expect.any(Number) + } + ] }); expect(response.statusCode).toBe(200); }); @@ -1089,7 +1095,13 @@ describe('challengeRoutes', () => { alreadyCompleted: false, points: 1, completedDate, - savedChallenges: [] + savedChallenges: [ + { + files: jsFiles, + id: JsProjectId, + lastSavedDate: expect.any(Number) + } + ] }); expect(response.statusCode).toBe(200); }); diff --git a/api/src/routes/protected/challenge.ts b/api/src/routes/protected/challenge.ts index 6e283a8fa01..9d43ceba97f 100644 --- a/api/src/routes/protected/challenge.ts +++ b/api/src/routes/protected/challenge.ts @@ -22,7 +22,7 @@ import { formatCoderoadChallengeCompletedValidation, formatProjectCompletedValidation } from '../../utils/error-formatting.js'; -import { challenges } from '../../utils/get-challenges.js'; +import { challenges, savableChallenges } from '../../utils/get-challenges.js'; import { ProgressTimestamp, getPoints } from '../../utils/progress.js'; import { validateExamFromDbSchema, @@ -1128,10 +1128,7 @@ async function postSaveChallenge( files }; - if ( - !multifileCertProjectIds.includes(challengeId) && - !multifilePythonCertProjectIds.includes(challengeId) - ) { + if (!savableChallenges.has(challengeId)) { logger.warn( { challengeId diff --git a/api/src/utils/common-challenge-functions.ts b/api/src/utils/common-challenge-functions.ts index dd331fcea05..57b438b8480 100644 --- a/api/src/utils/common-challenge-functions.ts +++ b/api/src/utils/common-challenge-functions.ts @@ -194,10 +194,7 @@ export async function updateUserChallengeData( ? [...progressTimestamps, newProgressTimeStamp] : progressTimestamps; - if ( - multifileCertProjectIds.includes(challengeId) || - multifilePythonCertProjectIds.includes(challengeId) - ) { + if (savableChallenges.has(challengeId)) { const challengeToSave: SavedChallenge = { id: challengeId, lastSavedDate: newProgressTimeStamp,