diff --git a/tests/services/thread.service.test.ts b/tests/services/thread.service.test.ts index fa70c19..303a5e8 100644 --- a/tests/services/thread.service.test.ts +++ b/tests/services/thread.service.test.ts @@ -109,6 +109,21 @@ describe("Thread Service", () => { const result = getThreadWithCandidates(db, 9999); expect(result).toBeNull(); }); + + it("includes pros and cons on each candidate", () => { + const thread = createThread(db, { name: "Tent Options", categoryId: 1 }); + createCandidate(db, thread.id, { + name: "Tent A", + categoryId: 1, + pros: "Lightweight", + cons: "Pricey", + }); + + const result = getThreadWithCandidates(db, thread.id); + expect(result).toBeDefined(); + expect(result?.candidates[0].pros).toBe("Lightweight"); + expect(result?.candidates[0].cons).toBe("Pricey"); + }); }); describe("createCandidate", () => { @@ -133,6 +148,30 @@ describe("Thread Service", () => { expect(candidate.notes).toBe("Ultralight 2-person"); expect(candidate.productUrl).toBe("https://example.com/tent"); }); + + it("stores and returns pros and cons", () => { + const thread = createThread(db, { name: "Tent Options", categoryId: 1 }); + const candidate = createCandidate(db, thread.id, { + name: "Tent A", + categoryId: 1, + pros: "Lightweight\nGood reviews", + cons: "Expensive", + }); + + expect(candidate.pros).toBe("Lightweight\nGood reviews"); + expect(candidate.cons).toBe("Expensive"); + }); + + it("returns null for pros and cons when not provided", () => { + const thread = createThread(db, { name: "Tent Options", categoryId: 1 }); + const candidate = createCandidate(db, thread.id, { + name: "Tent B", + categoryId: 1, + }); + + expect(candidate.pros).toBeNull(); + expect(candidate.cons).toBeNull(); + }); }); describe("updateCandidate", () => { @@ -157,6 +196,31 @@ describe("Thread Service", () => { const result = updateCandidate(db, 9999, { name: "Ghost" }); expect(result).toBeNull(); }); + + it("can set and clear pros and cons", () => { + const thread = createThread(db, { name: "Test", categoryId: 1 }); + const candidate = createCandidate(db, thread.id, { + name: "Original", + categoryId: 1, + }); + + // Set pros and cons + const withPros = updateCandidate(db, candidate.id, { + pros: "Lightweight", + cons: "Expensive", + }); + expect(withPros?.pros).toBe("Lightweight"); + expect(withPros?.cons).toBe("Expensive"); + + // Clear pros and cons by setting to empty string + const cleared = updateCandidate(db, candidate.id, { + pros: "", + cons: "", + }); + // Empty string stored as-is or null — either is acceptable + expect(cleared?.pros == null || cleared?.pros === "").toBe(true); + expect(cleared?.cons == null || cleared?.cons === "").toBe(true); + }); }); describe("deleteCandidate", () => {