refactor(api): move 4 misc methods to MiscApi (#6 commit 10/13)
Inlines `actions/misc.ts` into `apis/misc.ts::MiscApi`. The Api holds the methods that didn't naturally group into any other area: translation, mini-app ARK card builder, inline-keyboard callback, group sign-in. No renaming — these names are already descriptive at the call site under `apis.misc.X`. Callers updated: `actions/extended.ts` (4 sites). Tests rewritten to use `new MiscApi(bridge as any).method(...)`. 587/587 tests pass.
This commit is contained in:
1 parent
d953b9824c
commit
e5ac2a61b1
7 files changed
+168
-188
No files matched your search
@@ -23,10 +23,10 @@ vi.mock('../../src/bridge/bridge-oidb', async () => {
|
||||
});
|
||||
|
||||
import * as oidb from '../../src/bridge/bridge-oidb';
|
||||
import * as misc from '../../src/bridge/actions/misc';
|
||||
import { MiscApi } from '../../src/bridge/apis/misc';
|
||||
import { mockBridge } from './_helpers';
|
||||
|
||||
describe('actions/misc', () => {
|
||||
describe('apis/misc', () => {
|
||||
beforeEach(() => {
|
||||
vi.mocked(oidb.runOidb).mockReset();
|
||||
vi.mocked(oidb.runOidb).mockResolvedValue(new Uint8Array());
|
||||
@@ -40,7 +40,7 @@ describe('actions/misc', () => {
|
||||
body: { translateResp: { dstWords: ['你好', '世界'] } } as any,
|
||||
}),
|
||||
);
|
||||
const out = await misc.translateEn2Zh(bridge as any, ['hello', 'world']);
|
||||
const out = await new MiscApi(bridge as any).translateEn2Zh( ['hello', 'world']);
|
||||
expect(out).toEqual(['你好', '世界']);
|
||||
});
|
||||
|
||||
@@ -49,14 +49,14 @@ describe('actions/misc', () => {
|
||||
vi.mocked(oidb.runOidb).mockResolvedValueOnce(
|
||||
protobuf_encode<OidbBase<Oidb0x990Resp>>({ body: {} }),
|
||||
);
|
||||
await expect(misc.translateEn2Zh(bridge as any, ['hello']))
|
||||
await expect(new MiscApi(bridge as any).translateEn2Zh( ['hello']))
|
||||
.rejects.toThrow(/empty/);
|
||||
});
|
||||
|
||||
it('getMiniAppArk rejects unsupported types', async () => {
|
||||
const bridge = mockBridge();
|
||||
await expect(
|
||||
misc.getMiniAppArk(bridge as any, 'youtube', 't', 'd', 'p', 'u'),
|
||||
new MiscApi(bridge as any).getMiniAppArk( 'youtube', 't', 'd', 'p', 'u'),
|
||||
).rejects.toThrow(/unsupported type/);
|
||||
});
|
||||
|
||||
@@ -75,7 +75,7 @@ describe('actions/misc', () => {
|
||||
});
|
||||
// With null responseData, the action should throw on decode — that
|
||||
// still proves the right serviceCmd was used.
|
||||
await expect(misc.getMiniAppArk(bridge as any, 'bili', 't', 'd', 'p', 'u')).rejects.toThrow();
|
||||
await expect(new MiscApi(bridge as any).getMiniAppArk( 'bili', 't', 'd', 'p', 'u')).rejects.toThrow();
|
||||
expect(bridge.sendRawPacket).toHaveBeenCalledOnce();
|
||||
expect(bridge.sendRawPacket.mock.calls[0]![0])
|
||||
.toBe('LightAppSvc.mini_app_share.AdaptShareInfo');
|
||||
@@ -88,13 +88,13 @@ describe('actions/misc', () => {
|
||||
body: { result: 1, errMsg: 'ok', promptText: 'hi' } as any,
|
||||
}),
|
||||
);
|
||||
const out = await misc.clickInlineKeyboardButton(bridge as any, 1, 2, 'btn', 'data', 100);
|
||||
const out = await new MiscApi(bridge as any).clickInlineKeyboardButton( 1, 2, 'btn', 'data', 100);
|
||||
expect(out).toMatchObject({ result: 1, errMsg: 'ok', promptText: 'hi', status: 0 });
|
||||
});
|
||||
|
||||
it('sendGroupSign dispatches to 0xEB7_1', async () => {
|
||||
const bridge = mockBridge();
|
||||
await misc.sendGroupSign(bridge as any, 12345);
|
||||
await new MiscApi(bridge as any).sendGroupSign( 12345);
|
||||
const [, cmd] = vi.mocked(oidb.runOidb).mock.calls[0]!;
|
||||
expect(cmd).toBe('OidbSvcTrpcTcp.0xEB7_1');
|
||||
});
|
||||
|
||||
Reference in new issue
Block a user