Skip to content

Commit ce92b2f

Browse files
committed
fix(tests): correção de testes para ADM
1 parent 23757d0 commit ce92b2f

1 file changed

Lines changed: 32 additions & 0 deletions

File tree

backend/tests/integration/routes/admin.routes.test.ts

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,27 @@
11
import request from "supertest";
22
import { beforeEach, describe, expect, it, vi } from "vitest";
33

4+
const ROLE_LEVEL = {
5+
user: 0,
6+
support: 1,
7+
admin: 2,
8+
super_admin: 3,
9+
} as const;
10+
11+
const PERMISSION_MIN_ROLE = {
12+
"dashboard.read": "support",
13+
"scrapers.read": "support",
14+
"observability.health": "support",
15+
"users.read": "admin",
16+
"users.block": "admin",
17+
"users.reset_password": "admin",
18+
"scrapers.trigger": "admin",
19+
"observability.metrics": "admin",
20+
"audit.read": "admin",
21+
"users.change_role": "super_admin",
22+
"users.delete": "super_admin",
23+
} as const;
24+
425
const mocks = vi.hoisted(() => ({
526
dashboard: vi.fn((_req, res) => res.json({ ok: true, scope: "dashboard" })),
627
usersList: vi.fn((_req, res) => res.json({ data: [], total: 0 })),
@@ -63,6 +84,17 @@ vi.mock("iron-session", () => ({
6384
getIronSession: vi.fn(),
6485
}));
6586

87+
vi.mock("../../../src/modules/admin/permissions/permissions.service", () => ({
88+
permissionsService: {
89+
can: vi.fn(async (role: keyof typeof ROLE_LEVEL, resource: string, action: string) => {
90+
const key = `${resource}.${action}` as keyof typeof PERMISSION_MIN_ROLE;
91+
const minRole = PERMISSION_MIN_ROLE[key];
92+
if (!minRole) return false;
93+
return ROLE_LEVEL[role] >= ROLE_LEVEL[minRole];
94+
}),
95+
},
96+
}));
97+
6698
import { getIronSession } from "iron-session";
6799
import { createJobsApiApp } from "../../../src/app";
68100

0 commit comments

Comments
 (0)