Files
suixinkan_uikit/suixinkanTests/APIErrorTests.swift

30 lines
1.0 KiB
Swift
Raw Permalink Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

//
// 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, "密码错误")))
}
}