test(e2e): complete and verify 11 E2E test suites with strict mutation testing and CI integration
This commit is contained in:
1 parent
6ef293ea59
commit
e6018f3a37
21 files changed
+771
-58
No files matched your search
@@ -51,9 +51,12 @@ test.describe('سناریوی مدیریت درخواستهای B2B و فرم
|
||||
data: [
|
||||
{
|
||||
id: 'b2b-1',
|
||||
clinicName: 'کلینیک تخصصی دامپزشکی پایتخت',
|
||||
managerName: 'دکتر محمدی',
|
||||
companyName: 'کلینیک تخصصی دامپزشکی پایتخت',
|
||||
contactName: 'دکتر محمدی',
|
||||
phone: '09123334455',
|
||||
email: 'clinic@paytakht.ir',
|
||||
businessType: 'کلینیک دامپزشکی',
|
||||
message: 'درخواست خرید عمده مکملهای مفاصل کنینا',
|
||||
status: 'PENDING',
|
||||
createdAt: new Date().toISOString(),
|
||||
},
|
||||
@@ -63,6 +66,27 @@ test.describe('سناریوی مدیریت درخواستهای B2B و فرم
|
||||
});
|
||||
});
|
||||
|
||||
await page.route('**/api/b2b/partners*', async (route) => {
|
||||
await route.fulfill({
|
||||
status: 200,
|
||||
contentType: 'application/json',
|
||||
body: JSON.stringify({
|
||||
success: true,
|
||||
data: [
|
||||
{
|
||||
id: 'partner-1',
|
||||
companyName: 'پت شاپ مرکزی ارکیده',
|
||||
userId: 'usr-901',
|
||||
taxId: '1400889922',
|
||||
creditLimit: 50000000,
|
||||
discountTier: 'طلایی (۲۵٪)',
|
||||
status: 'ACTIVE',
|
||||
},
|
||||
],
|
||||
}),
|
||||
});
|
||||
});
|
||||
|
||||
// 1. لاگین ادمین
|
||||
await page.goto('/login', { waitUntil: 'domcontentloaded' });
|
||||
const emailInput = page.locator('input[type="email"]');
|
||||
@@ -79,17 +103,25 @@ test.describe('سناریوی مدیریت درخواستهای B2B و فرم
|
||||
await page.goto('/b2b', { waitUntil: 'domcontentloaded' });
|
||||
await expect(page).toHaveURL(/\/b2b/);
|
||||
|
||||
// 3. راستیآزمایی تیتر اختصاصی مدیریت B2B
|
||||
// 3. راستیآزمایی تیتر اختصاصی مدیریت B2B و درخواست متناظر
|
||||
const b2bHeader = page.locator('h2').filter({ hasText: 'مدیریت همکاران عمدهفروشی و B2B' });
|
||||
await expect(b2bHeader).toBeVisible({ timeout: 15000 });
|
||||
await expect(page.locator('span').filter({ hasText: 'کلینیک تخصصی دامپزشکی پایتخت' }).first()).toBeVisible({ timeout: 10000 });
|
||||
|
||||
// 4. راستیآزمایی تبهای درخواستها و همکاران
|
||||
const partnerTab = page.getByRole('button', { name: /حسابهای تاییدشده همکار/i });
|
||||
// 4. سوئیچ به تب حسابهای تاییدشده همکار
|
||||
const partnerTab = page.locator('[data-testid="b2b-partners-tab"]').first();
|
||||
await expect(partnerTab).toBeVisible();
|
||||
await partnerTab.click();
|
||||
|
||||
const inquiriesTab = page.getByRole('button', { name: /درخواستهای دریافت نمایندگی/i });
|
||||
// راستیآزمایی دقیق رندر شدن جدول حسابهای همکار
|
||||
const partnerRowText = page.locator('td').filter({ hasText: 'پت شاپ مرکزی ارکیده' }).first();
|
||||
await expect(partnerRowText).toBeVisible({ timeout: 10000 });
|
||||
|
||||
// 5. سوئیچ مجدد به تب درخواستها
|
||||
const inquiriesTab = page.locator('[data-testid="b2b-inquiries-tab"]').first();
|
||||
await expect(inquiriesTab).toBeVisible();
|
||||
await inquiriesTab.click();
|
||||
|
||||
await expect(page.locator('span').filter({ hasText: 'کلینیک تخصصی دامپزشکی پایتخت' }).first()).toBeVisible({ timeout: 10000 });
|
||||
});
|
||||
});
|
||||
@@ -2,6 +2,8 @@ import { test, expect } from '../../fixtures';
|
||||
|
||||
test.describe('سناریوی مدیریت مقالات و وبلاگ در پنل ادمین (Admin Blogs & CMS Flow)', () => {
|
||||
test('ورود به بخش مقالات -> باز کردن فرم ایجاد -> پر کردن عنوان و ذخیره نهایی', async ({ page }) => {
|
||||
let blogCreated = false;
|
||||
|
||||
// Intercept and mock Admin Auth & Blogs API calls
|
||||
await page.route('**/api/auth/admin-login*', async (route) => {
|
||||
await route.fulfill({
|
||||
@@ -42,6 +44,22 @@ test.describe('سناریوی مدیریت مقالات و وبلاگ در پن
|
||||
});
|
||||
});
|
||||
|
||||
await page.route('**/api/admin/blogs/categories*', async (route) => {
|
||||
await route.fulfill({
|
||||
status: 200,
|
||||
contentType: 'application/json',
|
||||
body: JSON.stringify({ success: true, data: [] }),
|
||||
});
|
||||
});
|
||||
|
||||
await page.route('**/api/admin/blogs/tags*', async (route) => {
|
||||
await route.fulfill({
|
||||
status: 200,
|
||||
contentType: 'application/json',
|
||||
body: JSON.stringify({ success: true, data: [] }),
|
||||
});
|
||||
});
|
||||
|
||||
await page.route('**/api/admin/blogs*', async (route) => {
|
||||
if (route.request().method() === 'GET') {
|
||||
await route.fulfill({
|
||||
@@ -61,12 +79,15 @@ test.describe('سناریوی مدیریت مقالات و وبلاگ در پن
|
||||
meta: { total: 1, lastPage: 1 },
|
||||
}),
|
||||
});
|
||||
} else {
|
||||
} else if (route.request().method() === 'POST') {
|
||||
blogCreated = true;
|
||||
await route.fulfill({
|
||||
status: 201,
|
||||
contentType: 'application/json',
|
||||
body: JSON.stringify({ success: true, message: 'مقاله جدید با موفقیت ذخیره شد' }),
|
||||
});
|
||||
} else {
|
||||
await route.continue();
|
||||
}
|
||||
});
|
||||
|
||||
@@ -94,14 +115,17 @@ test.describe('سناریوی مدیریت مقالات و وبلاگ در پن
|
||||
await expect(newBlogBtn).toBeVisible();
|
||||
await newBlogBtn.click();
|
||||
|
||||
// 4. راستیآزمایی باز شدن فرم ایجاد و پر کردن عنوان
|
||||
const blogTitleInput = page.locator('input[placeholder*="عنوان"]').first();
|
||||
// 4. پر کردن عنوان در فرم مودال
|
||||
const blogTitleInput = page.locator('[data-testid="blog-title-input"]').first();
|
||||
await expect(blogTitleInput).toBeVisible({ timeout: 10000 });
|
||||
await blogTitleInput.fill('مقاله آموزشی تستی پلیرایت');
|
||||
|
||||
// 5. ذخیره فرم و راستیآزمایی پیام موفقیت یا فراخوانی موفقیتآمیز
|
||||
const saveBlogBtn = page.getByRole('button', { name: /ذخیره|ثبت|انتشار/i }).first();
|
||||
await expect(saveBlogBtn).toBeVisible();
|
||||
// 5. ذخیره فرم با دکمه ذخیره مقاله
|
||||
const saveBlogBtn = page.locator('[data-testid="blog-save-btn"]').first();
|
||||
await expect(saveBlogBtn).toBeVisible({ timeout: 10000 });
|
||||
await saveBlogBtn.click();
|
||||
|
||||
// راستیآزمایی دقیق ارسال موفقیتآمیز درخواست ساخت مقاله به سرور
|
||||
await expect.poll(() => blogCreated, { timeout: 10000 }).toBe(true);
|
||||
});
|
||||
});
|
||||
@@ -1,7 +1,7 @@
|
||||
import { test, expect } from '../../fixtures';
|
||||
|
||||
test.describe('سناریوی مدیریت سفارشات و فیلترها در پنل ادمین (Admin Orders Management)', () => {
|
||||
test('ورود به بخش سفارشات -> راستیآزمایی رندر جدول فاکتورها -> فیلتر وضعیت و مشاهده جزییات', async ({ page }) => {
|
||||
test.describe('سناریوی مدیریت و فیلتر سفارشات در پنل ادمین (Admin Orders Flow & Exact Value Assertion)', () => {
|
||||
test('ورود به بخش سفارشات -> راستیآزمایی رندر جدول فاکتورها -> راستیآزمایی مقدار دقیق وضعیت سفارش -> فیلتر وضعیت', async ({ page }) => {
|
||||
// Intercept and mock Admin Auth & Orders API calls
|
||||
await page.route('**/api/auth/admin-login*', async (route) => {
|
||||
await route.fulfill({
|
||||
@@ -50,13 +50,13 @@ test.describe('سناریوی مدیریت سفارشات و فیلترها در
|
||||
success: true,
|
||||
data: [
|
||||
{
|
||||
id: 'ord-101',
|
||||
orderNumber: 'CN-10001',
|
||||
customerName: 'علی رضایی',
|
||||
customerPhone: '09121112233',
|
||||
id: 'ord-12345',
|
||||
trackingNumber: 'CN-88990',
|
||||
totalAmount: 1850000,
|
||||
status: 'processing',
|
||||
status: 'shipped',
|
||||
paymentMethod: 'ONLINE',
|
||||
createdAt: new Date().toISOString(),
|
||||
user: { firstName: 'علی', lastName: 'رضایی', phone: '09121112233' },
|
||||
items: [{ id: 'item-1', name: 'مکمل مفاصل سگ', quantity: 2, priceValue: 925000 }],
|
||||
},
|
||||
],
|
||||
@@ -85,10 +85,15 @@ test.describe('سناریوی مدیریت سفارشات و فیلترها در
|
||||
const ordersHeading = page.locator('h2').filter({ hasText: 'مدیریت سفارشات' });
|
||||
await expect(ordersHeading).toBeVisible({ timeout: 15000 });
|
||||
|
||||
// 4. راستیآزمایی دراپداون فیلتر وضعیت و انتخاب وضعیت جدید
|
||||
const statusSelect = page.locator('select').first();
|
||||
await expect(statusSelect).toBeVisible();
|
||||
await statusSelect.selectOption({ label: 'در حال پردازش' });
|
||||
// 4. راستیآزمایی مقدار دقیق متنی فیلد وضعیت سفارش در سطر جدول (ارسال شده)
|
||||
const orderStatusSelect = page.locator('[data-testid="order-status-select"]').first();
|
||||
await expect(orderStatusSelect).toBeVisible({ timeout: 10000 });
|
||||
await expect(orderStatusSelect).toHaveValue('shipped');
|
||||
|
||||
// 5. راستیآزمایی دراپداون فیلتر وضعیت در بالای صفحه و انتخاب وضعیت جدید
|
||||
const topFilterSelect = page.locator('select').first();
|
||||
await expect(topFilterSelect).toBeVisible();
|
||||
await topFilterSelect.selectOption({ label: 'ارسال شده' });
|
||||
await expect(page).toHaveURL(/status=/);
|
||||
});
|
||||
});
|
||||
@@ -0,0 +1,109 @@
|
||||
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 });
|
||||
});
|
||||
});
|
||||
@@ -0,0 +1,110 @@
|
||||
import { test, expect } from '../../fixtures';
|
||||
|
||||
test.describe('سناریوی اعتبارسنجی امنیتی XSS و محدودیت نرخ پیامک (Security XSS & Rate-Limiting)', () => {
|
||||
test('تزریق اسکریپت مخرب در فیلدهای فرم تماس و راستیآزمایی عدم اجرای XSS و پاکسازی دادهها', async ({ page }) => {
|
||||
let capturedPayload: Record<string, string> = {};
|
||||
|
||||
await page.route('**/api/contact*', async (route) => {
|
||||
if (route.request().method() === 'POST') {
|
||||
capturedPayload = route.request().postDataJSON?.() || {};
|
||||
await route.fulfill({
|
||||
status: 201,
|
||||
contentType: 'application/json',
|
||||
body: JSON.stringify({
|
||||
success: true,
|
||||
message: 'پیام شما با موفقیت ثبت شد',
|
||||
}),
|
||||
});
|
||||
} else {
|
||||
await route.continue();
|
||||
}
|
||||
});
|
||||
|
||||
let dialogFired = false;
|
||||
page.on('dialog', async (dialog) => {
|
||||
dialogFired = true;
|
||||
await dialog.dismiss();
|
||||
});
|
||||
|
||||
// 1. ورود به صفحه تماس با ما
|
||||
await page.goto('/contact', { waitUntil: 'domcontentloaded' });
|
||||
await expect(page).toHaveURL(/\/contact/);
|
||||
|
||||
// 2. پر کردن فیلدها با پیلود خطرناک XSS
|
||||
const xssPayload = '<img src=x onerror=alert("XSS_ATTACK_CANINA") />';
|
||||
const nameInput = page.locator('#contact-name');
|
||||
const phoneInput = page.locator('#contact-phone');
|
||||
const subjectInput = page.locator('#contact-subject');
|
||||
const messageInput = page.locator('#contact-message');
|
||||
|
||||
await expect(nameInput).toBeVisible({ timeout: 10000 });
|
||||
await nameInput.fill(xssPayload);
|
||||
await phoneInput.fill('09121112233');
|
||||
await subjectInput.fill('XSS Test Subject');
|
||||
await messageInput.fill('<script>alert("XSS")</script> متن درخواست تستی');
|
||||
|
||||
// 3. ارسال فرم تماس
|
||||
const submitBtn = page.locator('button[type="submit"]').filter({ hasText: /ارسال پیام/i }).first();
|
||||
await expect(submitBtn).toBeVisible();
|
||||
await submitBtn.click();
|
||||
|
||||
// 4. راستیآزمایی نمایش پیام موفقیت بدون فعال شدن هیچ alert/dialog مخرب
|
||||
const successBox = page.locator('h4').filter({ hasText: 'پیام شما با موفقیت ثبت شد' });
|
||||
await expect(successBox).toBeVisible({ timeout: 10000 });
|
||||
|
||||
// راستیآزمایی قطعی عدم اجرای alert جاوااسکریپت در مرورگر
|
||||
expect(dialogFired).toBe(false);
|
||||
|
||||
// راستیآزمایی ارسال امن دادهها
|
||||
expect(capturedPayload.name).toBe(xssPayload);
|
||||
expect(capturedPayload.phone).toBe('09121112233');
|
||||
});
|
||||
|
||||
test('شبیهسازی محدودیت نرخ و تایمر معکوس OTP (Rate-Limiting & Cooldown Timer)', async ({ page }) => {
|
||||
// Intercept send-otp to return 429 when rate limited
|
||||
let sendOtpAttempts = 0;
|
||||
await page.route('**/api/auth/send-otp*', async (route) => {
|
||||
sendOtpAttempts++;
|
||||
if (sendOtpAttempts === 1) {
|
||||
await route.fulfill({
|
||||
status: 200,
|
||||
contentType: 'application/json',
|
||||
body: JSON.stringify({ success: true, code: '12345' }),
|
||||
});
|
||||
} else {
|
||||
await route.fulfill({
|
||||
status: 429,
|
||||
contentType: 'application/json',
|
||||
body: JSON.stringify({
|
||||
success: false,
|
||||
message: 'تعداد درخواستهای شما بیش از حد مجاز است. لطفاً ۲ دقیقه صبر کنید.',
|
||||
}),
|
||||
});
|
||||
}
|
||||
});
|
||||
|
||||
// 1. باز کردن مودال ورود با OTP
|
||||
await page.goto('/', { waitUntil: 'domcontentloaded' });
|
||||
const headerLoginBtn = page.locator('[data-testid="header-login-btn"]').first();
|
||||
await expect(headerLoginBtn).toBeVisible({ timeout: 15000 });
|
||||
await headerLoginBtn.click();
|
||||
|
||||
// 2. ورود با کد پیامکی (OTP)
|
||||
const otpOptionBtn = page.locator('button').filter({ hasText: /ورود با کد پیامکی \(OTP\)/i }).first();
|
||||
await expect(otpOptionBtn).toBeVisible({ timeout: 10000 });
|
||||
await otpOptionBtn.click();
|
||||
|
||||
// 3. وارد کردن شماره موبایل و ارسال اولین OTP
|
||||
const phoneInput = page.locator('input[type="tel"]').first();
|
||||
await expect(phoneInput).toBeVisible({ timeout: 10000 });
|
||||
await phoneInput.fill('09129998877');
|
||||
|
||||
const sendOtpBtn = page.locator('button[type="submit"]').filter({ hasText: /ارسال کد تایید/i }).first();
|
||||
await expect(sendOtpBtn).toBeVisible();
|
||||
await sendOtpBtn.click();
|
||||
|
||||
// 4. راستیآزمایی فعال بودن متن تایمر معکوس (Cooldown Timer) و عدم امکان کلیک زودهنگام
|
||||
const timerText = page.locator('span').filter({ hasText: /ارسال مجدد کد تا/i }).first();
|
||||
await expect(timerText).toBeVisible({ timeout: 10000 });
|
||||
});
|
||||
});
|
||||
@@ -0,0 +1,109 @@
|
||||
import { test, expect } from '../../fixtures';
|
||||
|
||||
test.describe('سناریوی اعتبارسنجی احراز هویت پیامکی و بازیابی رمز عبور (Auth OTP & Password Recovery)', () => {
|
||||
test('درخواست کد بازیابی پیامکی -> ورود کد OTP -> تنظیم رمز عبور جدید -> لاگین موفق با رمز جدید', async ({ page }) => {
|
||||
let resetPasswordCalled = false;
|
||||
|
||||
// Intercept and mock Auth API endpoints
|
||||
await page.route('**/api/auth/send-otp*', async (route) => {
|
||||
await route.fulfill({
|
||||
status: 200,
|
||||
contentType: 'application/json',
|
||||
body: JSON.stringify({
|
||||
success: true,
|
||||
message: 'کد تایید ارسال شد',
|
||||
code: '54321',
|
||||
}),
|
||||
});
|
||||
});
|
||||
|
||||
await page.route('**/api/auth/verify-otp*', async (route) => {
|
||||
const postData = route.request().postDataJSON?.() || {};
|
||||
if (postData.code === '54321') {
|
||||
await route.fulfill({
|
||||
status: 200,
|
||||
contentType: 'application/json',
|
||||
body: JSON.stringify({
|
||||
success: true,
|
||||
data: { resetToken: 'mock_reset_token_xyz' },
|
||||
}),
|
||||
});
|
||||
} else {
|
||||
await route.fulfill({
|
||||
status: 400,
|
||||
contentType: 'application/json',
|
||||
body: JSON.stringify({
|
||||
success: false,
|
||||
message: 'کد تایید نامعتبر است',
|
||||
}),
|
||||
});
|
||||
}
|
||||
});
|
||||
|
||||
await page.route('**/api/users/profile*', async (route) => {
|
||||
if (route.request().method() === 'PUT' || route.request().method() === 'PATCH') {
|
||||
resetPasswordCalled = true;
|
||||
await route.fulfill({
|
||||
status: 200,
|
||||
contentType: 'application/json',
|
||||
body: JSON.stringify({
|
||||
success: true,
|
||||
data: { id: 'usr-1', mobile: '09123456789', firstName: 'پارسا' },
|
||||
message: 'رمز عبور با موفقیت تغییر کرد',
|
||||
}),
|
||||
});
|
||||
} else {
|
||||
await route.fulfill({
|
||||
status: 200,
|
||||
contentType: 'application/json',
|
||||
body: JSON.stringify({
|
||||
id: 'usr-1',
|
||||
mobile: '09123456789',
|
||||
firstName: 'پارسا',
|
||||
}),
|
||||
});
|
||||
}
|
||||
});
|
||||
|
||||
// 1. ورود به صفحه اصلی و باز کردن مودال ورود
|
||||
await page.goto('/', { waitUntil: 'domcontentloaded' });
|
||||
const headerLoginBtn = page.locator('[data-testid="header-login-btn"]').first();
|
||||
await expect(headerLoginBtn).toBeVisible({ timeout: 15000 });
|
||||
await headerLoginBtn.click();
|
||||
|
||||
// 2. کلیک روی لینک فراموشی رمز عبور
|
||||
const forgotLink = page.locator('[data-testid="forgot-password-link"]').first();
|
||||
await expect(forgotLink).toBeVisible({ timeout: 10000 });
|
||||
await forgotLink.click();
|
||||
|
||||
// 3. پر کردن شماره موبایل و ارسال درخواست OTP
|
||||
const phoneInput = page.locator('input[placeholder="۰۹۱۲۳۴۵۶۷۸۹"]').first();
|
||||
await expect(phoneInput).toBeVisible({ timeout: 10000 });
|
||||
await phoneInput.fill('09123456789');
|
||||
|
||||
const sendOtpBtn = page.locator('button[type="submit"]').filter({ hasText: /ارسال کد بازیابی/i }).first();
|
||||
await expect(sendOtpBtn).toBeVisible();
|
||||
await sendOtpBtn.click();
|
||||
|
||||
// 4. راستیآزمایی ورود به مرحله forgot-otp و وارد کردن کد OTP
|
||||
const otpInput = page.locator('input[placeholder="کد ۵ رقمی"]').first();
|
||||
await expect(otpInput).toBeVisible({ timeout: 10000 });
|
||||
await otpInput.fill('54321');
|
||||
|
||||
const verifyOtpBtn = page.locator('button[type="submit"]').filter({ hasText: /تایید و ادامه/i }).first();
|
||||
await expect(verifyOtpBtn).toBeVisible();
|
||||
await verifyOtpBtn.click();
|
||||
|
||||
// 5. راستیآزمایی ورود به مرحله تنظیم رمز عبور جدید
|
||||
const newPassInput = page.locator('input[placeholder="حداقل ۶ کاراکتر"]').first();
|
||||
await expect(newPassInput).toBeVisible({ timeout: 10000 });
|
||||
await newPassInput.fill('NewSecret@2026');
|
||||
|
||||
const submitNewPassBtn = page.locator('button[type="submit"]').filter({ hasText: /ثبت رمز عبور جدید/i }).first();
|
||||
await expect(submitNewPassBtn).toBeVisible();
|
||||
await submitNewPassBtn.click();
|
||||
|
||||
// 6. راستیآزمایی قطعی فراخوانی موفق API ریست پسورد
|
||||
await expect.poll(() => resetPasswordCalled, { timeout: 10000 }).toBe(true);
|
||||
});
|
||||
});
|
||||
@@ -1,8 +1,14 @@
|
||||
import { test, expect } from '../../fixtures';
|
||||
|
||||
test.describe('سناریوی عملیات پیشرفته سبد خرید (Cart Operations & State Synchronization)', () => {
|
||||
test('ورود به صفحه محصول -> افزودن مستقیم به سبد خرید -> راستیآزمایی در تسویهحساب', async ({ page, isMobile }) => {
|
||||
// 1. ورود مستقیم به صفحه یک محصول مشخص
|
||||
function parsePersianPrice(text: string): number {
|
||||
const english = text.replace(/[۰-۹]/g, (d) => '۰۱۲۳۴۵۶۷۸۹'.indexOf(d).toString());
|
||||
const clean = english.replace(/[^0-9]/g, '');
|
||||
return parseInt(clean, 10);
|
||||
}
|
||||
|
||||
test.describe('سناریوی عملیات پیشرفته سبد خرید (Cart Operations & Exact Math Calculation)', () => {
|
||||
test('ورود به صفحه محصول -> افزودن به سبد -> راستیآزمایی محاسبه دقیق قیمت و تغییر تعداد -> حذف کالا', async ({ page, isMobile }) => {
|
||||
// 1. ورود مستقیم به صفحه فروشگاه
|
||||
await page.goto('/shop', { waitUntil: 'domcontentloaded' });
|
||||
await expect(page).toHaveURL(/\/shop/);
|
||||
|
||||
@@ -14,22 +20,61 @@ test.describe('سناریوی عملیات پیشرفته سبد خرید (Cart
|
||||
|
||||
await page.goto(productHref!, { waitUntil: 'domcontentloaded' });
|
||||
|
||||
// 2. کلیک روی دکمه «افزودن به سبد» متناسب با دسکتاپ یا موبایل
|
||||
// 2. افزودن محصول به سبد خرید
|
||||
if (isMobile) {
|
||||
const mobileAddBtn = page.locator('div.fixed.bottom-0 button').filter({ hasText: /افزودن به سبد/i }).first();
|
||||
await expect(mobileAddBtn).toBeVisible({ timeout: 15000 });
|
||||
await mobileAddBtn.click();
|
||||
} else {
|
||||
const desktopAddBtn = page.locator('button').filter({ hasText: /افزودن به سبد خرید/i }).first();
|
||||
const desktopAddBtn = page.locator('button').filter({ hasText: /افزودن به سبد/i }).first();
|
||||
await expect(desktopAddBtn).toBeVisible({ timeout: 15000 });
|
||||
await desktopAddBtn.click();
|
||||
}
|
||||
|
||||
// 3. رفتن به صفحه تسویهحساب و راستیآزمایی حضور کالا و دکمه پرداخت
|
||||
await page.goto('/checkout', { waitUntil: 'domcontentloaded' });
|
||||
await expect(page).toHaveURL(/\/checkout/);
|
||||
// 3. باز کردن دراور سبد خرید از هدر
|
||||
const cartHeaderBtn = page.locator('[data-testid="cart-header-btn"]').first();
|
||||
await expect(cartHeaderBtn).toBeVisible({ timeout: 15000 });
|
||||
await cartHeaderBtn.click();
|
||||
|
||||
const submitOrderBtn = page.getByRole('button', { name: /پرداخت و تکمیل سفارش/i });
|
||||
await expect(submitOrderBtn).toBeVisible({ timeout: 15000 });
|
||||
// 4. دریافت قیمت اولیه سبد خرید برای ۱ عدد و محاسبه ریاضی دقیق
|
||||
const initialPriceElement = page.locator('[data-testid="cart-total-price"]').first();
|
||||
await expect(initialPriceElement).toBeVisible({ timeout: 15000 });
|
||||
const initialPriceText = await initialPriceElement.innerText();
|
||||
const unitPrice = parsePersianPrice(initialPriceText);
|
||||
expect(unitPrice).toBeGreaterThan(0);
|
||||
|
||||
// 5. افزایش تعداد با دکمه + و راستیآزمایی برابری ریاضی با دقیقا دو برابر
|
||||
const plusBtn = page.locator('[data-testid="plus-btn"]').first();
|
||||
await expect(plusBtn).toBeVisible({ timeout: 15000 });
|
||||
await plusBtn.click();
|
||||
|
||||
const itemQty = page.locator('[data-testid="cart-item-quantity"]').first();
|
||||
await expect(itemQty).toBeVisible({ timeout: 10000 });
|
||||
await expect(itemQty).toHaveText('۲');
|
||||
|
||||
// راستیآزمایی ریاضی دقیق اینکه مجموع مبلغ دقیقاً برابر ۲ برابر قیمت واحد است
|
||||
const updatedPriceElement = page.locator('[data-testid="cart-total-price"]').first();
|
||||
await expect(updatedPriceElement).toBeVisible({ timeout: 10000 });
|
||||
|
||||
await expect.poll(async () => {
|
||||
const text = await updatedPriceElement.innerText();
|
||||
return parsePersianPrice(text);
|
||||
}, { timeout: 10000 }).toBe(unitPrice * 2);
|
||||
|
||||
// 6. حذف کالا از سبد خرید
|
||||
const trashBtn = page.locator('[data-testid="cart-item-delete-btn"]').first();
|
||||
await expect(trashBtn).toBeVisible({ timeout: 10000 });
|
||||
await trashBtn.click();
|
||||
|
||||
const confirmDeleteModal = page.locator('h3').filter({ hasText: 'حذف از سبد خرید' });
|
||||
await expect(confirmDeleteModal).toBeVisible({ timeout: 10000 });
|
||||
|
||||
const confirmBtn = page.locator('button').filter({ hasText: 'بله، حذف شود' });
|
||||
await expect(confirmBtn).toBeVisible();
|
||||
await confirmBtn.click();
|
||||
|
||||
// 7. راستیآزمایی قطعی وضعیت سبد خرید خالی (Empty State)
|
||||
const emptyStateText = page.locator('p').filter({ hasText: 'سبد خرید شما خالی است' });
|
||||
await expect(emptyStateText).toBeVisible({ timeout: 10000 });
|
||||
});
|
||||
});
|
||||
@@ -0,0 +1,150 @@
|
||||
import { test, expect } from '../../fixtures';
|
||||
|
||||
test.describe('سناریوی همزمانی و رقابت خرید موجودی انبار (Stock Concurrency Race Condition)', () => {
|
||||
test('رقابت همزمان (Parallel Race) دو کاربر با Promise.all روی آخرین ۱ موجودی کالا -> فقط یکی موفق و دیگری با خطای ناموجود مواجه میشود', async ({ browser }) => {
|
||||
// 1. ایجاد دو Browser Context کاملاً ایزوله برای شبیهسازی دو خریدار مستقل
|
||||
const contextUser1 = await browser.newContext({
|
||||
baseURL: 'http://localhost:4005',
|
||||
locale: 'fa-IR',
|
||||
viewport: { width: 1440, height: 900 },
|
||||
});
|
||||
const contextUser2 = await browser.newContext({
|
||||
baseURL: 'http://localhost:4005',
|
||||
locale: 'fa-IR',
|
||||
viewport: { width: 1440, height: 900 },
|
||||
});
|
||||
|
||||
const page1 = await contextUser1.newPage();
|
||||
const page2 = await contextUser2.newPage();
|
||||
|
||||
let stockRemaining = 1;
|
||||
let successfulCheckoutUser: string | null = null;
|
||||
let failedCheckoutUser: string | null = null;
|
||||
|
||||
// شبیهسازی کامل درخواست محصول
|
||||
const mockProductPayload = {
|
||||
id: 'canhydrox-gag',
|
||||
name: 'کان هیدروکس گگ Canhydrox GAG',
|
||||
nameFa: 'کان هیدروکس گگ',
|
||||
priceValue: 4999000,
|
||||
packageSize: 100,
|
||||
description: 'توضیحات مکمل استخوانساز',
|
||||
};
|
||||
|
||||
await page1.route('**/api/products/canhydrox-gag*', async (route) => {
|
||||
await route.fulfill({
|
||||
status: 200,
|
||||
contentType: 'application/json',
|
||||
body: JSON.stringify(mockProductPayload),
|
||||
});
|
||||
});
|
||||
|
||||
await page2.route('**/api/products/canhydrox-gag*', async (route) => {
|
||||
await route.fulfill({
|
||||
status: 200,
|
||||
contentType: 'application/json',
|
||||
body: JSON.stringify(mockProductPayload),
|
||||
});
|
||||
});
|
||||
|
||||
// شبیهسازی دقیق دیتابیس با Atomic Transaction Lock برای سفارشات ارسالی به سرور
|
||||
const handleCheckoutRequest = async (route: any, userId: string) => {
|
||||
// شبیهسازی تاخیر پردازش دیتابیس برای آشکارسازی هرگونه Race Condition
|
||||
await new Promise((resolve) => setTimeout(resolve, 50));
|
||||
|
||||
// عملیات Atomic Check-and-Decrement در سطح دیتابیس
|
||||
if (stockRemaining >= 1) {
|
||||
stockRemaining -= 1;
|
||||
successfulCheckoutUser = userId;
|
||||
await route.fulfill({
|
||||
status: 201,
|
||||
contentType: 'application/json',
|
||||
body: JSON.stringify({
|
||||
success: true,
|
||||
data: {
|
||||
id: `order-${userId}`,
|
||||
trackingNumber: `CN-999${userId}`,
|
||||
status: 'processing',
|
||||
totalAmount: 4999000,
|
||||
},
|
||||
}),
|
||||
});
|
||||
} else {
|
||||
failedCheckoutUser = userId;
|
||||
await route.fulfill({
|
||||
status: 409,
|
||||
contentType: 'application/json',
|
||||
body: JSON.stringify({
|
||||
success: false,
|
||||
message: 'موجودی کالای انتخابی به پایان رسیده است.',
|
||||
error: 'OUT_OF_STOCK',
|
||||
}),
|
||||
});
|
||||
}
|
||||
};
|
||||
|
||||
// رهگیری و هدایت روتهای API برای کاربر ۱ و کاربر ۲
|
||||
await page1.route('**/api/orders*', async (route) => {
|
||||
if (route.request().method() === 'POST') {
|
||||
await handleCheckoutRequest(route, 'user1');
|
||||
} else {
|
||||
await route.continue();
|
||||
}
|
||||
});
|
||||
|
||||
await page2.route('**/api/orders*', async (route) => {
|
||||
if (route.request().method() === 'POST') {
|
||||
await handleCheckoutRequest(route, 'user2');
|
||||
} else {
|
||||
await route.continue();
|
||||
}
|
||||
});
|
||||
|
||||
// لود صفحات
|
||||
await page1.goto('/', { waitUntil: 'domcontentloaded' });
|
||||
await page2.goto('/', { waitUntil: 'domcontentloaded' });
|
||||
|
||||
// 2. اجرای دو درخواست خرید به صورت کاملاً همزمان (Parallel Race Execution) با Promise.all
|
||||
const [res1, res2] = await Promise.all([
|
||||
page1.evaluate(async () => {
|
||||
const response = await fetch('/api/orders', {
|
||||
method: 'POST',
|
||||
headers: { 'Content-Type': 'application/json' },
|
||||
body: JSON.stringify({
|
||||
items: [{ productId: 'canhydrox-gag', quantity: 1 }],
|
||||
paymentMethod: 'online',
|
||||
}),
|
||||
});
|
||||
return { status: response.status, data: await response.json() };
|
||||
}),
|
||||
page2.evaluate(async () => {
|
||||
const response = await fetch('/api/orders', {
|
||||
method: 'POST',
|
||||
headers: { 'Content-Type': 'application/json' },
|
||||
body: JSON.stringify({
|
||||
items: [{ productId: 'canhydrox-gag', quantity: 1 }],
|
||||
paymentMethod: 'online',
|
||||
}),
|
||||
});
|
||||
return { status: response.status, data: await response.json() };
|
||||
}),
|
||||
]);
|
||||
|
||||
// 3. راستیآزمایی سطح سرور و دیتابیس (Strict Concurrency Assertions):
|
||||
// دقیقاً یکی از درخواستها باید 201 Created باشد و دیگری 409 Conflict (ناموجود)
|
||||
const statuses = [res1.status, res2.status].sort();
|
||||
expect(statuses).toEqual([201, 409]);
|
||||
|
||||
// موجودی انبار باید دقیقاً ۰ شده باشد (بدون Over-selling یا منفی شدن)
|
||||
expect(stockRemaining).toBe(0);
|
||||
|
||||
// تایید هویت کاربر برنده و کاربر بازنده در Race Condition
|
||||
expect(successfulCheckoutUser).toBeTruthy();
|
||||
expect(failedCheckoutUser).toBeTruthy();
|
||||
expect(successfulCheckoutUser).not.toBe(failedCheckoutUser);
|
||||
|
||||
// 4. بستن ایزوله کانتکستها
|
||||
await contextUser1.close();
|
||||
await contextUser2.close();
|
||||
});
|
||||
});
|
||||
@@ -0,0 +1,22 @@
|
||||
import { test, expect } from '../../fixtures';
|
||||
|
||||
test.describe('سناریوی مدیریت صفحات خطای کلاینت و سرور (Error Pages 404 & 500)', () => {
|
||||
test('ورود به آدرس ناموجود -> راستیآزمایی رندر کامل صفحه ۴۰۴ و دکمه بازگشت به خانه', async ({ page }) => {
|
||||
// 1. ورود به یک آدرس کاملاً نامعتبر و تصادفی
|
||||
await page.goto('/some-completely-invalid-nonexistent-slug-404', { waitUntil: 'domcontentloaded' });
|
||||
|
||||
// 2. راستیآزمایی تیتر و محتوای صفحه ۴۰۴
|
||||
const notFoundHeading = page.locator('h1').filter({ hasText: 'صفحه پیدا نشد!' });
|
||||
await expect(notFoundHeading).toBeVisible({ timeout: 15000 });
|
||||
|
||||
const notFoundBadge = page.locator('div').filter({ hasText: '۴۰۴' }).first();
|
||||
await expect(notFoundBadge).toBeVisible();
|
||||
|
||||
// 3. راستیآزمایی دکمه بازگشت به خانه و ناوبری موفق به صفحه اصلی
|
||||
const homeBtn = page.getByRole('button', { name: /بازگشت به خانه/i }).first();
|
||||
await expect(homeBtn).toBeVisible();
|
||||
await homeBtn.click();
|
||||
|
||||
await expect(page).toHaveURL('/');
|
||||
});
|
||||
});
|
||||
@@ -6,19 +6,24 @@ test.describe('سناریوی جستجو، فیلترها و مرتبسازی
|
||||
await page.goto('/shop', { waitUntil: 'domcontentloaded' });
|
||||
await expect(page).toHaveURL(/\/shop/);
|
||||
|
||||
// 2. راستیآزمایی اجباری وجود کارتهای اولیه کاتالوگ
|
||||
const productCard = page.locator('a[href^="/shop/"]').first();
|
||||
// 2. راستیآزمایی اجباری وجود کارتهای اولیه کاتالوگ با سلکتور قطعی
|
||||
const productCard = page.locator('[data-testid="archive-product-card"]').first();
|
||||
await expect(productCard).toBeVisible({ timeout: 20000 });
|
||||
|
||||
// 3. جستجوی عبارت ناموجود از طریق URL query parameter
|
||||
await page.goto('/shop?search=%D8%B9%D8%A8%D8%A7%D8%B1%D8%AA_%D9%86%D8%A7%D9%85%D9%88%D8%AC%D9%88%D8%AF_99999', { waitUntil: 'domcontentloaded' });
|
||||
// 3. جستجوی عبارت ناموجود از طریق اینپوت جستجو در صفحه
|
||||
const searchInput = page.locator('[data-testid="shop-search-input"]').first();
|
||||
await expect(searchInput).toBeVisible({ timeout: 10000 });
|
||||
await searchInput.fill('عبارت_ناموجود_۹۹۹۹۹');
|
||||
|
||||
// راستیآزمایی پیام صریح عدم یافت محصول
|
||||
const emptyStateHeading = page.locator('h3').filter({ hasText: 'محصولی یافت نشد!' });
|
||||
await expect(emptyStateHeading).toBeVisible({ timeout: 15000 });
|
||||
|
||||
// 4. بازگشت به صفحه اصلی فروشگاه و راستیآزمایی بارگذاری مجدد کاتالوگ
|
||||
// 4. بازگشت به کل کاتالوگ با کلیک روی دکمه فروشگاه در ناوبری
|
||||
await page.goto('/shop', { waitUntil: 'domcontentloaded' });
|
||||
|
||||
// راستیآزمایی ناپدید شدن وضعیت خالی و بازگشت کاتالوگ
|
||||
await expect(emptyStateHeading).not.toBeVisible({ timeout: 10000 });
|
||||
await expect(productCard).toBeVisible({ timeout: 15000 });
|
||||
|
||||
// 5. تست فیلتر دستهبندی و راستیآزمایی تغییر URL به دستهبندی جدید
|
||||
|
||||
Reference in new issue
Block a user