Skip to content
38 changes: 21 additions & 17 deletions Braintree.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,6 @@
084135452ED0CBAD00884FE9 /* Assets.xcassets in Resources */ = {isa = PBXBuildFile; fileRef = 0841353E2ED0CBAD00884FE9 /* Assets.xcassets */; };
084135472ED0DCCC00884FE9 /* PaymentButtonColorProtocol.swift in Sources */ = {isa = PBXBuildFile; fileRef = 084135462ED0DCCC00884FE9 /* PaymentButtonColorProtocol.swift */; };
0848260C2FAB8DAD008C754F /* ExpirationDateFieldValidatorTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 0848260B2FAB8DAD008C754F /* ExpirationDateFieldValidatorTests.swift */; };
FDCDC009DA7E4809AA4BCE98 /* ExpirationDateFieldViewModelTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = C8A6A6CDCC4845908AF49560 /* ExpirationDateFieldViewModelTests.swift */; };
086D56D02F8566B500120B47 /* CardBrand.swift in Sources */ = {isa = PBXBuildFile; fileRef = 086D56CF2F8566B500120B47 /* CardBrand.swift */; };
086D56D62F8568BB00120B47 /* CardNumberFieldValidatorTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 086D56D52F8568BB00120B47 /* CardNumberFieldValidatorTests.swift */; };
087831332F7B09CE003BB460 /* BraintreeCard.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = A7C889901B5F043B007A0E9C /* BraintreeCard.framework */; platformFilter = ios; };
Expand Down Expand Up @@ -147,8 +146,6 @@
624454DE2DDE399D00A3383B /* CreateCustomerSessionMutationGraphQLBody.swift in Sources */ = {isa = PBXBuildFile; fileRef = 624454DD2DDE398200A3383B /* CreateCustomerSessionMutationGraphQLBody.swift */; };
624B27F72B6AE0C2000AC08A /* BTShopperInsightsError.swift in Sources */ = {isa = PBXBuildFile; fileRef = 624B27F62B6AE0C2000AC08A /* BTShopperInsightsError.swift */; };
625010722F9FF5E000EFB8E0 /* BTSEPADirectDebitClient_IntegrationTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 625010712F9FF5D700EFB8E0 /* BTSEPADirectDebitClient_IntegrationTests.swift */; };
701D2C1EC8604C8EBCB24E9A /* BraintreeShopperInsights_IntegrationTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 743B93AD5C7644ABAC2D5436 /* BraintreeShopperInsights_IntegrationTests.swift */; };
E943983246FD4C94BAA4C009 /* BraintreeShopperInsights.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 804698302B27C5340090878E /* BraintreeShopperInsights.framework */; };
625719C52F0DBAF6008D019E /* BTHTTPMethod.swift in Sources */ = {isa = PBXBuildFile; fileRef = 625719C42F0DBAE2008D019E /* BTHTTPMethod.swift */; };
62970D102B5AF2C000BAB584 /* BTShopperInsightsAnalytics_Tests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 62970D0E2B5AE1E400BAB584 /* BTShopperInsightsAnalytics_Tests.swift */; };
6298A1992B91010600E46EDF /* PrivacyInfo.xcprivacy in Resources */ = {isa = PBXBuildFile; fileRef = 6298A1982B91010600E46EDF /* PrivacyInfo.xcprivacy */; };
Expand All @@ -163,6 +160,8 @@
62D5754A2D5299A700DCDAC1 /* ThreeDSecureAuthenticateJWTPOSTBody.swift in Sources */ = {isa = PBXBuildFile; fileRef = 62D575492D5299A700DCDAC1 /* ThreeDSecureAuthenticateJWTPOSTBody.swift */; };
62DE8FBF2B9656BF00F08F53 /* PrivacyInfo.xcprivacy in Resources */ = {isa = PBXBuildFile; fileRef = 62DE8FBE2B9656BF00F08F53 /* PrivacyInfo.xcprivacy */; };
62EA90492B63071800DD79BC /* BTEligiblePaymentMethods.swift in Sources */ = {isa = PBXBuildFile; fileRef = 62EA90482B63071800DD79BC /* BTEligiblePaymentMethods.swift */; };
701D2C1EC8604C8EBCB24E9A /* BraintreeShopperInsights_IntegrationTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 743B93AD5C7644ABAC2D5436 /* BraintreeShopperInsights_IntegrationTests.swift */; };
7D23803B4E27445996D398A9 /* CardFieldsViewModelTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 86EB7865AE0445228D4BF677 /* CardFieldsViewModelTests.swift */; };
800E78C429E0DD5300D1B0FC /* FPTIBatchData.swift in Sources */ = {isa = PBXBuildFile; fileRef = 800E78C329E0DD5300D1B0FC /* FPTIBatchData.swift */; };
800ED7832B4F5B66007D8A30 /* BTEligiblePaymentsRequest.swift in Sources */ = {isa = PBXBuildFile; fileRef = 800ED7822B4F5B66007D8A30 /* BTEligiblePaymentsRequest.swift */; };
800FC544257FDC5100DEE132 /* BTApplePayCardNonce_Tests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 800FC543257FDC5100DEE132 /* BTApplePayCardNonce_Tests.swift */; };
Expand Down Expand Up @@ -441,6 +440,8 @@
BEFE9A3B29C8EC6B00BF69AB /* BTCardClient.swift in Sources */ = {isa = PBXBuildFile; fileRef = BEFE9A3A29C8EC6B00BF69AB /* BTCardClient.swift */; };
BEFE9A3D29C8ECAA00BF69AB /* BTCardError.swift in Sources */ = {isa = PBXBuildFile; fileRef = BEFE9A3C29C8ECAA00BF69AB /* BTCardError.swift */; };
CE836AA02E4FDCE300AC7FCA /* UIApplication+ApplicationState.swift in Sources */ = {isa = PBXBuildFile; fileRef = CE836A9F2E4FDCE000AC7FCA /* UIApplication+ApplicationState.swift */; };
E943983246FD4C94BAA4C009 /* BraintreeShopperInsights.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 804698302B27C5340090878E /* BraintreeShopperInsights.framework */; };
FDCDC009DA7E4809AA4BCE98 /* ExpirationDateFieldViewModelTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = C8A6A6CDCC4845908AF49560 /* ExpirationDateFieldViewModelTests.swift */; };
/* End PBXBuildFile section */

