Files
dify/web/app/page.spec.tsx
yyh ae59074c59 refactor(web): preserve all OAuth query params and remove legacy storage fallback
- Use searchParams.toString() to forward all query params instead of
  manually encoding only client_id and redirect_uri
- Remove legacy localStorage fallback since storage utility is now
  the sole persistence layer
- Add tests for OAuth authorize page, home page, and post-login redirect
2026-02-10 14:39:05 +08:00

72 lines
1.6 KiB
TypeScript

import { redirect } from 'next/navigation'
import Home from './page'
vi.mock('next/navigation', () => ({
redirect: vi.fn(),
}))
describe('Home page redirect', () => {
beforeEach(() => {
vi.clearAllMocks()
})
it('should redirect to /apps when search params are empty', async () => {
// Arrange
const props = {
searchParams: Promise.resolve({}),
}
// Act
await Home(props)
// Assert
expect(redirect).toHaveBeenCalledWith('/apps')
})
it('should preserve single query param when redirecting to /apps', async () => {
// Arrange
const props = {
searchParams: Promise.resolve({
oauth_redirect_url: 'https://example.com/callback',
}),
}
// Act
await Home(props)
// Assert
expect(redirect).toHaveBeenCalledWith('/apps?oauth_redirect_url=https%3A%2F%2Fexample.com%2Fcallback')
})
it('should preserve repeated query params when redirecting to /apps', async () => {
// Arrange
const props = {
searchParams: Promise.resolve({
scope: ['read:name', 'read:email'],
}),
}
// Act
await Home(props)
// Assert
expect(redirect).toHaveBeenCalledWith('/apps?scope=read%3Aname&scope=read%3Aemail')
})
it('should ignore undefined query values when building redirect url', async () => {
// Arrange
const props = {
searchParams: Promise.resolve({
client_id: 'abc',
state: undefined,
}),
}
// Act
await Home(props)
// Assert
expect(redirect).toHaveBeenCalledWith('/apps?client_id=abc')
})
})