fix(onebot): treat a successful status change as success
set_online_status applied the new status but still failed the action because QQ's success reply text was treated as an error. Closes #405
This commit is contained in:
2 files changed
+25
-3
No files matched your search
@@ -76,8 +76,9 @@ export class ProfileApi {
|
|||||||
if (!resp) {
|
if (!resp) {
|
||||||
throw new Error(result.errorMessage || 'set online status failed (network/timeout)');
|
throw new Error(result.errorMessage || 'set online status failed (network/timeout)');
|
||||||
}
|
}
|
||||||
if (resp.errCode !== undefined && resp.errCode !== 0) {
|
const message = resp.errMsg ?? '';
|
||||||
throw new Error(resp.errMsg || `set online status failed with errCode: ${resp.errCode}`);
|
if (message !== '' && message !== 'set status success') {
|
||||||
|
throw new Error(message);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -87,9 +87,30 @@ describe('apis/profile', () => {
|
|||||||
expect(decoded.batteryStatus ?? 0).toBe(0);
|
expect(decoded.batteryStatus ?? 0).toBe(0);
|
||||||
});
|
});
|
||||||
|
|
||||||
|
it('setOnlineStatus accepts QQ\'s success reply even when the reply code is non-zero (#405)', async () => {
|
||||||
|
const bridge = mockBridge();
|
||||||
|
const respBuf = Buffer.from(protobuf_encode<SetStatusResp>({
|
||||||
|
errCode: 1,
|
||||||
|
errMsg: 'set status success',
|
||||||
|
}));
|
||||||
|
expect(respBuf.length).toBeGreaterThan(0);
|
||||||
|
bridge.sendRawPacket.mockResolvedValueOnce({
|
||||||
|
success: true, gotResponse: true, errorCode: 0, errorMessage: '', responseData: respBuf,
|
||||||
|
} as any);
|
||||||
|
await expect(new ProfileApi(bridge as any).setOnlineStatus(10, 0, 100)).resolves.toBeUndefined();
|
||||||
|
});
|
||||||
|
|
||||||
|
it('setOnlineStatus accepts a success-only reply body (#405)', async () => {
|
||||||
|
const bridge = mockBridge();
|
||||||
|
const respBuf = Buffer.from(protobuf_encode<SetStatusResp>({ errMsg: 'set status success' }));
|
||||||
|
bridge.sendRawPacket.mockResolvedValueOnce({
|
||||||
|
success: true, gotResponse: true, errorCode: 0, errorMessage: '', responseData: respBuf,
|
||||||
|
} as any);
|
||||||
|
await expect(new ProfileApi(bridge as any).setOnlineStatus(10, 0)).resolves.toBeUndefined();
|
||||||
|
});
|
||||||
|
|
||||||
it('setDiyOnlineStatus surfaces server errors via the same path as setOnlineStatus', async () => {
|
it('setDiyOnlineStatus surfaces server errors via the same path as setOnlineStatus', async () => {
|
||||||
const bridge = mockBridge();
|
const bridge = mockBridge();
|
||||||
// Build a response that decodes to errCode != 0.
|
|
||||||
const respBuf = Buffer.from(protobuf_encode<SetStatusResp>({ errCode: 1, errMsg: 'denied' }));
|
const respBuf = Buffer.from(protobuf_encode<SetStatusResp>({ errCode: 1, errMsg: 'denied' }));
|
||||||
bridge.sendRawPacket.mockResolvedValueOnce({
|
bridge.sendRawPacket.mockResolvedValueOnce({
|
||||||
success: true, gotResponse: true, errorCode: 0, errorMessage: '', responseData: respBuf,
|
success: true, gotResponse: true, errorCode: 0, errorMessage: '', responseData: respBuf,
|
||||||
|
|||||||
Reference in new issue
Block a user