30 lines
1.1 KiB
Swift
30 lines
1.1 KiB
Swift
//
|
||
// APIErrorTests.swift
|
||
// suixinkanTests
|
||
//
|
||
// Created by Codex on 2026/6/20.
|
||
//
|
||
|
||
import XCTest
|
||
@testable import suixinkan
|
||
|
||
/// 网络错误测试,覆盖登录凭证失效判断。
|
||
final class APIErrorTests: XCTestCase {
|
||
/// 测试 HTTP 401 和 403 会被识别为登录失效。
|
||
func testAuthenticationExpiredForUnauthorizedHTTPStatus() {
|
||
XCTAssertTrue(APIError.isAuthenticationExpired(APIError.httpStatus(401, "Unauthorized")))
|
||
XCTAssertTrue(APIError.isAuthenticationExpired(APIError.httpStatus(403, "Forbidden")))
|
||
}
|
||
|
||
/// 测试后端业务码和中文失效文案会被识别为登录失效。
|
||
func testAuthenticationExpiredForServerTokenMessages() {
|
||
XCTAssertTrue(APIError.isAuthenticationExpired(APIError.serverCode(200001, "token 已过期")))
|
||
XCTAssertTrue(APIError.isAuthenticationExpired(APIError.serverCode(0, "登录失效,请重新登录")))
|
||
}
|
||
|
||
/// 测试普通网络错误不会被识别为登录失效。
|
||
func testNetworkErrorIsNotAuthenticationExpired() {
|
||
XCTAssertFalse(APIError.isAuthenticationExpired(APIError.networkFailed("请求超时,请稍后重试")))
|
||
}
|
||
}
|