fix(qdreader): archive immediately after sign
This commit is contained in:
@@ -238,67 +238,34 @@ test('quick submit rejects save when Autman JS has no user identity', () => {
|
||||
assert.equal(r.store.qdreader_user_bind_json, undefined);
|
||||
});
|
||||
|
||||
test('midnight cron archives previous run log and clears daily logs without running sign', () => {
|
||||
const previousRun = {
|
||||
runId: '20260518_cron',
|
||||
source: 'cron',
|
||||
startedAt: '2026-05-18T07:15:00.000Z',
|
||||
finishedAt: '2026-05-18T07:15:02.000Z',
|
||||
total: 1,
|
||||
okCount: 1,
|
||||
failCount: 0,
|
||||
items: [{ uid: '12345', ok: true, msg: '昨日签到成功', time: '2026-05-18T07:15:01.000Z' }],
|
||||
};
|
||||
test('cron signs then immediately archives and clears recent logs', () => {
|
||||
const store = {
|
||||
qdreader_cookie_json: JSON.stringify({ '12345': cookie }),
|
||||
qdreader_user_bind_json: JSON.stringify({ '12345': 'user-a' }),
|
||||
qdreader_last_run_json: JSON.stringify(previousRun),
|
||||
qdreader_last_result_json: JSON.stringify({ '12345': JSON.stringify({ ok: true, msg: '昨日签到成功' }) }),
|
||||
};
|
||||
const r = runPlugin({ content: '', store, userId: 'cron', globals: { Date: fixedDateClass('2026-05-19T00:00:00.000+08:00') } });
|
||||
assert.equal(r.calls.length, 0);
|
||||
assert.match(r.replies[0], /日志归档完成/);
|
||||
const archive = JSON.parse(r.store.qdreader_archive_json);
|
||||
assert.equal(archive['2026-05-18'].runId, '20260518_cron');
|
||||
assert.equal(archive['2026-05-18'].items[0].msg, '昨日签到成功');
|
||||
assert.deepEqual(JSON.parse(r.store.qdreader_last_run_json), {});
|
||||
assert.deepEqual(JSON.parse(r.store.qdreader_last_result_json), {});
|
||||
});
|
||||
|
||||
|
||||
test('single cron midnight branch archives without signing', () => {
|
||||
const previousRun = {
|
||||
runId: '20260518_cron',
|
||||
source: 'cron',
|
||||
finishedAt: '2026-05-18T07:15:02.000Z',
|
||||
total: 1,
|
||||
okCount: 1,
|
||||
failCount: 0,
|
||||
items: [{ uid: '12345', ok: true, msg: '昨日签到成功' }],
|
||||
};
|
||||
const store = {
|
||||
qdreader_cookie_json: JSON.stringify({ '12345': cookie }),
|
||||
qdreader_user_bind_json: JSON.stringify({ '12345': 'user-a' }),
|
||||
qdreader_last_run_json: JSON.stringify(previousRun),
|
||||
qdreader_last_result_json: JSON.stringify({ '12345': JSON.stringify({ ok: true, msg: '昨日签到成功' }) }),
|
||||
};
|
||||
const r = runPlugin({ content: '', store, userId: 'cron', globals: { Date: fixedDateClass('2026-05-19T00:01:00.000+08:00') } });
|
||||
assert.equal(r.calls.length, 0);
|
||||
assert.match(r.replies[0], /日志归档完成/);
|
||||
assert.equal(JSON.parse(r.store.qdreader_archive_json)['2026-05-18'].runId, '20260518_cron');
|
||||
});
|
||||
|
||||
|
||||
test('single cron morning branch signs without archiving', () => {
|
||||
const store = {
|
||||
qdreader_cookie_json: JSON.stringify({ '12345': cookie }),
|
||||
qdreader_user_bind_json: JSON.stringify({ '12345': 'user-a' }),
|
||||
qdreader_last_run_json: JSON.stringify({ source: 'cron', finishedAt: '2026-05-18T07:15:02.000Z', total: 1, okCount: 1, failCount: 0, items: [{ uid: '12345', ok: true }] }),
|
||||
};
|
||||
const r = runPlugin({ content: '', store, userId: 'cron', globals: { Date: fixedDateClass('2026-05-19T07:01:00.000+08:00') } });
|
||||
assert.equal(r.calls.length, 2);
|
||||
assert.match(r.replies[0], /启点读书签到结果/);
|
||||
assert.equal(r.store.qdreader_archive_json, undefined);
|
||||
assert.match(r.replies[0], /日志已归档:2026-05-19/);
|
||||
const archive = JSON.parse(r.store.qdreader_archive_json);
|
||||
assert.equal(archive['2026-05-19'].source, 'cron');
|
||||
assert.equal(archive['2026-05-19'].okCount, 1);
|
||||
assert.equal(archive['2026-05-19'].items[0].uid, '12345');
|
||||
assert.deepEqual(JSON.parse(r.store.qdreader_last_run_json), {});
|
||||
assert.deepEqual(JSON.parse(r.store.qdreader_last_result_json), {});
|
||||
});
|
||||
|
||||
test('manual sign also archives immediately after run', () => {
|
||||
const store = {
|
||||
qdreader_cookie_json: JSON.stringify({ '12345': cookie }),
|
||||
qdreader_user_bind_json: JSON.stringify({ '12345': 'user-a' }),
|
||||
};
|
||||
const r = runPlugin({ content: '启点签到', store, userId: 'user-a', globals: { Date: fixedDateClass('2026-05-19T08:01:00.000+08:00') } });
|
||||
assert.equal(r.calls.length, 2);
|
||||
assert.match(r.replies[0], /日志已归档:2026-05-19/);
|
||||
assert.equal(JSON.parse(r.store.qdreader_archive_json)['2026-05-19'].source, 'manual');
|
||||
assert.deepEqual(JSON.parse(r.store.qdreader_last_run_json), {});
|
||||
assert.deepEqual(JSON.parse(r.store.qdreader_last_result_json), {});
|
||||
});
|
||||
|
||||
test('query falls back to archived sign results after daily log was cleared', () => {
|
||||
@@ -339,9 +306,10 @@ test('manual sign and cron sign both call sign gateway then qidian checkin', ()
|
||||
assert.match(manual.calls[1].url, /h5\.if\.qidian\.com\/argus\/api\/v3\/checkin\/checkin$/);
|
||||
assert.match(manual.replies[0], /✅ 12\*\*\*45/);
|
||||
assert.match(manual.replies[0], /记录时间:/);
|
||||
assert.equal(JSON.parse(manual.store.qdreader_last_run_json).source, 'manual');
|
||||
assert.equal(JSON.parse(manual.store.qdreader_last_run_json).okCount, 1);
|
||||
assert.equal(JSON.parse(JSON.parse(manual.store.qdreader_last_result_json)['12345']).source, 'manual');
|
||||
assert.equal(JSON.parse(manual.store.qdreader_archive_json)['2026-05-20'].source, 'manual');
|
||||
assert.equal(JSON.parse(manual.store.qdreader_archive_json)['2026-05-20'].okCount, 1);
|
||||
assert.deepEqual(JSON.parse(manual.store.qdreader_last_run_json), {});
|
||||
assert.deepEqual(JSON.parse(manual.store.qdreader_last_result_json), {});
|
||||
const payload = JSON.parse(manual.calls[0].body);
|
||||
assert.equal(payload.qdh, 'qdh');
|
||||
assert.equal(payload.qdheader, 'MTIzNDV8eA==');
|
||||
@@ -349,8 +317,8 @@ test('manual sign and cron sign both call sign gateway then qidian checkin', ()
|
||||
const cron = runPlugin({ content: '', store: { ...store }, globals: { Date: fixedDateClass('2026-05-19T07:01:00.000+08:00') } });
|
||||
assert.equal(cron.calls.length, 2);
|
||||
assert.match(cron.replies[0], /启点读书签到结果/);
|
||||
assert.equal(JSON.parse(cron.store.qdreader_last_run_json).source, 'cron');
|
||||
assert.equal(cron.store.qdreader_archive_json, undefined);
|
||||
assert.equal(JSON.parse(cron.store.qdreader_archive_json)['2026-05-19'].source, 'cron');
|
||||
assert.deepEqual(JSON.parse(cron.store.qdreader_last_run_json), {});
|
||||
});
|
||||
|
||||
test('bucketGet/bucketSet fallback rejects when user identity is absent', () => {
|
||||
@@ -477,12 +445,12 @@ test('failed sign exceptions are written to last execution log', () => {
|
||||
};
|
||||
const r = runPlugin({ content: '启点签到', store, userId: 'user-a', requests: [new Error('sign api down'), new Error('sign api down')] });
|
||||
assert.match(r.replies[0], /sign api down/);
|
||||
const lastRun = JSON.parse(r.store.qdreader_last_run_json);
|
||||
const archived = JSON.parse(r.store.qdreader_archive_json);
|
||||
const lastRun = archived[Object.keys(archived)[0]];
|
||||
assert.equal(lastRun.failCount, 1);
|
||||
assert.equal(lastRun.items[0].error, true);
|
||||
const lastResult = JSON.parse(JSON.parse(r.store.qdreader_last_result_json)['12345']);
|
||||
assert.equal(lastResult.ok, false);
|
||||
assert.equal(lastResult.msg, 'sign api down');
|
||||
assert.deepEqual(JSON.parse(r.store.qdreader_last_run_json), {});
|
||||
assert.deepEqual(JSON.parse(r.store.qdreader_last_result_json), {});
|
||||
});
|
||||
|
||||
test('legacy ck query points to separated commands', () => {
|
||||
|
||||
Reference in New Issue
Block a user