Skip to content

Commit

Permalink
WIP: Add get many users test
Browse files Browse the repository at this point in the history
  • Loading branch information
justinliangg committed Feb 18, 2024
1 parent c3d787a commit 8f9ec3f
Showing 1 changed file with 77 additions and 0 deletions.
77 changes: 77 additions & 0 deletions tests/pages/api/user/get-many.test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,77 @@
import { PageConfig } from "next";
import { testApiHandler } from "next-test-api-route-handler";
import { clerkClient } from "@clerk/nextjs";
import { beforeAll, describe, expect, it, vi } from "vitest";

import endpoint from "@/pages/api/user";

import prisma from "../../../setup";
import { cleanup, seedTestData } from "../../../utils";
// Respect the Next.js config object if it's exported
const handler: typeof endpoint & { config?: PageConfig } = endpoint;

describe("GET /api/users", () => {
beforeAll(async () => {
await cleanup();
await seedTestData();

vi.mock("@clerk/nextjs/server");
vi.mock("@clerk/nextjs");

await prisma.staff.createMany({
data: [
{
clerkId: "Test",
role: "EVENT_MANAGER"
},
{
clerkId: "mock user",
role: "EVENT_MANAGER"
}
]
});
});

it("should be able to get users", async () => {
await testApiHandler({
handler,
params: { page: "1", perPage: "5" },
test: async ({ fetch }) => {
const res = await fetch({
method: "GET",
headers: {
"Content-Type": "application/json"
}
});

const result = await res.json();

expect(res.status).toBe(200);
expect(clerkClient.users.getUserList).toBeCalledWith({
orderBy: "-created_at",
limit: 5,
offset: (1 - 1) * 5,
query: "",
userId: undefined
});
expect(result.meta).toMatchObject({
perPage: 5,
lastPage: 1,
page: 1,
totalCount: 5
});
expect(result.items).toContainEqual({
id: "Test",
emailAddress: "[email protected]",
firstName: "Spongebob",
lastName: "",
role: "EVENT_MANAGER"
});
}
});
});

it("should be able to filter by roles", () => {});

it("should only allow filter by staff roles", async () => {});
});

0 comments on commit 8f9ec3f

Please sign in to comment.