mirror of
https://github.com/langgenius/dify.git
synced 2026-06-13 14:39:21 +08:00
cfc1cf2b8c
Co-authored-by: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
44 lines
1.4 KiB
TypeScript
44 lines
1.4 KiB
TypeScript
import type { StubServer } from '@test/fixtures/stub-server'
|
|
import { testHttpClient } from '@test/fixtures/http-client'
|
|
import { jsonResponder, startStubServer } from '@test/fixtures/stub-server'
|
|
import { afterEach, describe, expect, it } from 'vitest'
|
|
import { isBaseError } from '@/errors/base'
|
|
import { WorkspacesClient } from './workspaces.js'
|
|
|
|
// WorkspacesClient.switch is covered in members.test.ts; this file covers list().
|
|
|
|
function makeClient(host: string): WorkspacesClient {
|
|
return new WorkspacesClient(testHttpClient(host, 'dfoa_test'))
|
|
}
|
|
|
|
describe('WorkspacesClient.list', () => {
|
|
let stub: StubServer
|
|
|
|
afterEach(async () => {
|
|
await stub?.stop()
|
|
})
|
|
|
|
it('GETs /workspaces and returns the parsed list', async () => {
|
|
stub = await startStubServer(cap =>
|
|
jsonResponder(200, {
|
|
workspaces: [
|
|
{ id: 'ws-1', name: 'Default', role: 'owner', status: 'normal', current: true },
|
|
],
|
|
}, cap))
|
|
|
|
const res = await makeClient(stub.url).list()
|
|
|
|
expect(stub.captured.method).toBe('GET')
|
|
expect(stub.captured.url).toBe('/openapi/v1/workspaces')
|
|
expect(res.workspaces[0].id).toBe('ws-1')
|
|
})
|
|
|
|
it('maps 401 to a classified BaseError', async () => {
|
|
stub = await startStubServer(cap => jsonResponder(401, { error: 'expired' }, cap))
|
|
|
|
await expect(makeClient(stub.url).list()).rejects.toSatisfy(
|
|
err => isBaseError(err) && err.httpStatus === 401,
|
|
)
|
|
})
|
|
})
|