Skip to content

Commit

Permalink
Refactor DELETE tests
Browse files Browse the repository at this point in the history
  • Loading branch information
Advayp committed Jan 23, 2025
1 parent 97c6a8e commit 2288b12
Show file tree
Hide file tree
Showing 4 changed files with 22 additions and 52 deletions.
16 changes: 0 additions & 16 deletions backend/app/api/user/logout/auth.test.ts

This file was deleted.

15 changes: 0 additions & 15 deletions backend/app/api/user/logout/noAuth.test.ts

This file was deleted.

16 changes: 0 additions & 16 deletions backend/app/api/user/noAuth.test.ts

This file was deleted.

Original file line number Diff line number Diff line change
@@ -1,16 +1,21 @@
import { verifySession } from '@/lib/session';
import { prismaMock } from '@/__test__/singleton';
import { User } from '@prisma/client';
import { DELETE } from './route';

jest.mock('@/lib/session', () => ({
verifySession: jest.fn(() => ({
isAuth: true,
uid: 2,
})),
deleteSession: jest.fn(() => {}),
verifySession: jest.fn(),
deleteSession: jest.fn(),
}));

const mockVerifySession = verifySession as jest.Mock;

test('Delete succeeds if user is authenticated', async () => {
mockVerifySession.mockResolvedValue({
isAuth: true,
uid: 1,
});

const temporaryUser: User = {
id: 1,
username: 'test',
Expand All @@ -24,3 +29,15 @@ test('Delete succeeds if user is authenticated', async () => {

expect(data.success).toBe(true);
});

test('Delete fails for an invalid session', async () => {
mockVerifySession.mockResolvedValue({
isAuth: false,
});

const res = await DELETE();
const data = await res.json();

expect(res.status).toEqual(400);
expect(data.error).toBe('Invalid session');
});

0 comments on commit 2288b12

Please sign in to comment.