Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
42 changes: 40 additions & 2 deletions app/api/__tests__/jobs.test.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { NextRequest } from "next/server";
import { beforeEach, describe, expect, it, vi } from "vitest";
import { POST } from "@/app/api/jobs/route";
import { afterEach, beforeEach, describe, expect, it, vi } from "vitest";
import { DELETE, POST } from "@/app/api/jobs/route";
import { readJobs, writeJobs } from "@/lib/jobs-repository";
import { generateAiSummary } from "@/lib/job-summary-server";
import type { JobsData } from "@/lib/jobs";
Expand All @@ -22,6 +22,14 @@ function request(body: unknown) {
});
}

function deleteRequest(body: unknown) {
return new NextRequest("http://localhost/api/jobs", {
method: "DELETE",
body: JSON.stringify(body),
headers: { "Content-Type": "application/json" },
});
}

function emptyJobs(): JobsData {
return { applied: [], prospect: [], local: [], staffing: [], passed: [], pending: [] };
}
Expand Down Expand Up @@ -61,3 +69,33 @@ describe("POST /api/jobs", () => {
}));
});
});

describe("DELETE /api/jobs (move to applied)", () => {
beforeEach(() => {
vi.useFakeTimers();
vi.setSystemTime(new Date("2026-07-16T12:00:00Z"));
});

afterEach(() => {
vi.useRealTimers();
});

it("stamps today's date when a job with no date moves into applied", async () => {
vi.mocked(readJobs).mockResolvedValue({
...emptyJobs(),
prospect: [{ company: "Acme", role: "Designer", fit: "good", salary: "", notes: "", url: "" }],
});

const response = await DELETE(deleteRequest({
section: "prospect",
company: "Acme",
role: "Designer",
targetSection: "applied",
}));

expect(response.status).toBe(200);
expect(writeJobs).toHaveBeenCalledWith(expect.objectContaining({
applied: [expect.objectContaining({ date: "2026-07-16" })],
}));
});
});
2 changes: 1 addition & 1 deletion app/api/jobs/route.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ function normalizeJobForSection(job: AnyJob, targetSection: JobSection): AnyJob
const normalized = { ...job };
if (targetSection === "applied") {
if (!normalized.status) normalized.status = "applied";
if (normalized.date === undefined) normalized.date = "";
if (!normalized.date) normalized.date = new Date().toISOString().slice(0, 10);
} else if (targetSection === "prospect" || targetSection === "local" || targetSection === "staffing") {
if (!normalized.fit) normalized.fit = "good";
}
Expand Down
Loading