Files
order-notification-automation/tests/fixtures/query-performance.cjs
T

25 lines
2.5 KiB
JavaScript

'use strict';
const crypto=require('node:crypto');
const {DatabaseSync}=require('node:sqlite');
const {RuleStore}=require('../../src/modules/order-rules/store.cjs');
const {BpmVault}=require('../../src/platform/security/vault.cjs');
function fixture(n,{status='pending',huizhou=false}={}){
const db=new DatabaseSync(':memory:');db.exec('CREATE TABLE records(kind TEXT,id TEXT,payload BLOB,PRIMARY KEY(kind,id))');
const vault=Object.assign(Object.create(BpmVault.prototype),{key:crypto.randomBytes(32)}),counts={all:{},get:{},decode:0};let now=new Date('2026-10-26T01:00:00Z');
const store=Object.assign(Object.create(RuleStore.prototype),{db,vault,clock:()=>new Date(now),schedule:()=>({times:['11:00','17:00'],weekends:false}),calendar:()=>[],capabilities:{}});
store.put('settings',{id:'main',version:1,enabled:false,processingEnabled:false,channelId:'',maxMessageBytes:20971520});
for(const draft of require('../../src/modules/order-rules/catalog.cjs').seedRules())store.put('rules',{id:draft.id,draft,published:null});
const rule={id:'bs-change',categoryId:'bs-change',name:'Synthetic',version:1,processNames:['Synthetic'],nodeNames:['Node'],scopes:[{processName:'Synthetic',nodeName:'Node'}],huizhouEnabled:huizhou,to:['fixture@example.invalid']};
for(let i=0;i<n;i++){
const row={connectionId:'a',source:'todo',portalSource:'v4',instanceId:String(i),taskId:String(i),revision:'1',processName:'Synthetic',processVersion:'1',nodeName:'Node',receivedAt:'2026-10-26T00:30:00Z',orderNo:String(i),title:'Synthetic '+i};
store.put('orders',{id:'o'+i,categoryId:rule.categoryId,status,sample:row,event:row,ruleSnapshot:rule,createdAt:row.receivedAt,notifications:huizhou?{huizhou:{status:'pending',orderNos:['H'+i],issues:[]}}:undefined});
store.put('execution-tasks',{id:'t'+i,orderId:'o'+i,connectionId:'a',status,step:'complete',categoryIds:[rule.categoryId],row,createdAt:row.receivedAt});
}
const all=store.all,get=store.get,decode=vault.decode;
store.all=function(kind){counts.all[kind]=(counts.all[kind]||0)+1;return all.call(this,kind);};
store.get=function(kind,id){counts.get[kind]=(counts.get[kind]||0)+1;return get.call(this,kind,id);};
vault.decode=function(...args){counts.decode++;return decode.apply(this,args);};
return {store,counts,context:{orderRules:store,workspace:{recordSources:()=>[{id:'a',owner:'alice'}],businessIssue:()=>null}},actor:{username:'alice',role:'operator'},reset(){counts.all={};counts.get={};counts.decode=0;},setNow(value){now=new Date(value);},close(){db.close();vault.key.fill(0);}};
}
module.exports={fixture};