forked from longtao.wu/droboticflow
75 lines
4.0 KiB
JavaScript
75 lines
4.0 KiB
JavaScript
import test from "node:test";
|
|
import assert from "node:assert/strict";
|
|
import { readFile } from "node:fs/promises";
|
|
import ts from "typescript";
|
|
|
|
const root = new URL("../../", import.meta.url);
|
|
const read = (path) => readFile(new URL(path, root), "utf8");
|
|
|
|
const apiSource = (await read("src/services/api/supplier-authorizations.ts"))
|
|
.replace('import { apiRequest } from "./client";', "")
|
|
.replace(/import type [^;]+;/g, "");
|
|
const bundled = ts.transpileModule(apiSource, { compilerOptions: { module: ts.ModuleKind.ESNext } }).outputText;
|
|
const mock =
|
|
"async function apiRequest(path, init, body) { globalThis.supplierAuthorizationCalls.push({ path, method: init?.method || 'GET', body }); return path.endsWith('authorizations') ? { items: [] } : { convertedItemCount: 2, convertedBatchCount: 1, skippedItemCount: 1, operationId: 'op-1' }; }\n";
|
|
const { supplierAuthorizationsApi: api } = await import(
|
|
`data:text/javascript;base64,${Buffer.from(mock + bundled).toString("base64")}`
|
|
);
|
|
|
|
test("both grant views read the same authorization resource and writes target an encoded pair", async () => {
|
|
globalThis.supplierAuthorizationCalls = [];
|
|
await api.forSupplier("supplier/a");
|
|
await api.forProject("project/b");
|
|
await api.grant("project/b", "supplier/a");
|
|
await api.revoke("project/b", "supplier/a");
|
|
assert.deepEqual(globalThis.supplierAuthorizationCalls, [
|
|
{ path: "/api/suppliers/supplier%2Fa/project-authorizations", method: "GET", body: undefined },
|
|
{ path: "/api/projects/project%2Fb/supplier-authorizations", method: "GET", body: undefined },
|
|
{ path: "/api/projects/project%2Fb/supplier-authorizations/supplier%2Fa", method: "PUT", body: undefined },
|
|
{ path: "/api/projects/project%2Fb/supplier-authorizations/supplier%2Fa", method: "DELETE", body: undefined },
|
|
]);
|
|
});
|
|
|
|
test("legacy conversion sends the preview token in a separate confirmed request", async () => {
|
|
globalThis.supplierAuthorizationCalls = [];
|
|
await api.previewPool("project/b");
|
|
await api.convertPool("project/b", "fresh-token");
|
|
assert.deepEqual(globalThis.supplierAuthorizationCalls, [
|
|
{ path: "/api/projects/project%2Fb/supplier-pool-preview", method: "GET", body: undefined },
|
|
{
|
|
path: "/api/projects/project%2Fb/supplier-pool-conversions",
|
|
method: "POST",
|
|
body: { previewToken: "fresh-token" },
|
|
},
|
|
]);
|
|
});
|
|
|
|
test("Fanyu template entry points use explicit public-pool capability while legacy workflows keep supplier binding", async () => {
|
|
const [projects, templates, users, detail, panel, types] = await Promise.all([
|
|
read("src/pages/Projects.tsx"),
|
|
read("src/pages/Templates.tsx"),
|
|
read("src/pages/Users.tsx"),
|
|
read("src/pages/ProjectDetail.tsx"),
|
|
read("src/components/SupplierAuthorizationsPanel.tsx"),
|
|
read("src/types.ts"),
|
|
]);
|
|
assert.match(types, /usesPublicSupplierPool\?: boolean/);
|
|
assert.match(projects, /usesPublicSupplierPool \? undefined : templateSupplierId \|\| undefined/);
|
|
assert.match(projects, /if \(usesPublicSupplierPool\) await saveSelectedAuthorizations\(created\.id\)/);
|
|
assert.match(projects, /requiresLegacySupplier/);
|
|
assert.match(projects, /roles\.has\(role\)/);
|
|
assert.match(templates, /supplierAuthorizationsApi\s*\.forProject\(selectedProjectId\)/);
|
|
assert.match(templates, /release\.usesPublicSupplierPool \? undefined : selectedSupplierId \|\| undefined/);
|
|
assert.match(templates, /!release\.usesPublicSupplierPool &&\s*release\.requiredPluginIds/);
|
|
assert.match(users, /<SupplierAuthorizationsPanel/);
|
|
assert.match(detail, /<SupplierAuthorizationsPanel projectId=\{project\.id\} canManage=\{role === "admin"\}/);
|
|
assert.match(panel, /!window\.confirm\(/);
|
|
assert.match(panel, /preview\.previewToken/);
|
|
assert.match(panel, /result\.operationId/);
|
|
assert.match(panel, /result\.skippedItemCount/);
|
|
assert.match(panel, /preview\.excludedReasons/);
|
|
assert.match(panel, /!grant\.qualityReviewerAvailable/);
|
|
assert.match(panel, /request !== loadRequest\.current/);
|
|
assert.match(panel, /已撤销,仅可处理存量及退回返工任务/);
|
|
});
|