XuqmGroup-iOSSDK/Tests/XuqmSDKTests/SmokeTests.swift
XuqmGroup e016adbb71 chore(ci): 更新 Jenkins 配置以支持多模块版本管理
- 为 Android、Flutter、iOS 和 RN SDK 的 Jenkinsfile 添加模块化版本控制
- 引入版本升级策略选择(major/minor/patch)和自定义版本号功能
- 实现多模块独立版本管理和选择性构建发布
- 更新 iOS SDK Package.swift 以支持独立模块化库
- 修改 iOS SDK podspec 文件以适应新的标签命名约定
- 优化 Jenkins 构建流程以支持按需选择特定模块进行构建和发布
- 修复 iOS 测试中的可选类型转换问题以提高代码健壮性
2026-05-23 01:20:57 +08:00

102 行
3.1 KiB
Swift

import XCTest
@testable import XuqmSDK
final class SmokeTests: XCTestCase {
func testSDKConfig() {
let config = SDKConfig(appKey: "ak_test", debug: true, autoRegisterPush: false)
XCTAssertEqual(config.appKey, "ak_test")
XCTAssertTrue(config.debug)
XCTAssertFalse(config.autoRegisterPush)
XCTAssertEqual(config.appKey, "ak_test")
}
func testTokenStoreSaveGetClear() {
let store = TokenStore()
store.save("test_token_123")
XCTAssertEqual(store.get(), "test_token_123")
store.clear()
XCTAssertNil(store.get())
}
func testImMessageCoding() throws {
let msg = ImMessage(
id: "msg_1",
appKey: "ak_test",
fromUserId: "user_a",
fromId: "user_a",
toId: "user_b",
chatType: .single,
msgType: .text,
content: "Hello",
status: .sent,
mentionedUserIds: nil as String?,
groupReadCount: nil as Int?,
revoked: false,
createdAt: 1714300000000,
editedAt: nil as Int64?
)
let data = try JSONEncoder().encode(msg)
let decoded = try JSONDecoder().decode(ImMessage.self, from: data)
XCTAssertEqual(decoded.id, "msg_1")
XCTAssertEqual(decoded.content, "Hello")
XCTAssertEqual(decoded.status, .sent)
}
func testChatTypeAndMsgTypeRawValues() {
XCTAssertEqual(ChatType.single.rawValue, "SINGLE")
XCTAssertEqual(ChatType.group.rawValue, "GROUP")
XCTAssertEqual(MsgType.text.rawValue, "TEXT")
XCTAssertEqual(MsgType.revoked.rawValue, "REVOKED")
}
func testPageResultDecoding() throws {
let json = """
{
"content": [{"id": "1"}],
"totalElements": 10,
"totalPages": 1,
"size": 20,
"number": 0,
"numberOfElements": 1,
"first": true,
"last": true,
"empty": false
}
""".data(using: .utf8)!
struct Item: Codable, Sendable { let id: String }
let result = try JSONDecoder().decode(PageResult<Item>.self, from: json)
XCTAssertEqual(result.content.count, 1)
XCTAssertEqual(result.totalElements, 10)
XCTAssertTrue(result.first)
}
func testApiResponseDecoding() throws {
let json = """
{
"code": 200,
"status": "0",
"data": {"token": "abc123"},
"message": "success"
}
""".data(using: .utf8)!
struct TokenData: Decodable { let token: String }
let response = try JSONDecoder().decode(ApiResponse<TokenData>.self, from: json)
XCTAssertEqual(response.code, 200)
XCTAssertEqual(response.data?.token, "abc123")
}
func testEmptyResponse() throws {
let json = """
{
"code": 200,
"status": "0",
"data": null,
"message": "success"
}
""".data(using: .utf8)!
let response = try JSONDecoder().decode(ApiResponse<EmptyResponse>.self, from: json)
XCTAssertEqual(response.code, 200)
}
}