سامانه صدور فاکتور و حسابداری
Mirrored from https://github.com/davoodmehraban89/Factor-easy.git
Synced Dec 3, 22:00 UTC
test(invoice): preserve membership guard during real sync fixture (#216)
davoodmehraban89 committed
Nov 22, 2026 at 01:52 UTC
e13a492bd593c004c39280587a3ca94b53bbb2a4
1 file changed
+14
-4
scripts/phase0-invoice-persistence.spec.js
+14
-4
@@ -58,13 +58,22 @@ async function authenticatedMockBrowser(page,companyId='QA_CO',url=BASE){
58
window.confirm=()=>false;
59
fetchCurrentUser=async()=>({id:'FINORA_F0_FIXTURE_ONLY',organizationId:'QA_ORG',username:'qa-only',email:'qa@example.invalid',fullName:'QA F0',role:'admin',maxCompanies:2,subscription:{type:'lifetime',status:'active',endDate:'2099-12-31'}});
60
maybeMigrateLegacyData=()=>{};
61
- sb.from=collection=>({
62
- select:()=>({
61
+ // Distinguish the authorized synthetic membership query from the records
62
+ // pagination mock. Missing membership data must not silently invalidate a
63
+ // legitimate fixture during longer save/logout/reload tests.
64
+ sb.from=collection=>collection==='organization_members'
65
+ ? {select:()=>{const filters={};return {
66
+ eq(field,value){filters[field]=value;return this;},
67
+ then(resolve,reject){
68
+ const allowed=filters.user_id===currentUser?.id&&filters.status==='active';
69
+ return Promise.resolve({data:allowed?[{id:'QA_F0_MEMBER',organization_id:'QA_ORG',status:'active'}]:[],error:null}).then(resolve,reject);
70
+ }
71
+ }}}
72
+ : {select:()=>({
73
eq(){return this;},
74
order(){return this;},
75
async range(from,to){const rows=(await window.qaF0Read()).filter(r=>r.collection).sort((a,b)=>a.collection.localeCompare(b.collection)||a.id.localeCompare(b.id));return {data:rows.slice(from,to+1),error:null};}
66
- })
67
- });
76
+ })};
77
sb.rpc=async(name,args)=>{
78
if(name!=='finora_sync_records_v2')throw Error('Unexpected RPC '+name);
79
return await window.qaF0Write(args);
@@ -75,6 +84,7 @@ async function authenticatedMockBrowser(page,companyId='QA_CO',url=BASE){
84
switchView('view-invoices');
85
});
86
await expect(page.locator('#auth-screen')).toBeHidden();
87
+ expect(await page.evaluate(()=>window.revalidateFinoraMembership({sensitive:true}))).toBe(true);
88
await expect(page.locator('#invoice-company-id')).toHaveValue(companyId);
89
await expect(page.locator('#invoice-items-table-body .row-product-select').first().locator('option[value="QA_PROD"]')).toHaveCount(1);
90
}