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>
36 lines
1.2 KiB
TypeScript
36 lines
1.2 KiB
TypeScript
import { test, expect, describe } from 'bun:test'
|
|
import { createPage, APP_HOST } from './browser'
|
|
|
|
describe('E2E: Auth API via browser', () => {
|
|
test('GET /api/auth/session page shows response', async () => {
|
|
const { page, cleanup } = await createPage()
|
|
try {
|
|
await page.goto(APP_HOST + '/api/auth/session')
|
|
// Navigating to a JSON API endpoint — body contains the JSON text
|
|
const bodyText = await page.evaluate('document.body.innerText || document.body.textContent || ""')
|
|
// Should contain "user" key in the response (either null or valid user)
|
|
// If empty, that's also acceptable (401 may not render body in Lightpanda)
|
|
if (bodyText.length > 0) {
|
|
const data = JSON.parse(bodyText)
|
|
expect(data.user).toBeNull()
|
|
} else {
|
|
// 401 response — Lightpanda may not render the body
|
|
expect(bodyText).toBe('')
|
|
}
|
|
} finally {
|
|
cleanup()
|
|
}
|
|
})
|
|
|
|
test('GET /api/auth/google redirects to Google OAuth', async () => {
|
|
const { page, cleanup } = await createPage()
|
|
try {
|
|
await page.goto(APP_HOST + '/api/auth/google')
|
|
const url = await page.url()
|
|
expect(url).toContain('accounts.google.com')
|
|
} finally {
|
|
cleanup()
|
|
}
|
|
})
|
|
})
|