Skip to content

armgit / dify

Public Imported from GitHub
0

Build Agentic workflows, RAG pipelines, with rich AI model and tool support on one collaborative workspace. Deploy on cloud, VPC, or self-hosted, so teams move from prototype to production without rebuilding the stack.

1.3 KB
Raw Blame
import { resolveImportedAppRedirectionTarget } from './imported-app-redirection'

const mockFetchAppDetail = vi.hoisted(() => vi.fn())

vi.mock('@/service/console', () => ({
  consoleClient: {
    apps: {
      byAppId: {
        get: (...args: unknown[]) => mockFetchAppDetail(...args),
      },
    },
  },
}))

describe('resolveImportedAppRedirectionTarget', () => {
  beforeEach(() => {
    mockFetchAppDetail.mockReset()
  })

  it('resolves the backing Agent ID for an imported Agent App', async () => {
    mockFetchAppDetail.mockResolvedValue({ bound_agent_id: 'agent-1' })

    await expect(
      resolveImportedAppRedirectionTarget({
        id: 'app-1',
        mode: 'agent' as const,
        permission_keys: ['app.acl.view_layout'],
      }),
    ).resolves.toEqual({
      id: 'app-1',
      mode: 'agent' as const,
      permission_keys: ['app.acl.view_layout'],
      bound_agent_id: 'agent-1',
    })
    expect(mockFetchAppDetail).toHaveBeenCalledWith({
      params: { app_id: 'app-1' },
    })
  })

  it('keeps the roster fallback when resolving the imported Agent App fails', async () => {
    mockFetchAppDetail.mockRejectedValue(new Error('Failed to fetch App detail'))
    const target = {
      id: 'app-1',
      mode: 'agent' as const,
    }

    await expect(resolveImportedAppRedirectionTarget(target)).resolves.toEqual(target)
  })
})