-
Notifications
You must be signed in to change notification settings - Fork 12
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: Adjust user role assignment based on environment (#268)
Co-authored-by: Eva Decker <[email protected]>
- Loading branch information
1 parent
1d4ed14
commit 872064c
Showing
3 changed files
with
87 additions
and
31 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,5 @@ | ||
--- | ||
"namesake": patch | ||
--- | ||
|
||
Default the user role to admin during signup when the environment is set to development. |
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,50 @@ | ||
import { convexTest } from "convex-test"; | ||
import { describe, expect, it, vi } from "vitest"; | ||
import { api } from "./_generated/api"; | ||
import { createOrUpdateUser } from "./auth"; | ||
import schema from "./schema"; | ||
import { modules } from "./test.setup"; | ||
|
||
describe("auth", () => { | ||
describe("createOrUpdateUser", () => { | ||
it("should set role to admin in development environment", async () => { | ||
const t = convexTest(schema, modules); | ||
|
||
vi.stubEnv("NODE_ENV", "development"); | ||
await t.run(async (ctx) => { | ||
return await createOrUpdateUser(ctx, { | ||
profile: { | ||
email: "[email protected]", | ||
}, | ||
}); | ||
}); | ||
|
||
const user = await t.query(api.users.getByEmail, { | ||
email: "[email protected]", | ||
}); | ||
|
||
expect(user?.role).toBe("admin"); | ||
vi.unstubAllEnvs(); | ||
}); | ||
|
||
it("should set role to user in production environment", async () => { | ||
const t = convexTest(schema, modules); | ||
|
||
vi.stubEnv("NODE_ENV", "production"); | ||
await t.run(async (ctx) => { | ||
return await createOrUpdateUser(ctx, { | ||
profile: { | ||
email: "[email protected]", | ||
}, | ||
}); | ||
}); | ||
|
||
const user = await t.query(api.users.getByEmail, { | ||
email: "[email protected]", | ||
}); | ||
|
||
expect(user?.role).toBe("user"); | ||
vi.unstubAllEnvs(); | ||
}); | ||
}); | ||
}); |
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