mirror of
https://github.com/langgenius/dify.git
synced 2026-02-13 07:01:23 -05:00
- 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
72 lines
1.6 KiB
TypeScript
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')
|
|
})
|
|
})
|