aboutsummaryrefslogtreecommitdiff
path: root/src/lib/server/services/groceries.test.ts
diff options
context:
space:
mode:
authorMartin Kagamino Lehoux <martin@lehoux.net>2026-10-07 19:17:14 +0200
committerMartin Kagamino Lehoux <martin@lehoux.net>2026-10-07 19:17:14 +0200
commit66939bab93cdcb9b7732c45d7bc3b99b6951fe15 (patch)
treeec6bc1631464410f8735da49e02e99abff0f3863 /src/lib/server/services/groceries.test.ts
parent6e5dcdb53cea4c3f082d01c937fe5fc1d580c45b (diff)
feat: promote a reference as the primary shown in lists
Add an is_primary flag to references; the promoted ref sorts first on the item page and is the one shown under the item in the list and catalog. Item page gets a star toggle per reference.
Diffstat (limited to 'src/lib/server/services/groceries.test.ts')
-rw-r--r--src/lib/server/services/groceries.test.ts24
1 files changed, 24 insertions, 0 deletions
diff --git a/src/lib/server/services/groceries.test.ts b/src/lib/server/services/groceries.test.ts
index d12111f..dbf46b7 100644
--- a/src/lib/server/services/groceries.test.ts
+++ b/src/lib/server/services/groceries.test.ts
@@ -77,6 +77,30 @@ describe('groceries service', () => {
expect(result.items[0].bestRef?.reference).toBe('Brand A');
});
+ it('bestRef prefers the promoted ref over a higher score', async () => {
+ const now = Temporal.Now.instant().toString({
+ smallestUnit: 'millisecond',
+ });
+ const [g] = await db
+ .insert(groceries)
+ .values({ name: 'coffee', checked: false, createdAt: now })
+ .returning();
+ const [, b] = await db
+ .insert(references)
+ .values([
+ { groceryId: g.id, reference: 'Brand A', qualityScore: 80 },
+ { groceryId: g.id, reference: 'Brand B', qualityScore: 20 },
+ ])
+ .returning();
+ await db
+ .update(references)
+ .set({ isPrimary: true })
+ .where(eq(references.id, b.id));
+
+ const result = await loadAll(db);
+ expect(result.items[0].bestRef?.reference).toBe('Brand B');
+ });
+
it('toggle flips checked state', async () => {
const now = Temporal.Now.instant().toString({
smallestUnit: 'millisecond',