-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
c3d787a
commit 8f9ec3f
Showing
1 changed file
with
77 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 () => {}); | ||
}); |