#Problem testing convex function with convex-test.

17 messages · Page 1 of 1 (latest)

fervent sable
#

I'm using ents to handle my db logic.

twilit cloud
#

Is this something that was working before, is it a regression? Or has this never worked?

#

Also what's not working here, the test or the implementation?

fervent sable
#

Hello, only the test is not working, the implementation is working fine

#

I just copied the code in the documentation and replace it with my own function that I know is working to test the water.

import { convexTest } from "convex-test";
import { expect, test } from "vitest";
import { api } from "./_generated/api";
import schema from "./schema";

test("sending messages", async () => {
  const t = convexTest(schema);
  await t.mutation(api.messages.send, { body: "Hi!", author: "Sarah" });
  await t.mutation(api.messages.send, { body: "Hey!", author: "Tom" });
  const messages = await t.query(api.messages.list);
  expect(messages).toMatchObject([
    { body: "Hi!", author: "Sarah" },
    { body: "Hey!", author: "Tom" }
  ]);
});
#

And this is my code:

// Start of test 
import { convexTest } from "convex-test";
import { expect, test } from "vitest";
import { api } from "./_generated/api";
import schema from "./schema";
import { Id } from "./_generated/dataModel";

test.only("test", async() => {
  const t = convexTest(schema);
  await t.mutation(api.users.storeUser, {firstName: "Yvens",lastName: "Belaston",email: "yvens@gmail.com"});
})

// End of test

// Store User function 
export const storeUser = mutation({
  args: {
    firstName: v.string(),
    lastName: v.string(),
    email: v.string(),
  },
  handler: async (ctx, args) => {
    const user = await ctx.table("users").get("email", args.email);
    if (!user) {
      const userId = await ctx.table("users").insert({
        firstname: args.firstName,
        lastname: args.lastName,
        email: args.email,
      })
      return userId;
    }

    return user._id;
  }
})
#

Please let me know if you need anything else @twilit cloud

twilit cloud
fervent sable
#

I think the repo is private

twilit cloud
#

ah thanks, sorry about that!

#

this is very new

#

I'll file this, bet it gets fixed next week.

#

I would just make it public but I didn't write it so want to confirm with the folks that did

fervent sable
sage sage
#

This particular issue has been fixed, please upgrade to latest version of convex-test