@davoodmehraban89 / Factor-easy-2 Mirror · read-only / commits / 89a2d2c
Fork 0

سامانه صدور فاکتور و حسابداری

Mirrored from https://github.com/davoodmehraban89/Factor-easy.git

Synced Dec 3, 22:00 UTC

test: mock admin direct account creation and reject non-admin/invalid password

davoodmehraban89 committed Oct 11, 2026 at 20:15 UTC 89a2d2ccd51c20beb346d974bb426abea8565bd7
1 file changed +48
scripts/admin-provisioning.spec.js new
+48
@@ -0,0 +1,48 @@
1 +const {test,expect}=require('@playwright/test');
2 +const BASE=process.env.FINORA_TEST_BASE_URL||'http://127.0.0.1:4173/index.html';
3 +test('central administrator provisions account via server-only endpoint, with no prior signup',async({page})=>{
4 + await page.goto(BASE,{waitUntil:'domcontentloaded'});
5 + await page.waitForFunction(()=>typeof adminOpenCreateUser==='function'&&typeof adminCreateUser==='function');
6 + await page.evaluate(()=>{
7 + window.__adminCalls=[];
8 + currentUser={id:'OWNER_QA',role:'user'};
9 + sb.functions.invoke=async(name,{body})=>{window.__adminCalls.push({name,body});return {data:{ok:true,user_id:'CREATED_QA'},error:null}};
10 + renderAdminPanel=async()=>{};
11 + window.confirm=()=>true;window.alert=()=>{};
12 + adminOpenCreateUser();
13 + });
14 + await expect(page.locator('#modal-admin-create-user')).not.toHaveClass(/active/);
15 + await page.evaluate(()=>{currentUser.role='admin';adminOpenCreateUser()});
16 + await expect(page.locator('#modal-admin-create-user.active')).toBeVisible();
17 + await page.locator('#admin-new-fullname').fill('کاربر آزمایشی');
18 + await page.locator('#admin-new-email').fill('user@example.invalid');
19 + await page.locator('#admin-new-username').fill('sample.user');
20 + await page.locator('#admin-new-password').fill('VeryStrong!Password12');
21 + await page.locator('#admin-create-submit').click();
22 + await expect(page.locator('#modal-admin-create-user')).not.toHaveClass(/active/);
23 + const result=await page.evaluate(()=>({calls:window.__adminCalls,cleared:document.getElementById('admin-new-password').value}));
24 + expect(result.calls).toHaveLength(1);
25 + expect(result.calls[0]).toEqual({name:'admin-user-management',body:{action:'create',email:'user@example.invalid',full_name:'کاربر آزمایشی',username:'sample.user',temporary_password:'VeryStrong!Password12'}});
26 + expect(result.cleared).toBe('');
27 + await page.evaluate(()=>{currentUser.role='user';adminCreateUser()});
28 + expect(await page.evaluate(()=>window.__adminCalls.length)).toBe(1);
29 +});
30 +test('invalid email/weak password are rejected client-side without invoking server',async({page})=>{
31 + await page.goto(BASE,{waitUntil:'domcontentloaded'});
32 + await page.evaluate(()=>{
33 + currentUser={id:'OWNER_QA',role:'admin'};
34 + window.__calls=0;
35 + sb.functions.invoke=async()=>{window.__calls++;return {data:{ok:true},error:null}};
36 + adminOpenCreateUser();
37 + });
38 + await page.locator('#admin-new-email').fill('not-an-email');
39 + await page.locator('#admin-new-password').fill('123');
40 + await page.locator('#admin-create-submit').click();
41 + await expect(page.locator('#admin-create-status')).toContainText('ایمیل معتبر');
42 + await page.locator('#admin-new-email').fill('ok@example.invalid');
43 + await page.locator('#admin-create-submit').click();
44 + await expect(page.locator('#admin-create-status')).toContainText('رمز اولیه');
45 + expect(await page.evaluate(()=>window.__calls)).toBe(0);
46 + await page.locator('#modal-admin-create-user button').filter({hasText:'بستن'}).click();
47 + await expect(page.locator('#modal-admin-create-user')).not.toHaveClass(/active/);
48 +});