mirror of
https://github.com/freeCodeCamp/freeCodeCamp.git
synced 2026-05-25 10:01:30 -04:00
fix(api): return after reply (save-challenge) (#57487)
This commit is contained in:
committed by
GitHub
parent
9c7a36c440
commit
3e0b2b914c
@@ -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
|
||||
|
||||
@@ -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(
|
||||
|
||||
Reference in New Issue
Block a user