mirror of
https://wget.la/https://github.com/Wxw-Gu/WechatExplorer
synced 2026-08-17 19:47:08 +08:00
feat: 完善多账号连接诊断与聊天媒体导出
- 新增微信账号发现、环境诊断和分步数据库连接引导 - 支持按账号安全保存数据库密钥及快速切换账号 - 完善 WCDB 历史消息分片读取和分页状态提示 - 支持导出图片、视频和语音,提供原图优先及缩略图回退 - 更新安装指引、兼容版本说明和相关自动化测试
This commit is contained in:
@@ -0,0 +1,69 @@
|
||||
import fs from 'fs-extra'
|
||||
import os from 'os'
|
||||
import path from 'path'
|
||||
import { afterEach, beforeEach, describe, expect, it, vi } from 'vitest'
|
||||
|
||||
const mocked = vi.hoisted(() => ({
|
||||
userData: `${process.env.TEMP || process.env.TMP || '.'}/wxe-account-discovery-tests`
|
||||
}))
|
||||
|
||||
vi.mock('electron', () => ({
|
||||
app: { getPath: () => mocked.userData }
|
||||
}))
|
||||
|
||||
import { discoverAccounts } from '../../src/main/services/account-discovery'
|
||||
|
||||
describe('account discovery', () => {
|
||||
let root: string
|
||||
const keyStore = {
|
||||
getStatus: vi.fn(async (accountRoot: string) => ({
|
||||
saved: accountRoot.endsWith('account-b'),
|
||||
encryptionAvailable: true
|
||||
}))
|
||||
}
|
||||
|
||||
beforeEach(async () => {
|
||||
root = await fs.mkdtemp(path.join(os.tmpdir(), 'wxe-accounts-'))
|
||||
await Promise.all(
|
||||
['account-a', 'account-b', 'account-c'].map((name) =>
|
||||
fs.ensureDir(path.join(root, name, 'db_storage'))
|
||||
)
|
||||
)
|
||||
await fs.ensureDir(path.join(root, 'Backup'))
|
||||
})
|
||||
|
||||
afterEach(async () => {
|
||||
await fs.remove(root)
|
||||
await fs.remove(mocked.userData)
|
||||
})
|
||||
|
||||
it('rejects an invalid Backup directory without continuing', async () => {
|
||||
const result = await discoverAccounts(path.join(root, 'Backup'), keyStore as never)
|
||||
expect(result.success).toBe(false)
|
||||
expect(result.accounts).toEqual([])
|
||||
})
|
||||
|
||||
it('lists every direct account and never preselects one from a root directory', async () => {
|
||||
const result = await discoverAccounts(root, keyStore as never)
|
||||
expect(result.success).toBe(true)
|
||||
expect(result.accounts.map((account) => account.directoryName).sort()).toEqual([
|
||||
'account-a',
|
||||
'account-b',
|
||||
'account-c'
|
||||
])
|
||||
expect(result.preselectedAccountId).toBeUndefined()
|
||||
expect(
|
||||
result.accounts.find((account) => account.directoryName === 'account-b')?.hasSavedDbKey
|
||||
).toBe(true)
|
||||
})
|
||||
|
||||
it('preselects a directly selected account directory while retaining its card', async () => {
|
||||
const accountRoot = path.join(root, 'account-c')
|
||||
const result = await discoverAccounts(accountRoot, keyStore as never)
|
||||
expect(result.success).toBe(true)
|
||||
expect(result.accounts).toHaveLength(1)
|
||||
expect(result.accounts[0].accountRoot).toBe(accountRoot)
|
||||
expect(result.preselectedAccountId).toBe(result.accounts[0].id)
|
||||
expect(result.accounts[0].selectedByInput).toBe(true)
|
||||
})
|
||||
})
|
||||
Reference in New Issue
Block a user