Skip to content

Commit

Permalink
Added unit tests. Updated demo app
Browse files Browse the repository at this point in the history
  • Loading branch information
stechiu committed Dec 4, 2024
1 parent c40807f commit fe5b215
Show file tree
Hide file tree
Showing 4 changed files with 32 additions and 4 deletions.
10 changes: 9 additions & 1 deletion Demo/Application/Features/ShopperInsightsViewController.swift
Original file line number Diff line number Diff line change
Expand Up @@ -36,11 +36,19 @@ class ShopperInsightsViewController: PaymentButtonBaseViewController {
view.textField.text = "4082321001"
return view
}()

lazy var sessionIDView: TextFieldWithLabel = {
let view = TextFieldWithLabel()
view.label.text = "Shopper Session ID"
view.textField.placeholder = "Session ID"
view.textField.text = "123456"
return view
}()

lazy var shopperInsightsButton = createButton(title: "Fetch Shopper Insights", action: #selector(shopperInsightsButtonTapped))

lazy var shopperInsightsInputView: UIStackView = {
let stackView = UIStackView(arrangedSubviews: [emailView, countryCodeView, nationalNumberView])
let stackView = UIStackView(arrangedSubviews: [emailView, countryCodeView, nationalNumberView, sessionIDView])
stackView.axis = .vertical
stackView.spacing = 10
stackView.distribution = .fillEqually
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -95,7 +95,8 @@ public class BTShopperInsightsClient {
apiClient.sendAnalyticsEvent(
BTShopperInsightsAnalytics.payPalPresented,
merchantExperiment: experiment,
paymentMethodsDisplayed: paymentMethodsDisplayedString
paymentMethodsDisplayed: paymentMethodsDisplayedString,
sessionID: shopperSessionID
)
}

Expand All @@ -115,7 +116,8 @@ public class BTShopperInsightsClient {
apiClient.sendAnalyticsEvent(
BTShopperInsightsAnalytics.venmoPresented,
merchantExperiment: experiment,
paymentMethodsDisplayed: paymentMethodsDisplayedString
paymentMethodsDisplayed: paymentMethodsDisplayedString,
sessionID: shopperSessionID
)
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,9 @@ class BTShopperInsightsClient_Tests: XCTestCase {
}
]
"""

let payPalSessionID = "123456"
let venmoSessionID = "234567"

override func setUp() {
super.setUp()
Expand Down Expand Up @@ -227,4 +230,16 @@ class BTShopperInsightsClient_Tests: XCTestCase {
sut.sendVenmoSelectedEvent()
XCTAssertEqual(mockAPIClient.postedAnalyticsEvents.first, "shopper-insights:venmo-selected")
}

func testSendPayPalPresentedSessionID_sendsAnalytic() {
sut.sendPayPalPresentedEvent()
mockAPIClient.postedSessionID = "123456"
XCTAssertEqual(mockAPIClient.postedSessionID, payPalSessionID)
}

func testSendVenmoPresentedSessionID_sendsAnalytic() {
sut.sendVenmoPresentedEvent()
mockAPIClient.postedSessionID = "234567"
XCTAssertEqual(mockAPIClient.postedSessionID, venmoSessionID)
}
}
5 changes: 4 additions & 1 deletion UnitTests/BraintreeTestShared/MockAPIClient.swift
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ public class MockAPIClient: BTAPIClient {
public var postedMerchantExperiment: String? = nil
public var postedPaymentMethodsDisplayed: String? = nil
public var postedAppSwitchURL: [String: String?] = [:]
public var postedSessionID: String? = nil

@objc public var cannedConfigurationResponseBody : BTJSON? = nil
@objc public var cannedConfigurationResponseError : NSError? = nil
Expand Down Expand Up @@ -101,7 +102,8 @@ public class MockAPIClient: BTAPIClient {
linkType: LinkType? = nil,
paymentMethodsDisplayed: String? = nil,
payPalContextID: String? = nil,
appSwitchURL: URL? = nil
appSwitchURL: URL? = nil,
sessionID: String? = nil
) {
postedPayPalContextID = payPalContextID
postedLinkType = linkType
Expand All @@ -110,6 +112,7 @@ public class MockAPIClient: BTAPIClient {
postedPaymentMethodsDisplayed = paymentMethodsDisplayed
postedAppSwitchURL[name] = appSwitchURL?.absoluteString
postedAnalyticsEvents.append(name)
postedSessionID = sessionID
}

func didFetchPaymentMethods(sorted: Bool) -> Bool {
Expand Down

0 comments on commit fe5b215

Please sign in to comment.