fix: robustisera cooking-sessions-analytics-test + rätta eventName-alias

This commit is contained in:
Sven (AAMOS AI)
2026-08-11 05:47:56 +07:00
parent 4116653b51
commit 95c934cbec
+8 -8
View File
@@ -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");
});