dify/web/service/explore.spec.ts
Stephen Zhou 61650d34ce
refactor(web): remove custom console contract loaders (#38284)
Co-authored-by: autofix-ci[bot] <114827586+autofix-ci[bot]@users.noreply.github.com>
2026-07-02 03:32:02 +00:00

95 lines
2.1 KiB
TypeScript

import { beforeEach, describe, expect, it, vi } from 'vitest'
import {
fetchAppDetail,
fetchAppList,
fetchInstalledAppMeta,
} from './explore'
const mockExploreAppsGet = vi.hoisted(() => vi.fn())
const mockExploreAppDetailGet = vi.hoisted(() => vi.fn())
const mockInstalledAppMetaGet = vi.hoisted(() => vi.fn())
vi.mock('./client', () => ({
consoleClient: {
explore: {
apps: {
get: mockExploreAppsGet,
byAppId: {
get: mockExploreAppDetailGet,
},
},
},
installedApps: {
byInstalledAppId: {
meta: {
get: mockInstalledAppMetaGet,
},
},
},
},
}))
describe('explore service normalizers', () => {
beforeEach(() => {
vi.resetAllMocks()
})
it('preserves backend app modes that are not part of the legacy frontend enum', async () => {
mockExploreAppsGet.mockResolvedValue({
categories: [],
recommended_apps: [{
app_id: 'agent-app',
app: {
id: 'agent-app',
name: 'Agent app',
mode: 'agent',
icon: '',
icon_background: '',
},
}],
})
mockExploreAppDetailGet.mockResolvedValue({
id: 'pipeline-app',
name: 'Pipeline app',
icon: '',
icon_background: '',
mode: 'rag-pipeline',
export_data: 'kind: app',
})
await expect(fetchAppList()).resolves.toMatchObject({
recommended_apps: [{
app: {
mode: 'agent',
},
}],
})
await expect(fetchAppDetail('pipeline-app')).resolves.toMatchObject({
mode: 'rag-pipeline',
})
})
it('preserves provider-defined tool icon payload objects', async () => {
const providerIcon = {
type: 'custom',
value: {
content: 'tool',
background: '#fff',
},
}
mockInstalledAppMetaGet.mockResolvedValue({
tool_icons: {
builtin: '/tool.svg',
provider: providerIcon,
},
})
await expect(fetchInstalledAppMeta('installed-app-id')).resolves.toEqual({
tool_icons: {
builtin: '/tool.svg',
provider: providerIcon,
},
})
})
})