Skip to content

Commit 8ed051d

Browse files
committed
test calling with function handles
1 parent 652fa41 commit 8ed051d

File tree

1 file changed

+25
-0
lines changed

1 file changed

+25
-0
lines changed

example/convex/example.test.ts

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ import { afterEach, beforeEach, describe, expect, test, vi } from "vitest";
22
import { initConvexTest } from "./setup.test";
33
import { components, internal } from "./_generated/api";
44
import { runToCompletion } from "@convex-dev/migrations";
5+
import { createFunctionHandle, getFunctionName } from "convex/server";
56

67
describe("example", () => {
78
beforeEach(async () => {
@@ -48,4 +49,28 @@ describe("example", () => {
4849
}),
4950
).rejects.toThrow("This migration fails after the first");
5051
});
52+
53+
test("test migrating with function handle", async () => {
54+
const t = initConvexTest();
55+
await t.mutation(internal.example.seed, { count: 10 });
56+
await t.run(async (ctx) => {
57+
const docs = await ctx.db.query("myTable").collect();
58+
expect(docs).toHaveLength(10);
59+
expect(docs.some((doc) => doc.optionalField === undefined)).toBe(true);
60+
});
61+
await t.run(async (ctx) => {
62+
const fnHandle = await createFunctionHandle(
63+
internal.example.setDefaultValue,
64+
);
65+
await runToCompletion(ctx, components.migrations, fnHandle, {
66+
name: getFunctionName(internal.example.setDefaultValue),
67+
batchSize: 2,
68+
});
69+
});
70+
await t.run(async (ctx) => {
71+
const after = await ctx.db.query("myTable").collect();
72+
expect(after).toHaveLength(10);
73+
expect(after.every((doc) => doc.optionalField !== undefined)).toBe(true);
74+
});
75+
});
5176
});

0 commit comments

Comments
 (0)