mirror of
https://wget.la/https://github.com/Wxw-Gu/WechatExplorer
synced 2026-10-08 15:43:22 +08:00
fix: 修复联系人 API 因昵称备注未补全导致搜索结果为空 #51
Fixes https://github.com/Wxw-Gu/TraceMemo/issues/51
This commit is contained in:
@@ -0,0 +1,44 @@
|
||||
import { describe, expect, it } from 'vitest'
|
||||
import type { Contact } from '../../src/shared/types'
|
||||
import { buildContactSearchIndex, filterContactSearchIndex } from '../../src/shared/contact-search'
|
||||
|
||||
/**
|
||||
* Issue #51 regression guard for the *shared* search primitives.
|
||||
*
|
||||
* The bug report claims that when one keyword matches a private contact AND a
|
||||
* group chat, the API returns nothing. These tests pin down that multi-match is
|
||||
* itself NOT the problem: the shared index/filter pair already returns every
|
||||
* match. The real defect lived in the data the HTTP layer fed into it.
|
||||
*/
|
||||
|
||||
const user: Contact = {
|
||||
m_nsUsrName: 'wxid_fixture_user',
|
||||
m_nsNickName: '张三',
|
||||
md5: 'fixture-user-md5',
|
||||
type: 'user',
|
||||
remark: '张三'
|
||||
}
|
||||
|
||||
const group: Contact = {
|
||||
m_nsUsrName: 'fixture_group@chatroom',
|
||||
m_nsNickName: '张三的测试群',
|
||||
md5: 'fixture-group-md5',
|
||||
type: 'group'
|
||||
}
|
||||
|
||||
describe('filterContactSearchIndex with a keyword hitting a contact and a group', () => {
|
||||
it('returns both matches instead of collapsing to an empty list', () => {
|
||||
const index = buildContactSearchIndex([user, group])
|
||||
expect(filterContactSearchIndex(index, '张三')).toEqual([user, group])
|
||||
})
|
||||
|
||||
it('still isolates the results with type=user', () => {
|
||||
const index = buildContactSearchIndex([user, group])
|
||||
expect(filterContactSearchIndex(index, '张三', 'user')).toEqual([user])
|
||||
})
|
||||
|
||||
it('still isolates the results with type=group', () => {
|
||||
const index = buildContactSearchIndex([user, group])
|
||||
expect(filterContactSearchIndex(index, '张三', 'group')).toEqual([group])
|
||||
})
|
||||
})
|
||||
Reference in New Issue
Block a user