//
//  APIErrorTests.swift
//  suixinkanTests
//

import XCTest
@testable import suixinkan

/// 网络错误测试，覆盖登录凭证失效判断。
final class APIErrorTests: XCTestCase {
    func testAuthenticationExpiredForUnauthorizedHTTPStatus() {
        XCTAssertTrue(APIError.isAuthenticationExpired(APIError.httpStatus(401, "Unauthorized")))
        XCTAssertTrue(APIError.isAuthenticationExpired(APIError.httpStatus(403, "Forbidden")))
    }

    func testAuthenticationExpiredForAndroidTokenInvalidCodes() {
        for code in [180024, 100091, 100090, 100060] {
            XCTAssertTrue(
                APIError.isAuthenticationExpired(APIError.serverCode(code, "token 失效")),
                "code \(code) 应识别为 token 失效"
            )
        }
    }

    func testNetworkErrorIsNotAuthenticationExpired() {
        XCTAssertFalse(APIError.isAuthenticationExpired(APIError.networkFailed("请求超时，请稍后重试")))
        XCTAssertFalse(APIError.isAuthenticationExpired(APIError.serverCode(100001, "密码错误")))
    }
}
