dify/web/app/(commonLayout)/agents/__tests__/feature-guard.spec.ts
zyssyz123 925f97be20
feat: daily sync (#38593)
Co-authored-by: 盐粒 Yanli <mail@yanli.one>
Co-authored-by: yyh <yuanyouhuilyz@gmail.com>
Co-authored-by: Joel <iamjoel007@gmail.com>
Co-authored-by: autofix-ci[bot] <114827586+autofix-ci[bot]@users.noreply.github.com>
Co-authored-by: QuantumGhost <obelisk.reg+git@gmail.com>
Co-authored-by: yyh <92089059+lyzno1@users.noreply.github.com>
Co-authored-by: 盐粒 Yanli <yanli@dify.ai>
2026-07-09 10:35:15 +00:00

42 lines
1004 B
TypeScript

const mocks = vi.hoisted(() => ({
agentV2Enabled: true,
notFound: vi.fn(() => {
throw new Error('NEXT_NOT_FOUND')
}),
}))
vi.mock('@/env', () => ({
env: {
get NEXT_PUBLIC_ENABLE_AGENT_V2() {
return mocks.agentV2Enabled
},
},
}))
vi.mock('@/next/navigation', () => ({
notFound: () => mocks.notFound(),
}))
describe('guardAgentV2Route', () => {
beforeEach(() => {
vi.clearAllMocks()
mocks.agentV2Enabled = true
})
it('should allow roster routes when Agent v2 is enabled', async () => {
const { guardAgentV2Route } = await import('../feature-guard')
expect(() => guardAgentV2Route()).not.toThrow()
expect(mocks.notFound).not.toHaveBeenCalled()
})
it('should throw notFound when Agent v2 is disabled', async () => {
mocks.agentV2Enabled = false
const { guardAgentV2Route } = await import('../feature-guard')
expect(() => guardAgentV2Route()).toThrow('NEXT_NOT_FOUND')
expect(mocks.notFound).toHaveBeenCalledTimes(1)
})
})