سامانه صدور فاکتور و حسابداری
Mirrored from https://github.com/davoodmehraban89/Factor-easy.git
Synced Dec 4, 01:45 UTC
test: cover initial purchase server posting and draft retry path
davoodmehraban89 committed
Nov 17, 2026 at 14:03 UTC
1caee8a1d7d734a5402dadc87cca3d2ed39a8235
1 file changed
+21
scripts/journal-rpc-adapter.test.mjs
+21
@@ -180,6 +180,9 @@ test('sale auto-post persists source first and delegates authoritative lines to
180
assert.equal(call.args.p_header.companyId,'CO_A');
181
assert.deepEqual(Array.from(call.args.p_lines),[]);
182
assert.equal(v.id,'JV_SERVER_sale');
183
+ assert.equal(h.source.journalVoucherId,v.id);
184
+ assert.equal(h.source.accountingStatus,'posted');
185
+ assert.equal(h.source.documentStatus,'posted');
186
assert.equal(h.calls.some(x=>x.name==='finora_sync_records'),false);
187
});
188
@@ -191,6 +194,9 @@ test('purchase auto-post uses the same server-owned source contract with purchas
194
assert.equal(call.args.p_header.sourceType,'purchase');
195
assert.equal(call.args.p_header.sourceId,h.source.id);
196
assert.equal(v.id,'JV_SERVER_purchase');
197
+ assert.equal(h.source.journalVoucherId,v.id);
198
+ assert.equal(h.source.accountingStatus,'posted');
199
+ assert.equal(h.source.documentStatus,'posted');
200
});
201
202
test('auto-post fails closed when local generic sync contains dirty journal rows',async()=>{
@@ -242,3 +248,18 @@ test('sync hydration reads database row version required by journal CAS operatio
248
assert.match(syncSource,/obj\._serverVersion=Number\(r\.version\)/);
249
assert.match(syncSource,/p_organization_id:currentUser\.organizationId\|\|null/);
250
});
251
+
252
+
253
+test('initial purchase creation uses the server autopost path and remains retryable as a draft',async()=>{
254
+ const purchaseSource=await readFile(new URL('../js/purchases.js',import.meta.url),'utf8');
255
+ const start=purchaseSource.indexOf('window.purSave=async function(){');
256
+ const end=purchaseSource.indexOf('window.purCancelEdit=function(){',start);
257
+ assert.ok(start>=0&&end>start);
258
+ const saveFlow=purchaseSource.slice(start,end);
259
+ assert.match(saveFlow,/accountingStatus:'draft',documentStatus:'draft'/);
260
+ assert.match(saveFlow,/jeRpcAutoPost\('purchase',record\.id\)/);
261
+ assert.doesNotMatch(saveFlow,/jePostSourceRecord/);
262
+ const finalizer=purchaseSource.slice(purchaseSource.indexOf('window.finalizePurchasePilotDraft=async function'),
263
+ purchaseSource.indexOf('window.deletePurchasePilotDraft',purchaseSource.indexOf('window.finalizePurchasePilotDraft=async function')));
264
+ assert.doesNotMatch(finalizer,/!p\.correctsPurchaseId/);
265
+});