Skip to content

Commit 79fc9a4

Browse files
committed
add a test for threads
1 parent 102b0f7 commit 79fc9a4

File tree

3 files changed

+29
-2
lines changed

3 files changed

+29
-2
lines changed

example/convex/threads.test.ts

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
import { expect, test } from "vitest";
2+
import { components } from "./_generated/api.js";
3+
import { createThread } from "@convex-dev/agent";
4+
import { initConvexTest } from "./setup.test.js";
5+
6+
test("Agent createThread", async () => {
7+
const t = initConvexTest();
8+
9+
const threadId = await t.run(async (ctx) => {
10+
return await createThread(ctx, components.agent, {
11+
title: "Hello, world!",
12+
});
13+
});
14+
const thread = await t.query(components.agent.threads.getThread, {
15+
threadId,
16+
});
17+
expect(thread).toMatchObject({
18+
title: "Hello, world!",
19+
});
20+
});

src/component/messages.test.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,11 +6,11 @@ import { api } from "./_generated/api.js";
66
import type { Id } from "./_generated/dataModel.js";
77
import { getMaxMessage } from "./messages.js";
88
import schema from "./schema.js";
9-
import { modules } from "./setup.test.js";
9+
import { initConvexTest, modules } from "./setup.test.js";
1010

1111
describe("agent", () => {
1212
test("getMaxMessage works for threads", async () => {
13-
const t = convexTest(schema, modules);
13+
const t = initConvexTest();
1414
const thread = await t.mutation(api.threads.createThread, {
1515
userId: "test",
1616
});

src/component/setup.test.ts

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,12 @@
11
/// <reference types="vite/client" />
2+
import { convexTest } from "convex-test";
23
import { test } from "vitest";
4+
import schema from "./schema.js";
35
export const modules = import.meta.glob("./**/*.*s");
46

7+
export function initConvexTest() {
8+
const t = convexTest(schema, modules);
9+
return t;
10+
}
11+
512
test("setup", () => {});

0 commit comments

Comments
 (0)