mirror of
https://github.com/freeCodeCamp/freeCodeCamp.git
synced 2026-05-23 13:00:41 -04:00
feat(api): add socials links endpoint (#50332)
* feat(api): add socials links endpoint
* Sort the typo in body call
Co-authored-by: Naomi Carrigan <nhcarrigan@gmail.com>
* Revert "Sort the typo in body call"
This reverts commit 0588d3d70d.
---------
Co-authored-by: Naomi Carrigan <nhcarrigan@gmail.com>
This commit is contained in:
@@ -211,6 +211,41 @@ describe('settingRoutes', () => {
|
||||
});
|
||||
});
|
||||
|
||||
describe('/update-my-socials', () => {
|
||||
test('PUT returns 200 status code with "success" message', async () => {
|
||||
const response = await request(fastify?.server)
|
||||
.put('/update-my-socials')
|
||||
.set('Cookie', cookies)
|
||||
.send({
|
||||
website: 'https://www.freecodecamp.org/',
|
||||
twitter: 'https://twitter.com/ossia',
|
||||
linkedin: 'https://www.linkedin.com/in/quincylarson',
|
||||
githubProfile: 'https://github.com/QuincyLarson'
|
||||
});
|
||||
|
||||
expect(response?.statusCode).toEqual(200);
|
||||
|
||||
expect(response?.body).toEqual({
|
||||
message: 'flash.updated-socials',
|
||||
type: 'success'
|
||||
});
|
||||
});
|
||||
|
||||
test('PUT returns 400 status code with invalid socials setting', async () => {
|
||||
const response = await request(fastify?.server)
|
||||
.put('/update-my-socials')
|
||||
.set('Cookie', cookies)
|
||||
.send({
|
||||
website: 'invalid',
|
||||
twitter: 'invalid',
|
||||
linkedin: 'invalid',
|
||||
githubProfile: 'invalid'
|
||||
});
|
||||
|
||||
expect(response?.statusCode).toEqual(400);
|
||||
});
|
||||
});
|
||||
|
||||
describe('/update-my-quincy-email', () => {
|
||||
test('PUT returns 200 status code with "success" message', async () => {
|
||||
const response = await superRequest('/update-my-quincy-email', {
|
||||
|
||||
@@ -117,6 +117,52 @@ export const settingRoutes: FastifyPluginCallbackTypebox = (
|
||||
}
|
||||
);
|
||||
|
||||
fastify.put(
|
||||
'/update-my-socials',
|
||||
{
|
||||
schema: {
|
||||
body: Type.Object({
|
||||
website: Type.Optional(Type.String({ format: 'url' })),
|
||||
twitter: Type.Optional(Type.String({ format: 'url' })),
|
||||
githubProfile: Type.Optional(Type.String({ format: 'url' })),
|
||||
linkedin: Type.Optional(Type.String({ format: 'url' }))
|
||||
}),
|
||||
response: {
|
||||
200: Type.Object({
|
||||
message: Type.Literal('flash.updated-socials'),
|
||||
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: {
|
||||
website: req.body.website,
|
||||
twitter: req.body.twitter,
|
||||
githubProfile: req.body.githubProfile,
|
||||
linkedin: req.body.linkedin
|
||||
}
|
||||
});
|
||||
|
||||
return {
|
||||
message: 'flash.updated-socials',
|
||||
type: 'success'
|
||||
} as const;
|
||||
} catch (err) {
|
||||
fastify.log.error(err);
|
||||
void reply.code(500);
|
||||
return { message: 'flash.wrong-updating', type: 'danger' } as const;
|
||||
}
|
||||
}
|
||||
);
|
||||
|
||||
fastify.put(
|
||||
'/update-my-keyboard-shortcuts',
|
||||
{
|
||||
|
||||
Reference in New Issue
Block a user