#1 PDF Application on GitHub that lets you edit PDFs on any device anywhere
TypeScript dockerhacktoberfestjavapdfpdf-converterpdf-editorpdf-manipulationpdf-mergerpdf-ocrpdf-toolspdf-web-appspdfmergerself-hosted
// @vitest-environment node
import { describe, it, expect } from "vitest";
import {
fromBackendPolicy,
type BackendPolicy,
} from "@editor/services/policyPipeline";
const backendPolicy: BackendPolicy = {
id: "p1",
name: "Security",
owner: "",
enabled: true,
trigger: null,
steps: [{ operation: "/api/v1/misc/compress-pdf", parameters: {} }],
output: {
type: "inline",
options: {
mode: "new_version",
name: "secured",
position: "suffix",
maxRetries: 2,
retryDelayMinutes: 10,
automation: {
id: "auto-1",
name: "Security",
operations: [{ operation: "compress", parameters: {} }],
createdAt: "",
updatedAt: "",
},
categoryId: "security",
sources: [],
scopeTypes: ["Contracts"],
reviewerEmail: "[email protected]",
fieldValues: { minConfidence: "80%" },
},
},
editor: { allowed: true, runOn: "export" },
};
describe("fromBackendPolicy", () => {
it("does not admit an unknown first endpoint for automatic enforcement", () => {
const decoded = fromBackendPolicy({
...backendPolicy,
steps: [
{ operation: "/unknown", parameters: {} },
...backendPolicy.steps,
],
});
expect(decoded.firstOperation).toBeNull();
});
it("decodes a stored policy's output.options bag into frontend settings", () => {
const decoded = fromBackendPolicy(backendPolicy);
expect(decoded.id).toBe("p1");
expect(decoded.firstOperation).toBe("/api/v1/misc/compress-pdf");
expect(decoded.policyKey).toBe("security");
expect(decoded.enabled).toBe(true);
expect(decoded.sources).toEqual([]);
expect(decoded.runsOnEditor).toBe(true);
expect(decoded.scopeTypes).toEqual(["Contracts"]);
expect(decoded.reviewerEmail).toBe("[email protected]");
expect(decoded.fieldValues).toEqual({ minConfidence: "80%" });
expect(decoded.folder).toEqual({
runOn: "export",
outputMode: "new_version",
outputName: "secured",
outputNamePosition: "suffix",
maxRetries: 2,
retryDelayMinutes: 10,
});
expect(decoded.automation?.operations).toEqual([
{ operation: "compress", parameters: {} },
]);
});
});