Files
suixinkan_ios_new/suixinkanTests/AuthModelsTests.swift
汉秋 d27438b264 补充 Auth/Tasks/ScenicPermission/Live 单元测试,并完善 UI Test 登录与会话稳定性。
移除 LoginViewModel 硬编码账号,扩展登录流程测试覆盖;调整 ZLoginSmokeUITests 执行顺序与路由直达逻辑,避免清空 Keychain 影响其它用例。

Co-authored-by: Cursor <cursoragent@cursor.com>
2026-06-26 12:44:10 +08:00

96 lines
3.7 KiB
Swift
Raw 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.

//
// AuthModelsTests.swift
// suixinkanTests
//
// Created by Codex on 2026/6/26.
//
import XCTest
@testable import suixinkan
/// Auth v9
final class AuthModelsTests: XCTestCase {
/// fixture
func testV9AuthResponseDecodesMultiAccountFixture() throws {
let response = try TestFixture.payload(V9AuthResponse.self, named: "v9_login_multi_success")
XCTAssertEqual(response.token, "person-temp-token")
XCTAssertEqual(response.scenicUsers.count, 1)
XCTAssertEqual(response.storeUsers.count, 1)
XCTAssertEqual(response.accounts.map(\.businessUserId), [101, 201])
}
/// 使 ss_user_id ID
func testV9ScenicUserBusinessUserIdPrefersSsUserId() throws {
let json = """
{
"account_type": "scenic_user",
"id": 1,
"user_id": 2,
"scenic_user_id": 3,
"ss_user_id": 101,
"username": "scenic_admin",
"real_name": "",
"nickname": "",
"phone": "13800138000",
"scenic_id": 10,
"scenic_name": "",
"is_current": false
}
""".data(using: .utf8)!
let user = try JSONDecoder().decode(V9ScenicUser.self, from: json)
XCTAssertEqual(user.businessUserId, 101)
XCTAssertEqual(user.toAccountSwitchAccount().accountType, V9ScenicUser.accountTypeValue)
XCTAssertEqual(user.toAccountSwitchAccount().toSetUserRequest(), SetUserRequest(ssUserId: 101))
}
/// 使 store_user_id ID
func testV9StoreUserBusinessUserIdPrefersStoreUserId() throws {
let json = """
{
"account_type": "store_user",
"id": 1,
"user_id": 2,
"store_user_id": 201,
"username": "store_admin",
"user_name": "store_admin",
"real_name": "",
"phone": "13800138000",
"avatar": "",
"scenic_id": 10,
"scenic_name": "",
"store_id": 20,
"store_name": "",
"is_current": false
}
""".data(using: .utf8)!
let user = try JSONDecoder().decode(V9StoreUser.self, from: json)
XCTAssertEqual(user.businessUserId, 201)
XCTAssertEqual(user.toAccountSwitchAccount().accountType, V9StoreUser.accountTypeValue)
XCTAssertEqual(user.toAccountSwitchAccount().toSetUserRequest(), SetUserRequest(storeUserId: 201))
}
///
func testV9AuthResponseDerivesScopesFromAccounts() throws {
let response = try TestFixture.payload(V9AuthResponse.self, named: "v9_login_multi_success")
XCTAssertEqual(response.scenicScopes.map(\.id), [10])
XCTAssertEqual(response.storeScopes.map(\.id), [20])
XCTAssertEqual(response.primaryProfile?.displayName, "示例门店")
}
/// LoginRequest
func testLoginRequestEncodesExpectedDefaults() throws {
let request = LoginRequest(username: "18651857230", password: "secret123")
let json = try JSONSerialization.jsonObject(with: JSONEncoder().encode(request)) as? [String: Any]
XCTAssertEqual(json?["username"] as? String, "18651857230")
XCTAssertEqual(json?["password"] as? String, "secret123")
XCTAssertEqual(json?["type"] as? Int, 1)
XCTAssertEqual(json?["mobile"] as? String, "")
XCTAssertEqual(json?["code"] as? String, "")
}
}