2026-04-28 10:27:23 +08:00
|
|
|
import XCTest
|
|
|
|
|
@testable import XuqmSDK
|
|
|
|
|
|
|
|
|
|
final class SmokeTests: XCTestCase {
|
2026-04-30 19:23:22 +08:00
|
|
|
|
|
|
|
|
func testSDKConfig() {
|
2026-05-05 17:54:59 +08:00
|
|
|
let config = SDKConfig(appKey: "ak_test", debug: true, autoRegisterPush: false)
|
2026-04-30 19:23:22 +08:00
|
|
|
XCTAssertEqual(config.appKey, "ak_test")
|
2026-05-05 17:54:59 +08:00
|
|
|
XCTAssertTrue(config.debug)
|
|
|
|
|
XCTAssertFalse(config.autoRegisterPush)
|
2026-05-07 19:39:48 +08:00
|
|
|
XCTAssertEqual(config.appKey, "ak_test")
|
2026-04-30 19:23:22 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
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",
|
2026-05-07 19:39:48 +08:00
|
|
|
appKey: "ak_test",
|
2026-04-30 19:23:22 +08:00
|
|
|
fromUserId: "user_a",
|
|
|
|
|
fromId: "user_a",
|
|
|
|
|
toId: "user_b",
|
|
|
|
|
chatType: .single,
|
|
|
|
|
msgType: .text,
|
|
|
|
|
content: "Hello",
|
|
|
|
|
status: .sent,
|
|
|
|
|
mentionedUserIds: nil,
|
|
|
|
|
groupReadCount: nil,
|
|
|
|
|
revoked: false,
|
|
|
|
|
createdAt: 1714300000000,
|
|
|
|
|
editedAt: nil
|
|
|
|
|
)
|
|
|
|
|
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)
|
2026-04-28 10:27:23 +08:00
|
|
|
}
|
|
|
|
|
}
|