From 95c934cbec3c62a88e28e58eab290bd176f21b76 Mon Sep 17 00:00:00 2001 From: "Sven (AAMOS AI)" Date: Tue, 11 Aug 2026 05:47:56 +0700 Subject: [PATCH] =?UTF-8?q?fix:=20robustisera=20cooking-sessions-analytics?= =?UTF-8?q?-test=20+=20r=C3=A4tta=20eventName-alias?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- apps/api/test/cooking-sessions.test.ts | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) diff --git a/apps/api/test/cooking-sessions.test.ts b/apps/api/test/cooking-sessions.test.ts index 74a8db8..746ae5b 100644 --- a/apps/api/test/cooking-sessions.test.ts +++ b/apps/api/test/cooking-sessions.test.ts @@ -138,10 +138,10 @@ describe("cooking sessions", () => { expect(body.session.plannedPortions).toBe(4); const events = await testDb.db - .select({ name: schema.productAnalyticsEvents.eventName }) + .select({ eventName: schema.productAnalyticsEvents.eventName }) .from(schema.productAnalyticsEvents) .where(eq(schema.productAnalyticsEvents.userId, userId)); - expect(events.filter((e) => e.name === "cooking_session_started").length).toBe(0); + expect(events.filter((e) => e.eventName === "cooking_session_started").length).toBe(0); }); it("starts a planned session and fires cooking_session_started", async () => { @@ -338,9 +338,10 @@ describe("cooking sessions", () => { it("legacy /cook writes cooking_session_started and cooking_session_completed analytics", async () => { const before = await testDb.db - .select({ name: schema.productAnalyticsEvents.eventName }) + .select({ id: schema.productAnalyticsEvents.id, eventName: schema.productAnalyticsEvents.eventName }) .from(schema.productAnalyticsEvents) .where(eq(schema.productAnalyticsEvents.userId, userId)); + const beforeIds = new Set(before.map((e) => e.id)); const res = await app.inject({ method: "POST", @@ -354,9 +355,8 @@ describe("cooking sessions", () => { const after = await testDb.db .select() .from(schema.productAnalyticsEvents) - .where(eq(schema.productAnalyticsEvents.userId, userId)) - .orderBy(schema.productAnalyticsEvents.occurredAt); - const newEvents = after.slice(before.length); + .where(eq(schema.productAnalyticsEvents.userId, userId)); + const newEvents = after.filter((e) => !beforeIds.has(e.id)); const props = (e: (typeof after)[number]) => (e.properties ?? {}) as { cookingSessionId?: string }; const started = newEvents.filter((e) => e.eventName === "cooking_session_started" && props(e).cookingSessionId === sessionId); const completed = newEvents.filter((e) => e.eventName === "cooking_session_completed" && props(e).cookingSessionId === sessionId); @@ -591,10 +591,10 @@ describe("cooking sessions", () => { const names = ( await testDb.db - .select({ name: schema.productAnalyticsEvents.eventName }) + .select({ eventName: schema.productAnalyticsEvents.eventName }) .from(schema.productAnalyticsEvents) .where(eq(schema.productAnalyticsEvents.userId, userId)) - ).map((r) => r.name); + ).map((r) => r.eventName); expect(names).toContain("cooking_session_completed"); expect(names).toContain("cooking_session_cancelled"); });