mirror of
https://github.com/freeCodeCamp/freeCodeCamp.git
synced 2026-05-26 13:01:43 -04:00
fix(api): allow empty string for social, not undefined (#54621)
This commit is contained in:
committed by
GitHub
parent
9d6c5ebde1
commit
f26a9b9bc0
@@ -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'
|
||||
});
|
||||
|
||||
|
||||
@@ -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({
|
||||
|
||||
Reference in New Issue
Block a user