feat(qzone): delete_qzone_msg — delete a 说说 by tid via web API
deleteQzoneMsg POSTs a form-urlencoded tid to taotao.qzone.qq.com's emotion_cgi_delete_v6 (proxied through h5.qzone), on the bot's own space. Success has no positive payload beyond code 0, so the contract is throw-on-non-zero-code (foreign/unknown tid or auth failure); the server only deletes feeds the hostUin owns. Rejects empty tid pre-flight. - core: QzoneApi.delete; onebot: delete_qzone_msg action; regen catalog. - tests: tid form-body/url/headers lock, empty-tid preflight, non-zero code throw, and bridge self-space threading.
This commit is contained in:
6 files changed
+159
-2
No files matched your search
@@ -1,5 +1,5 @@
|
||||
import { describe, it, expect, vi, afterEach } from 'vitest';
|
||||
import { getQzoneFeeds, getQzoneMsgList, mapFeeds, mapMsgList, parseQzoneJson, publishQzoneMsg } from '@snowluma/protocol/web/qzone';
|
||||
import { deleteQzoneMsg, getQzoneFeeds, getQzoneMsgList, mapFeeds, mapMsgList, parseQzoneJson, publishQzoneMsg } from '@snowluma/protocol/web/qzone';
|
||||
import { RequestUtil } from '@snowluma/protocol/web/request-util';
|
||||
|
||||
// The 说说 list comes from taotao.qzone.qq.com's emotion_cgi_msglist_v6 CGI,
|
||||
@@ -243,3 +243,37 @@ describe('qzone / publishQzoneMsg (HTTP layer)', () => {
|
||||
await expect(publishQzoneMsg(cookies, '10000', 'hi')).rejects.toThrow('缺少 tid');
|
||||
});
|
||||
});
|
||||
|
||||
describe('qzone / deleteQzoneMsg (HTTP layer)', () => {
|
||||
afterEach(() => vi.restoreAllMocks());
|
||||
|
||||
it('POSTs the tid form body to the proxied delete CGI and resolves on code 0', async () => {
|
||||
const spy = vi.spyOn(RequestUtil, 'HttpGetText').mockResolvedValue('{"code":0,"subcode":0,"message":""}');
|
||||
|
||||
await expect(deleteQzoneMsg(cookies, '10000', 'TID123')).resolves.toBeUndefined();
|
||||
|
||||
const [url, method, body, headers] = spy.mock.calls[0]!;
|
||||
expect(method).toBe('POST');
|
||||
expect(url).toBe(
|
||||
`https://h5.qzone.qq.com/proxy/domain/taotao.qzone.qq.com/cgi-bin/emotion_cgi_delete_v6?g_tk=${expectedGtk}`,
|
||||
);
|
||||
const h = headers as Record<string, string>;
|
||||
expect(h['Content-Type']).toBe('application/x-www-form-urlencoded');
|
||||
expect(h.Cookie).toContain('p_skey=PSK');
|
||||
const form = new URLSearchParams(body as string);
|
||||
expect(form.get('tid')).toBe('TID123');
|
||||
expect(form.get('hostuin')).toBe('10000');
|
||||
expect(form.get('format')).toBe('json');
|
||||
});
|
||||
|
||||
it('rejects an empty tid before any request', async () => {
|
||||
const spy = vi.spyOn(RequestUtil, 'HttpGetText');
|
||||
await expect(deleteQzoneMsg(cookies, '10000', '')).rejects.toThrow('tid is required');
|
||||
expect(spy).not.toHaveBeenCalled();
|
||||
});
|
||||
|
||||
it('throws on a non-zero qzone code (foreign/unknown tid or auth failure)', async () => {
|
||||
vi.spyOn(RequestUtil, 'HttpGetText').mockResolvedValue('{"code":-4001,"message":"no permission"}');
|
||||
await expect(deleteQzoneMsg(cookies, '10000', 'TID123')).rejects.toThrow('code=-4001');
|
||||
});
|
||||
});
|
||||
Reference in new issue
Block a user