fix: route payment pushes to orders and prevent refresh crash

This commit is contained in:
2026-09-08 09:59:51 +08:00
parent 10249776ad
commit c4b0e7798b
10 changed files with 333 additions and 47 deletions
+34 -4
View File
@@ -27,10 +27,10 @@ final class PushNotificationTests: XCTestCase {
super.tearDown()
}
func testPayloadRoutesPaymentTypesToTheirPages() {
func testPayloadRoutesOrderAndScanTypesToTheirPages() {
XCTAssertEqual(
PushPayload(userInfo: ["type": 1, "route": "message_center"]).destination,
.paymentRecord
.orders
)
XCTAssertEqual(
PushPayload(userInfo: ["type": "6", "action": "task_management"]).destination,
@@ -38,6 +38,36 @@ final class PushNotificationTests: XCTestCase {
)
}
func testOrderTypesSupportNumbersStringsAndVendorWrappers() {
for type in [1, 5] {
XCTAssertEqual(PushPayload(userInfo: ["type": type]).destination, .orders)
XCTAssertEqual(PushPayload(userInfo: ["type": "\(type)"]).destination, .orders)
XCTAssertEqual(PushPayload(userInfo: ["extras": "{\"type\":\(type)}"]).destination, .orders)
XCTAssertEqual(PushPayload(values: ["type": "\(type)"]).destination, .orders)
}
}
func testOrderNotificationReturnsToOrdersRootAndDeduplicatesPendingRoute() {
let coordinator = PushRouteCoordinator(appStore: appStore)
let window = UIWindow(frame: UIScreen.main.bounds)
coordinator.attach(window: window)
coordinator.handle(destination: .orders, requestIdentifier: "order-request")
authenticate(userID: "100")
let mainTab = MainTabBarController()
mainTab.loadViewIfNeeded()
mainTab.selectTab(.orders)
let ordersNavigation = mainTab.selectedViewController as? TabNavigationController
ordersNavigation?.pushViewController(UIViewController(), animated: false)
mainTab.selectTab(.home)
window.rootViewController = mainTab
coordinator.routePendingIfPossible()
XCTAssertTrue(mainTab.selectedViewController === ordersNavigation)
XCTAssertEqual(ordersNavigation?.viewControllers.count, 1)
XCTAssertTrue(ordersNavigation?.topViewController is OrdersViewController)
coordinator.handle(destination: .messageCenter, requestIdentifier: "order-request")
XCTAssertTrue(mainTab.selectedViewController === ordersNavigation)
}
func testPayloadIgnoresNonTypeRoutingFieldsAndOtherTypesFallBackToMessageCenter() {
let conflictingFields: [AnyHashable: Any] = [
"type": 2,
@@ -46,7 +76,7 @@ final class PushNotificationTests: XCTestCase {
"action": "收款",
]
[0, 2, 3, 4, 5, 7, 8, 9, 10, 11, 12, 100, 999].forEach { type in
[0, 2, 3, 4, 7, 8, 9, 10, 11, 12, 100, 999].forEach { type in
XCTAssertEqual(PushPayload(userInfo: ["type": type]).destination, .messageCenter)
}
XCTAssertEqual(PushPayload(userInfo: conflictingFields).destination, .messageCenter)
@@ -220,7 +250,7 @@ final class PushNotificationTests: XCTestCase {
payload: PushPayload(userInfo: ["type": 1, "route": "task_management"]),
requestIdentifier: "request-1"
)
XCTAssertEqual(router.destinations, [.paymentRecord])
XCTAssertEqual(router.destinations, [.orders])
}
func testRemoteNotificationNotifiesUnreadMessageStateChange() async {