Some checks failed
build-images / web (push) Has been cancelled
vision2026-ci / Python SDK resource tests (push) Has been cancelled
build-images / api (push) Has been cancelled
build-images / worker-gpu (push) Has been cancelled
vision2026-ci / Shared packages (TS≡Python golden parity) (comfy-workflow-schema) (push) Has been cancelled
vision2026-ci / Shared packages (TS≡Python golden parity) (effects-core) (push) Has been cancelled
vision2026-ci / Shared packages (TS≡Python golden parity) (eventbus-types) (push) Has been cancelled
vision2026-ci / Shared packages (TS≡Python golden parity) (growth-analytics) (push) Has been cancelled
vision2026-ci / Shared packages (TS≡Python golden parity) (provider-adapter-kit) (push) Has been cancelled
vision2026-ci / Shared packages (TS≡Python golden parity) (publishing-connectors) (push) Has been cancelled
vision2026-ci / Shared packages (TS≡Python golden parity) (render-core) (push) Has been cancelled
vision2026-ci / Shared packages (TS≡Python golden parity) (shot-template-schema) (push) Has been cancelled
vision2026-ci / Shared packages (TS≡Python golden parity) (trends-schema) (push) Has been cancelled
vision2026-ci / Desktop engine crates (test + clippy + fmt) (push) Has been cancelled
codeql / Analyze (javascript-typescript) (push) Has been cancelled
codeql / Analyze (python) (push) Has been cancelled
perf / API hot-path micro-smoke (budgeted) (push) Has been cancelled
perf / Desktop engine crates (release build check) (push) Has been cancelled
vision2026-ci / API phase modules (ruff + pytest) (push) Has been cancelled
vision2026-ci / Alembic upgrade + drift check (push) Has been cancelled
vision2026-ci / Shared packages (TS≡Python golden parity) (caption-engine) (push) Has been cancelled
Paid, hosted product at menivor.com, now retired as a company project. Fresh squashed history of the cleaned working tree (secret-scanned, no .env, no customer data, no outreach logs). Built on MoneyPrinterTurbo (MIT, harry0703) — see NOTICE.
76 lines
2.6 KiB
TypeScript
76 lines
2.6 KiB
TypeScript
import { afterEach, describe, expect, it, vi } from "vitest";
|
|
import { cleanup, fireEvent, render, screen } from "@testing-library/react";
|
|
|
|
import { ApprovalItemCard } from "./ApprovalItemCard";
|
|
import type { ApprovalItem } from "./api";
|
|
|
|
const mocks = vi.hoisted(() => ({ decideApproval: vi.fn() }));
|
|
|
|
vi.mock("@clerk/nextjs", () => ({ useAuth: () => ({ getToken: async () => "test-token" }) }));
|
|
vi.mock("./api", async (importOriginal) => ({
|
|
...(await importOriginal<typeof import("./api")>()),
|
|
decideApproval: mocks.decideApproval,
|
|
}));
|
|
vi.mock("next/link", () => ({
|
|
default: ({ children, href }: { children: React.ReactNode; href: string }) => <a href={href}>{children}</a>,
|
|
}));
|
|
|
|
function item(source: ApprovalItem["source"]): ApprovalItem {
|
|
return {
|
|
id: "item-1",
|
|
source,
|
|
external_ref: "ref-1",
|
|
title: "Held post for tiktok",
|
|
summary: "",
|
|
risk: "medium",
|
|
payload: {},
|
|
edited_payload: null,
|
|
status: "pending",
|
|
decided_by: null,
|
|
decided_via: "",
|
|
decided_at: null,
|
|
decision_note: "",
|
|
result: {},
|
|
error: "",
|
|
expires_at: null,
|
|
created_at: null,
|
|
updated_at: null,
|
|
open_url: null,
|
|
can_decide: true,
|
|
};
|
|
}
|
|
|
|
const CLOSED = { open: false, reason: "Posting to social platforms opens at public launch." };
|
|
|
|
afterEach(() => {
|
|
cleanup();
|
|
mocks.decideApproval.mockReset();
|
|
});
|
|
|
|
describe("ApprovalItemCard launch gate", () => {
|
|
it("blocks approving a post-scheduling item while publishing is closed, but allows reject", () => {
|
|
render(<ApprovalItemCard item={item("publish_hold")} onDecided={vi.fn()} publishGate={CLOSED} />);
|
|
expect(screen.getByRole("status")).toHaveTextContent(/opens at public launch/i);
|
|
expect(screen.getByRole("button", { name: /^approve$/i })).toBeDisabled();
|
|
expect(screen.getByRole("button", { name: /^reject$/i })).toBeEnabled();
|
|
});
|
|
|
|
it("does not gate items that never post (ad budget)", () => {
|
|
render(<ApprovalItemCard item={item("ad_budget")} onDecided={vi.fn()} publishGate={CLOSED} />);
|
|
expect(screen.queryByRole("status")).toBeNull();
|
|
expect(screen.getByRole("button", { name: /^approve$/i })).toBeEnabled();
|
|
});
|
|
|
|
it("shows a server refusal without the request id", async () => {
|
|
mocks.decideApproval.mockRejectedValue(
|
|
Object.assign(
|
|
new Error("0123456789abcdef0123456789abcdef: this post is no longer held"),
|
|
{ status: 409 },
|
|
),
|
|
);
|
|
render(<ApprovalItemCard item={item("publish_hold")} onDecided={vi.fn()} />);
|
|
fireEvent.click(screen.getByRole("button", { name: /^approve$/i }));
|
|
expect(await screen.findByText("This post is no longer held")).toBeInTheDocument();
|
|
});
|
|
});
|