Skip to content

🪢 Open source agent evals & observability: Trace, evaluate, and improve LLM applications with one open platform.

feat: move session tests to async suite (#4636)

Max Deichmannc389d4f01a47
diff --git a/web/src/__tests__/async/sessions-api.servertest.ts b/web/src/__tests__/async/sessions-api.servertest.ts
index 6d91d5e8b1..fecfb7a62a 100644
--- a/web/src/__tests__/async/sessions-api.servertest.ts
+++ b/web/src/__tests__/async/sessions-api.servertest.ts
@@ -1,9 +1,15 @@
-import { makeZodVerifiedAPICall } from "@/src/__tests__/test-utils";
+import {
+ createOrgProjectAndApiKey,
+ makeZodVerifiedAPICall,
+} from "@/src/__tests__/test-utils";
import { v4 } from "uuid";
import { prisma } from "@langfuse/shared/src/db";
import { createTracesCh } from "@/src/__tests__/async/repositories/clickhouse-helpers";
import { createTrace } from "@/src/__tests__/fixtures/tracing-factory";
-import { GetSessionV1Response } from "@/src/features/public-api/types/sessions";
+import {
+ GetSessionsV1Response,
+ GetSessionV1Response,
+} from "@/src/features/public-api/types/sessions";
const projectId = "7a88fb47-b4e2-43b8-a06c-a5ce950dc53a";
@@ -44,4 +50,147 @@ describe("/api/public/sessions API Endpoint", () => {
);
});
});
+ describe("GET /api/public/sessions API Endpoint", () => {
+ let projectId: string;
+ let auth: string;
+
+ beforeAll(async () => {
+ const { projectId: newProjectId, auth: newAuth } =
+ await createOrgProjectAndApiKey();
+ projectId = newProjectId;
+ auth = newAuth;
+
+ await prisma.traceSession.createMany({
+ data: [
+ {
+ id: "session-2021-01-01",
+ createdAt: new Date("2021-01-01T00:00:00Z"),
+ projectId: projectId,
+ },
+ {
+ id: "session-2021-02-01",
+ createdAt: new Date("2021-02-01T00:00:00Z"),
+ projectId: projectId,
+ },
+ {
+ id: "session-2021-03-01",
+ createdAt: new Date("2021-03-01T00:00:00Z"),
+ projectId: projectId,
+ },
+ {
+ id: "session-2021-04-01",
+ createdAt: new Date("2021-04-01T00:00:00Z"),
+ projectId: projectId,
+ },
+ {
+ id: "session-2021-05-01",
+ createdAt: new Date("2021-05-01T00:00:00Z"),
+ projectId: projectId,
+ },
+ ],
+ });
+ });
+
+ it("should return all sessions", async () => {
+ const sessions = await makeZodVerifiedAPICall(
+ GetSessionsV1Response,
+ "GET",
+ "/api/public/sessions",
+ undefined,
+ auth,
+ );
+ expect(sessions.body.data.length).toEqual(5);
+ expect(sessions.body.data.map((session) => session.id)).toEqual(
+ expect.arrayContaining([
+ "session-2021-01-01",
+ "session-2021-02-01",
+ "session-2021-03-01",
+ "session-2021-04-01",
+ "session-2021-05-01",
+ ]),
+ );
+ });
+
+ it("should return paginated sessions with limit and page number", async () => {
+ const limit = 2;
+ const page = 2;
+
+ const sessions = await makeZodVerifiedAPICall(
+ GetSessionsV1Response,
+ "GET",
+ `/api/public/sessions?limit=${limit}&page=${page}`,
+ undefined,
+ auth,
+ );
+
+ expect(sessions.body.data).toHaveLength(2);
+ expect(sessions.body.data.map((session) => session.id)).toEqual([
+ "session-2021-03-01",
+ "session-2021-02-01",
+ ]);
+ expect(sessions.body.meta.totalItems).toBe(5);
+ expect(sessions.body.meta.totalPages).toBe(3);
+ expect(sessions.body.meta.page).toBe(page);
+ expect(sessions.body.meta.limit).toBe(limit);
+ });
+
+ it("should return sessions within a specific date range", async () => {
+ const fromTimestamp = "2021-02-01T00:00:00Z";
+ const toTimestamp = "2021-04-01T00:00:00Z";
+
+ const sessions = await makeZodVerifiedAPICall(
+ GetSessionsV1Response,
+ "GET",
+ `/api/public/sessions?fromTimestamp=${fromTimestamp}&toTimestamp=${toTimestamp}`,
+ undefined,
+ auth,
+ );
+
+ expect(sessions.body.data).toHaveLength(2);
+ expect(sessions.body.data.map((session) => session.id)).toEqual([
+ "session-2021-03-01",
+ "session-2021-02-01",
+ ]);
+ expect(sessions.body.meta.totalItems).toBe(2);
+ });
+
+ it("should return sessions from a specific date onwards (including the date)", async () => {
+ const fromTimestamp = "2021-03-01T00:00:00Z";
+
+ const sessions = await makeZodVerifiedAPICall(
+ GetSessionsV1Response,
+ "GET",
+ `/api/public/sessions?fromTimestamp=${fromTimestamp}`,
+ undefined,
+ auth,
+ );
+
+ expect(sessions.body.data).toHaveLength(3);
+ expect(sessions.body.data.map((session) => session.id)).toEqual([
+ "session-2021-05-01",
+ "session-2021-04-01",
+ "session-2021-03-01",
+ ]);
+ expect(sessions.body.meta.totalItems).toBe(3);
+ });
+
+ it("should return sessions up to a specific date (excluding it)", async () => {
+ const toTimestamp = "2021-03-01T00:00:00Z";
+
+ const sessions = await makeZodVerifiedAPICall(
+ GetSessionsV1Response,
+ "GET",
+ `/api/public/sessions?toTimestamp=${toTimestamp}`,
+ undefined,
+ auth,
+ );
+
+ expect(sessions.body.data).toHaveLength(2);
+ expect(sessions.body.data.map((session) => session.id)).toEqual([
+ "session-2021-02-01",
+ "session-2021-01-01",
+ ]);
+ expect(sessions.body.meta.totalItems).toBe(2);
+ });
+ });
});
diff --git a/web/src/__tests__/sessions.servertest.ts b/web/src/__tests__/sessions.servertest.ts
index 1b1db9c838..459a61c242 100644
--- a/web/src/__tests__/sessions.servertest.ts
+++ b/web/src/__tests__/sessions.servertest.ts
@@ -4,7 +4,6 @@ import {
makeZodVerifiedAPICall,
pruneDatabase,
} from "@/src/__tests__/test-utils";
-import { GetSessionsV1Response } from "@/src/features/public-api/types/sessions";
import { PostTracesV1Response } from "@/src/features/public-api/types/traces";
import { prisma } from "@langfuse/shared/src/db";
@@ -39,122 +38,3 @@ describe("Create and get sessions", () => {
});
});
});
-
-describe("GET /api/public/sessions API Endpoint", () => {
- beforeEach(async () => {
- await pruneDatabase();
- await prisma.traceSession.createMany({
- data: [
- {
- id: "session-2021-01-01",
- createdAt: new Date("2021-01-01T00:00:00Z"),
- projectId: "7a88fb47-b4e2-43b8-a06c-a5ce950dc53a",
- },
- {
- id: "session-2021-02-01",
- createdAt: new Date("2021-02-01T00:00:00Z"),
- projectId: "7a88fb47-b4e2-43b8-a06c-a5ce950dc53a",
- },
- {
- id: "session-2021-03-01",
- createdAt: new Date("2021-03-01T00:00:00Z"),
- projectId: "7a88fb47-b4e2-43b8-a06c-a5ce950dc53a",
- },
- {
- id: "session-2021-04-01",
- createdAt: new Date("2021-04-01T00:00:00Z"),
- projectId: "7a88fb47-b4e2-43b8-a06c-a5ce950dc53a",
- },
- {
- id: "session-2021-05-01",
- createdAt: new Date("2021-05-01T00:00:00Z"),
- projectId: "7a88fb47-b4e2-43b8-a06c-a5ce950dc53a",
- },
- ],
- });
- });
- afterEach(async () => await pruneDatabase());
-
- it("should return all sessions", async () => {
- const sessions = await makeZodVerifiedAPICall(
- GetSessionsV1Response,
- "GET",
- "/api/public/sessions",
- );
- expect(sessions.body.data).toHaveLength(5);
- });
-
- it("should return paginated sessions with limit and page number", async () => {
- const limit = 2;
- const page = 2;
-
- const sessions = await makeZodVerifiedAPICall(
- GetSessionsV1Response,
- "GET",
- `/api/public/sessions?limit=${limit}&page=${page}`,
- );
-
- expect(sessions.body.data).toHaveLength(2);
- expect(sessions.body.data.map((session) => session.id)).toEqual([
- "session-2021-03-01",
- "session-2021-02-01",
- ]);
- expect(sessions.body.meta.totalItems).toBe(5);
- expect(sessions.body.meta.totalPages).toBe(3);
- expect(sessions.body.meta.page).toBe(page);
- expect(sessions.body.meta.limit).toBe(limit);
- });
-
- it("should return sessions within a specific date range", async () => {
- const fromTimestamp = "2021-02-01T00:00:00Z";
- const toTimestamp = "2021-04-01T00:00:00Z";
-
- const sessions = await makeZodVerifiedAPICall(
- GetSessionsV1Response,
- "GET",
- `/api/public/sessions?fromTimestamp=${fromTimestamp}&toTimestamp=${toTimestamp}`,
- );
-
- expect(sessions.body.data).toHaveLength(2);
- expect(sessions.body.data.map((session) => session.id)).toEqual([
- "session-2021-03-01",
- "session-2021-02-01",
- ]);
- expect(sessions.body.meta.totalItems).toBe(2);
- });
-
- it("should return sessions from a specific date onwards (including the date)", async () => {
- const fromTimestamp = "2021-03-01T00:00:00Z";
-
- const sessions = await makeZodVerifiedAPICall(
- GetSessionsV1Response,
- "GET",
- `/api/public/sessions?fromTimestamp=${fromTimestamp}`,
- );
-
- expect(sessions.body.data).toHaveLength(3);
- expect(sessions.body.data.map((session) => session.id)).toEqual([
- "session-2021-05-01",
- "session-2021-04-01",
- "session-2021-03-01",
- ]);
- expect(sessions.body.meta.totalItems).toBe(3);
- });
-
- it("should return sessions up to a specific date (excluding it)", async () => {
- const toTimestamp = "2021-03-01T00:00:00Z";
-
- const sessions = await makeZodVerifiedAPICall(
- GetSessionsV1Response,
- "GET",
- `/api/public/sessions?toTimestamp=${toTimestamp}`,
- );
-
- expect(sessions.body.data).toHaveLength(2);
- expect(sessions.body.data.map((session) => session.id)).toEqual([
- "session-2021-02-01",
- "session-2021-01-01",
- ]);
- expect(sessions.body.meta.totalItems).toBe(2);
- });
-});