test: add API route tests

This commit is contained in:
张翔
2026-03-10 12:41:17 +08:00
parent 7d67c8eef3
commit 65ea3f0e7e
3 changed files with 477 additions and 0 deletions
@@ -0,0 +1,39 @@
import { GET, POST } from './route';
jest.mock('@/lib/auth', () => ({
handlers: {
GET: jest.fn(() => new Response('GET response')),
POST: jest.fn(() => new Response('POST response')),
},
}));
describe('/api/auth/[...nextauth]', () => {
describe('GET handler', () => {
it('should export GET handler', () => {
expect(typeof GET).toBe('function');
});
it('should call auth GET handler', async () => {
const response = await GET(new Request('http://localhost/api/auth/signin'));
expect(response).toBeDefined();
expect(response.status).toBe(200);
});
});
describe('POST handler', () => {
it('should export POST handler', () => {
expect(typeof POST).toBe('function');
});
it('should call auth POST handler', async () => {
const response = await POST(
new Request('http://localhost/api/auth/signin', {
method: 'POST',
body: JSON.stringify({ email: 'test@example.com', password: 'password' }),
})
);
expect(response).toBeDefined();
expect(response.status).toBe(200);
});
});
});