Skip to content

Commit ab9835d

Browse files
author
Amrit
committed
test(auth): add authenticate decorator to test buildApp
1 parent d9af1b4 commit ab9835d

1 file changed

Lines changed: 8 additions & 0 deletions

File tree

apps/backend/src/__tests__/auth.test.ts

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,14 @@ async function buildApp() {
3636
await app.register(cookie);
3737
await app.register(jwt, { secret: 'test-secret-for-unit-tests-only' });
3838
app.decorate('prisma', mockPrisma as unknown as PrismaClient);
39+
app.decorate('authenticate', async (request: any, reply: any) => {
40+
try {
41+
const payload = await request.jwtVerify();
42+
request.user = payload;
43+
} catch (err) {
44+
reply.status(401).send({ error: 'Unauthorized' });
45+
}
46+
});
3947
await app.register(authRoutes, { prefix: '/auth' });
4048
await app.ready();
4149
return app;

0 commit comments

Comments
 (0)