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 <noreply@anthropic.com>
This commit is contained in:
2026-03-16 14:07:51 +01:00
parent 9e1a875581
commit 9342085dd1
2 changed files with 82 additions and 0 deletions

View File

@@ -54,6 +54,7 @@ export function createTestDb() {
notes TEXT, notes TEXT,
product_url TEXT, product_url TEXT,
image_filename TEXT, image_filename TEXT,
status TEXT NOT NULL DEFAULT 'researching',
created_at INTEGER NOT NULL DEFAULT (unixepoch()), created_at INTEGER NOT NULL DEFAULT (unixepoch()),
updated_at INTEGER NOT NULL DEFAULT (unixepoch()) updated_at INTEGER NOT NULL DEFAULT (unixepoch())
) )

View File

@@ -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", () => { describe("resolveThread", () => {
it("atomically creates collection item from candidate data and archives thread", () => { it("atomically creates collection item from candidate data and archives thread", () => {
const thread = createThread(db, { name: "Tent Decision", categoryId: 1 }); const thread = createThread(db, { name: "Tent Decision", categoryId: 1 });