接通审核中结果核对、受理记账与后续调度
This commit is contained in:
1 parent
d157c179c8
commit
f0be4f5596
18 files changed
+510
-57
No files matched your search
+29
-2
@@ -6,7 +6,7 @@ const path=require('node:path');
|
||||
const vm=require('node:vm');
|
||||
const flush=async()=>{for(let i=0;i<12;i++)await new Promise(resolve=>setImmediate(resolve));};
|
||||
|
||||
function fixture({holdImport=false,holdHeartbeat=false,rejectSkip=false}={}) {
|
||||
function fixture({holdImport=false,holdHeartbeat=false,rejectSkip=false,result=null,stopOnAccept=false}={}) {
|
||||
const handlers=new Map(),calls=[],navigations=[],storage=new Map(),timers=new Set();
|
||||
const job={id:'first',state:'preparing',title:'标题',source:'来源',fid:125,account:{uid:'123',name:'账号'}};
|
||||
const run={running:true,epoch:1,active:job.id,owner:'tab-a'};
|
||||
@@ -38,6 +38,8 @@ function fixture({holdImport=false,holdHeartbeat=false,rejectSkip=false}={}) {
|
||||
if(rejectSkip){reply(id,null,'状态已改变');return;}
|
||||
job.state='skipped';run.active=null;run.epoch++;value={ok:true,fid:125,run};
|
||||
}
|
||||
if(route==='current')value={job,run};
|
||||
if(route==='accept'){job.state=body.state;run.active=null;value={ok:true};if(stopOnAccept)run.running=false;}
|
||||
if(route==='stop')run.running=false;
|
||||
reply(id,value);
|
||||
});
|
||||
@@ -47,7 +49,7 @@ function fixture({holdImport=false,holdHeartbeat=false,rejectSkip=false}={}) {
|
||||
location:{href:'https://www.dww11.com/forum.php?mod=post&action=newthread&fid=125',assign:url=>navigations.push(url)},
|
||||
setInterval:fn=>{tick=fn;},setTimeout:(fn,ms)=>{const t=setTimeout(fn,ms);timers.add(t);return t;},clearTimeout:t=>{clearTimeout(t);timers.delete(t);}
|
||||
};
|
||||
context.window={DWW11Importer:{stagePackage:async()=>({}),importPrepared:async({signal})=>{
|
||||
context.window={DWW11Results:result?{inspect:()=>result,clean:v=>String(v||'').trim()}:null,DWW11Importer:{stagePackage:async()=>({}),importPrepared:async({signal})=>{
|
||||
if(holdImport)await new Promise((resolve,reject)=>{finishImport=()=>{rolledBack=true;reject(signal.reason);};signal.addEventListener('abort',()=>{}, {once:true});});
|
||||
signal.throwIfAborted();subject.value='标题';return {attachmentOrder:[]};
|
||||
},verifyEditorImages:async()=>{}},DWW11Formatter:{format(){}}};
|
||||
@@ -104,3 +106,28 @@ test('跳过请求失败时暂停且保留当前稿件',async()=>{
|
||||
assert.equal(f.storage.has('auto-news-current'),true);
|
||||
}finally{f.close();}
|
||||
});
|
||||
|
||||
const acceptedResult={kind:'accepted',thread_id:'236999',first_post_pid:'238791',author_uid:'123',fid:125,title:'标题',state:'accepted_pending_moderation',post_url:'https://www.dww11.com/thread/23699911.html',evidence:{thread_id:'236999',integrity_issues:[]}};
|
||||
for(const stopOnAccept of [false,true])test(`受理后先持久记账;停止=${stopOnAccept} 时禁止回首页`,async()=>{
|
||||
const f=fixture({result:acceptedResult,stopOnAccept});try{
|
||||
await flush();f.doc.dispatchEvent(new f.Event('click',{isTrusted:true,target:{closest:()=>true}}));await flush();
|
||||
await f.tick();await flush();
|
||||
assert.equal(f.calls.filter(x=>x.route==='accept').length,1);
|
||||
assert.equal(f.calls.find(x=>x.route==='accept').body.thread_id,'236999');
|
||||
assert.deepEqual(f.navigations,stopOnAccept?[]:['https://www.dww11.com/']);
|
||||
assert.equal(f.storage.has('auto-news-current'),false);
|
||||
}finally{f.close();}
|
||||
});
|
||||
test('结果首帖作者不匹配时暂停且不记账',async()=>{
|
||||
const f=fixture({result:{...acceptedResult,author_uid:'999'}});try{
|
||||
await flush();f.doc.dispatchEvent(new f.Event('click',{isTrusted:true,target:{closest:()=>true}}));await flush();await f.tick();
|
||||
assert.equal(f.calls.some(x=>x.route==='accept'),false);assert.equal(f.run.running,false);assert.deepEqual(f.navigations,[]);
|
||||
}finally{f.close();}
|
||||
});
|
||||
|
||||
test('明确标题拒绝只记录并暂停,不修稿或重试发表',async()=>{
|
||||
const f=fixture({result:{kind:'rejected',error:'标题超过80字符'}});try{
|
||||
await flush();f.doc.dispatchEvent(new f.Event('click',{isTrusted:true,target:{closest:()=>true}}));await flush();await f.tick();
|
||||
assert.equal(f.job.state,'rejected');assert.equal(f.calls.some(x=>x.route==='accept'),false);assert.deepEqual(f.navigations,[]);
|
||||
}finally{f.close();}
|
||||
});
|
||||
Reference in new issue
Block a user