import { test, expect } from '../../fixtures'; test.describe('سناریوی سطوح دسترسی و تفکیک نقش‌های کاربران و ادمین (Admin RBAC Roles)', () => { test('لاگین سوپر ادمین -> مدیریت کاربران -> مشاهده تفکیک دقیق نقش‌های کاربری، همکار B2B و مدیر کل', async ({ page }) => { // Intercept and mock Admin Auth & Users API await page.route('**/api/auth/admin-login*', async (route) => { await route.fulfill({ status: 200, contentType: 'application/json', body: JSON.stringify({ success: true, data: { accessToken: 'mock_e2e_superadmin_jwt', user: { id: 'super-admin-1', email: 'admin@canina.ir', role: 'SUPER_ADMIN' }, }, }), }); }); await page.route('**/api/auth/refresh*', async (route) => { await route.fulfill({ status: 200, contentType: 'application/json', body: JSON.stringify({ success: true, data: { accessToken: 'mock_e2e_superadmin_jwt', user: { id: 'super-admin-1', email: 'admin@canina.ir', role: 'SUPER_ADMIN' }, }, }), }); }); await page.route('**/api/users/profile*', async (route) => { await route.fulfill({ status: 200, contentType: 'application/json', body: JSON.stringify({ id: 'super-admin-1', email: 'admin@canina.ir', role: 'SUPER_ADMIN', }), }); }); await page.route('**/api/admin/users*', async (route) => { await route.fulfill({ status: 200, contentType: 'application/json', body: JSON.stringify({ success: true, data: [ { id: 'user-regular', firstName: 'مهرداد', lastName: 'صادقی', mobile: '09121110001', role: 'User_PetOwner', walletBalance: 150000, }, { id: 'user-b2b', firstName: 'دکتر علوی', lastName: 'کلینیک پارس', mobile: '09121110002', role: 'User_Wholesale', walletBalance: 5000000, }, { id: 'user-admin', firstName: 'مدیر ارشد', lastName: 'سیستم', mobile: '09121110003', role: 'ADMIN', walletBalance: 0, }, ], meta: { total: 3, lastPage: 1 }, }), }); }); // 1. لاگین ادمین await page.goto('/login', { waitUntil: 'domcontentloaded' }); const emailInput = page.locator('input[type="email"]'); const passwordInput = page.locator('input[type="password"]'); await expect(emailInput).toBeVisible({ timeout: 10000 }); await emailInput.fill('admin@canina.ir'); await passwordInput.fill('Admin@123456'); const submitBtn = page.getByRole('button', { name: /ورود با رمز عبور|ورود به پنل|ورود/i }).first(); await submitBtn.click(); await page.waitForTimeout(500); // 2. ورود به صفحه مدیریت کاربران await page.goto('/users', { waitUntil: 'domcontentloaded' }); await expect(page).toHaveURL(/\/users/); // 3. راستی‌آزمایی تفکیک قطعی نقش‌های RBAC در ردیف‌های جدول const regularBadge = page.locator('span').filter({ hasText: 'مشتری عادی' }).first(); await expect(regularBadge).toBeVisible({ timeout: 10000 }); const wholesaleBadge = page.locator('span').filter({ hasText: 'خریدار عمده' }).first(); await expect(wholesaleBadge).toBeVisible({ timeout: 10000 }); const adminBadge = page.locator('span').filter({ hasText: 'مدیر سیستم' }).first(); await expect(adminBadge).toBeVisible({ timeout: 10000 }); }); });