ray-template/__test__/mock/connection.spec.ts
XiaoDaiGua-Ray bca3f3ff24
feat(admin): add user management and HTTP mock APIs
Add user CRUD, account-scoped navigation history and favorites.

Unify HTTP mocks, backend contracts and route configuration.

Reuse existing scrolling components and add Harness reuse guidance.
2026-11-05 17:21:59 +08:00

39 lines
1.1 KiB
TypeScript

import { createMockConnection } from '@/mocks/connection'
it('does not restart a healthy worker', async () => {
const restart = vi.fn(async () => {})
await createMockConnection(async () => true, restart)()
expect(restart).not.toHaveBeenCalled()
})
it('recovers once for concurrent requests after the worker loses its client state', async () => {
let ready = false
const restart = vi.fn(async () => {
ready = true
})
const ensure = createMockConnection(async () => ready, restart)
await Promise.all([ensure(), ensure(), ensure()])
expect(restart).toHaveBeenCalledTimes(1)
await ensure()
expect(restart).toHaveBeenCalledTimes(1)
})
it('blocks business traffic when recovery fails, then allows a later retry', async () => {
let available = false
const ensure = createMockConnection(
async () => available,
async () => {},
)
const write = vi.fn()
await expect(ensure().then(write)).rejects.toThrow(
'Mock connection could not be restored',
)
expect(write).not.toHaveBeenCalled()
available = true
await ensure().then(write)
expect(write).toHaveBeenCalledTimes(1)
})