mirror of
https://github.com/freeCodeCamp/freeCodeCamp.git
synced 2026-01-06 15:03:08 -05:00
feat(api): add subscribe to quincy email endpoint (#50305)
This commit is contained in:
@@ -159,6 +159,31 @@ describe('settingRoutes', () => {
|
||||
expect(response?.statusCode).toEqual(400);
|
||||
});
|
||||
});
|
||||
|
||||
describe('/update-my-quincy-email', () => {
|
||||
test('PUT returns 200 status code with "success" message', async () => {
|
||||
const response = await request(fastify?.server)
|
||||
.put('/update-my-quincy-email')
|
||||
.set('Cookie', cookies)
|
||||
.send({ sendQuincyEmail: true });
|
||||
|
||||
expect(response?.statusCode).toEqual(200);
|
||||
|
||||
expect(response?.body).toEqual({
|
||||
message: 'flash.subscribe-to-quincy-updated',
|
||||
type: 'success'
|
||||
});
|
||||
});
|
||||
|
||||
test('PUT returns 400 status code with invalid sendQuincyEmail', async () => {
|
||||
const response = await request(fastify?.server)
|
||||
.put('/update-my-quincy-email')
|
||||
.set('Cookie', cookies)
|
||||
.send({ sendQuincyEmail: 'invalid' });
|
||||
|
||||
expect(response?.statusCode).toEqual(400);
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
describe('Unauthenticated User', () => {
|
||||
|
||||
@@ -152,5 +152,46 @@ export const settingRoutes: FastifyPluginCallbackTypebox = (
|
||||
}
|
||||
}
|
||||
);
|
||||
|
||||
fastify.put(
|
||||
'/update-my-quincy-email',
|
||||
{
|
||||
schema: {
|
||||
body: Type.Object({
|
||||
sendQuincyEmail: Type.Boolean()
|
||||
}),
|
||||
response: {
|
||||
200: Type.Object({
|
||||
message: Type.Literal('flash.subscribe-to-quincy-updated'),
|
||||
type: Type.Literal('success')
|
||||
}),
|
||||
500: Type.Object({
|
||||
message: Type.Literal('flash.wrong-updating'),
|
||||
type: Type.Literal('danger')
|
||||
})
|
||||
}
|
||||
}
|
||||
},
|
||||
async (req, reply) => {
|
||||
try {
|
||||
await fastify.prisma.user.update({
|
||||
where: { id: req.session.user.id },
|
||||
data: {
|
||||
sendQuincyEmail: req.body.sendQuincyEmail
|
||||
}
|
||||
});
|
||||
|
||||
return {
|
||||
message: 'flash.subscribe-to-quincy-updated',
|
||||
type: 'success'
|
||||
} as const;
|
||||
} catch (err) {
|
||||
fastify.log.error(err);
|
||||
void reply.code(500);
|
||||
return { message: 'flash.wrong-updating', type: 'danger' } as const;
|
||||
}
|
||||
}
|
||||
);
|
||||
|
||||
done();
|
||||
};
|
||||
|
||||
Reference in New Issue
Block a user