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>
This commit is contained in:
42
tests/integration/auth-google.test.ts
Normal file
42
tests/integration/auth-google.test.ts
Normal file
@@ -0,0 +1,42 @@
|
||||
import { test, expect, describe, afterAll } from 'bun:test'
|
||||
import { createTestApp, cleanupTestData, prisma } from '../helpers'
|
||||
|
||||
const app = createTestApp()
|
||||
|
||||
afterAll(async () => {
|
||||
await cleanupTestData()
|
||||
await prisma.$disconnect()
|
||||
})
|
||||
|
||||
describe('GET /api/auth/google', () => {
|
||||
test('redirects to Google OAuth', async () => {
|
||||
const res = await app.handle(new Request('http://localhost/api/auth/google'))
|
||||
|
||||
// Elysia returns 302 for redirects
|
||||
expect(res.status).toBe(302)
|
||||
const location = res.headers.get('location')
|
||||
expect(location).toContain('accounts.google.com/o/oauth2/v2/auth')
|
||||
expect(location).toContain('client_id=')
|
||||
expect(location).toContain('redirect_uri=')
|
||||
expect(location).toContain('scope=openid+email+profile')
|
||||
expect(location).toContain('response_type=code')
|
||||
})
|
||||
|
||||
test('redirect_uri points to callback endpoint', async () => {
|
||||
const res = await app.handle(new Request('http://localhost/api/auth/google'))
|
||||
const location = res.headers.get('location')!
|
||||
const url = new URL(location)
|
||||
const redirectUri = url.searchParams.get('redirect_uri')
|
||||
expect(redirectUri).toBe('http://localhost/api/auth/callback/google')
|
||||
})
|
||||
})
|
||||
|
||||
describe('GET /api/auth/callback/google', () => {
|
||||
test('redirects to login with error when no code provided', async () => {
|
||||
const res = await app.handle(new Request('http://localhost/api/auth/callback/google'))
|
||||
|
||||
expect(res.status).toBe(302)
|
||||
const location = res.headers.get('location')
|
||||
expect(location).toContain('/login?error=google_failed')
|
||||
})
|
||||
})
|
||||
Reference in New Issue
Block a user