Elysia.js API with session-based auth (email/password + Google OAuth), role system (USER/ADMIN/SUPER_ADMIN), Prisma + PostgreSQL, React 19 with Mantine UI, TanStack Router, dark theme, and comprehensive test suite (unit, integration, E2E with Lightpanda). Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
28 lines
959 B
TypeScript
28 lines
959 B
TypeScript
import { test, expect, describe } from 'bun:test'
|
|
import { createTestApp } from '../helpers'
|
|
|
|
const app = createTestApp()
|
|
|
|
describe('Error handling', () => {
|
|
test('unknown API route returns 404 JSON', async () => {
|
|
const res = await app.handle(new Request('http://localhost/api/nonexistent'))
|
|
expect(res.status).toBe(404)
|
|
const body = await res.json()
|
|
expect(body).toEqual({ error: 'Not Found', status: 404 })
|
|
})
|
|
|
|
test('unknown nested API route returns 404', async () => {
|
|
const res = await app.handle(new Request('http://localhost/api/foo/bar/baz'))
|
|
expect(res.status).toBe(404)
|
|
const body = await res.json()
|
|
expect(body.error).toBe('Not Found')
|
|
})
|
|
|
|
test('wrong HTTP method returns 404', async () => {
|
|
const res = await app.handle(new Request('http://localhost/api/hello', { method: 'DELETE' }))
|
|
expect(res.status).toBe(404)
|
|
const body = await res.json()
|
|
expect(body.error).toBe('Not Found')
|
|
})
|
|
})
|