27 lines
1.0 KiB
TypeScript
27 lines
1.0 KiB
TypeScript
import assert from 'node:assert/strict';
|
|
import test from 'node:test';
|
|
import { requestAnalysis } from './analysis-api';
|
|
import { __resetApiAvailabilityForTests, resolveApiBase } from './api';
|
|
|
|
test('requestAnalysis posts to /ai/analysis', async () => {
|
|
const originalFetch = globalThis.fetch;
|
|
const calls: string[] = [];
|
|
const apiBase = resolveApiBase();
|
|
globalThis.fetch = (async (input: RequestInfo | URL) => {
|
|
calls.push(String(input));
|
|
return new Response(JSON.stringify(calls.length === 1 ? {} : { ok: false, code: 'NO_DATA', message: 'no rows' }), {
|
|
status: 200,
|
|
headers: { 'Content-Type': 'application/json' },
|
|
});
|
|
}) as typeof fetch;
|
|
|
|
try {
|
|
__resetApiAvailabilityForTests();
|
|
const result = await requestAnalysis({ question: '哪个部门最忙', context: { surface: 'ai_assistant' } }, ['management:view']);
|
|
assert.equal(result.ok, false);
|
|
assert.deepEqual(calls, [`${apiBase}/config/ai`, `${apiBase}/ai/analysis`]);
|
|
} finally {
|
|
globalThis.fetch = originalFetch;
|
|
}
|
|
});
|