docs: Update architecture for supabase
test: Add tests for auth workflow
This commit is contained in:
24
tests/unit/auth-middleware.test.ts
Normal file
24
tests/unit/auth-middleware.test.ts
Normal file
@@ -0,0 +1,24 @@
|
||||
// @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()
|
||||
})
|
||||
})
|
||||
Reference in New Issue
Block a user