|
4 | 4 | customCtx, |
5 | 5 | customMutation, |
6 | 6 | customQuery, |
| 7 | + NoOp, |
7 | 8 | } from "./customFunctions.js"; |
8 | 9 | import { wrapDatabaseWriter } from "./rowLevelSecurity.js"; |
9 | 10 | import type { SessionId } from "./sessions.js"; |
@@ -35,6 +36,7 @@ import { |
35 | 36 | beforeEach, |
36 | 37 | describe, |
37 | 38 | expect, |
| 39 | + expectTypeOf, |
38 | 40 | test, |
39 | 41 | vi, |
40 | 42 | } from "vitest"; |
@@ -519,6 +521,54 @@ describe("custom functions with api auth", () => { |
519 | 521 | }); |
520 | 522 |
|
521 | 523 | describe("custom functions", () => { |
| 524 | + test("noop", async () => { |
| 525 | + const noopQuery = customQuery(query, NoOp); |
| 526 | + const noopQueryFn = noopQuery({ |
| 527 | + args: { foo: v.string() }, |
| 528 | + handler: async (ctx, args) => { |
| 529 | + return { bar: args.foo }; |
| 530 | + }, |
| 531 | + }); |
| 532 | + queryMatches(noopQueryFn, { foo: "" }, { bar: "" }); |
| 533 | + const sameQuery = query({ |
| 534 | + args: { foo: v.string() }, |
| 535 | + handler: async (ctx, args) => { |
| 536 | + return { bar: args.foo }; |
| 537 | + }, |
| 538 | + }); |
| 539 | + expectTypeOf(noopQueryFn).toEqualTypeOf(sameQuery); |
| 540 | + |
| 541 | + const noopMutation = customMutation(mutation, NoOp); |
| 542 | + const noopMutationFn = noopMutation({ |
| 543 | + args: { foo: v.string() }, |
| 544 | + handler: async (ctx, args) => { |
| 545 | + return { bar: args.foo }; |
| 546 | + }, |
| 547 | + }); |
| 548 | + const sameMutation = mutation({ |
| 549 | + args: { foo: v.string() }, |
| 550 | + handler: async (ctx, args) => { |
| 551 | + return { bar: args.foo }; |
| 552 | + }, |
| 553 | + }); |
| 554 | + expectTypeOf(noopMutationFn).toEqualTypeOf(sameMutation); |
| 555 | + |
| 556 | + const noopAction = customAction(action, NoOp); |
| 557 | + const noopActionFn = noopAction({ |
| 558 | + args: { foo: v.string() }, |
| 559 | + handler: async (ctx, args) => { |
| 560 | + return { bar: args.foo }; |
| 561 | + }, |
| 562 | + }); |
| 563 | + const sameAction = action({ |
| 564 | + args: { foo: v.string() }, |
| 565 | + handler: async (ctx, args) => { |
| 566 | + return { bar: args.foo }; |
| 567 | + }, |
| 568 | + }); |
| 569 | + expectTypeOf(noopActionFn).toEqualTypeOf(sameAction); |
| 570 | + }); |
| 571 | + |
522 | 572 | test("add args", async () => { |
523 | 573 | const t = convexTest(schema, modules); |
524 | 574 | expect(await t.query(testApi.add, {})).toMatchObject({ |
|
0 commit comments