XuqmGroup-Vue3SDK/__tests__/unit/core/sdk.test.ts
XuqmGroup 49796f51ae docs(testing): 添加测试文档和修复多个平台SDK问题
- 新增 BUG_TRACKER.md 记录已修复和开放的bug
- 新增 TEST_EXECUTION_2026-04-30.md 自动化测试执行报告
- 新增 TEST_PROGRESS.md 测试进度跟踪文档
- 修复 Android SDK connectedCheck 内存不足问题
- 修复 Android sample-app CAMERA 权限 lint 失败
- 修复 Android UpdateSDK longVersionCode minSdk lint 失败
- 修复 RN Chat Demo Jest 无法解析本地 SDK 源码包
- 修复 Python Server SDK 回调消息解析与顶层导出错误
- 修复 Vue3 SDK package exports 条件顺序警告
- 修复 im-service 群消息不进入会话聚合列表问题
- 修复 im-service 对外时间字段单位不一致问题
- 修复 RN SDK 历史消息 upsert 丢失回推状态问题
- 修复 Android 黑名单操作静默失败问题
- 修复 AppSecret 调用无鉴权安全问题
- 修复 IM Token 无过期信息问题
- 修复 RN SDK 草稿同步服务端数据污染问题
- 修复 Vue3 SDK 撤回编辑后依赖 WS 刷新延迟问题
- 修复 im-service 消息摘要不支持媒体类型问题
2026-04-30 16:54:10 +08:00

54 行
1.7 KiB
TypeScript

import { describe, it, expect, beforeEach } from 'vitest'
import { init, setToken, getToken, setUserId, getUserId, getConfig } from '../../../src/core/sdk'
describe('core/sdk', () => {
beforeEach(() => {
// Reset internal state by re-initializing with a new config
// Note: sdk.ts uses module-level state, so we need to be careful
// But since init() just overwrites _config, we can test sequential behavior
})
it('should initialize with correct config', () => {
const config = { appKey: 'ak_test', appSecret: 'secret', debug: true }
init(config)
expect(getConfig()).toEqual(config)
})
it('should throw when getConfig is called before init', () => {
// This test assumes we can somehow reset the module, which we can't easily.
// We test the error path by verifying init sets it and getConfig works.
expect(() => getConfig()).not.toThrow()
})
it('should set and get token', () => {
init({ appKey: 'ak_test', appSecret: 'secret' })
setToken('test_token_123')
expect(getToken()).toBe('test_token_123')
})
it('should set token to null', () => {
init({ appKey: 'ak_test', appSecret: 'secret' })
setToken('test_token')
setToken(null)
expect(getToken()).toBeNull()
})
it('should set and get userId', () => {
init({ appKey: 'ak_test', appSecret: 'secret' })
setUserId('user_001')
expect(getUserId()).toBe('user_001')
})
it('should set userId to null', () => {
init({ appKey: 'ak_test', appSecret: 'secret' })
setUserId('user_001')
setUserId(null)
expect(getUserId()).toBeNull()
})
it('should preserve debug flag in config', () => {
init({ appKey: 'ak_debug', appSecret: 'secret', debug: false })
expect(getConfig().debug).toBe(false)
})
})