fix(api): return after reply (save-challenge) (#57487)

This commit is contained in:
Oliver Eyton-Williams
2024-12-12 18:05:14 +01:00
committed by GitHub
parent 9c7a36c440
commit 3e0b2b914c
2 changed files with 22 additions and 4 deletions

View File

@@ -912,9 +912,9 @@ describe('challengeRoutes', () => {
});
});
describe('/save-challenge', () => {
describe('POST /save-challenge', () => {
describe('validation', () => {
test('POST returns 403 status for unsavable challenges', async () => {
test('returns 400 status for unsavable challenges', async () => {
const response = await superPost('/save-challenge').send({
savedChallenges: {
// valid mongo id, but not a saveable one
@@ -941,7 +941,23 @@ describe('challengeRoutes', () => {
});
});
test('POST update the user savedchallenges and return them', async () => {
test('rejects requests for challenges that cannot be saved', async () => {
const response = await superPost('/save-challenge').send({
id: '66ebd4ae2812430bb883c786',
files: multiFileCertProjectBody.files
});
const { savedChallenges } =
await fastifyTestInstance.prisma.user.findFirstOrThrow({
where: { email: 'foo@bar.com' }
});
expect(response.statusCode).toBe(400);
expect(response.text).toEqual('That challenge type is not saveable.');
expect(savedChallenges).toHaveLength(0);
});
test('update the user savedchallenges and return them', async () => {
const response = await superPost('/save-challenge').send({
id: multiFileCertProjectId,
files: updatedMultiFileCertProjectBody.files

View File

@@ -391,7 +391,9 @@ export const challengeRoutes: FastifyPluginCallbackTypebox = (
!multifileCertProjectIds.includes(challengeId) &&
!multifilePythonCertProjectIds.includes(challengeId)
) {
void reply.code(403).send('That challenge type is not saveable.');
return void reply
.code(400)
.send('That challenge type is not saveable.');
}
const userSavedChallenges = saveUserChallengeData(