fix(api): allow empty string for social, not undefined (#54621)

This commit is contained in:
Oliver Eyton-Williams
2024-05-03 09:23:47 +02:00
committed by GitHub
parent 9d6c5ebde1
commit f26a9b9bc0
2 changed files with 26 additions and 8 deletions

View File

@@ -530,11 +530,26 @@ Please wait 5 minutes to resend an authentication link.`
expect(response.statusCode).toEqual(200);
});
test('PUT accepts empty strings for socials', async () => {
const response = await superPut('/update-my-socials').send({
website: 'https://www.freecodecamp.org/',
twitter: '',
linkedin: '',
githubProfile: ''
});
expect(response.body).toEqual({
message: 'flash.updated-socials',
type: 'success'
});
expect(response.statusCode).toEqual(200);
});
test('PUT returns 400 status code with invalid socials setting', async () => {
const response = await superPut('/update-my-socials').send({
website: 'invalid',
twitter: 'invalid',
linkedin: 'invalid',
twitter: '',
linkedin: '',
githubProfile: 'invalid'
});

View File

@@ -1,13 +1,16 @@
import { Type } from '@fastify/type-provider-typebox';
const urlOrEmptyString = Type.Union([
Type.Literal(''),
Type.String({ format: 'uri', maxLength: 1024 })
]);
export const updateMySocials = {
body: Type.Object({
website: Type.Optional(Type.String({ format: 'url', maxLength: 1024 })),
twitter: Type.Optional(Type.String({ format: 'url', maxLength: 1024 })),
githubProfile: Type.Optional(
Type.String({ format: 'url', maxLength: 1024 })
),
linkedin: Type.Optional(Type.String({ format: 'url', maxLength: 1024 }))
website: urlOrEmptyString,
twitter: urlOrEmptyString,
githubProfile: urlOrEmptyString,
linkedin: urlOrEmptyString
}),
response: {
200: Type.Object({