fix(api): update-my-username response body (#54901)

This commit is contained in:
Oliver Eyton-Williams
2024-05-23 01:44:36 +02:00
committed by GitHub
parent d4cad32e68
commit aae96b3af9
3 changed files with 13 additions and 13 deletions

View File

@@ -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);
});

View File

@@ -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' });
}
}
);

View File

@@ -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()),