From 9342085dd11a4a2e8e6c816d876bf883de074a32 Mon Sep 17 00:00:00 2001 From: Jean-Luc Makiola Date: Mon, 16 Mar 2026 14:07:51 +0100 Subject: [PATCH] test(08-01): add failing tests for candidate status field - 5 tests: create with/without status, update status, getThreadWithCandidates includes status - Test helper updated with status column in thread_candidates CREATE TABLE Co-Authored-By: Claude Opus 4.6 --- tests/helpers/db.ts | 1 + tests/services/thread.service.test.ts | 81 +++++++++++++++++++++++++++ 2 files changed, 82 insertions(+) diff --git a/tests/helpers/db.ts b/tests/helpers/db.ts index 9cdc1f0..08cc89e 100644 --- a/tests/helpers/db.ts +++ b/tests/helpers/db.ts @@ -54,6 +54,7 @@ export function createTestDb() { notes TEXT, product_url TEXT, image_filename TEXT, + status TEXT NOT NULL DEFAULT 'researching', created_at INTEGER NOT NULL DEFAULT (unixepoch()), updated_at INTEGER NOT NULL DEFAULT (unixepoch()) ) diff --git a/tests/services/thread.service.test.ts b/tests/services/thread.service.test.ts index fc6157d..fa70c19 100644 --- a/tests/services/thread.service.test.ts +++ b/tests/services/thread.service.test.ts @@ -217,6 +217,87 @@ describe("Thread Service", () => { }); }); + describe("candidate status", () => { + it("createCandidate without status returns a candidate with status 'researching'", () => { + const thread = createThread(db, { name: "Test Thread", categoryId: 1 }); + const candidate = createCandidate(db, thread.id, { + name: "No Status", + categoryId: 1, + }); + + expect(candidate.status).toBe("researching"); + }); + + it("createCandidate with status 'ordered' returns a candidate with status 'ordered'", () => { + const thread = createThread(db, { name: "Test Thread", categoryId: 1 }); + const candidate = createCandidate(db, thread.id, { + name: "Ordered Item", + categoryId: 1, + status: "ordered", + }); + + expect(candidate.status).toBe("ordered"); + }); + + it("updateCandidate can change status from 'researching' to 'ordered'", () => { + const thread = createThread(db, { name: "Test Thread", categoryId: 1 }); + const candidate = createCandidate(db, thread.id, { + name: "Status Change", + categoryId: 1, + }); + + expect(candidate.status).toBe("researching"); + + const updated = updateCandidate(db, candidate.id, { + status: "ordered", + }); + + expect(updated?.status).toBe("ordered"); + }); + + it("updateCandidate can change status from 'ordered' to 'arrived'", () => { + const thread = createThread(db, { name: "Test Thread", categoryId: 1 }); + const candidate = createCandidate(db, thread.id, { + name: "Arriving Item", + categoryId: 1, + status: "ordered", + }); + + const updated = updateCandidate(db, candidate.id, { + status: "arrived", + }); + + expect(updated?.status).toBe("arrived"); + }); + + it("getThreadWithCandidates includes status field on each candidate", () => { + const thread = createThread(db, { name: "Status Thread", categoryId: 1 }); + createCandidate(db, thread.id, { + name: "Candidate A", + categoryId: 1, + }); + createCandidate(db, thread.id, { + name: "Candidate B", + categoryId: 1, + status: "ordered", + }); + + const result = getThreadWithCandidates(db, thread.id); + expect(result).toBeDefined(); + expect(result?.candidates).toHaveLength(2); + + const candidateA = result?.candidates.find( + (c) => c.name === "Candidate A", + ); + const candidateB = result?.candidates.find( + (c) => c.name === "Candidate B", + ); + + expect(candidateA?.status).toBe("researching"); + expect(candidateB?.status).toBe("ordered"); + }); + }); + describe("resolveThread", () => { it("atomically creates collection item from candidate data and archives thread", () => { const thread = createThread(db, { name: "Tent Decision", categoryId: 1 });