Files
WechatExplorer/tests/unit/personal-wechat-capability-service.test.ts
T
Wxw-Gu cf9ea8a83b feat: 优化 macOS 微信发送消息能力
参考 wechat_chatter PR #36:
https://github.com/yincongcyincong/wechat_chatter/pull/36

补充 WeChat 4.1.11.53 的 GetService / CdnManager 地址,
并适配绑定后的发送能力检测逻辑。
2026-09-14 15:59:08 +08:00

75 lines
2.4 KiB
TypeScript

import { describe, expect, it, vi } from 'vitest'
vi.mock('electron', () => ({ app: { getPath: () => '/tmp/tracememo-test-user-data' } }))
import { PersonalWechatCapabilityService } from '../../src/main/services/personal-wechat-capability-service'
import type { PersonalWechatSenderStatus } from '../../src/shared/personal-wechat'
const status = (
overrides: Partial<PersonalWechatSenderStatus> = {}
): PersonalWechatSenderStatus => ({
state: 'hook_not_ready',
platform: 'darwin',
arch: 'arm64',
sipDisabled: true,
wechatRunning: true,
wechatPid: 123,
endpoint: '127.0.0.1:58080',
endpointReady: true,
runtimeReady: true,
attachReady: true,
baseAddressReady: true,
textHookInstalled: true,
textHookReady: false,
imageHookInstalled: true,
imageHookReady: false,
messageListenerReady: true,
canSend: false,
canSendText: false,
canSendImage: false,
canSendVoice: false,
message: 'pending',
...overrides
})
describe('PersonalWechatCapabilityService', () => {
it.each([
['unsupported', status({ platform: 'linux' })],
['unconfigured', status({ runtimeReady: false, boundWechatPid: undefined })],
['needs_binding', status({ runtimeReady: true, boundWechatPid: undefined })],
['needs_binding', status({ runtimeReady: true, boundWechatPid: 999 })],
['initializing', status({ boundWechatPid: 123 })],
['ready', status({ state: 'online', boundWechatPid: 123, canSendImage: true, canSend: true })],
[
'ready',
status({
state: 'online',
boundWechatPid: 123,
canSend: true,
canSendText: true,
canSendImage: false,
canSendVoice: true
})
],
['error', status({ state: 'error', boundWechatPid: 123, error: 'hook failed' })],
['initializing', status({ platform: 'win32', endpoint: '127.0.0.1:4567' })],
[
'ready',
status({
platform: 'win32',
state: 'online',
endpoint: '127.0.0.1:4567',
canSend: true,
canSendText: true,
canSendImage: true,
canSendVoice: true
})
]
])('maps %s', (expected, senderStatus) => {
const service = new PersonalWechatCapabilityService({ getStatus: async () => senderStatus })
return expect(service.getPersonalWechatSendCapability()).resolves.toMatchObject({
status: expected,
ready: expected === 'ready',
supported: expected !== 'unsupported'
})
})
})