Files
oysqn.app/tests/unit/auth-middleware.test.ts
Patrick Toal c789454810 docs: Update architecture for supabase
test: Add tests for auth workflow
2026-04-12 10:14:44 -04:00

25 lines
790 B
TypeScript

// @vitest-environment node
import { describe, it, expect } from 'vitest'
import { checkAuthRedirect } from '~/utils/auth'
describe('checkAuthRedirect', () => {
it.each(['/', '/login', '/signup', '/auth/callback'])(
'returns null for unauthenticated user on public route: %s',
(path) => {
expect(checkAuthRedirect(null, path)).toBeNull()
}
)
it('returns "/" for unauthenticated user on protected route', () => {
expect(checkAuthRedirect(null, '/boats')).toBe('/')
})
it('returns null for authenticated user on protected route', () => {
expect(checkAuthRedirect({ id: 'user-123' }, '/boats')).toBeNull()
})
it('returns null for authenticated user on public route', () => {
expect(checkAuthRedirect({ id: 'user-123' }, '/')).toBeNull()
})
})