fix: push qdreader cron results to account owners
This commit is contained in:
@@ -20,12 +20,16 @@ function fixedDateClass(iso) {
|
||||
|
||||
function runPlugin({ pluginCode = code, filename = pluginPath, content = '', store = {}, bucketStore = {}, requests = [], userId = 'user-a', listens = [], senderOverrides = {}, globals = {}, admin = true } = {}) {
|
||||
const replies = [];
|
||||
const pushes = [];
|
||||
const calls = [];
|
||||
let requestIndex = 0;
|
||||
let listenIndex = 0;
|
||||
const baseSender = {
|
||||
reply: (msg) => replies.push(String(msg)),
|
||||
push: (msg) => replies.push(typeof msg === 'string' ? msg : String((msg && (msg.content || msg.message || msg.text)) || JSON.stringify(msg))),
|
||||
push: (msg) => {
|
||||
pushes.push(msg);
|
||||
replies.push(typeof msg === 'string' ? msg : String((msg && (msg.content || msg.message || msg.text)) || JSON.stringify(msg)));
|
||||
},
|
||||
sendText: (msg) => replies.push(String(msg)),
|
||||
getMessage: () => content,
|
||||
getContent: () => content,
|
||||
@@ -38,7 +42,10 @@ function runPlugin({ pluginCode = code, filename = pluginPath, content = '', sto
|
||||
Buffer,
|
||||
sender: { ...baseSender, ...senderOverrides },
|
||||
sendText: (msg) => replies.push(String(msg)),
|
||||
push: (msg) => replies.push(typeof msg === 'string' ? msg : String((msg && (msg.content || msg.message || msg.text)) || JSON.stringify(msg))),
|
||||
push: (msg) => {
|
||||
pushes.push(msg);
|
||||
replies.push(typeof msg === 'string' ? msg : String((msg && (msg.content || msg.message || msg.text)) || JSON.stringify(msg)));
|
||||
},
|
||||
GetUserID: () => userId,
|
||||
GetContent: () => content,
|
||||
getContent: () => content,
|
||||
@@ -60,7 +67,7 @@ function runPlugin({ pluginCode = code, filename = pluginPath, content = '', sto
|
||||
};
|
||||
vm.createContext(ctx);
|
||||
vm.runInContext(pluginCode, ctx, { filename });
|
||||
return { replies, calls, store, bucketStore };
|
||||
return { replies, pushes, calls, store, bucketStore };
|
||||
}
|
||||
|
||||
const cookie = 'uid=12345; QDHeader=MTIzNDV8eA==; qdh=qdh; ywguid=guid; qimei=qimei; qimei36=qimei36; sessionyw=s; appId=10';
|
||||
@@ -769,9 +776,13 @@ test('cron detection uses ImType cron/fake and does not consume input as command
|
||||
},
|
||||
});
|
||||
assert.equal(r.calls.length, 4, imType);
|
||||
assert.equal(r.replies.length, 1, imType);
|
||||
assert.match(r.replies[0], /汇总:成功 1 \/ 失败 0 \/ 总计 1/, imType);
|
||||
assert.match(r.replies[0], /定时任务\/零点任务/, imType);
|
||||
assert.equal(r.replies.length, 2, imType);
|
||||
assert.equal(r.pushes.length, 1, imType);
|
||||
assert.equal(r.pushes[0].userID, 'user-a', imType);
|
||||
assert.match(r.pushes[0].content, /汇总:成功 1 \/ 失败 0 \/ 总计 1/, imType);
|
||||
assert.match(r.pushes[0].content, /日志已归档:2026-05-19/, imType);
|
||||
assert.match(r.replies.join('\n'), /汇总:成功 1 \/ 失败 0 \/ 总计 1/, imType);
|
||||
assert.match(r.replies.join('\n'), /定时任务\/零点任务/, imType);
|
||||
}
|
||||
});
|
||||
|
||||
@@ -786,7 +797,9 @@ test('manual sign only runs current user accounts while cron runs all accounts',
|
||||
const cron = runPlugin({ content: '', store: { ...store }, userId: 'cron', globals: { Date: fixedDateClass('2026-05-19T07:01:00.000+08:00') } });
|
||||
assert.equal(cron.calls.length, 8);
|
||||
assert.equal(cron.replies.length, 3);
|
||||
assert.match(cron.replies[2], /总计 2/);
|
||||
assert.equal(cron.pushes.length, 2);
|
||||
assert.deepEqual(cron.pushes.map((p) => p.userID).sort(), ['user-a', 'user-b']);
|
||||
assert.match(cron.replies.join('\n'), /总计 2/);
|
||||
});
|
||||
|
||||
test('unbound global cookies are not visible or usable by normal users', () => {
|
||||
|
||||
Reference in New Issue
Block a user