Add updateRole endpoint (#6771)

This commit is contained in:
Tom Moor
2024-04-06 07:32:15 -06:00
committed by GitHub
parent 52643c511c
commit 3f209101e6
14 changed files with 314 additions and 207 deletions

View File

@@ -555,6 +555,55 @@ describe("#users.update", () => {
});
});
describe("#users.updateRole", () => {
it("should promote", async () => {
const team = await buildTeam();
const admin = await buildAdmin({ teamId: team.id });
const user = await buildUser({ teamId: team.id });
const res = await server.post("/api/users.updateRole", {
body: {
token: admin.getJwtToken(),
id: user.id,
role: UserRole.Admin,
},
});
expect(res.status).toEqual(200);
expect((await user.reload()).role).toEqual(UserRole.Admin);
});
it("should demote", async () => {
const team = await buildTeam();
const admin = await buildAdmin({ teamId: team.id });
const user = await buildAdmin({ teamId: team.id });
const res = await server.post("/api/users.updateRole", {
body: {
token: admin.getJwtToken(),
id: user.id,
role: UserRole.Viewer,
},
});
expect(res.status).toEqual(200);
expect((await user.reload()).role).toEqual(UserRole.Viewer);
});
it("should error on same role", async () => {
const team = await buildTeam();
const admin = await buildAdmin({ teamId: team.id });
const user = await buildAdmin({ teamId: team.id });
const res = await server.post("/api/users.updateRole", {
body: {
token: admin.getJwtToken(),
id: user.id,
role: UserRole.Admin,
},
});
expect(res.status).toEqual(400);
});
});
describe("#users.promote", () => {
it("should promote a new admin", async () => {
const team = await buildTeam();
@@ -631,6 +680,7 @@ describe("#users.demote", () => {
it("should not allow demoting self", async () => {
const admin = await buildAdmin();
await buildAdmin({ teamId: admin.teamId });
const res = await server.post("/api/users.demote", {
body: {
token: admin.getJwtToken(),