- 添加 expiresAt 和 refreshUserSig 参数支持自动续签 - 修改 PushSDK 初始化方式,自动完成设备注册和厂商初始化 - 调整过期续签策略,从提前 15 分钟改为提前 5 分钟触发 - 重构 RN SDK 文档结构,简化安装和使用方式 - 更新统一登录流程,支持 profile 信息传递 - 添加 IM 数据库自动隔离功能 - 修复 Android 群消息聚合问题 - 补充自动化测试验证和错误处理机制
35 行
1.7 KiB
TypeScript
35 行
1.7 KiB
TypeScript
import test from 'node:test'
|
|
import assert from 'node:assert/strict'
|
|
import { buildDbName, sortConversations, sortMessages } from '../src/runtime'
|
|
|
|
test('buildDbName derives a stable per-user database name', () => {
|
|
assert.equal(buildDbName('ak_demo_chat', 'demo_alice'), 'xuqm_im_ak_demo_chat_demo_alice')
|
|
})
|
|
|
|
test('sortConversations keeps pinned conversations first and then sorts by time', () => {
|
|
const conversations = sortConversations([
|
|
{ targetId: 'c', chatType: 'SINGLE', lastMsgTime: 100, unreadCount: 0, isMuted: false, isPinned: false },
|
|
{ targetId: 'a', chatType: 'SINGLE', lastMsgTime: 80, unreadCount: 0, isMuted: false, isPinned: true },
|
|
{ targetId: 'b', chatType: 'GROUP', lastMsgTime: 120, unreadCount: 0, isMuted: false, isPinned: false },
|
|
{ targetId: 'd', chatType: 'GROUP', lastMsgTime: 120, unreadCount: 0, isMuted: false, isPinned: false },
|
|
])
|
|
|
|
assert.deepEqual(
|
|
conversations.map((item) => `${item.chatType}:${item.targetId}`),
|
|
['SINGLE:a', 'GROUP:b', 'GROUP:d', 'SINGLE:c'],
|
|
)
|
|
})
|
|
|
|
test('sortMessages deduplicates by message id and sorts newest first', () => {
|
|
const messages = sortMessages([
|
|
{ id: 'm2', appId: 'ak', fromUserId: 'u1', toId: 'peer', chatType: 'SINGLE', msgType: 'TEXT', content: 'old', status: 'SENT', createdAt: 100 },
|
|
{ id: 'm1', appId: 'ak', fromUserId: 'u1', toId: 'peer', chatType: 'SINGLE', msgType: 'TEXT', content: 'latest', status: 'SENT', createdAt: 200 },
|
|
{ id: 'm1', appId: 'ak', fromUserId: 'u1', toId: 'peer', chatType: 'SINGLE', msgType: 'TEXT', content: 'duplicate', status: 'READ', createdAt: 180 },
|
|
])
|
|
|
|
assert.deepEqual(
|
|
messages.map((item) => `${item.id}:${item.createdAt}:${item.content}`),
|
|
['m1:200:latest', 'm2:100:old'],
|
|
)
|
|
})
|