执行时真实时钟与持久授权回读(撤销/过期即停并保留预备份)、写集合写前落盘、 租约与 attempt 身份、恢复队列与原发送身份分离、成功收尾必须释放维护后再登记终态。
This commit is contained in:
@@ -0,0 +1,45 @@
|
||||
import { afterEach, expect, it, vi } from 'vitest'
|
||||
import { renderToStaticMarkup } from 'react-dom/server'
|
||||
import { associateLegacySource, LegacySourceAssociation } from './LegacySourceAssociation'
|
||||
|
||||
afterEach(() => vi.unstubAllGlobals())
|
||||
const reply = (status: number, data: unknown) => new Response(JSON.stringify(data), { status })
|
||||
|
||||
it('only sends exact snapshot and scope; association is not publishing', async () => {
|
||||
const fetchMock = vi
|
||||
.fn()
|
||||
.mockResolvedValue(
|
||||
reply(200, { associated: true, published: false, snapshot_id: 'snapshot', source_id: 'a'.repeat(64) })
|
||||
)
|
||||
vi.stubGlobal('fetch', fetchMock)
|
||||
expect(await associateLegacySource('internal', 'snapshot')).toBe('a'.repeat(64))
|
||||
expect(fetchMock.mock.calls).toHaveLength(1)
|
||||
expect(fetchMock.mock.calls[0][0]).toBe('/api/v1/library/source-associations')
|
||||
expect(JSON.parse(fetchMock.mock.calls[0][1].body)).toEqual({ scope: 'internal', snapshot_id: 'snapshot' })
|
||||
})
|
||||
|
||||
it('rejects wrong-snapshot and incomplete readback, and shows evidence errors', async () => {
|
||||
for (const value of [
|
||||
{ associated: true, published: false, snapshot_id: 'wrong', source_id: 'a'.repeat(64) },
|
||||
{ associated: true, snapshot_id: 'snapshot' },
|
||||
]) {
|
||||
vi.stubGlobal('fetch', vi.fn().mockResolvedValue(reply(200, value)))
|
||||
await expect(associateLegacySource('internal', 'snapshot')).rejects.toThrow('来源关联回执')
|
||||
}
|
||||
vi.stubGlobal('fetch', vi.fn().mockResolvedValue(reply(409, { error: 'original capture identity mismatch' })))
|
||||
await expect(associateLegacySource('internal', 'snapshot')).rejects.toThrow('original capture identity mismatch')
|
||||
})
|
||||
|
||||
it('hides association controls from non-admin and distinguishes it from publication', () => {
|
||||
expect(
|
||||
renderToStaticMarkup(
|
||||
<LegacySourceAssociation scope="internal" snapshots={[]} admin={false} onBound={async () => {}} />
|
||||
)
|
||||
).toBe('')
|
||||
const html = renderToStaticMarkup(
|
||||
<LegacySourceAssociation scope="internal" snapshots={[]} admin onBound={async () => {}} />
|
||||
)
|
||||
expect(html).toContain('只追加治理关联')
|
||||
expect(html).toContain('disabled')
|
||||
expect(html).toContain('核验原证据并关联')
|
||||
})
|
||||
Reference in New Issue
Block a user