diff --git a/api/src/routes/settings.test.ts b/api/src/routes/settings.test.ts index 490bb9b3a93..4234aac421c 100644 --- a/api/src/routes/settings.test.ts +++ b/api/src/routes/settings.test.ts @@ -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); }); diff --git a/api/src/routes/settings.ts b/api/src/routes/settings.ts index 81a07deaffc..c80f7f4eddb 100644 --- a/api/src/routes/settings.ts +++ b/api/src/routes/settings.ts @@ -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' }); } } ); diff --git a/api/src/schemas/settings/update-my-username.ts b/api/src/schemas/settings/update-my-username.ts index f7f04779eca..46df9b368ae 100644 --- a/api/src/schemas/settings/update-my-username.ts +++ b/api/src/schemas/settings/update-my-username.ts @@ -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()),