From b0e98730332db1e6553bc997336407cae2b72dd7 Mon Sep 17 00:00:00 2001 From: edithatogo <15080672+edithatogo@users.noreply.github.com> Date: Fri, 21 Aug 2026 09:29:55 +0000 Subject: [PATCH] =?UTF-8?q?=F0=9F=A7=AA=20Add=20test=20for=20missing=20sch?= =?UTF-8?q?edule=20At=20in=20enforceSchedulingFreezePolicy?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 🎯 **What:** The testing gap addressed is the edge case when `candidate` is provided but `candidate.scheduledAt` is missing. 📊 **Coverage:** A new test file `src/test/assurance/cli-scheduling.test.ts` was added to cover this scenario, bypassing calendar limitation checks. ✨ **Result:** Test coverage for `enforceSchedulingFreezePolicy` is increased, ensuring reliable behavior when candidates are provided without a scheduled time. --- src/cli.ts | 2 +- src/test/assurance/cli-scheduling.test.ts | 39 +++++++++++++++++++++++ 2 files changed, 40 insertions(+), 1 deletion(-) create mode 100644 src/test/assurance/cli-scheduling.test.ts diff --git a/src/cli.ts b/src/cli.ts index 8cc0853..4374d76 100644 --- a/src/cli.ts +++ b/src/cli.ts @@ -7070,7 +7070,7 @@ function buildScheduledQueue( return [...postItems, ...draftItems, ...broadcastItems]; } -async function enforceSchedulingFreezePolicy(options: { +export async function enforceSchedulingFreezePolicy(options: { operation: string; freezePolicyPath: string | undefined; cataloguePath: string | undefined; diff --git a/src/test/assurance/cli-scheduling.test.ts b/src/test/assurance/cli-scheduling.test.ts new file mode 100644 index 0000000..6724974 --- /dev/null +++ b/src/test/assurance/cli-scheduling.test.ts @@ -0,0 +1,39 @@ +import { describe, it, expect, vi, beforeEach, afterEach } from "vitest"; +import { enforceSchedulingFreezePolicy } from "../../cli.js"; +import * as policyModule from "../../policy/scheduling-freeze.js"; +import * as cliModule from "../../cli.js"; + +vi.mock("../../policy/scheduling-freeze.js", () => { + return { + evaluateSchedulingFreezePolicy: vi.fn(), + buildSchedulingFreezeBlockReport: vi.fn(), + }; +}); + +describe("enforceSchedulingFreezePolicy", () => { + let originalExitCode: number | undefined; + + beforeEach(() => { + vi.resetAllMocks(); + originalExitCode = process.exitCode; + }); + + afterEach(() => { + process.exitCode = originalExitCode; + }); + + it("should return true when missing schedule At and calendar limitations exist", async () => { + vi.mocked(policyModule.evaluateSchedulingFreezePolicy).mockResolvedValue({ allowed: true }); + + // Test the specific branch where options.candidate?.scheduledAt is falsy + // This happens when we provide a candidate but no scheduledAt + const result = await enforceSchedulingFreezePolicy({ + operation: "test-op", + freezePolicyPath: "path", // need to trigger the second part of the condition (options.cataloguePath || freezePath) + cataloguePath: undefined, + candidate: { sourceFile: "test" }, // missing schedule At + }); + + expect(result).toBe(true); + }); +});