From 656b473454fa8774d504b3d343696390d908ba1a Mon Sep 17 00:00:00 2001 From: Vladimir Espinola Date: Thu, 11 Jul 2024 15:38:31 -0400 Subject: [PATCH] updated events init signatures to accept deeplink --- Sources/Public/Events/ATTNAddToCartEvent.swift | 10 ++++++++-- Sources/Public/Events/ATTNProductViewEvent.swift | 8 +++++++- Tests/TestCases/ATTNProductViewEventTests.swift | 3 +-- 3 files changed, 16 insertions(+), 5 deletions(-) diff --git a/Sources/Public/Events/ATTNAddToCartEvent.swift b/Sources/Public/Events/ATTNAddToCartEvent.swift index 4323338..7e02c09 100644 --- a/Sources/Public/Events/ATTNAddToCartEvent.swift +++ b/Sources/Public/Events/ATTNAddToCartEvent.swift @@ -12,9 +12,15 @@ public final class ATTNAddToCartEvent: NSObject, ATTNEvent { @objc public let items: [ATTNItem] @objc public var deeplink: String? - @objc - public init(items: [ATTNItem]) { + @objc(initWithItems:) + public convenience init(items: [ATTNItem]) { + self.init(items: items) + } + + @objc(initWithItems:deeplink:) + public init(items: [ATTNItem], deeplink: String?) { self.items = items + self.deeplink = deeplink super.init() } diff --git a/Sources/Public/Events/ATTNProductViewEvent.swift b/Sources/Public/Events/ATTNProductViewEvent.swift index 22b0cb6..7ac0176 100644 --- a/Sources/Public/Events/ATTNProductViewEvent.swift +++ b/Sources/Public/Events/ATTNProductViewEvent.swift @@ -13,8 +13,14 @@ public final class ATTNProductViewEvent: NSObject, ATTNEvent { @objc public var deeplink: String? @objc(initWithItems:) - public init(items: [ATTNItem]) { + public convenience init(items: [ATTNItem]) { + self.init(items: items, deeplink: nil) + } + + @objc(initWithItems:deeplink:) + public init(items: [ATTNItem], deeplink: String?) { self.items = items + self.deeplink = deeplink super.init() } diff --git a/Tests/TestCases/ATTNProductViewEventTests.swift b/Tests/TestCases/ATTNProductViewEventTests.swift index 3ba71e7..33ebf6b 100644 --- a/Tests/TestCases/ATTNProductViewEventTests.swift +++ b/Tests/TestCases/ATTNProductViewEventTests.swift @@ -20,8 +20,7 @@ final class ATTNProductViewEventTests: XCTestCase { func testProductView_GivenData_ShouldBuildURLWithRequestURL() { let item = ATTNTestEventUtils.buildItem() - let productView = ATTNProductViewEvent(items: [item]) - productView.deeplink = "https://www.clientapp.com/flow=payment" + let productView = ATTNProductViewEvent(items: [item], deeplink: "https://www.clientapp.com/flow=payment") XCTAssertFalse(productView.eventRequests.isEmpty) let requestURL = productView.eventRequests.first?.metadata["requestURL"] as? String XCTAssertNotNil(requestURL)