30 lines
1.7 KiB
JavaScript
30 lines
1.7 KiB
JavaScript
|
|
import assert from 'node:assert/strict';
|
||
|
|
import { readFileSync } from 'node:fs';
|
||
|
|
import test from 'node:test';
|
||
|
|
|
||
|
|
const flexPanel = readFileSync(new URL('../../apps/web/src/master/FlexPanel.tsx', import.meta.url), 'utf8');
|
||
|
|
const backend = readFileSync(new URL('../../server/gateway/app.py', import.meta.url), 'utf8');
|
||
|
|
const contracts = readFileSync(new URL('../../server/aps_domain/report_contracts.py', import.meta.url), 'utf8');
|
||
|
|
|
||
|
|
test('flex workbench exports use the authenticated download helper', () => {
|
||
|
|
assert.match(flexPanel, /downloadAuthenticatedFile/);
|
||
|
|
assert.match(flexPanel, /\/api\/reports\/schedule-order\?versionId=/);
|
||
|
|
assert.match(flexPanel, /\/api\/reports\/schedule-equipment\?versionId=/);
|
||
|
|
assert.match(flexPanel, /\/api\/reports\/schedule-template/);
|
||
|
|
// 浏览器直接打开 /api 链接拿不到鉴权头,导出必须走 fetch 而不是 href。
|
||
|
|
assert.doesNotMatch(flexPanel, /href=\{\s*[`'"]\/api\//);
|
||
|
|
assert.doesNotMatch(flexPanel, /window\.location\s*=/);
|
||
|
|
});
|
||
|
|
|
||
|
|
test('schedule template endpoint serves the same contract the exports declare', () => {
|
||
|
|
const templateRoute = backend.indexOf('@app.get("/api/reports/schedule-template")');
|
||
|
|
const dynamicRoute = backend.indexOf('@app.get("/api/reports/{report_type}")');
|
||
|
|
assert.ok(templateRoute > 0, 'schedule-template route must exist');
|
||
|
|
assert.ok(dynamicRoute > templateRoute, 'template route must be declared before the dynamic route');
|
||
|
|
assert.match(backend, /build_contract_template\(reportType or "schedule-plan"\)/);
|
||
|
|
assert.match(backend, /X-APS-Contract-Digest/);
|
||
|
|
assert.match(backend, /status_code=404/);
|
||
|
|
assert.match(contracts, /def build_contract_template\(report_type: str\)/);
|
||
|
|
assert.match(contracts, /defects = validate_workbook_contract\(payload, contract\)/);
|
||
|
|
});
|