fix(settings): complete DingTalk scan login flow
This commit is contained in:
@@ -0,0 +1,29 @@
|
||||
import { afterEach, describe, expect, it, vi } from 'vitest'
|
||||
|
||||
import { DingtalkRequestError, registerDingtalkSpace, startDingtalkSession } from './dingtalkSession'
|
||||
|
||||
afterEach(() => vi.unstubAllGlobals())
|
||||
|
||||
describe('DingTalk session client', () => {
|
||||
it('returns the starting state immediately while the QR is being generated', async () => {
|
||||
const fetchMock = vi.fn().mockResolvedValue(new Response(JSON.stringify({
|
||||
id: 'session-1', state: 'starting', created_at: 1, expires_at: 2,
|
||||
}), { status: 201 }))
|
||||
vi.stubGlobal('fetch', fetchMock)
|
||||
|
||||
await expect(startDingtalkSession()).resolves.toMatchObject({ id: 'session-1', state: 'starting' })
|
||||
expect(fetchMock).toHaveBeenCalledWith('/api/v1/dingtalk-session', expect.objectContaining({ method: 'POST' }))
|
||||
})
|
||||
|
||||
it('preserves login_required as a machine-readable error for automatic QR fallback', async () => {
|
||||
vi.stubGlobal('fetch', vi.fn().mockResolvedValue(new Response(
|
||||
JSON.stringify({ error: 'login_required' }),
|
||||
{ status: 409, headers: { 'Content-Type': 'application/json' } },
|
||||
)))
|
||||
|
||||
const error = await registerDingtalkSpace('https://alidocs.dingtalk.com/i/spaces/9JOGOQneRgkneX4Q/overview')
|
||||
.then(() => null, (cause: unknown) => cause)
|
||||
expect(error).toBeInstanceOf(DingtalkRequestError)
|
||||
expect(error).toMatchObject({ code: 'login_required', status: 409 })
|
||||
})
|
||||
})
|
||||
Reference in New Issue
Block a user