Initial commit: suixinkan_ios UIKit rewrite project.

Co-authored-by: Cursor <cursoragent@cursor.com>
This commit is contained in:
2026-06-26 14:33:31 +08:00
commit 9edf993432
297 changed files with 47151 additions and 0 deletions

View File

@ -0,0 +1,95 @@
//
// AuthModelsTests.swift
// suixinkanTests
//
// Created by Codex on 2026/6/26.
//
import XCTest
@testable import suixinkan_ios
/// 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, "")
}
}