From b7b5306619cc4420bd0ae494881ee7161391dec4 Mon Sep 17 00:00:00 2001 From: MohamedBassem Date: Sat, 2 Mar 2024 09:53:24 +0000 Subject: feature: Make the first user an admin automatically --- packages/web/server/api/routers/users.test.ts | 57 +++++++++++++++++++++++++++ 1 file changed, 57 insertions(+) create mode 100644 packages/web/server/api/routers/users.test.ts (limited to 'packages/web/server/api/routers/users.test.ts') diff --git a/packages/web/server/api/routers/users.test.ts b/packages/web/server/api/routers/users.test.ts new file mode 100644 index 00000000..b188d3a0 --- /dev/null +++ b/packages/web/server/api/routers/users.test.ts @@ -0,0 +1,57 @@ +import { CustomTestContext, defaultBeforeEach } from "@/lib/testUtils"; +import { expect, describe, test, beforeEach } from "vitest"; + +beforeEach(defaultBeforeEach(false)); + +describe("User Routes", () => { + test("create user", async ({ unauthedAPICaller }) => { + const user = await unauthedAPICaller.users.create({ + name: "Test User", + email: "test123@test.com", + password: "pass1234", + confirmPassword: "pass1234", + }); + + expect(user.name).toEqual("Test User"); + expect(user.email).toEqual("test123@test.com"); + }); + + test("first user is admin", async ({ + unauthedAPICaller, + }) => { + const user1 = await unauthedAPICaller.users.create({ + name: "Test User", + email: "test123@test.com", + password: "pass1234", + confirmPassword: "pass1234", + }); + + const user2 = await unauthedAPICaller.users.create({ + name: "Test User", + email: "test124@test.com", + password: "pass1234", + confirmPassword: "pass1234", + }); + + expect(user1.role).toEqual("admin"); + expect(user2.role).toEqual("user"); + }); + + test("unique emails", async ({ unauthedAPICaller }) => { + await unauthedAPICaller.users.create({ + name: "Test User", + email: "test123@test.com", + password: "pass1234", + confirmPassword: "pass1234", + }); + + await expect(() => + unauthedAPICaller.users.create({ + name: "Test User", + email: "test123@test.com", + password: "pass1234", + confirmPassword: "pass1234", + }), + ).rejects.toThrow(/Email is already taken/); + }); +}); -- cgit v1.2.3-70-g09d2