feat(qdreader): add full task switches

This commit is contained in:
2026-05-20 17:13:23 +08:00
parent 277ad71042
commit 93d529ec5f
5 changed files with 236 additions and 37 deletions
+31 -8
View File
@@ -244,7 +244,8 @@ test('cron signs then immediately archives and clears recent logs', () => {
qdreader_user_bind_json: JSON.stringify({ '12345': 'user-a' }),
};
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.equal(r.calls.length, 4);
assert.match(r.calls[3].url, /getcurrentweekcheckininfo$/);
assert.match(r.replies[0], /启点读书签到结果/);
assert.match(r.replies[0], /日志已归档:2026-05-19/);
const archive = JSON.parse(r.store.qdreader_archive_json);
@@ -261,7 +262,8 @@ test('manual sign also archives immediately after run', () => {
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.equal(r.calls.length, 4);
assert.match(r.calls[3].url, /getcurrentweekcheckininfo$/);
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), {});
@@ -337,9 +339,10 @@ test('manual sign and cron sign both call sign gateway then qidian checkin', ()
qdreader_user_bind_json: JSON.stringify({ '12345': 'user-a' }),
};
const manual = runPlugin({ content: '启点签到', store: { ...store } });
assert.equal(manual.calls.length, 2);
assert.equal(manual.calls.length, 4);
assert.match(manual.calls[0].url, /api\.120399\.xyz\/qdreader\/sign$/);
assert.match(manual.calls[1].url, /h5\.if\.qidian\.com\/argus\/api\/v3\/checkin\/checkin$/);
assert.match(manual.calls[3].url, /getcurrentweekcheckininfo$/);
assert.match(manual.replies[0], /✅ 12\*\*\*45/);
assert.match(manual.replies[0], /记录时间:/);
assert.equal(JSON.parse(manual.store.qdreader_archive_json)['2026-05-20'].source, 'manual');
@@ -351,7 +354,8 @@ test('manual sign and cron sign both call sign gateway then qidian checkin', ()
assert.equal(payload.qdheader, 'MTIzNDV8eA==');
const cron = runPlugin({ content: '', store: { ...store }, globals: { Date: fixedDateClass('2026-05-19T07:01:00.000+08:00') } });
assert.equal(cron.calls.length, 2);
assert.equal(cron.calls.length, 4);
assert.match(cron.calls[3].url, /getcurrentweekcheckininfo$/);
assert.match(cron.replies[0], /启点读书签到结果/);
assert.equal(JSON.parse(cron.store.qdreader_archive_json)['2026-05-19'].source, 'cron');
assert.deepEqual(JSON.parse(cron.store.qdreader_last_run_json), {});
@@ -394,9 +398,11 @@ test('qidian request retries transient request errors', () => {
{ body: { code: 0, data: { headers: { 'QD-Sign': 'sig' } } } },
new Error('timeout'),
{ statusCode: 200, body: { code: 0, msg: '重试后成功' } },
{ body: { code: 0, data: { headers: { 'QD-Sign': 'sig' } } } },
{ statusCode: 200, body: { code: 0, msg: '奖励完成' } },
],
});
assert.equal(r.calls.length, 3);
assert.equal(r.calls.length, 5);
assert.match(r.replies[0], /重试后成功/);
});
@@ -531,10 +537,10 @@ test('manual sign only runs current user accounts while cron runs all accounts',
qdreader_user_bind_json: JSON.stringify({ '12345': 'user-a', '67890': 'user-b' }),
};
const manual = runPlugin({ content: '启点签到', store: { ...store }, userId: 'user-a' });
assert.equal(manual.calls.length, 2);
assert.equal(manual.calls.length, 4);
assert.match(manual.replies[0], /总计 1/);
const cron = runPlugin({ content: '', store: { ...store }, userId: 'cron', globals: { Date: fixedDateClass('2026-05-19T07:01:00.000+08:00') } });
assert.equal(cron.calls.length, 4);
assert.equal(cron.calls.length, 8);
assert.match(cron.replies[0], /总计 2/);
});
@@ -548,7 +554,7 @@ test('unbound global cookies are not visible or usable by normal users', () => {
assert.match(manual.replies[0], /还没有保存启点读书CK/);
const cron = runPlugin({ content: '', store: { ...store }, userId: 'cron', globals: { Date: fixedDateClass('2026-05-19T07:01:00.000+08:00') } });
assert.equal(cron.calls.length, 2);
assert.equal(cron.calls.length, 4);
assert.match(cron.replies[0], /总计 1/);
});
@@ -563,3 +569,20 @@ test('user cannot overwrite another user bound cookie', () => {
assert.equal(JSON.parse(r.store.qdreader_cookie_json)['12345'], cookie);
assert.equal(JSON.parse(r.store.qdreader_user_bind_json)['12345'], '987654321');
});
test('task menu toggles full task switches and enabled tasks are called', () => {
const store = {
qdreader_cookie_json: JSON.stringify({ '12345': cookie }),
qdreader_user_bind_json: JSON.stringify({ '12345': 'user-a' }),
};
const menu = runPlugin({ content: '启点任务', store: { ...store }, userId: 'user-a', listens: ['2 on'] });
assert.match(menu.replies[0], /激励任务:关闭/);
assert.match(menu.replies[1], /激励任务已开启/);
assert.equal(menu.store.qdreader_adv_job_enable, 'true');
const sign = runPlugin({ content: '启点签到', store: { ...store, qdreader_adv_job_enable: 'true' }, userId: 'user-a' });
assert.equal(sign.calls.length, 6);
assert.match(sign.calls[3].url, /getcurrentweekcheckininfo$/);
assert.match(sign.calls[5].url, /video\/adv\/mainPage$/);
assert.match(sign.replies[0], /激励任务/);
});