mirror of
https://github.com/freeCodeCamp/freeCodeCamp.git
synced 2026-03-24 11:03:17 -04:00
fix(api): update-my-username response body (#54901)
This commit is contained in:
committed by
GitHub
parent
d4cad32e68
commit
aae96b3af9
@@ -409,10 +409,10 @@ Please wait 5 minutes to resend an authentication link.`
|
||||
username: 'TwaHa1'
|
||||
});
|
||||
|
||||
expect(response.body).toEqual({
|
||||
expect(response.body).toStrictEqual({
|
||||
message: 'flash.username-updated',
|
||||
type: 'success',
|
||||
username: 'TwaHa1'
|
||||
variables: { username: 'TwaHa1' }
|
||||
});
|
||||
|
||||
const user = await fastifyTestInstance.prisma.user.findFirst({
|
||||
@@ -470,10 +470,10 @@ Please wait 5 minutes to resend an authentication link.`
|
||||
username: 'TWaha3'
|
||||
});
|
||||
|
||||
expect(response.body).toEqual({
|
||||
expect(response.body).toStrictEqual({
|
||||
message: 'flash.username-updated',
|
||||
type: 'success',
|
||||
username: 'TWaha3'
|
||||
variables: { username: 'TWaha3' }
|
||||
});
|
||||
expect(response.statusCode).toEqual(200);
|
||||
});
|
||||
|
||||
@@ -358,11 +358,11 @@ ${isLinkSentWithinLimitTTL}`
|
||||
|
||||
if (!validation.valid) {
|
||||
void reply.code(400);
|
||||
return {
|
||||
return reply.send({
|
||||
// TODO(Post-MVP): custom validation errors.
|
||||
message: `Username ${newUsername} ${validation.error}`,
|
||||
type: 'info'
|
||||
} as const;
|
||||
});
|
||||
}
|
||||
|
||||
const isUserNameProfane = isProfane(newUsername);
|
||||
@@ -377,10 +377,10 @@ ${isLinkSentWithinLimitTTL}`
|
||||
|
||||
if (usernameTaken || isUserNameProfane || onBlocklist) {
|
||||
void reply.code(400);
|
||||
return {
|
||||
return reply.send({
|
||||
message: 'flash.username-taken',
|
||||
type: 'info'
|
||||
} as const;
|
||||
});
|
||||
}
|
||||
|
||||
await fastify.prisma.user.update({
|
||||
@@ -391,15 +391,15 @@ ${isLinkSentWithinLimitTTL}`
|
||||
}
|
||||
});
|
||||
|
||||
return {
|
||||
return reply.send({
|
||||
message: 'flash.username-updated',
|
||||
type: 'success',
|
||||
username: newUsernameDisplay
|
||||
} as const;
|
||||
variables: { username: newUsernameDisplay }
|
||||
});
|
||||
} catch (err) {
|
||||
fastify.log.error(err);
|
||||
void reply.code(500);
|
||||
return { message: 'flash.wrong-updating', type: 'danger' } as const;
|
||||
await reply.send({ message: 'flash.wrong-updating', type: 'danger' });
|
||||
}
|
||||
}
|
||||
);
|
||||
|
||||
@@ -8,7 +8,7 @@ export const updateMyUsername = {
|
||||
200: Type.Object({
|
||||
message: Type.String(),
|
||||
type: Type.Literal('success'),
|
||||
username: Type.String()
|
||||
variables: Type.Object({ username: Type.String() })
|
||||
}),
|
||||
400: Type.Object({
|
||||
message: Type.Optional(Type.String()),
|
||||
|
||||
Reference in New Issue
Block a user