@davoodmehraban89 / Factor-easy / commits / 6b0915b
Fork 0

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

test: force delayed organization loader and verify lifetime license never snapshots placeholder

davoodmehraban89 committed Oct 14, 2026 at 23:47 UTC 6b0915bdb1054b4f79628a6bbee9d739495dafc4
1 file changed +81
scripts/phase0-startup-performance.spec.js
+81
@@ -200,6 +200,87 @@ test('F0 organization-scoped record hydration respects abort and tenant boundary
200 expect(observed).toEqual({selectedTenant:'org-fixture',preserved:true,noLeakedDummy:true,noStaleSnapshot:true});
201 });
202
203 +
204 +test('F0 test-account lifetime entitlement waits for delayed organization adapter, not placeholder profile',async({page})=>{
205 + // The account and license below are synthetic; no real login or customer data.
206 + // Deliberately restore a "session" BEFORE the organization extension executes.
207 + await page.route('**/js/organization-rbac.js*',async route=>{
208 + await new Promise(resolve=>setTimeout(resolve,1600));
209 + await route.continue();
210 + });
211 + await page.goto(BASE,{waitUntil:'domcontentloaded'});
212 + const observed=await page.evaluate(async()=>{
213 + window.finoraFixtureLegacyProfileCalls=0;
214 + // This is the original profile-only loader, captured by the later wrapper.
215 + window.fetchCurrentUser=async authUser=>{
216 + window.finoraFixtureLegacyProfileCalls++;
217 + return {id:authUser.id,email:'synthetic@example.test',role:'accountant',
218 + subscription:{type:'none',status:'unavailable',endDate:null}};
219 + };
220 + const rows={
221 + organization_members:[{
222 + id:'fixture-membership',user_id:'synthetic-session',organization_id:'fixture-org',
223 + status:'active',is_owner:true,unit_id:null,position_title:null
224 + }],
225 + organizations:[{id:'fixture-org',name:'Fixture Company',status:'active'}],
226 + licenses:[{
227 + organization_id:'fixture-org',plan:'lifetime',status:'active',
228 + starts_at:'2026-01-01',ends_at:'2099-01-01',
229 + max_companies:5,max_users:5,modules:['full_suite']
230 + }],
231 + member_module_permissions:[],
232 + organization_roles:[],
233 + organization_role_permissions:[],
234 + organization_member_roles:[],
235 + records:[]
236 + };
237 + const originalFrom=sb.from;
238 + const originalPullAll=pullAll;
239 + const originalFetch=fetchCurrentUser;
240 + sb.from=table=>({
241 + select(){return this;},
242 + eq(){return this;},
243 + in(){return this;},
244 + order(){return this;},
245 + range(){return this;},
246 + abortSignal(){return this;},
247 + then(resolve){resolve({data:rows[table]||[],error:null});}
248 + });
249 + // No real Supabase requests or writes.
250 + pullAll=async()=>{};
251 + const pending=enterApp({id:'synthetic-session'},{timeoutMs:8500});
252 + await new Promise(resolve=>setTimeout(resolve,90));
253 + const profileFetchedBeforeOrgAdapter=window.finoraFixtureLegacyProfileCalls;
254 + await pending;
255 + const selected=currentUser?.subscription||null;
256 + const selectedOrganization=currentUser?.organizationName||null;
257 + const licenseBadge=document.getElementById('user-license-status-badge')?.innerText||'';
258 + const allowWrite=canWrite();
259 + // Verify that an unavailable snapshot is NEVER presented as expired.
260 + updateLicenseDisplay({subscription:{type:'none',status:'unavailable',endDate:null}});
261 + const unavailableBadge=document.getElementById('user-license-status-badge')?.innerText||'';
262 + updateLicenseDisplay(currentUser);
263 + return {
264 + profileFetchedBeforeOrgAdapter,
265 + finalFetches:window.finoraFixtureLegacyProfileCalls,
266 + selected,selectedOrganization,licenseBadge,allowWrite,
267 + unavailableBadge,finalBadge:document.getElementById('user-license-status-badge')?.innerText||'',
268 + authHidden:getComputedStyle(document.getElementById('auth-screen')).display==='none'
269 + };
270 + });
271 + expect(observed.profileFetchedBeforeOrgAdapter).toBe(0);
272 + expect(observed.finalFetches).toBe(1);
273 + expect(observed.selected).toMatchObject({type:'lifetime',status:'active',endDate:'2099-01-01'});
274 + expect(observed.selectedOrganization).toBe('Fixture Company');
275 + expect(observed.allowWrite).toBe(true);
276 + expect(observed.licenseBadge).toContain('نامحدود');
277 + expect(observed.unavailableBadge).toContain('قابل بررسی نیست');
278 + expect(observed.unavailableBadge).not.toContain('منقضی');
279 + expect(observed.finalBadge).toContain('نامحدود');
280 + expect(observed.authHidden).toBe(true);
281 +});
282 +
283 +
284 test('F0 bootstrap timeout reports ACCOUNT_CONTEXT without email, token or private profile',async({page})=>{
285 await page.goto(BASE,{waitUntil:'domcontentloaded'});
286 await expect.poll(()=>page.evaluate(()=>window.FinoraStartupStatus?.authChecked),{timeout:15000}).toBe(true);