dify/web/service/explore.spec.ts
非法操作 c1fdd6fb78
chore: paginate installed apps (#39739)
Co-authored-by: autofix-ci[bot] <114827586+autofix-ci[bot]@users.noreply.github.com>
Co-authored-by: yyh <yuanyouhuilyz@gmail.com>
Co-authored-by: yyh <92089059+lyzno1@users.noreply.github.com>
2026-07-29 09:51:34 +00:00

83 lines
1.9 KiB
TypeScript

import { beforeEach, describe, expect, it, vi } from 'vitest'
import { fetchAppDetail, fetchAppList, fetchInstalledAppList } from './explore'
const mockExploreAppsGet = vi.hoisted(() => vi.fn())
const mockExploreAppDetailGet = vi.hoisted(() => vi.fn())
const mockInstalledAppsGet = vi.hoisted(() => vi.fn())
vi.mock('./client', () => ({
consoleClient: {
explore: {
apps: {
get: mockExploreAppsGet,
byAppId: {
get: mockExploreAppDetailGet,
},
},
},
installedApps: {
get: mockInstalledAppsGet,
},
},
}))
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',
can_trial: false,
})
await expect(fetchAppList()).resolves.toMatchObject({
recommended_apps: [
{
app: {
mode: 'agent',
},
},
],
})
await expect(fetchAppDetail('pipeline-app')).resolves.toMatchObject({
mode: 'rag-pipeline',
})
})
it('preserves installed app pagination metadata', async () => {
mockInstalledAppsGet.mockResolvedValue({
installed_apps: [],
has_more: true,
next_cursor: 'next-page',
})
await expect(fetchInstalledAppList()).resolves.toEqual({
installed_apps: [],
has_more: true,
next_cursor: 'next-page',
})
})
})