refactor(api): move 3 friend methods to FriendApi (#6 commit 7/13)
Inlines `actions/friend.ts` into `apis/friend.ts::FriendApi`. The roster READ side (fetchFriendList) stays on ContactsApi where it naturally lives next to fetchGroupList — the friend/group rosters share the same pipeline. Method renaming (Api namespace already says "friend"): setFriendAddRequest → handleRequest (accept/reject UID-or-flag) deleteFriend → delete (with cache refresh) setFriendRemark → setRemark `delete` still does the post-OIDB best-effort `apis.contacts.fetchFriendList()` refresh to evict the stale entry. Callers updated: `instance-context.ts`, `actions/extended.ts`. Tests rewritten to use `new FriendApi(bridge as any).method(...)`. 587/587 tests pass.
This commit is contained in:
1 parent
73f1cd3c80
commit
2ec72d59f9
8 files changed
+97
-80
No files matched your search
@@ -1,50 +0,0 @@
|
|||||||
import { protobuf_encode } from '@snowluma/proton';
|
|
||||||
import type { Bridge } from '../bridge';
|
|
||||||
import { makeOidbEnvelope, runOidb } from '../bridge-oidb';
|
|
||||||
import { OidbBase } from '@snowluma/proto-defs/oidb';
|
|
||||||
import type {
|
|
||||||
OidbDeleteFriend,
|
|
||||||
OidbFriendRequestAction,
|
|
||||||
OidbSetFriendRemark,
|
|
||||||
} from '@snowluma/proto-defs/oidb-actions/base';
|
|
||||||
|
|
||||||
export async function setFriendAddRequest(bridge: Bridge, uidOrFlag: string, approve: boolean): Promise<void> {
|
|
||||||
let targetUid = uidOrFlag;
|
|
||||||
if (/^\d+$/.test(uidOrFlag)) {
|
|
||||||
targetUid = await bridge.resolveUserUid(parseInt(uidOrFlag, 10));
|
|
||||||
}
|
|
||||||
const env = makeOidbEnvelope<OidbFriendRequestAction>(0xB5D, 44, { accept: approve ? 3 : 5, targetUid });
|
|
||||||
await runOidb(bridge, 'OidbSvcTrpcTcp.0xb5d_44', protobuf_encode<OidbBase<OidbFriendRequestAction>>(env));
|
|
||||||
}
|
|
||||||
|
|
||||||
export async function deleteFriend(bridge: Bridge, userId: number, block = false): Promise<void> {
|
|
||||||
const targetUid = await bridge.resolveUserUid(userId);
|
|
||||||
const env = makeOidbEnvelope<OidbDeleteFriend>(0x126B, 0, {
|
|
||||||
field1: {
|
|
||||||
targetUid,
|
|
||||||
field2: {
|
|
||||||
field1: 130,
|
|
||||||
field2: 109,
|
|
||||||
field3: {
|
|
||||||
field1: 8,
|
|
||||||
field2: 8,
|
|
||||||
field3: 50,
|
|
||||||
},
|
|
||||||
},
|
|
||||||
block,
|
|
||||||
field4: false,
|
|
||||||
},
|
|
||||||
});
|
|
||||||
await runOidb(bridge, 'OidbSvcTrpcTcp.0x126b_0', protobuf_encode<OidbBase<OidbDeleteFriend>>(env));
|
|
||||||
|
|
||||||
// Refresh friend cache after deletion so subsequent reads don't
|
|
||||||
// surface a ghost entry. Best-effort: a transient OIDB hiccup here
|
|
||||||
// shouldn't make the delete itself look failed.
|
|
||||||
try { await bridge.apis.contacts.fetchFriendList(); } catch { /* ignore */ }
|
|
||||||
}
|
|
||||||
|
|
||||||
export async function setFriendRemark(bridge: Bridge, userId: number, remark: string): Promise<void> {
|
|
||||||
const uid = await bridge.resolveUserUid(userId);
|
|
||||||
const env = makeOidbEnvelope<OidbSetFriendRemark>(0xB6E, 2, { targetUid: uid, remark });
|
|
||||||
await runOidb(bridge, 'OidbSvcTrpcTcp.0xb6e_2', protobuf_encode<OidbBase<OidbSetFriendRemark>>(env));
|
|
||||||
}
|
|
||||||
@@ -0,0 +1,70 @@
|
|||||||
|
// FriendApi — friend roster mutations (handle add request /
|
||||||
|
// delete / set remark). Inlined from `actions/friend.ts` (deleted
|
||||||
|
// alongside actions/* in commit 13). The READ side of friends
|
||||||
|
// (fetchFriendList) lives on ContactsApi because friends/groups
|
||||||
|
// share the same roster pipeline.
|
||||||
|
|
||||||
|
import { protobuf_encode } from '@snowluma/proton';
|
||||||
|
import type { OidbBase } from '@snowluma/proto-defs/oidb';
|
||||||
|
import type {
|
||||||
|
OidbDeleteFriend,
|
||||||
|
OidbFriendRequestAction,
|
||||||
|
OidbSetFriendRemark,
|
||||||
|
} from '@snowluma/proto-defs/oidb-actions/base';
|
||||||
|
import type { BridgeContext } from '../bridge-context';
|
||||||
|
import type { Bridge } from '../bridge';
|
||||||
|
import { makeOidbEnvelope, runOidb } from '../bridge-oidb';
|
||||||
|
|
||||||
|
function asBridge(ctx: BridgeContext): Bridge { return ctx as unknown as Bridge; }
|
||||||
|
|
||||||
|
export class FriendApi {
|
||||||
|
constructor(private readonly ctx: BridgeContext) {}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Accept or reject an inbound friend request. `uidOrFlag` is either a
|
||||||
|
* pre-resolved UID string or a numeric uin (then resolved on the fly).
|
||||||
|
*/
|
||||||
|
async handleRequest(uidOrFlag: string, approve: boolean): Promise<void> {
|
||||||
|
const bridge = asBridge(this.ctx);
|
||||||
|
let targetUid = uidOrFlag;
|
||||||
|
if (/^\d+$/.test(uidOrFlag)) {
|
||||||
|
targetUid = await this.ctx.resolveUserUid(parseInt(uidOrFlag, 10));
|
||||||
|
}
|
||||||
|
const env = makeOidbEnvelope<OidbFriendRequestAction>(0xB5D, 44, { accept: approve ? 3 : 5, targetUid });
|
||||||
|
await runOidb(bridge, 'OidbSvcTrpcTcp.0xb5d_44', protobuf_encode<OidbBase<OidbFriendRequestAction>>(env));
|
||||||
|
}
|
||||||
|
|
||||||
|
async delete(userId: number, block = false): Promise<void> {
|
||||||
|
const bridge = asBridge(this.ctx);
|
||||||
|
const targetUid = await this.ctx.resolveUserUid(userId);
|
||||||
|
const env = makeOidbEnvelope<OidbDeleteFriend>(0x126B, 0, {
|
||||||
|
field1: {
|
||||||
|
targetUid,
|
||||||
|
field2: {
|
||||||
|
field1: 130,
|
||||||
|
field2: 109,
|
||||||
|
field3: {
|
||||||
|
field1: 8,
|
||||||
|
field2: 8,
|
||||||
|
field3: 50,
|
||||||
|
},
|
||||||
|
},
|
||||||
|
block,
|
||||||
|
field4: false,
|
||||||
|
},
|
||||||
|
});
|
||||||
|
await runOidb(bridge, 'OidbSvcTrpcTcp.0x126b_0', protobuf_encode<OidbBase<OidbDeleteFriend>>(env));
|
||||||
|
|
||||||
|
// Refresh friend cache after deletion so subsequent reads don't
|
||||||
|
// surface a ghost entry. Best-effort: a transient OIDB hiccup here
|
||||||
|
// shouldn't make the delete itself look failed.
|
||||||
|
try { await this.ctx.apis.contacts.fetchFriendList(); } catch { /* ignore */ }
|
||||||
|
}
|
||||||
|
|
||||||
|
async setRemark(userId: number, remark: string): Promise<void> {
|
||||||
|
const bridge = asBridge(this.ctx);
|
||||||
|
const uid = await this.ctx.resolveUserUid(userId);
|
||||||
|
const env = makeOidbEnvelope<OidbSetFriendRemark>(0xB6E, 2, { targetUid: uid, remark });
|
||||||
|
await runOidb(bridge, 'OidbSvcTrpcTcp.0xb6e_2', protobuf_encode<OidbBase<OidbSetFriendRemark>>(env));
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -22,6 +22,7 @@
|
|||||||
|
|
||||||
import type { BridgeContext } from '../bridge-context';
|
import type { BridgeContext } from '../bridge-context';
|
||||||
import { ContactsApi } from './contacts';
|
import { ContactsApi } from './contacts';
|
||||||
|
import { FriendApi } from './friend';
|
||||||
import { GroupAdminApi } from './group-admin';
|
import { GroupAdminApi } from './group-admin';
|
||||||
import { GroupAlbumApi } from './group-album';
|
import { GroupAlbumApi } from './group-album';
|
||||||
import { GroupFileApi } from './group-file';
|
import { GroupFileApi } from './group-file';
|
||||||
@@ -41,8 +42,9 @@ export interface ApiHub {
|
|||||||
readonly groupAlbum: GroupAlbumApi;
|
readonly groupAlbum: GroupAlbumApi;
|
||||||
/** Interactive engagement: poke / like / reaction / essence / emoji-like-list. */
|
/** Interactive engagement: poke / like / reaction / essence / emoji-like-list. */
|
||||||
readonly interaction: InteractionApi;
|
readonly interaction: InteractionApi;
|
||||||
|
/** Friend roster mutations: handleRequest / delete / setRemark. */
|
||||||
|
readonly friend: FriendApi;
|
||||||
// Pending — added as later commits land:
|
// Pending — added as later commits land:
|
||||||
// readonly friend: FriendApi;
|
|
||||||
// readonly interaction: InteractionApi;
|
// readonly interaction: InteractionApi;
|
||||||
// readonly profile: ProfileApi;
|
// readonly profile: ProfileApi;
|
||||||
// readonly forward: ForwardApi;
|
// readonly forward: ForwardApi;
|
||||||
@@ -67,6 +69,7 @@ export function buildApiHub(ctx: BridgeContext): ApiHub {
|
|||||||
groupFile: new GroupFileApi(ctx),
|
groupFile: new GroupFileApi(ctx),
|
||||||
groupAlbum: new GroupAlbumApi(ctx),
|
groupAlbum: new GroupAlbumApi(ctx),
|
||||||
interaction: new InteractionApi(ctx),
|
interaction: new InteractionApi(ctx),
|
||||||
|
friend: new FriendApi(ctx),
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -74,6 +77,7 @@ export function buildApiHub(ctx: BridgeContext): ApiHub {
|
|||||||
// `import type { MessageApi } from '@snowluma/core/.../apis'` for
|
// `import type { MessageApi } from '@snowluma/core/.../apis'` for
|
||||||
// signature use. Concrete instances always come from `bridge.apis.*`.
|
// signature use. Concrete instances always come from `bridge.apis.*`.
|
||||||
export { ContactsApi } from './contacts';
|
export { ContactsApi } from './contacts';
|
||||||
|
export { FriendApi } from './friend';
|
||||||
export { GroupAdminApi } from './group-admin';
|
export { GroupAdminApi } from './group-admin';
|
||||||
export { GroupAlbumApi } from './group-album';
|
export { GroupAlbumApi } from './group-album';
|
||||||
export { GroupFileApi } from './group-file';
|
export { GroupFileApi } from './group-file';
|
||||||
|
|||||||
@@ -46,10 +46,8 @@ export interface BridgeInterface {
|
|||||||
// ─── Group admin (moved to apis.groupAdmin) ───
|
// ─── Group admin (moved to apis.groupAdmin) ───
|
||||||
// ─── Group reaction / essence (moved to apis.interaction) ───
|
// ─── Group reaction / essence (moved to apis.interaction) ───
|
||||||
|
|
||||||
// ─── Friend ───
|
// ─── Friend (moved to apis.friend) ───
|
||||||
setFriendAddRequest(uidOrFlag: string, approve: boolean): Promise<void>;
|
// - handleRequest / delete / setRemark
|
||||||
deleteFriend(userId: number, block?: boolean): Promise<void>;
|
|
||||||
setFriendRemark(userId: number, remark: string): Promise<void>;
|
|
||||||
|
|
||||||
// ─── Files (moved to apis.groupFile) ───
|
// ─── Files (moved to apis.groupFile) ───
|
||||||
// - upload / uploadPrivate / publish
|
// - upload / uploadPrivate / publish
|
||||||
|
|||||||
@@ -26,11 +26,7 @@ import {
|
|||||||
fetchForwardNodes as fetchForwardNodes_,
|
fetchForwardNodes as fetchForwardNodes_,
|
||||||
uploadForwardNodes as uploadForwardNodes_,
|
uploadForwardNodes as uploadForwardNodes_,
|
||||||
} from './actions/forward';
|
} from './actions/forward';
|
||||||
import {
|
// actions/friend.ts removed — moved to apis/friend.ts::FriendApi.
|
||||||
deleteFriend as deleteFriend_,
|
|
||||||
setFriendAddRequest as setFriendAddRequest_,
|
|
||||||
setFriendRemark as setFriendRemark_,
|
|
||||||
} from './actions/friend';
|
|
||||||
// actions/group-admin.ts removed — moved to `apis/group-admin.ts::GroupAdminApi`.
|
// actions/group-admin.ts removed — moved to `apis/group-admin.ts::GroupAdminApi`.
|
||||||
// actions/group-album.ts removed — moved to `apis/group-album.ts::GroupAlbumApi`.
|
// actions/group-album.ts removed — moved to `apis/group-album.ts::GroupAlbumApi`.
|
||||||
// Group file CRUD + private c2c upload + media URL resolvers moved to
|
// Group file CRUD + private c2c upload + media URL resolvers moved to
|
||||||
@@ -318,8 +314,8 @@ export class Bridge implements BridgeInterface {
|
|||||||
// GroupAdmin methods (mute/kick/admin/card/name/title/leave/
|
// GroupAdmin methods (mute/kick/admin/card/name/title/leave/
|
||||||
// add-option/search/add-request/remark/at-all-remain) moved to
|
// add-option/search/add-request/remark/at-all-remain) moved to
|
||||||
// apis.groupAdmin (apis/group-admin.ts::GroupAdminApi).
|
// apis.groupAdmin (apis/group-admin.ts::GroupAdminApi).
|
||||||
async setFriendAddRequest(uidOrFlag: string, approve: boolean): Promise<void> { return setFriendAddRequest_(this, uidOrFlag, approve); }
|
// Friend methods (handleRequest/delete/setRemark) moved to
|
||||||
async deleteFriend(userId: number, block = false): Promise<void> { return deleteFriend_(this, userId, block); }
|
// apis.friend.
|
||||||
// GroupFile methods (upload/uploadPrivate/publish/list/getUrl/
|
// GroupFile methods (upload/uploadPrivate/publish/list/getUrl/
|
||||||
// getPrivateUrl/{Ptt,Video}Url/getPrivate{Ptt,Video}Url/delete/move/
|
// getPrivateUrl/{Ptt,Video}Url/getPrivate{Ptt,Video}Url/delete/move/
|
||||||
// createFolder/deleteFolder/renameFolder/getCount) moved to
|
// createFolder/deleteFolder/renameFolder/getCount) moved to
|
||||||
@@ -329,7 +325,6 @@ export class Bridge implements BridgeInterface {
|
|||||||
// Interaction methods (sendPoke/sendLike/setReaction/setEssence/
|
// Interaction methods (sendPoke/sendLike/setReaction/setEssence/
|
||||||
// getEmojiLikes) moved to apis.interaction.
|
// getEmojiLikes) moved to apis.interaction.
|
||||||
// recall* / markRead* moved to apis/message.ts::MessageApi.
|
// recall* / markRead* moved to apis/message.ts::MessageApi.
|
||||||
async setFriendRemark(userId: number, remark: string): Promise<void> { return setFriendRemark_(this, userId, remark); }
|
|
||||||
async getGroupHonorInfo(groupId: number, type: WebHonorType | string): Promise<any> {
|
async getGroupHonorInfo(groupId: number, type: WebHonorType | string): Promise<any> {
|
||||||
return getGroupHonorInfo_(this, groupId, type);
|
return getGroupHonorInfo_(this, groupId, type);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -540,7 +540,7 @@ export function register(h: ApiHandler, ctx: ApiActionContext): void {
|
|||||||
if (params.remark === undefined) {
|
if (params.remark === undefined) {
|
||||||
return failedResponse(RETCODE.BAD_REQUEST, 'remark is required (pass an empty string to clear)');
|
return failedResponse(RETCODE.BAD_REQUEST, 'remark is required (pass an empty string to clear)');
|
||||||
}
|
}
|
||||||
await ctx.bridge.setFriendRemark(userId, asString(params.remark));
|
await ctx.bridge.apis.friend.setRemark(userId, asString(params.remark));
|
||||||
return okResponse();
|
return okResponse();
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|||||||
@@ -133,7 +133,7 @@ export function buildApiContext(ref: OneBotInstanceContext): ApiActionContext {
|
|||||||
getPrivateFileUrl: (userId, fileId, fileHash) => bridge.apis.groupFile.getPrivateUrl(userId, fileId, fileHash),
|
getPrivateFileUrl: (userId, fileId, fileHash) => bridge.apis.groupFile.getPrivateUrl(userId, fileId, fileHash),
|
||||||
|
|
||||||
// Requests — name translation.
|
// Requests — name translation.
|
||||||
handleFriendRequest: (flag, approve) => bridge.setFriendAddRequest(flag, approve),
|
handleFriendRequest: (flag, approve) => bridge.apis.friend.handleRequest(flag, approve),
|
||||||
handleGroupRequest: (flag, _subType, approve, reason) => handleGroupAddRequest(bridge, flag, approve, reason),
|
handleGroupRequest: (flag, _subType, approve, reason) => handleGroupAddRequest(bridge, flag, approve, reason),
|
||||||
|
|
||||||
// Pokes — flatten isGroup into the bridge signature.
|
// Pokes — flatten isGroup into the bridge signature.
|
||||||
@@ -161,9 +161,9 @@ export function buildApiContext(ref: OneBotInstanceContext): ApiActionContext {
|
|||||||
sendForwardMsg: (messages, groupId) => uploadForwardMessage(ref, messages, groupId),
|
sendForwardMsg: (messages, groupId) => uploadForwardMessage(ref, messages, groupId),
|
||||||
getForwardMsg: (resId) => getForwardMessage(ref, resId),
|
getForwardMsg: (resId) => getForwardMessage(ref, resId),
|
||||||
forwardSingleMsg: (messageId, target) => forwardSingleMessage(ref, messageId, target),
|
forwardSingleMsg: (messageId, target) => forwardSingleMessage(ref, messageId, target),
|
||||||
handleDeleteFriend: (userId, block) => bridge.deleteFriend(userId, !!block),
|
handleDeleteFriend: (userId, block) => bridge.apis.friend.delete(userId, !!block),
|
||||||
forceFetchClientKey: () => bridge.forceFetchClientKey(),
|
forceFetchClientKey: () => bridge.forceFetchClientKey(),
|
||||||
setFriendRemark: (userId, remark) => bridge.setFriendRemark(userId, remark),
|
setFriendRemark: (userId, remark) => bridge.apis.friend.setRemark(userId, remark),
|
||||||
setGroupRemark: (groupId, remark) => bridge.apis.groupAdmin.setRemark(groupId, remark),
|
setGroupRemark: (groupId, remark) => bridge.apis.groupAdmin.setRemark(groupId, remark),
|
||||||
setGroupAvatar: (groupId, source) => bridge.setGroupAvatar(groupId, source),
|
setGroupAvatar: (groupId, source) => bridge.setGroupAvatar(groupId, source),
|
||||||
getGroupFileCount: (groupId) => bridge.apis.groupFile.getCount(groupId),
|
getGroupFileCount: (groupId) => bridge.apis.groupFile.getCount(groupId),
|
||||||
|
|||||||
@@ -8,34 +8,34 @@ vi.mock('../../src/bridge/bridge-oidb', () => ({
|
|||||||
}));
|
}));
|
||||||
|
|
||||||
import * as oidb from '../../src/bridge/bridge-oidb';
|
import * as oidb from '../../src/bridge/bridge-oidb';
|
||||||
import * as friend from '../../src/bridge/actions/friend';
|
import { FriendApi } from '../../src/bridge/apis/friend';
|
||||||
import { mockBridge } from './_helpers';
|
import { mockBridge } from './_helpers';
|
||||||
|
|
||||||
describe('actions/friend', () => {
|
describe('apis/friend', () => {
|
||||||
beforeEach(() => {
|
beforeEach(() => {
|
||||||
vi.mocked(oidb.runOidb).mockClear();
|
vi.mocked(oidb.runOidb).mockClear();
|
||||||
vi.mocked(oidb.makeOidbEnvelope).mockClear();
|
vi.mocked(oidb.makeOidbEnvelope).mockClear();
|
||||||
});
|
});
|
||||||
|
|
||||||
it('setFriendAddRequest: numeric input is treated as UIN and resolved', async () => {
|
it('handleRequest: numeric input is treated as UIN and resolved', async () => {
|
||||||
const bridge = mockBridge();
|
const bridge = mockBridge();
|
||||||
await friend.setFriendAddRequest(bridge as any, '10001', true);
|
await new FriendApi(bridge as any).handleRequest('10001', true);
|
||||||
expect(bridge.resolveUserUid).toHaveBeenCalledWith(10001);
|
expect(bridge.resolveUserUid).toHaveBeenCalledWith(10001);
|
||||||
const body = vi.mocked(oidb.makeOidbEnvelope).mock.calls[0]![2];
|
const body = vi.mocked(oidb.makeOidbEnvelope).mock.calls[0]![2];
|
||||||
expect(body).toMatchObject({ accept: 3, targetUid: 'resolved-uid' });
|
expect(body).toMatchObject({ accept: 3, targetUid: 'resolved-uid' });
|
||||||
});
|
});
|
||||||
|
|
||||||
it('setFriendAddRequest: non-numeric flag is forwarded as-is', async () => {
|
it('handleRequest: non-numeric flag is forwarded as-is', async () => {
|
||||||
const bridge = mockBridge();
|
const bridge = mockBridge();
|
||||||
await friend.setFriendAddRequest(bridge as any, 'flag-abc', false);
|
await new FriendApi(bridge as any).handleRequest('flag-abc', false);
|
||||||
expect(bridge.resolveUserUid).not.toHaveBeenCalled();
|
expect(bridge.resolveUserUid).not.toHaveBeenCalled();
|
||||||
const body = vi.mocked(oidb.makeOidbEnvelope).mock.calls[0]![2];
|
const body = vi.mocked(oidb.makeOidbEnvelope).mock.calls[0]![2];
|
||||||
expect(body).toMatchObject({ accept: 5, targetUid: 'flag-abc' });
|
expect(body).toMatchObject({ accept: 5, targetUid: 'flag-abc' });
|
||||||
});
|
});
|
||||||
|
|
||||||
it('deleteFriend resolves UID, calls 0x126b_0, and triggers a friend-list refresh', async () => {
|
it('delete resolves UID, calls 0x126b_0, and triggers a friend-list refresh', async () => {
|
||||||
const bridge = mockBridge();
|
const bridge = mockBridge();
|
||||||
await friend.deleteFriend(bridge as any, 10001, true);
|
await new FriendApi(bridge as any).delete(10001, true);
|
||||||
expect(bridge.resolveUserUid).toHaveBeenCalledWith(10001);
|
expect(bridge.resolveUserUid).toHaveBeenCalledWith(10001);
|
||||||
const [, cmd] = vi.mocked(oidb.runOidb).mock.calls[0]!;
|
const [, cmd] = vi.mocked(oidb.runOidb).mock.calls[0]!;
|
||||||
expect(cmd).toBe('OidbSvcTrpcTcp.0x126b_0');
|
expect(cmd).toBe('OidbSvcTrpcTcp.0x126b_0');
|
||||||
@@ -44,19 +44,19 @@ describe('actions/friend', () => {
|
|||||||
expect(bridge.apis.contacts.fetchFriendList).toHaveBeenCalled();
|
expect(bridge.apis.contacts.fetchFriendList).toHaveBeenCalled();
|
||||||
});
|
});
|
||||||
|
|
||||||
it('deleteFriend still succeeds when the friend-list refresh throws', async () => {
|
it('delete still succeeds when the friend-list refresh throws', async () => {
|
||||||
const bridge = mockBridge();
|
const bridge = mockBridge();
|
||||||
// `fetchFriendList` lives on `apis.contacts` post-#6 refactor;
|
// `fetchFriendList` lives on `apis.contacts` post-#6 refactor;
|
||||||
// override the default no-op stub to make the friend-list refresh
|
// override the default no-op stub to make the friend-list refresh
|
||||||
// throw and verify deleteFriend swallows the error.
|
// throw and verify delete swallows the error.
|
||||||
bridge.apis.contacts.fetchFriendList = vi.fn(async () => { throw new Error('cache miss'); });
|
bridge.apis.contacts.fetchFriendList = vi.fn(async () => { throw new Error('cache miss'); });
|
||||||
await expect(friend.deleteFriend(bridge as any, 10001))
|
await expect(new FriendApi(bridge as any).delete(10001))
|
||||||
.resolves.toBeUndefined();
|
.resolves.toBeUndefined();
|
||||||
});
|
});
|
||||||
|
|
||||||
it('setFriendRemark resolves UID and sends 0xb6e_2', async () => {
|
it('setRemark resolves UID and sends 0xb6e_2', async () => {
|
||||||
const bridge = mockBridge();
|
const bridge = mockBridge();
|
||||||
await friend.setFriendRemark(bridge as any, 10001, 'best-friend');
|
await new FriendApi(bridge as any).setRemark(10001, 'best-friend');
|
||||||
const [, cmd] = vi.mocked(oidb.runOidb).mock.calls[0]!;
|
const [, cmd] = vi.mocked(oidb.runOidb).mock.calls[0]!;
|
||||||
expect(cmd).toBe('OidbSvcTrpcTcp.0xb6e_2');
|
expect(cmd).toBe('OidbSvcTrpcTcp.0xb6e_2');
|
||||||
const body = vi.mocked(oidb.makeOidbEnvelope).mock.calls[0]![2];
|
const body = vi.mocked(oidb.makeOidbEnvelope).mock.calls[0]![2];
|
||||||
|
|||||||
Reference in new issue
Block a user