feat(settings): 集中刷新策略与账号授权并独立设置审计
build / build (push) Successful in 1m11s

This commit is contained in:
姚章浩
2026-10-27 09:28:16 +08:00
parent a55d7f454e
commit 8930ef29cd
8 changed files with 520 additions and 214 deletions
+52
View File
@@ -0,0 +1,52 @@
import { describe, expect, it, vi, afterEach } from 'vitest'
import { configuredInterval, saveSourceRefresh } from './sourceRefreshPolicy'
import type { SourceConnectionListItem, SourceSettingsRevision } from './sourceConnections'
const source = {
id: 'source-1',
name: '测试来源',
source_type: 'dingtalk',
enabled: true,
schedule_configured: true,
} as SourceConnectionListItem
const revision = { id: 'r1', state: 'active', refresh_interval_seconds: '21600' } as SourceSettingsRevision
const response = (data: unknown) => ({ ok: true, json: async () => data })
afterEach(() => vi.unstubAllGlobals())
describe('source refresh policy', () => {
it('uses the persisted interval, never the next-run countdown', () => {
expect(configuredInterval(source, [revision])).toBe(21600)
})
it('refuses to overwrite an unreadable configured policy', () => {
expect(() => configuredInterval(source, [])).toThrow('未修改设置')
})
it('preserves the interval when pausing', async () => {
const fetch = vi
.fn()
.mockResolvedValueOnce(
response({
data: [
{
...revision,
revision_number: 1,
name: '测试来源',
endpoint: '',
credential_ref: '',
enabled: true,
created_by: 'admin',
created_at: '2026-10-26',
validated_at: null,
activated_at: null,
retired_at: null,
},
],
})
)
.mockResolvedValueOnce(response({ operation: 'created', data: { id: 'r2' } }))
.mockResolvedValueOnce(response({ operation: 'created', data: {} }))
vi.stubGlobal('fetch', fetch)
await saveSourceRefresh(source, false)
expect(JSON.parse(fetch.mock.calls[1][1].body)).toMatchObject({
enabled: false,
schedule: { refresh_interval_seconds: 21600 },
})
})
})