diff --git a/src/__tests__/integration/api/cron/daily-recap.test.ts b/src/__tests__/integration/api/cron/daily-recap.test.ts index aaabe0ebc2..0959188343 100644 --- a/src/__tests__/integration/api/cron/daily-recap.test.ts +++ b/src/__tests__/integration/api/cron/daily-recap.test.ts @@ -6,9 +6,9 @@ import { NextRequest } from "next/server"; * * Tests verify: * - Authentication via CRON_SECRET (401 when missing/invalid) - * - Config guard (STAKWORK_DAILY_RECAP_WORKFLOW_ID presence) - * - Response shape when workflow ID is absent - * - Response shape when cron is enabled and runs successfully + * - Workflow ID gating (STAKWORK_DAILY_RECAP_WORKFLOW_ID) + * - Response shape when workflow ID is missing + * - Response shape when cron runs successfully */ // ── Mocks ──────────────────────────────────────────────────────────────────── @@ -71,9 +71,9 @@ describe("GET /api/cron/daily-recap", () => { expect(body.error).toBe("Unauthorized"); }); - // ── Config guard ────────────────────────────────────────────────────────── + // ── Workflow ID gate ────────────────────────────────────────────────────── - it("returns 200 with not-configured message when STAKWORK_DAILY_RECAP_WORKFLOW_ID is unset", async () => { + it("returns 200 with skip message when STAKWORK_DAILY_RECAP_WORKFLOW_ID is unset", async () => { delete process.env.STAKWORK_DAILY_RECAP_WORKFLOW_ID; const res = await GET(createAuthenticatedRequest()); @@ -81,14 +81,16 @@ describe("GET /api/cron/daily-recap", () => { const body = await res.json(); expect(body.success).toBe(true); - expect(body.message).toMatch(/not configured/i); + expect(body.message).toMatch(/STAKWORK_DAILY_RECAP_WORKFLOW_ID not configured/i); + expect(body.usersProcessed).toBe(0); + expect(body.dispatched).toBe(0); expect(mockExecuteScheduledDailyRecapRuns).not.toHaveBeenCalled(); }); // ── Enabled ─────────────────────────────────────────────────────────────── it("calls executeScheduledDailyRecapRuns and returns summary JSON when workflow ID is set", async () => { - process.env.STAKWORK_DAILY_RECAP_WORKFLOW_ID = "12345"; + process.env.STAKWORK_DAILY_RECAP_WORKFLOW_ID = "42"; mockExecuteScheduledDailyRecapRuns.mockResolvedValue({ usersProcessed: 5, dispatched: 4, @@ -113,7 +115,7 @@ describe("GET /api/cron/daily-recap", () => { }); it("returns success=false when errors are present", async () => { - process.env.STAKWORK_DAILY_RECAP_WORKFLOW_ID = "12345"; + process.env.STAKWORK_DAILY_RECAP_WORKFLOW_ID = "42"; mockExecuteScheduledDailyRecapRuns.mockResolvedValue({ usersProcessed: 3, dispatched: 2, @@ -131,7 +133,7 @@ describe("GET /api/cron/daily-recap", () => { }); it("returns 500 when executeScheduledDailyRecapRuns throws", async () => { - process.env.STAKWORK_DAILY_RECAP_WORKFLOW_ID = "12345"; + process.env.STAKWORK_DAILY_RECAP_WORKFLOW_ID = "42"; mockExecuteScheduledDailyRecapRuns.mockRejectedValue(new Error("unexpected crash")); const res = await GET(createAuthenticatedRequest()); diff --git a/src/app/api/cron/daily-recap/route.ts b/src/app/api/cron/daily-recap/route.ts index 1820ee2b51..c291b2b749 100644 --- a/src/app/api/cron/daily-recap/route.ts +++ b/src/app/api/cron/daily-recap/route.ts @@ -16,7 +16,16 @@ export async function GET(request: NextRequest) { if (!process.env.STAKWORK_DAILY_RECAP_WORKFLOW_ID) { console.log("[DailyRecapCron] STAKWORK_DAILY_RECAP_WORKFLOW_ID not configured, skipping"); - return NextResponse.json({ success: true, message: "Daily recap cron not configured" }); + return NextResponse.json({ + success: true, + message: "STAKWORK_DAILY_RECAP_WORKFLOW_ID not configured, skipping", + usersProcessed: 0, + dispatched: 0, + skipped: 0, + errorCount: 0, + errors: [], + timestamp: new Date().toISOString(), + }); } console.log("[DailyRecapCron] Starting scheduled execution");