-
-
Notifications
You must be signed in to change notification settings - Fork 433
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feature: Make the first user an admin automatically
- Loading branch information
1 parent
a942e69
commit b7b5306
Showing
4 changed files
with
86 additions
and
11 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
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
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,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/); | ||
}); | ||
}); |
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