fix: confirm cooling off account switch

This commit is contained in:
2026-08-31 17:01:26 +08:00
parent b8343ad9eb
commit 9b65913bc4
2 changed files with 38 additions and 0 deletions
@@ -120,6 +120,16 @@ final class AccountSwitchViewController: BaseViewController, UITableViewDelegate
navigationController?.popViewController(animated: true)
return
}
if account.requiresDeregistrationConfirmation {
present(
makeDeregistrationLoginAlert(account: account) { [weak self] in
guard let self else { return }
Task { await self.switchAccount(account) }
},
animated: true
)
return
}
Task { await switchAccount(account) }
}
@@ -47,6 +47,34 @@ final class AccountSwitchViewModelTests: XCTestCase {
XCTAssertEqual(viewModel.selectedAccount?.businessUserId, 9001)
}
func testSwitchableAccountsPreserveCoolingOffStoreStatus() async throws {
let json = """
{
"code": 100000,
"msg": "success",
"data": {
"store_users": [
{
"account_type": "store_user",
"store_user_id": 2001,
"store_name": "冷静期门店",
"status": 2
}
]
}
}
""".data(using: .utf8)!
let session = MockURLSession(responses: [json])
let api = ProfileAPI(client: APIClient(environment: .testing, session: session))
let viewModel = AccountSwitchViewModel()
try await viewModel.load(api: api, force: true)
XCTAssertEqual(viewModel.accounts.first?.status, 2)
XCTAssertTrue(viewModel.accounts.first?.requiresDeregistrationConfirmation == true)
}
func testSwitchAccountThrowsWhenBusinessUserIdInvalid() async {
let viewModel = AccountSwitchViewModel()
let account = AccountSwitchAccount(