test: add API route tests
This commit is contained in:
@@ -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);
|
||||
});
|
||||
});
|
||||
});
|
||||
Reference in New Issue
Block a user