mirror of
https://wget.la/https://github.com/Wxw-Gu/WechatExplorer
synced 2026-08-17 19:47:08 +08:00
1. 修复数据量较大时,历史数据可能无法完整导出的问题 2. 优化分享 Tab 的信息展示,支持小程序、链接、地图等消息 3. 优化系统 Tab 的信息展示,支持红包、转账、拍一拍、撤回等消息 4. 修复默认进入时,时间轴不随消息自动定位的问题 5. 增加“定位到聊天位置”功能
72 lines
2.5 KiB
TypeScript
72 lines
2.5 KiB
TypeScript
import { describe, expect, it, vi } from 'vitest'
|
|
import { WechatDb, type WechatMessage } from '../../src/main/wechat-db'
|
|
|
|
describe('WechatDb normalized messages', () => {
|
|
it('keeps normalized identity fields when raw table columns conflict', async () => {
|
|
const normalized = {
|
|
mesLocalID: '1',
|
|
serverId: 'server-1',
|
|
mesDes: 0,
|
|
messageType: '1',
|
|
msgCreateTime: '1731327263',
|
|
msgContent: 'fixture',
|
|
sender: 'wxid_self',
|
|
senderNickname: 'Nanin',
|
|
raw: {
|
|
mesDes: 1,
|
|
sender: '',
|
|
senderNickname: ''
|
|
}
|
|
}
|
|
const client = { getMessagesAsync: vi.fn(async () => [normalized]) }
|
|
const db = Object.assign(Object.create(WechatDb.prototype), {
|
|
wcdb4Client: client,
|
|
chatMd5ToUsername: new Map([['fixture-md5', 'fixture-user']]),
|
|
ensureChatTableMapping: vi.fn()
|
|
}) as WechatDb
|
|
|
|
const start = Math.floor(new Date(2024, 10, 11).getTime() / 1000)
|
|
const end = Math.floor(new Date(2024, 11, 1).getTime() / 1000)
|
|
const messages = await db.getUserMessagesForExport('fixture-md5', start, end)
|
|
|
|
expect(messages[0]).toMatchObject({
|
|
mesDes: 0,
|
|
sender: 'wxid_self',
|
|
senderNickname: 'Nanin'
|
|
})
|
|
})
|
|
|
|
it('scans without time bounds, then filters, deduplicates and sorts in application code', async () => {
|
|
const row = (id: string, createTime: number): WechatMessage => ({
|
|
mesLocalID: id,
|
|
serverId: `server-${id}`,
|
|
mesDes: 0,
|
|
messageType: '1',
|
|
msgCreateTime: String(createTime),
|
|
msgContent: id,
|
|
raw: {}
|
|
})
|
|
const start = Math.floor(new Date(2025, 0, 1).getTime() / 1000)
|
|
const end = Math.floor(new Date(2025, 0, 4).getTime() / 1000)
|
|
const shardBoundaryMessage = row('jan-2-boundary', start + 32 * 60 * 60)
|
|
const getMessagesAsync = vi.fn(async () => [
|
|
row('before-range', start - 1),
|
|
row('newest', start + 48 * 60 * 60),
|
|
shardBoundaryMessage,
|
|
{ ...shardBoundaryMessage },
|
|
row('after-range', end + 1)
|
|
])
|
|
const db = Object.assign(Object.create(WechatDb.prototype), {
|
|
wcdb4Client: { getMessagesAsync },
|
|
chatMd5ToUsername: new Map([['fixture-md5', 'fixture-user']]),
|
|
ensureChatTableMapping: vi.fn()
|
|
}) as WechatDb
|
|
|
|
const messages = await db.getUserMessagesForExport('fixture-md5', start, end)
|
|
|
|
expect(getMessagesAsync).toHaveBeenCalledOnce()
|
|
expect(getMessagesAsync).toHaveBeenCalledWith('fixture-user')
|
|
expect(messages.map((message) => message.mesLocalID)).toEqual(['jan-2-boundary', 'newest'])
|
|
})
|
|
})
|