سامانه صدور فاکتور و حسابداری
Mirrored from https://github.com/davoodmehraban89/Factor-easy.git
Synced Dec 4, 00:30 UTC
test: use versioned sync endpoint in operational settings browser flow
davoodmehraban89 committed
Nov 17, 2026 at 21:30 UTC
0a3edcbd00739cf96d52624adb494b0d3a63292d
1 file changed
+18
-7
scripts/dom-smoke.spec.js
+18
-7
@@ -167,11 +167,22 @@ test('operational settings persist warehouse, currency and costing with an accur
167
const request=route.request(),path=new URL(request.url()).pathname;
168
const headers={'access-control-allow-origin':'*','access-control-allow-headers':'*','access-control-allow-methods':'GET,POST,OPTIONS'};
169
if(request.method()==='OPTIONS')return route.fulfill({status:204,headers});
170
- if(path==='/rest/v1/rpc/finora_sync_records'){
171
- writes++;const args=request.postDataJSON();
172
- for(const row of args.p_upserts||[])rows.set(row.collection+'|'+row.id,JSON.parse(JSON.stringify(row)));
173
- for(const row of args.p_deletes||[])rows.delete(row.collection+'|'+row.id);
174
- return route.fulfill({status:200,contentType:'application/json',headers,body:'null'});
170
+ if(path==='/rest/v1/rpc/finora_sync_records_v2'){
171
+ writes++;const args=request.postDataJSON(),upserts=[],deletes=[];
172
+ if(args.p_organization_id!=='QA_ORG')return route.fulfill({status:403,contentType:'application/json',headers,body:JSON.stringify({code:'42501',message:'Unexpected organization scope'})});
173
+ for(const row of args.p_upserts||[]){
174
+ const key=row.collection+'|'+row.id,current=rows.get(key),currentVersion=current?Number(current.version)||1:0;
175
+ if(Number(row.expected_version||0)!==currentVersion)return route.fulfill({status:409,contentType:'application/json',headers,body:JSON.stringify({code:'40001',message:'FINORA_VERSION_CONFLICT'})});
176
+ const version=currentVersion+1;
177
+ rows.set(key,{collection:row.collection,id:row.id,data:JSON.parse(JSON.stringify(row.data)),version});
178
+ upserts.push({collection:row.collection,id:row.id,version});
179
+ }
180
+ for(const row of args.p_deletes||[]){
181
+ const key=row.collection+'|'+row.id,current=rows.get(key),currentVersion=current?Number(current.version)||1:0;
182
+ if(!current||Number(row.expected_version)!==currentVersion)return route.fulfill({status:409,contentType:'application/json',headers,body:JSON.stringify({code:'40001',message:'FINORA_VERSION_CONFLICT'})});
183
+ rows.delete(key);deletes.push({collection:row.collection,id:row.id});
184
+ }
185
+ return route.fulfill({status:200,contentType:'application/json',headers,body:JSON.stringify({upserts,deletes})});
186
}
187
if(path==='/rest/v1/records')return route.fulfill({status:200,contentType:'application/json',headers,body:JSON.stringify([...rows.values()])});
188
return route.abort();
@@ -180,7 +191,7 @@ test('operational settings persist warehouse, currency and costing with an accur
191
await page.waitForFunction(()=>window.FinoraStartupStatus?.extensionsReady===true&&window.FinoraStartupStatus?.failedExtensionCount===0&&window.FinoraStartupStatus?.authChecked===true);
192
await page.evaluate(()=>{
193
window.alert=()=>{};window.confirm=()=>false;
183
- currentUser={id:'QA_OPS_SETTINGS',role:'admin',modules:['full_suite'],subscription:{type:'lifetime',status:'active',endDate:'2099-01-01'}};
194
+ currentUser={id:'QA_OPS_SETTINGS',organizationId:'QA_ORG',role:'admin',modules:['full_suite'],subscription:{type:'lifetime',status:'active',endDate:'2099-01-01'}};
195
const fresh={};COLLS.forEach(key=>fresh[key]=[]);datastore=fresh;syncSnap.clear();
196
datastore.companies=[{id:'QA_OPS_CO',ownerUserId:currentUser.id,name:'Operational Settings Fixture'}];
197
datastore.settings=[{id:'main',ownerUserId:currentUser.id,default_company_id:'QA_OPS_CO',defaultWarehouseId:'QA_WH_A',baseCurrencyCode:'IRR',inventoryCostMethod:'weighted_average'}];
@@ -217,7 +228,7 @@ test('operational settings persist warehouse, currency and costing with an accur
228
await page.evaluate(async()=>{
229
window.alert=()=>{};window.confirm=()=>false;
230
maybeMigrateLegacyData=()=>{};maybeShowUserOnboarding=()=>{};
220
- fetchCurrentUser=async auth=>({id:auth.id,fullName:'Operational Settings Fixture',role:'admin',modules:['full_suite'],subscription:{type:'lifetime',status:'active',endDate:'2099-01-01'}});
231
+ fetchCurrentUser=async auth=>({id:auth.id,organizationId:'QA_ORG',fullName:'Operational Settings Fixture',role:'admin',modules:['full_suite'],subscription:{type:'lifetime',status:'active',endDate:'2099-01-01'}});
232
await enterApp({id:'QA_OPS_SETTINGS'});
233
navigateShell('settings','view-data-center');
234
});