Files
monitoring-app/tests/e2e/auth-api.test.ts
bipproduction 08a1054e3c Initial commit: full-stack Bun + Elysia + React template
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>
2026-04-01 10:12:19 +08:00

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()
}
})
})