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:
Muhammed Mustafa
2023-05-18 16:29:43 +03:00
committed by GitHub
parent 9e905b58e1
commit 885cf86cd6
2 changed files with 81 additions and 0 deletions

View File

@@ -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', {

View File

@@ -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',
{