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.9 KB
Raw Blame
import { knowledgeFsMetadataFieldsQueryOptions } from '../metadata'

const metadataGet = vi.hoisted(() => vi.fn())
vi.mock('@/service/console', async (importOriginal) => {
  const actual = await importOriginal<typeof import('@/service/console')>()
  const { withConsoleClientResponses } = await import('@/test/console/service-responses')
  return {
    ...actual,
    consoleClient: withConsoleClientResponses(actual.consoleClient, {
      'knowledgeFs.spaces.byControlSpaceId.metadata.get': metadataGet,
    }),
  }
})

describe('knowledgeFsMetadataFieldsQueryOptions', () => {
  it('collects every cursor page before exposing metadata fields', async () => {
    metadataGet
      .mockResolvedValueOnce({
        data: [
          {
            count: 1,
            created_at: '2026-08-01T00:00:00Z',
            id: 'field-1',
            name: 'category',
            row_version: 1,
            type: 'string',
            updated_at: '2026-08-01T00:00:00Z',
          },
        ],
        next_cursor: 'page-2',
      })
      .mockResolvedValueOnce({
        data: [
          {
            count: 2,
            created_at: '2026-08-02T00:00:00Z',
            id: 'field-2',
            name: 'priority',
            row_version: 3,
            type: 'number',
            updated_at: '2026-08-03T00:00:00Z',
          },
        ],
        next_cursor: null,
      })

    const options = knowledgeFsMetadataFieldsQueryOptions('space-1')
    const response = await options.queryFn()
    const fields = options.select(response)

    expect(metadataGet).toHaveBeenNthCalledWith(1, {
      params: { control_space_id: 'space-1' },
      query: { limit: 100 },
    })
    expect(metadataGet).toHaveBeenNthCalledWith(2, {
      params: { control_space_id: 'space-1' },
      query: { cursor: 'page-2', limit: 100 },
    })
    expect(fields.map((field) => field.name)).toEqual(['category', 'priority'])
  })
})