fix: confirm cooling off account switch
This commit is contained in:
@@ -120,6 +120,16 @@ final class AccountSwitchViewController: BaseViewController, UITableViewDelegate
|
|||||||
navigationController?.popViewController(animated: true)
|
navigationController?.popViewController(animated: true)
|
||||||
return
|
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) }
|
Task { await switchAccount(account) }
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -47,6 +47,34 @@ final class AccountSwitchViewModelTests: XCTestCase {
|
|||||||
XCTAssertEqual(viewModel.selectedAccount?.businessUserId, 9001)
|
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 {
|
func testSwitchAccountThrowsWhenBusinessUserIdInvalid() async {
|
||||||
let viewModel = AccountSwitchViewModel()
|
let viewModel = AccountSwitchViewModel()
|
||||||
let account = AccountSwitchAccount(
|
let account = AccountSwitchAccount(
|
||||||
|
|||||||
Reference in New Issue
Block a user