Skip to content

#1 PDF Application on GitHub that lets you edit PDFs on any device anywhere

1.7 KB
Raw Blame
// @vitest-environment node
import { describe, expect, it, vi } from "vitest";
import { policyCreditContext } from "@editor/services/policyCreditContext";

vi.mock("@editor/services/policyStorage", () => ({
  loadPolicies: () => ({
    rotate: {
      backendId: "rotate-id",
      name: "Quarterly rotation",
      configured: true,
      enabled: true,
      runsOnEditor: true,
      runOn: "upload",
    },
    watermark: {
      backendId: "watermark-id",
      name: "Confidential watermark",
      configured: true,
      enabled: true,
      runsOnEditor: true,
      runOn: "export",
    },
  }),
}));
vi.mock("@editor/services/policyCatalog", () => ({
  loadPolicyCatalog: () => ({ categories: [] }),
}));

describe("credit failure pipeline context", () => {
  it("identifies upload and export pipelines by saved name", () => {
    expect(policyCreditContext("rotate-id")).toEqual({
      pipelineId: "rotate-id",
      pipelineName: "Quarterly rotation",

      trigger: "upload",
    });
    expect(policyCreditContext("watermark-id").trigger).toBe("export");
  });
  it("identifies an explicit retry independently of the configured automatic trigger", () => {
    expect(policyCreditContext("rotate-id", "foreground").trigger).toBe(
      "manual",
    );
  });
  it("keeps an uncached pipeline navigable without displaying its internal id as a name", () => {
    expect(policyCreditContext("unknown")).toEqual({
      pipelineId: "unknown",
      pipelineName: undefined,

      trigger: "automatic",
    });
  });
  it("handles failures without a policy identifier", () => {
    expect(policyCreditContext(null).pipelineId).toBeUndefined();
    expect(policyCreditContext(null).trigger).toBe("automatic");
  });
});