/* Begin PBXContainerItemProxy section */
Expand Down Expand Up @@ -486,21 +487,21 @@
remoteGlobalIDString = A7C8898F1B5F043B007A0E9C;
remoteInfo = BraintreeCard;
};
622160F32FA103570072377B /* PBXContainerItemProxy */ = {
19BBD08D78BD4A2AB8A39FC4 /* PBXContainerItemProxy */ = {
isa = PBXContainerItemProxy;
containerPortal = A75DA344192138F000D997A2 /* Project object */;
proxyType = 1;
remoteGlobalIDString = BEF3F17227CE9EC600072467;
remoteInfo = BraintreeSEPADirectDebit;
remoteGlobalIDString = 8046982F2B27C5340090878E;
remoteInfo = BraintreeShopperInsights;
};
804698432B27C5530090878E /* PBXContainerItemProxy */ = {
622160F32FA103570072377B /* PBXContainerItemProxy */ = {
isa = PBXContainerItemProxy;
containerPortal = A75DA344192138F000D997A2 /* Project object */;
proxyType = 1;
remoteGlobalIDString = 8046982F2B27C5340090878E;
remoteInfo = BraintreeShopperInsights;
remoteGlobalIDString = BEF3F17227CE9EC600072467;
remoteInfo = BraintreeSEPADirectDebit;
};
19BBD08D78BD4A2AB8A39FC4 /* PBXContainerItemProxy */ = {
804698432B27C5530090878E /* PBXContainerItemProxy */ = {
isa = PBXContainerItemProxy;
containerPortal = A75DA344192138F000D997A2 /* Project object */;
proxyType = 1;
Expand Down Expand Up @@ -853,7 +854,6 @@
084135402ED0CBAD00884FE9 /* VenmoButtonColor.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = VenmoButtonColor.swift; sourceTree = "<group>"; };
084135462ED0DCCC00884FE9 /* PaymentButtonColorProtocol.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = PaymentButtonColorProtocol.swift; sourceTree = "<group>"; };
0848260B2FAB8DAD008C754F /* ExpirationDateFieldValidatorTests.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = ExpirationDateFieldValidatorTests.swift; sourceTree = "<group>"; };
C8A6A6CDCC4845908AF49560 /* ExpirationDateFieldViewModelTests.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = ExpirationDateFieldViewModelTests.swift; sourceTree = "<group>"; };
086D56CF2F8566B500120B47 /* CardBrand.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = CardBrand.swift; sourceTree = "<group>"; };
086D56D52F8568BB00120B47 /* CardNumberFieldValidatorTests.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = CardNumberFieldValidatorTests.swift; sourceTree = "<group>"; };
087831382F7C1666003BB460 /* ValidationResult.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = ValidationResult.swift; sourceTree = "<group>"; };
Expand Down Expand Up @@ -982,7 +982,6 @@
624454DD2DDE398200A3383B /* CreateCustomerSessionMutationGraphQLBody.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = CreateCustomerSessionMutationGraphQLBody.swift; sourceTree = "<group>"; };
624B27F62B6AE0C2000AC08A /* BTShopperInsightsError.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = BTShopperInsightsError.swift; sourceTree = "<group>"; };
625010712F9FF5D700EFB8E0 /* BTSEPADirectDebitClient_IntegrationTests.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = BTSEPADirectDebitClient_IntegrationTests.swift; sourceTree = "<group>"; };
743B93AD5C7644ABAC2D5436 /* BraintreeShopperInsights_IntegrationTests.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = BraintreeShopperInsights_IntegrationTests.swift; sourceTree = "<group>"; };
625719C42F0DBAE2008D019E /* BTHTTPMethod.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = BTHTTPMethod.swift; sourceTree = "<group>"; };
62970D0E2B5AE1E400BAB584 /* BTShopperInsightsAnalytics_Tests.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = BTShopperInsightsAnalytics_Tests.swift; sourceTree = "<group>"; };
6298A1982B91010600E46EDF /* PrivacyInfo.xcprivacy */ = {isa = PBXFileReference; lastKnownFileType = text.xml; path = PrivacyInfo.xcprivacy; sourceTree = "<group>"; };
Expand All @@ -997,6 +996,7 @@
62D575492D5299A700DCDAC1 /* ThreeDSecureAuthenticateJWTPOSTBody.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = ThreeDSecureAuthenticateJWTPOSTBody.swift; sourceTree = "<group>"; };
62DE8FBE2B9656BF00F08F53 /* PrivacyInfo.xcprivacy */ = {isa = PBXFileReference; lastKnownFileType = text.xml; path = PrivacyInfo.xcprivacy; sourceTree = "<group>"; };
62EA90482B63071800DD79BC /* BTEligiblePaymentMethods.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = BTEligiblePaymentMethods.swift; sourceTree = "<group>"; };
743B93AD5C7644ABAC2D5436 /* BraintreeShopperInsights_IntegrationTests.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = BraintreeShopperInsights_IntegrationTests.swift; sourceTree = "<group>"; };
800E23DC22206A8300C5D22E /* BTThreeDSecureAuthenticateJWT_Tests.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = BTThreeDSecureAuthenticateJWT_Tests.swift; sourceTree = "<group>"; };
800E78C329E0DD5300D1B0FC /* FPTIBatchData.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = FPTIBatchData.swift; sourceTree = "<group>"; };
800ED7822B4F5B66007D8A30 /* BTEligiblePaymentsRequest.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = BTEligiblePaymentsRequest.swift; sourceTree = "<group>"; };
Expand Down Expand Up @@ -1058,6 +1058,7 @@
842B68F01BCF083E0039634F /* BTAPIClient_Tests.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = BTAPIClient_Tests.swift; sourceTree = "<group>"; };
844ED5E61BCC3F0B002B590C /* BTDataCollector_Tests.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = BTDataCollector_Tests.swift; sourceTree = "<group>"; };
85BD589D380436A0C9D1DEC1 /* Pods_Tests_IntegrationTests.framework */ = {isa = PBXFileReference; explicitFileType = wrapper.framework; includeInIndex = 0; path = Pods_Tests_IntegrationTests.framework; sourceTree = BUILT_PRODUCTS_DIR; };
86EB7865AE0445228D4BF677 /* CardFieldsViewModelTests.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = CardFieldsViewModelTests.swift; sourceTree = "<group>"; };
9239C9FE850C3587DE61A3A2 /* Pods_Tests_BraintreeCoreTests.framework */ = {isa = PBXFileReference; explicitFileType = wrapper.framework; includeInIndex = 0; path = Pods_Tests_BraintreeCoreTests.framework; sourceTree = BUILT_PRODUCTS_DIR; };
95BE4D272F10173D003C139D /* BTPayPalFundingSource.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = BTPayPalFundingSource.swift; sourceTree = "<group>"; };
9C36BD4226B30AA600F0A559 /* PPRiskMagnes.xcframework */ = {isa = PBXFileReference; expectedSignature = "AppleDeveloperProgram:XEZPTDFLAS:changching chi"; lastKnownFileType = wrapper.xcframework; name = PPRiskMagnes.xcframework; path = Frameworks/XCFrameworks/PPRiskMagnes.xcframework; sourceTree = "<group>"; };
Expand Down Expand Up @@ -1267,6 +1268,7 @@
BEFE6DA927E28A0B002BE9C8 /* MockViewController.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = MockViewController.swift; sourceTree = "<group>"; };
BEFE9A3A29C8EC6B00BF69AB /* BTCardClient.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = BTCardClient.swift; sourceTree = "<group>"; };
BEFE9A3C29C8ECAA00BF69AB /* BTCardError.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = BTCardError.swift; sourceTree = "<group>"; };
C8A6A6CDCC4845908AF49560 /* ExpirationDateFieldViewModelTests.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = ExpirationDateFieldViewModelTests.swift; sourceTree = "<group>"; };
CE836A9F2E4FDCE000AC7FCA /* UIApplication+ApplicationState.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = "UIApplication+ApplicationState.swift"; sourceTree = "<group>"; };
/* End PBXFileReference section */

Expand Down Expand Up @@ -1560,6 +1562,7 @@
081F74722EF099D8002D53EA /* VenmoButton_Tests.swift */,
086D56D52F8568BB00120B47 /* CardNumberFieldValidatorTests.swift */,
08804D472F86D61E005ED3AC /* CVVFieldViewModelTests.swift */,
86EB7865AE0445228D4BF677 /* CardFieldsViewModelTests.swift */,
2863A507CC454374A3E14E6A /* CardNumberFieldViewModelTests.swift */,
08804D482F86D61E005ED3AC /* CVVFieldValidatorTests.swift */,
0848260B2FAB8DAD008C754F /* ExpirationDateFieldValidatorTests.swift */,
Expand Down Expand Up @@ -3684,6 +3687,7 @@
FDCDC009DA7E4809AA4BCE98 /* ExpirationDateFieldViewModelTests.swift in Sources */,
081F74732EF099D8002D53EA /* VenmoButton_Tests.swift in Sources */,
08804D492F86D61E005ED3AC /* CVVFieldViewModelTests.swift in Sources */,
7D23803B4E27445996D398A9 /* CardFieldsViewModelTests.swift in Sources */,
2863A507CC454374A3E14E6B /* CardNumberFieldViewModelTests.swift in Sources */,
08804D4A2F86D61E005ED3AC /* CVVFieldValidatorTests.swift in Sources */,
);
Expand Down Expand Up @@ -4215,16 +4219,16 @@
target = BEF3F17227CE9EC600072467 /* BraintreeSEPADirectDebit */;
targetProxy = 622160F32FA103570072377B /* PBXContainerItemProxy */;
};
804698442B27C5530090878E /* PBXTargetDependency */ = {
66A126AF330B4AF798BC043F /* PBXTargetDependency */ = {
isa = PBXTargetDependency;
platformFilter = ios;
target = 8046982F2B27C5340090878E /* BraintreeShopperInsights */;
targetProxy = 804698432B27C5530090878E /* PBXContainerItemProxy */;
targetProxy = 19BBD08D78BD4A2AB8A39FC4 /* PBXContainerItemProxy */;
};
66A126AF330B4AF798BC043F /* PBXTargetDependency */ = {
804698442B27C5530090878E /* PBXTargetDependency */ = {
isa = PBXTargetDependency;
platformFilter = ios;
target = 8046982F2B27C5340090878E /* BraintreeShopperInsights */;
targetProxy = 19BBD08D78BD4A2AB8A39FC4 /* PBXContainerItemProxy */;
targetProxy = 804698432B27C5530090878E /* PBXContainerItemProxy */;
};
80AB42522B27CAC200249218 /* PBXTargetDependency */ = {
isa = PBXTargetDependency;
Expand Down
2 changes: 2 additions & 0 deletions Sources/BraintreeUIComponents/CardFields/CardFields.swift
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import BraintreeCard
import BraintreeCore
import SwiftUI

/// A SwiftUI view that renders a complete card entry form, including fields for card number,
Expand Down Expand Up @@ -60,6 +61,7 @@ public struct CardFields: View {
}
.padding()
.onAppear {
viewModel.sendAnalyticsEvent(UIComponentsAnalytics.cardFieldsPresented)
onValidityChange?(viewModel.isFormValid, viewModel.tokenize)
}
.onChange(of: viewModel.isFormValid) { _, isValid in
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import BraintreeCard
import BraintreeCore
import Combine
import Foundation

Expand All @@ -15,6 +16,7 @@ final class CardFieldsViewModel: ObservableObject {

// MARK: - Private Properties

var apiClient: BTAPIClient

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

does this need to be private 👀

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ah yep! Good call thanks

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actually sorry it is exposed for testing like the current pattern for the other clients. I moved and added docstring to follow existing pattern

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Your comment and Jax's below sort of intersected, so ended up changing this up

private let cardClient: BTCardClient
private let card: BTCard
private let completion: (BTCardNonce?, Error?) -> Void
Expand All @@ -27,6 +29,7 @@ final class CardFieldsViewModel: ObservableObject {
card: BTCard,
completion: @escaping (BTCardNonce?, Error?) -> Void
) {
self.apiClient = BTAPIClient(authorization: authorization)
self.cardClient = BTCardClient(authorization: authorization)
self.card = card
self.completion = completion
Expand All @@ -45,9 +48,15 @@ final class CardFieldsViewModel: ObservableObject {

// MARK: - Internal Methods

func sendAnalyticsEvent(_ event: String) {
apiClient.sendAnalyticsEvent(event)
}

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nit: can we add a docstring to this? It took me a second to wrap my head around what was going on. Alternatively we could consider constructing the apiClient in CardFields and passing it as a param to the view model? That way we aren't constructing it twice which on fast connections could mean 2 config calls before it's in the cache. Then we can send both events in the same place. What do you think?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

yep passing the client in from CardFields works! I briefly thought about going down that road early on, but I think it makes much more sense than having this weird phantom 2nd apiClient.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Updated

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Updated again to remove the apiClient directly from the viewModel. I had to create a submitAction to house the analytics and tokenize call to use it in the onvalid closure check


func tokenize() {
guard isFormValid else { return }

sendAnalyticsEvent(UIComponentsAnalytics.cardFieldsSelected)

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nit: could we callapiClient.sendAnalyticsEvent() directly here instead of going through the helper 👀


let card = card.merging(
cardNumber: cardNumberViewModel.value,
expirationMonth: expirationDateViewModel.expirationMonth,
Expand Down
5 changes: 5 additions & 0 deletions Sources/BraintreeUIComponents/UIComponentsAnalytics.swift
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,11 @@ import Foundation

enum UIComponentsAnalytics {

// MARK: - Card Fields Events

static let cardFieldsPresented = "ui-components:card-fields:presented"
static let cardFieldsSelected = "ui-components:card-fields:selected"

// MARK: - PayPal Button Events

static let payPalButtonPresented = "ui-components:paypal-button:presented"
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
import XCTest
import BraintreeCard
import BraintreeCore
@testable import BraintreeTestShared
@testable import BraintreeUIComponents

@MainActor
final class CardFieldsViewModelTests: XCTestCase {

private var mockAPIClient = MockAPIClient(authorization: "development_testing_tokenization_key_sandbox")
private var viewModel = CardFieldsViewModel(

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nit: it looks like we're initializing the same on line 19

Suggested change
private var viewModel = CardFieldsViewModel(
private var viewModel = CardFieldsViewModel

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ope yep fixed!

authorization: "development_testing_tokenization_key_sandbox",
card: BTCard()
) { _, _ in }

override func setUp() {
super.setUp()
mockAPIClient = MockAPIClient(authorization: "development_testing_tokenization_key_sandbox")
viewModel = CardFieldsViewModel(
authorization: "development_testing_tokenization_key_sandbox",
card: BTCard()
) { _, _ in }
viewModel.apiClient = mockAPIClient
}

// MARK: - Analytics

func testSendAnalyticsEvent_cardFieldsPresented_postsCorrectEvent() {
viewModel.sendAnalyticsEvent(UIComponentsAnalytics.cardFieldsPresented)

XCTAssertTrue(mockAPIClient.postedAnalyticsEvents.contains(UIComponentsAnalytics.cardFieldsPresented))
}

func testTokenize_whenFormIsValid_postsSubmittedEvent() {
viewModel.cardNumberViewModel.updateValue("4111111111111111")
viewModel.expirationDateViewModel.updateValue("12/45")
viewModel.cvvViewModel.updateValue("123")

viewModel.tokenize()

XCTAssertTrue(mockAPIClient.postedAnalyticsEvents.contains(UIComponentsAnalytics.cardFieldsSelected))
}
}
Loading