Share stored document retry flow across tender detail and vault

This commit is contained in:
2026-09-06 09:37:56 +03:00
parent ba1f93bd76
commit 6dc6fadda8
7 changed files with 114 additions and 37 deletions
+38
View File
@@ -0,0 +1,38 @@
import {test} from 'node:test';
import assert from 'node:assert/strict';
import {retryDocumentExtraction} from '../src/services/storedDocument.js';
test('stored document retry uses owned file ID and stops before a changed session can publish',async()=>{
const originalFetch=globalThis.fetch;
const storage=Object.getOwnPropertyDescriptor(globalThis,'localStorage');
let token='account-a';
Object.defineProperty(globalThis,'localStorage',{configurable:true,value:{getItem:()=>token}});
const doc={id:'owned-doc',ad:'cetvel.docx',ikn:'2026/123',tur:'ihale',isleme:{status:'awaiting_text'}};
const calls=[];
try {
globalThis.fetch=async(url,options)=>{
calls.push({url,options});
if(url.includes('/text?')) return Response.json({success:true,metin:'Source table'});
return Response.json({success:true,sayi:2});
};
assert.equal((await retryDocumentExtraction(doc)).sayi,2);
const payload=JSON.parse(calls[1].options.body);
assert.equal(payload.documentId,doc.id);assert.equal(payload.ikn,doc.ikn);assert.equal(payload.metin,'Source table');
calls.length=0;
globalThis.fetch=async(url)=>{calls.push(url);token='account-b';return Response.json({success:true,metin:'old account document'});};
await assert.rejects(retryDocumentExtraction(doc),/Oturum değişti/);
assert.equal(calls.length,1);
token='account-a';calls.length=0;
globalThis.fetch=async(url,options)=>{
calls.push({url,options});
return url.includes('/text?') ? Response.json({success:false,error:'Okunamadı'},{status:422}) : Response.json({success:true});
};
await assert.rejects(retryDocumentExtraction(doc),/Okunamadı/);
assert.equal(calls[1].url,'/api/me/documents/read-error');
assert.deepEqual(JSON.parse(calls[1].options.body),{id:doc.id,expectedProcessing:doc.isleme});
assert.equal(calls.length,2);
} finally {
globalThis.fetch=originalFetch;
if(storage) Object.defineProperty(globalThis,'localStorage',storage);else delete globalThis.localStorage;
}
});