// // yanaAPITests.swift // yanaAPITests // // Created by P on 2025/5/27. // import XCTest @testable import yana final class yanaAPITests: XCTestCase { override func setUpWithError() throws { // Put setup code here. This method is called before the invocation of each test method in the class. } override func tearDownWithError() throws { // Put teardown code here. This method is called after the invocation of each test method in the class. } func testExample() throws { // This is an example of a functional test case. // Use XCTAssert and related functions to verify your tests produce the correct results. // Any test you write for XCTest can be annotated as throws and async. // Mark your test throws to produce an unexpected failure when your test encounters an uncaught error. // Mark your test async to allow awaiting for asynchronous code to complete. Check the results with assertions afterwards. } func testPerformanceExample() throws { // This is an example of a performance test case. measure { // Put the code you want to measure the time of here. } } func testIDLoginRequest_Creation() { // 测试ID登录请求的创建 let userID = "399113" let password = "a123456" let request = LoginHelper.createIDLoginRequest(userID: userID, password: password) XCTAssertNotNil(request, "登录请求应该创建成功") XCTAssertEqual(request?.endpoint, "/oauth/token", "端点应该正确") XCTAssertEqual(request?.method, .POST, "请求方法应该是POST") } func testIDLoginResponse_Success() { // 测试登录响应的成功解析 let successResponse = IDLoginResponse( status: "success", message: "登录成功", code: 200, data: IDLoginData( accessToken: "test_token", refreshToken: "refresh_token", tokenType: "Bearer", expiresIn: 3600, scope: "read write", userInfo: UserInfo( userId: "123", username: "testuser", nickname: "Test User", avatar: nil, email: "test@example.com", phone: "399113", status: "active", createTime: "2024-01-01", updateTime: "2024-01-01" ) ) ) XCTAssertTrue(successResponse.isSuccess, "响应应该标记为成功") XCTAssertEqual(successResponse.data?.accessToken, "test_token", "访问令牌应该正确") } }