import Foundation import Testing @testable import PediFoods @Test("PushDeepLinkParser parses order_status with an explicit orderId") func parsesOrderStatusWithExplicitOrderId() { let userInfo: [AnyHashable: Any] = ["type": "order_status", "orderId": "order-1", "shortId": "SHORT1"] let destination = PushDeepLinkParser.parse(userInfo) #expect(destination == .orderTracking(orderId: "order-1", shortId: "SHORT1")) } @Test("PushDeepLinkParser falls back to shortId as the orderId when orderId is absent") func fallsBackToShortIdAsOrderId() { let userInfo: [AnyHashable: Any] = ["type": "order_status", "shortId": "SHORT1"] let destination = PushDeepLinkParser.parse(userInfo) #expect(destination == .orderTracking(orderId: "SHORT1", shortId: "SHORT1")) } @Test("PushDeepLinkParser returns nil for order_status with neither orderId nor shortId") func returnsNilForOrderStatusWithNoIdentifiers() { let userInfo: [AnyHashable: Any] = ["type": "order_status"] #expect(PushDeepLinkParser.parse(userInfo) == nil) } @Test("PushDeepLinkParser parses a targetScreen payload into .screen with its params") func parsesTargetScreenWithParams() { let userInfo: [AnyHashable: Any] = [ "targetScreen": "promo", "couponId": "abc123", "storeId": "store-9" ] guard case let .screen(name, params) = PushDeepLinkParser.parse(userInfo) else { Issue.record("expected .screen destination") return } #expect(name == "promo") #expect(params == ["couponId": "abc123", "storeId": "store-9"]) } @Test("PushDeepLinkParser excludes type and targetScreen keys from the screen's params") func excludesRoutingKeysFromScreenParams() { let userInfo: [AnyHashable: Any] = ["type": "campaign", "targetScreen": "promo", "couponId": "abc123"] guard case let .screen(_, params) = PushDeepLinkParser.parse(userInfo) else { Issue.record("expected .screen destination") return } #expect(params["type"] == nil) #expect(params["targetScreen"] == nil) #expect(params["couponId"] == "abc123") } @Test("PushDeepLinkParser returns nil for a payload with neither order_status nor targetScreen") func returnsNilForUnroutablePayload() { let userInfo: [AnyHashable: Any] = ["type": "campaign", "campaignId": "c1"] #expect(PushDeepLinkParser.parse(userInfo) == nil) } @Test("PushDeepLinkParser drops non-String param values from a screen payload") func dropsNonStringParamValues() { let userInfo: [AnyHashable: Any] = ["targetScreen": "promo", "count": 5, "label": "sale"] guard case let .screen(_, params) = PushDeepLinkParser.parse(userInfo) else { Issue.record("expected .screen destination") return } #expect(params["count"] == nil) #expect(params["label"] == "sale") }