-
Notifications
You must be signed in to change notification settings - Fork 14
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: Allow modifying user email from settings
- Loading branch information
1 parent
454b6ed
commit fcbae31
Showing
11 changed files
with
277 additions
and
26 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 |
---|---|---|
|
@@ -41,6 +41,4 @@ node_modules | |
.npmrc | ||
|
||
# Local files | ||
*.local | ||
|
||
.env.local | ||
*.local |
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,3 @@ | ||
export const INVALID_PASSWORD = "INVALID_PASSWORD"; | ||
export const INVALID_EMAIL = "INVALID_EMAIL"; | ||
export const DUPLICATE_EMAIL = "DUPLICATE_EMAIL"; |
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 |
---|---|---|
@@ -1,6 +1,7 @@ | ||
import { convexTest } from "convex-test"; | ||
import { describe, expect, it } from "vitest"; | ||
import { api } from "./_generated/api"; | ||
import { DUPLICATE_EMAIL, INVALID_EMAIL } from "./errors"; | ||
import schema from "./schema"; | ||
import { modules } from "./test.setup"; | ||
|
||
|
@@ -149,6 +150,68 @@ describe("users", () => { | |
}); | ||
}); | ||
|
||
describe("setEmail", () => { | ||
it("should update the user's email", async () => { | ||
const t = convexTest(schema, modules); | ||
|
||
const userId = await t.run(async (ctx) => { | ||
return await ctx.db.insert("users", { | ||
email: "[email protected]", | ||
role: "user", | ||
}); | ||
}); | ||
|
||
const asUser = t.withIdentity({ subject: userId }); | ||
await asUser.mutation(api.users.setEmail, { | ||
email: "[email protected]", | ||
}); | ||
|
||
const user = await t.run(async (ctx) => { | ||
return await ctx.db.get(userId); | ||
}); | ||
expect(user?.email).toBe("[email protected]"); | ||
}); | ||
|
||
it("should throw an error for an invalid email", async () => { | ||
const t = convexTest(schema, modules); | ||
|
||
const userId = await t.run(async (ctx) => { | ||
return await ctx.db.insert("users", { | ||
email: "[email protected]", | ||
role: "user", | ||
}); | ||
}); | ||
|
||
const asUser = t.withIdentity({ subject: userId }); | ||
await expect( | ||
asUser.mutation(api.users.setEmail, { email: "invalid-email" }), | ||
).rejects.toThrow(INVALID_EMAIL); | ||
}); | ||
|
||
it("should throw an error for a duplicate email", async () => { | ||
const t = convexTest(schema, modules); | ||
|
||
await t.run(async (ctx) => { | ||
await ctx.db.insert("users", { | ||
email: "[email protected]", | ||
role: "user", | ||
}); | ||
}); | ||
|
||
const userId = await t.run(async (ctx) => { | ||
return await ctx.db.insert("users", { | ||
email: "[email protected]", | ||
role: "user", | ||
}); | ||
}); | ||
|
||
const asUser = t.withIdentity({ subject: userId }); | ||
await expect( | ||
asUser.mutation(api.users.setEmail, { email: "[email protected]" }), | ||
).rejects.toThrow(DUPLICATE_EMAIL); | ||
}); | ||
}); | ||
|
||
describe("setBirthplace", () => { | ||
it("should update user birthplace", async () => { | ||
const t = convexTest(schema, modules); | ||
|
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
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
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
Oops, something went wrong.