diff options
| author | MohamedBassem <me@mbassem.com> | 2024-03-02 09:53:24 +0000 |
|---|---|---|
| committer | MohamedBassem <me@mbassem.com> | 2024-03-02 09:53:24 +0000 |
| commit | b7b5306619cc4420bd0ae494881ee7161391dec4 (patch) | |
| tree | 3e284af6160373b4c6873301ea57ab43e36130dd /packages/web/server/api/routers/users.test.ts | |
| parent | a942e69c9a830142c7ead9cbf7c1aa67fd87bf38 (diff) | |
| download | karakeep-b7b5306619cc4420bd0ae494881ee7161391dec4.tar.zst | |
feature: Make the first user an admin automatically
Diffstat (limited to 'packages/web/server/api/routers/users.test.ts')
| -rw-r--r-- | packages/web/server/api/routers/users.test.ts | 57 |
1 files changed, 57 insertions, 0 deletions
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<CustomTestContext>(defaultBeforeEach(false)); + +describe("User Routes", () => { + test<CustomTestContext>("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<CustomTestContext>("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<CustomTestContext>("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/); + }); +}); |
