Skip to content

Commit

Permalink
Fixed failing unit test
Browse files Browse the repository at this point in the history
  • Loading branch information
stechiu committed Dec 17, 2024
1 parent 2e56774 commit 4fa49cf
Show file tree
Hide file tree
Showing 4 changed files with 11 additions and 21 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -122,7 +122,11 @@ public class BTShopperInsightsClient {
/// Call this method when a button has been selected/tapped by the buyer.
/// This method sends analytics to help improve the Shopper Insights feature experience.
public func sendSelectedEvent(for buttonType: BTButtonType) {
apiClient.sendAnalyticsEvent(BTShopperInsightsAnalytics.buttonSelected, shopperSessionID: shopperSessionID)
apiClient.sendAnalyticsEvent(
BTShopperInsightsAnalytics.buttonSelected,
buttonType: buttonType.rawValue,
shopperSessionID: shopperSessionID
)
}

/// Indicates whether the PayPal App is installed.
Expand Down
18 changes: 0 additions & 18 deletions UnitTests/BraintreePayPalTests/BTPayPalClient_Tests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -982,24 +982,6 @@ class BTPayPalClient_Tests: XCTestCase {
XCTAssertNil(lastPostParameters["merchant_app_return_url"] as? String)
}

func testInvokedOpenURLSuccessfully_whenSuccess_sendsAppSwitchSucceededWithAppSwitchURL() {
let eventName = BTPayPalAnalytics.appSwitchSucceeded
let fakeURL = URL(string: "some-url")!
payPalClient.invokedOpenURLSuccessfully(true, url: fakeURL) { _, _ in }

XCTAssertEqual(mockAPIClient.postedAnalyticsEvents.last!, eventName)
XCTAssertEqual(mockAPIClient.postedAppSwitchURL[eventName], fakeURL.absoluteString)
}

func testInvokedOpenURLSuccessfully_whenFailure_sendsAppSwitchFailedWithAppSwitchURL() {
let eventName = BTPayPalAnalytics.appSwitchFailed
let fakeURL = URL(string: "some-url")!
payPalClient.invokedOpenURLSuccessfully(false, url: fakeURL) { _, _ in }

XCTAssertEqual(mockAPIClient.postedAnalyticsEvents.first!, eventName)
XCTAssertEqual(mockAPIClient.postedAppSwitchURL[eventName], fakeURL.absoluteString)
}

// MARK: - Analytics

func testAPIClientMetadata_hasIntegrationSetToCustom() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -224,8 +224,9 @@ class BTShopperInsightsClient_Tests: XCTestCase {
sut.sendSelectedEvent(for: .payPal)
XCTAssertEqual(mockAPIClient.postedAnalyticsEvents.first, "shopper-insights:button-selected")
XCTAssertEqual(mockAPIClient.postedShopperSessionID, "fake-shopper-session-id")
XCTAssertEqual(mockAPIClient.postedButtonType, "PayPal")
}

func testSendVenmoPresentedEvent_sendsAnalytic() {
sut.sendVenmoPresentedEvent()
XCTAssertEqual(mockAPIClient.postedAnalyticsEvents.first, "shopper-insights:venmo-presented")
Expand All @@ -235,6 +236,7 @@ class BTShopperInsightsClient_Tests: XCTestCase {
func testSendVenmoSelectedEvent_sendsAnalytic() {
sut.sendSelectedEvent(for: .venmo)
XCTAssertEqual(mockAPIClient.postedAnalyticsEvents.first, "shopper-insights:button-selected")
XCTAssertEqual(mockAPIClient.postedButtonType, "Venmo")
}

func testShopperInsightsClient_withSessionID_setSessionIDInMetadata() {
Expand Down
4 changes: 3 additions & 1 deletion UnitTests/BraintreeTestShared/MockAPIClient.swift
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,8 @@ public class MockAPIClient: BTAPIClient {
public var lastGETParameters = [:] as [String: Any]?
public var lastGETAPIClientHTTPType: BTAPIClientHTTPService?

public var postedAnalyticsEvents : [String] = []
public var postedButtonType: String? = nil
public var postedAnalyticsEvents: [String] = []
public var postedPayPalContextID: String? = nil
public var postedLinkType: LinkType? = nil
public var postedIsVaultRequest = false
Expand Down Expand Up @@ -106,6 +107,7 @@ public class MockAPIClient: BTAPIClient {
appSwitchURL: URL? = nil,
shopperSessionID: String? = nil
) {
postedButtonType = buttonType
postedPayPalContextID = payPalContextID
postedLinkType = linkType
postedIsVaultRequest = isVaultRequest ?? false
Expand Down

0 comments on commit 4fa49cf

Please sign in to comment.