fix: clear orphan qdreader bindings on save

This commit is contained in:
2026-05-17 21:59:47 +08:00
parent 5d67f06a60
commit 89de9452b1
3 changed files with 37 additions and 4 deletions
+23
View File
@@ -166,6 +166,29 @@ test('quick submit can bind user from alternate Autman sender fields', () => {
assert.equal(JSON.parse(r.store.qdreader_user_bind_json)['12345'], 'sender-42');
});
test('quick submit can re-add cookie when old binding remains but cookie was manually deleted', () => {
const store = {
qdreader_cookie_json: JSON.stringify({}),
qdreader_user_bind_json: JSON.stringify({ '12345': 'old-user' }),
};
const r = runPlugin({ content: '启点ck ' + cookie, store, userId: 'user-a', listens: ['n'] });
assert.match(r.replies.join('\n'), /已自动清理残留绑定/);
assert.match(r.replies.join('\n'), /CK新增成功/);
assert.equal(JSON.parse(r.store.qdreader_cookie_json)['12345'], cookie);
assert.equal(JSON.parse(r.store.qdreader_user_bind_json)['12345'], 'user-a');
});
test('quick submit still rejects overwrite when cookie and another owner binding both exist', () => {
const store = {
qdreader_cookie_json: JSON.stringify({ '12345': cookie }),
qdreader_user_bind_json: JSON.stringify({ '12345': 'old-user' }),
};
const r = runPlugin({ content: '启点ck ' + cookie.replace('qdh=qdh', 'qdh=newqdh'), store, userId: 'user-a', listens: ['n'] });
assert.match(r.replies.join('\n'), /无权更新 uid: 12345/);
assert.equal(JSON.parse(r.store.qdreader_cookie_json)['12345'], cookie);
assert.equal(JSON.parse(r.store.qdreader_user_bind_json)['12345'], 'old-user');
});
test('quick submit rejects save when Autman JS has no user identity', () => {
const r = runPlugin({
content: '启点ck ' + cookie,