Pull the cache→DB→network-fetch fallback cascade for UIN→UID translation into a single async `resolveUid` on IdentityService, and drop the duplicated `resolveUserUid` helper that used to live in bridge-oidb. Bridge injects itself as the IdentityFetcher post-construction so the network fallback runs through the same OIDB profile fetch the helper used. Each action module's `resolveUserUid(bridge, uin, groupId?)` call becomes `bridge.resolveUserUid(uin, groupId?)` — same signature on Bridge, but internally it now goes through `identity.resolveUid` so future changes (retry, coalescing, alternative resolvers) only need to land in one place. This is part 1 of the IdentityService deepening (RoadMap item 1). The QQInfo bypass in msg-push-handler and the broader QQInfo absorption land in the follow-up commit.
60 lines
2.5 KiB
TypeScript
60 lines
2.5 KiB
TypeScript
import { describe, it, expect, vi, beforeEach } from 'vitest';
|
|
|
|
vi.mock('../../src/bridge/bridge-oidb', () => ({
|
|
sendOidbAndCheck: vi.fn(async () => undefined),
|
|
sendOidbAndDecode: vi.fn(async () => ({})),
|
|
makeOidbRequest: vi.fn(() => new Uint8Array(0)),
|
|
}));
|
|
|
|
import * as oidb from '../../src/bridge/bridge-oidb';
|
|
import * as friend from '../../src/bridge/actions/friend';
|
|
import { mockBridge } from './_helpers';
|
|
|
|
describe('actions/friend', () => {
|
|
beforeEach(() => {
|
|
vi.mocked(oidb.sendOidbAndCheck).mockClear();
|
|
});
|
|
|
|
it('setFriendAddRequest: numeric input is treated as UIN and resolved', async () => {
|
|
const bridge = mockBridge();
|
|
await friend.setFriendAddRequest(bridge as any, '10001', true);
|
|
expect(bridge.resolveUserUid).toHaveBeenCalledWith(10001);
|
|
const payload: any = vi.mocked(oidb.sendOidbAndCheck).mock.calls[0]![4];
|
|
expect(payload).toMatchObject({ accept: 3, targetUid: 'resolved-uid' });
|
|
});
|
|
|
|
it('setFriendAddRequest: non-numeric flag is forwarded as-is', async () => {
|
|
const bridge = mockBridge();
|
|
await friend.setFriendAddRequest(bridge as any, 'flag-abc', false);
|
|
expect(bridge.resolveUserUid).not.toHaveBeenCalled();
|
|
const payload: any = vi.mocked(oidb.sendOidbAndCheck).mock.calls[0]![4];
|
|
expect(payload).toMatchObject({ accept: 5, targetUid: 'flag-abc' });
|
|
});
|
|
|
|
it('deleteFriend resolves UID, calls 0x126b_0, and triggers a friend-list refresh', async () => {
|
|
const bridge = mockBridge();
|
|
await friend.deleteFriend(bridge as any, 10001, true);
|
|
expect(bridge.resolveUserUid).toHaveBeenCalledWith(10001);
|
|
const call = vi.mocked(oidb.sendOidbAndCheck).mock.calls[0]!;
|
|
expect(call[1]).toBe('OidbSvcTrpcTcp.0x126b_0');
|
|
expect((call[4] as any).field1.block).toBe(true);
|
|
expect(bridge.fetchFriendList).toHaveBeenCalled();
|
|
});
|
|
|
|
it('deleteFriend still succeeds when the friend-list refresh throws', async () => {
|
|
const bridge = mockBridge({
|
|
fetchFriendList: vi.fn(async () => { throw new Error('cache miss'); }),
|
|
});
|
|
await expect(friend.deleteFriend(bridge as any, 10001))
|
|
.resolves.toBeUndefined();
|
|
});
|
|
|
|
it('setFriendRemark resolves UID and sends 0xb6e_2', async () => {
|
|
const bridge = mockBridge();
|
|
await friend.setFriendRemark(bridge as any, 10001, 'best-friend');
|
|
const call = vi.mocked(oidb.sendOidbAndCheck).mock.calls[0]!;
|
|
expect(call[1]).toBe('OidbSvcTrpcTcp.0xb6e_2');
|
|
expect(call[4]).toMatchObject({ targetUid: 'resolved-uid', remark: 'best-friend' });
|
|
});
|
|
});
|