From f4a45878b776f70da06cc36a241144117e870b4a Mon Sep 17 00:00:00 2001 From: Oliver Eyton-Williams Date: Fri, 4 Aug 2023 15:43:37 +0200 Subject: [PATCH] fix(test): confirm the decoded token is correct (#51143) --- api/src/routes/user.test.ts | 13 ++++--------- 1 file changed, 4 insertions(+), 9 deletions(-) diff --git a/api/src/routes/user.test.ts b/api/src/routes/user.test.ts index a8d7fceeb85..0486bc8c688 100644 --- a/api/src/routes/user.test.ts +++ b/api/src/routes/user.test.ts @@ -15,7 +15,6 @@ import { superRequest } from '../../jest.utils'; import { JWT_SECRET } from '../utils/env'; -import { encodeUserToken } from '../utils/user-token'; // This is used to build a test user. const testUserData: Prisma.userCreateInput = { @@ -504,8 +503,6 @@ describe('userRoutes', () => { created: new Date() }; - const encodedToken = encodeUserToken(tokenData.id); - await fastifyTestInstance.prisma.userToken.create({ data: tokenData }); @@ -518,13 +515,11 @@ describe('userRoutes', () => { setCookies }); - const { - user: { foobar } - } = response.body as unknown as { - user: { foobar: unknown }; - }; + const { userToken } = jwt.decode( + response.body.user.foobar.userToken + ) as { userToken: string }; - expect(foobar).toMatchObject({ userToken: encodedToken }); + expect(tokenData.id).toBe(userToken); }); test('GET returns a minimal user when all optional properties are missing', async () => { // To get a minimal test user we first delete the existing one...