Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

No clear way to interface with convex-auth #32

Open
mez opened this issue Dec 20, 2024 · 2 comments
Open

No clear way to interface with convex-auth #32

mez opened this issue Dec 20, 2024 · 2 comments

Comments

@mez
Copy link

mez commented Dec 20, 2024

I can do the following in my test:

      const ctx = t.withIdentity({ id: userId.toString(), tokenIdentifier: "test" });

but const userId = await getAuthUserId(ctx); call from inside a convex function being tested doesn't seem to return the correct userId created in the test.

@mez
Copy link
Author

mez commented Dec 20, 2024

I got it working by mocking the convex auth module like the following:

// Mock the auth module
vi.mock("@convex-dev/auth/server", async (importOriginal) => {
  const actual = await importOriginal()
  return {
    ...actual,
    getAuthUserId: vi.fn(),
  }
});

@Dewald928
Copy link

Dewald928 commented Mar 6, 2025

test("Create auctions", async () => {
  const t = convexTest(schema);

// 
  const asAdmin = t.withIdentity({
    email: "[email protected]",
    subject: "jx7aebd73g2em3rfv0jv1ek17x7bh5f2",
  });
  const result = await asAdmin.mutation(api.auctions.createAuction, {
    title: "Test Auction",
    description: "Test Description",
    startingPrice: 10,
    startTime: Date.now() + 1000 * 60,
    endTime: Date.now() + 1000 * 60 * 10,
    bidIncrementMinimum: 1,
    numberOfAuctions: 10,
    separationTimeInMinutes: 0,
  });
  expect(result).toBeDefined();
});

This is also failing for me, but it works when I run it in function caller on dashboard.
Also using convex auth.
This is kinda critical regarding testing. What am I doing wrong?

EDIT: I now notice this is a mocked environment, so things won't appear in the DB

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants