backpack1098B
Convex Communityโ€ข3y agoโ€ข
6 replies
backpack1098

how to mock two tables?

hi! i currently have the following snippet
it("createUserProfile should  create a person", async () => {
  const ctx = {
    db: {
      insert: vi.fn(),
      query: vi.fn().mockReturnValue({
        withIndex: vi.fn().mockReturnValue({
          unique: vi.fn().mockReturnValue(null),
        }),
      }),
    },
    auth: {
      getUserIdentity: vi.fn().mockReturnValue(
        Promise.resolve({
          tokenIdentifier: "user id",
        })
      ),
    },
  }

  // @ts-ignore
  await createUserProfile(ctx, { clerkOrgId: "fake org id" })
  expect(ctx.db.insert.mock.calls.length === 1)
  expect(ctx.db.insert.mock.calls[0]).toEqual([
    "user",
    {
      clerkOrgId: "fake org id",
      clerkUserId: "user id",
    },
  ])
})

what happens if createUserProfile so happen to call 2 DBs? can i do something like
const ctx = {
    db: 
       db1: {},
       db2: {},
...

getting an error when i try it ๐Ÿ˜…
Was this page helpful?