From d8f53255c38a1558fd1fafe1541d532c9197310e Mon Sep 17 00:00:00 2001 From: erenbesel Date: Thu, 25 Jan 2024 10:27:15 +0100 Subject: [PATCH] chore: review updates --- Adyen.xcodeproj/project.pbxproj | 8 ++--- Adyen/Analytics/Models/AdyenAnalytics.swift | 5 ---- ...AbstractPersonalInformationComponent.swift | 2 +- .../StoredPaymentMethodComponent.swift | 2 +- .../Core Protocols/PresentableComponent.swift | 6 ++-- .../UI/{Dimentions.swift => Dimensions.swift} | 0 .../Stored Card/StoredCardComponent.swift | 2 +- .../Scenes/Input/BACSInputPresenter.swift | 2 +- .../BACSDirectDebitComponentTracker.swift | 4 +-- AdyenComponents/Boleto/BoletoComponent.swift | 2 +- .../Analytics/AnalyticsProviderTests.swift | 29 ++----------------- .../Analytics/TelemetryTrackerTests.swift | 12 ++++---- ...ectDebitComponentTrackerProtocolMock.swift | 2 +- ...BACSDirectDebitComponentTrackerTests.swift | 2 +- 14 files changed, 25 insertions(+), 53 deletions(-) rename Adyen/UI/{Dimentions.swift => Dimensions.swift} (100%) diff --git a/Adyen.xcodeproj/project.pbxproj b/Adyen.xcodeproj/project.pbxproj index dc50e54c96..5a7f9097ed 100644 --- a/Adyen.xcodeproj/project.pbxproj +++ b/Adyen.xcodeproj/project.pbxproj @@ -435,7 +435,7 @@ E72375DD27AABF450020DCF9 /* AdyenWeChatPayInternal in Frameworks */ = {isa = PBXBuildFile; productRef = E72375DC27AABF450020DCF9 /* AdyenWeChatPayInternal */; }; E72521EE25517EB100533E35 /* BLIKComponentTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = E72521ED25517EB100533E35 /* BLIKComponentTests.swift */; }; E7275BF9255012F600907CF9 /* FormLabelItem.swift in Sources */ = {isa = PBXBuildFile; fileRef = E7275BF8255012F600907CF9 /* FormLabelItem.swift */; }; - E72D9BAA26A6E66800FBDA48 /* Dimentions.swift in Sources */ = {isa = PBXBuildFile; fileRef = E72D9BA926A6E66800FBDA48 /* Dimentions.swift */; }; + E72D9BAA26A6E66800FBDA48 /* Dimensions.swift in Sources */ = {isa = PBXBuildFile; fileRef = E72D9BA926A6E66800FBDA48 /* Dimensions.swift */; }; E72DA33F23E19DE300707638 /* PreselectedPaymentMethodComponent.swift in Sources */ = {isa = PBXBuildFile; fileRef = E72DA33C23E19DE300707638 /* PreselectedPaymentMethodComponent.swift */; }; E72DA34123E1BE5300707638 /* DropInNavigationController.swift in Sources */ = {isa = PBXBuildFile; fileRef = E72DA34023E1BE5300707638 /* DropInNavigationController.swift */; }; E7388D8523DB1F9A008E62B8 /* DimmingPresentationController.swift in Sources */ = {isa = PBXBuildFile; fileRef = E7388D8423DB1F9A008E62B8 /* DimmingPresentationController.swift */; }; @@ -1699,7 +1699,7 @@ E71E8F3D257921D10054B03D /* StoredBLIKPaymentMethod.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = StoredBLIKPaymentMethod.swift; sourceTree = ""; }; E72521ED25517EB100533E35 /* BLIKComponentTests.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = BLIKComponentTests.swift; sourceTree = ""; }; E7275BF8255012F600907CF9 /* FormLabelItem.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = FormLabelItem.swift; sourceTree = ""; }; - E72D9BA926A6E66800FBDA48 /* Dimentions.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = Dimentions.swift; sourceTree = ""; }; + E72D9BA926A6E66800FBDA48 /* Dimensions.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = Dimensions.swift; sourceTree = ""; }; E72DA33C23E19DE300707638 /* PreselectedPaymentMethodComponent.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = PreselectedPaymentMethodComponent.swift; sourceTree = ""; }; E72DA34023E1BE5300707638 /* DropInNavigationController.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = DropInNavigationController.swift; sourceTree = ""; }; E736497E25277B6500AB76AE /* StringExtension.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = StringExtension.swift; sourceTree = ""; }; @@ -3540,7 +3540,7 @@ E28098B9220DB9E70087928F /* List */, E2C0E0BF220D7E53008616F6 /* Views */, F9175F7625948EDF00D653BE /* View Controllers */, - E72D9BA926A6E66800FBDA48 /* Dimentions.swift */, + E72D9BA926A6E66800FBDA48 /* Dimensions.swift */, ); path = UI; sourceTree = ""; @@ -6478,7 +6478,7 @@ F96F44DD23BE487500871C1F /* LocalizationParameters.swift in Sources */, E7085A8D2627132B00D0153B /* PostalAddress.swift in Sources */, F9589D272601F19E00E4113F /* EmailFormItemInjector.swift in Sources */, - E72D9BAA26A6E66800FBDA48 /* Dimentions.swift in Sources */, + E72D9BAA26A6E66800FBDA48 /* Dimensions.swift in Sources */, F9620DB323C75C19005209FC /* PaymentComponentBuilder.swift in Sources */, F96757BF27CF690600A16FB6 /* PartialPaymentError.swift in Sources */, E7085B122628B29600D0153B /* BasePickerInputControl.swift in Sources */, diff --git a/Adyen/Analytics/Models/AdyenAnalytics.swift b/Adyen/Analytics/Models/AdyenAnalytics.swift index 1684075aab..dc57c9bc46 100644 --- a/Adyen/Analytics/Models/AdyenAnalytics.swift +++ b/Adyen/Analytics/Models/AdyenAnalytics.swift @@ -27,8 +27,3 @@ public final class AdyenAnalytics { internal protocol AdyenAnalyticsCommonFields: Encodable { var commonFields: AdyenAnalytics.CommonFields { get } } - -//@_spi(AdyenInternal) -//public protocol AdyenAnalyticEvent { -// var commonFields: AdyenAnalytics.CommonFields { get } -//} diff --git a/Adyen/Core/Components/AbstractPersonalInformationComponent/AbstractPersonalInformationComponent.swift b/Adyen/Core/Components/AbstractPersonalInformationComponent/AbstractPersonalInformationComponent.swift index 2955caaa15..ab94070530 100644 --- a/Adyen/Core/Components/AbstractPersonalInformationComponent/AbstractPersonalInformationComponent.swift +++ b/Adyen/Core/Components/AbstractPersonalInformationComponent/AbstractPersonalInformationComponent.swift @@ -258,7 +258,7 @@ extension AbstractPersonalInformationComponent: ViewControllerDelegate { // MARK: - ViewControllerDelegate public func viewWillAppear(viewController: UIViewController) { - fetchCheckoutAttemptId() + sendInitialAnalytics() populateFields() } } diff --git a/Adyen/Core/Components/StoredPaymentMethodComponent.swift b/Adyen/Core/Components/StoredPaymentMethodComponent.swift index 6148553d0b..e879714f99 100644 --- a/Adyen/Core/Components/StoredPaymentMethodComponent.swift +++ b/Adyen/Core/Components/StoredPaymentMethodComponent.swift @@ -47,7 +47,7 @@ public final class StoredPaymentMethodComponent: PaymentComponent, flavor: _isDropIn ? .dropin : .components, context: context.apiContext ) - fetchCheckoutAttemptId() + sendInitialAnalytics() let localizationParameters = configuration.localizationParameters let displayInformation = storedPaymentMethod.displayInformation(using: localizationParameters) diff --git a/Adyen/Core/Core Protocols/PresentableComponent.swift b/Adyen/Core/Core Protocols/PresentableComponent.swift index 02af4f94c7..96b6b9b9f8 100644 --- a/Adyen/Core/Core Protocols/PresentableComponent.swift +++ b/Adyen/Core/Core Protocols/PresentableComponent.swift @@ -63,13 +63,13 @@ public extension PresentableComponent { @_spi(AdyenInternal) public protocol TrackableComponent: Component { - func fetchCheckoutAttemptId() + func sendInitialAnalytics() } @_spi(AdyenInternal) extension TrackableComponent where Self: PaymentMethodAware { - public func fetchCheckoutAttemptId() { + public func sendInitialAnalytics() { let flavor: TelemetryFlavor = _isDropIn ? .dropInComponent : .components(type: paymentMethod.type) let amount = context.payment?.amount let additionalFields = AdditionalAnalyticsFields(amount: amount, sessionId: AdyenAnalytics.sessionId) @@ -82,6 +82,6 @@ extension TrackableComponent where Self: PaymentMethodAware { extension TrackableComponent where Self: ViewControllerDelegate { public func viewWillAppear(viewController: UIViewController) { - fetchCheckoutAttemptId() + sendInitialAnalytics() } } diff --git a/Adyen/UI/Dimentions.swift b/Adyen/UI/Dimensions.swift similarity index 100% rename from Adyen/UI/Dimentions.swift rename to Adyen/UI/Dimensions.swift diff --git a/AdyenCard/Components/Stored Card/StoredCardComponent.swift b/AdyenCard/Components/Stored Card/StoredCardComponent.swift index 19c39075ad..84828a9d5b 100644 --- a/AdyenCard/Components/Stored Card/StoredCardComponent.swift +++ b/AdyenCard/Components/Stored Card/StoredCardComponent.swift @@ -42,7 +42,7 @@ internal final class StoredCardComponent: PaymentComponent, PaymentAware, Presen flavor: _isDropIn ? .dropin : .components, context: context.apiContext ) - fetchCheckoutAttemptId() + sendInitialAnalytics() let manager = StoredCardAlertManager(paymentMethod: storedCardPaymentMethod, context: context, diff --git a/AdyenComponents/BACS Direct Debit/Scenes/Input/BACSInputPresenter.swift b/AdyenComponents/BACS Direct Debit/Scenes/Input/BACSInputPresenter.swift index 08e0cead3e..01ce7afcd1 100644 --- a/AdyenComponents/BACS Direct Debit/Scenes/Input/BACSInputPresenter.swift +++ b/AdyenComponents/BACS Direct Debit/Scenes/Input/BACSInputPresenter.swift @@ -56,7 +56,7 @@ internal class BACSInputPresenter: BACSInputPresenterProtocol { // MARK: - BACSInputPresenterProtocol internal func viewDidLoad() { - tracker.fetchCheckoutAttemptId() + tracker.sendInitialAnalytics() createItems() setupView() } diff --git a/AdyenComponents/BACS Direct Debit/Trackers/BACSDirectDebitComponentTracker.swift b/AdyenComponents/BACS Direct Debit/Trackers/BACSDirectDebitComponentTracker.swift index 2de7b4b0ef..c725362eb6 100644 --- a/AdyenComponents/BACS Direct Debit/Trackers/BACSDirectDebitComponentTracker.swift +++ b/AdyenComponents/BACS Direct Debit/Trackers/BACSDirectDebitComponentTracker.swift @@ -8,7 +8,7 @@ import Foundation internal protocol BACSDirectDebitComponentTrackerProtocol: AnyObject { - func fetchCheckoutAttemptId() + func sendInitialAnalytics() } internal class BACSDirectDebitComponentTracker: BACSDirectDebitComponentTrackerProtocol { @@ -31,7 +31,7 @@ internal class BACSDirectDebitComponentTracker: BACSDirectDebitComponentTrackerP // MARK: - BACSDirectDebitComponentTrackerProtocol - internal func fetchCheckoutAttemptId() { + internal func sendInitialAnalytics() { let flavor: TelemetryFlavor = isDropIn ? .dropInComponent : .components(type: paymentMethod.type) let amount = context.payment?.amount let additionalFields = AdditionalAnalyticsFields(amount: amount, sessionId: AdyenAnalytics.sessionId) diff --git a/AdyenComponents/Boleto/BoletoComponent.swift b/AdyenComponents/Boleto/BoletoComponent.swift index abe53ce21c..bf113ac175 100644 --- a/AdyenComponents/Boleto/BoletoComponent.swift +++ b/AdyenComponents/Boleto/BoletoComponent.swift @@ -188,7 +188,7 @@ extension BoletoComponent: ViewControllerDelegate { public func viewDidAppear(viewController: UIViewController) {} public func viewWillAppear(viewController: UIViewController) { - fetchCheckoutAttemptId() + sendInitialAnalytics() prefillFields(for: formComponent) } } diff --git a/Tests/Adyen Tests/Analytics/AnalyticsProviderTests.swift b/Tests/Adyen Tests/Analytics/AnalyticsProviderTests.swift index d2bf83b064..c6779f2268 100644 --- a/Tests/Adyen Tests/Analytics/AnalyticsProviderTests.swift +++ b/Tests/Adyen Tests/Analytics/AnalyticsProviderTests.swift @@ -35,19 +35,11 @@ class AnalyticsProviderTests: XCTestCase { let checkoutAttemptIdResponse = CheckoutAttemptIdResponse(identifier: expectedCheckoutAttemptId) let checkoutAttemptIdResult: Result = .success(checkoutAttemptIdResponse) apiClient.mockedResults = [checkoutAttemptIdResult] - - let fetchCheckoutAttemptIdExpection = expectation(description: "checkoutAttemptId completion") // When sut.sendInitialAnalytics(with: .components(type: .achDirectDebit), additionalFields: nil) - fetchCheckoutAttemptIdExpection.fulfill() - - wait(for: .milliseconds(200)) - - XCTAssertNotNil(sut.checkoutAttemptId, "The checkoutAttemptId is nil.") - XCTAssertEqual(expectedCheckoutAttemptId, sut.checkoutAttemptId, "The received checkoutAttemptId is not the expected one.") - waitForExpectations(timeout: 10) + wait(until: sut, at: \.checkoutAttemptId, is: expectedCheckoutAttemptId) } func testFetchCheckoutAttemptIdWhenAnalyticsIsDisabledShouldNotTriggerCheckoutAttemptIdRequest() throws { @@ -75,20 +67,12 @@ class AnalyticsProviderTests: XCTestCase { let checkoutAttemptIdResponse = CheckoutAttemptIdResponse(identifier: expectedCheckoutAttemptId) let checkoutAttemptIdResult: Result = .success(checkoutAttemptIdResponse) apiClient.mockedResults = [checkoutAttemptIdResult] - - let fetchCheckoutAttemptIdExpection = expectation(description: "checkoutAttemptId completion") // When sut.sendInitialAnalytics(with: .components(type: .achDirectDebit), additionalFields: nil) - fetchCheckoutAttemptIdExpection.fulfill() - - wait(for: .milliseconds(200)) // Then - XCTAssertNotNil(sut.checkoutAttemptId, "The checkoutAttemptId is nil.") - XCTAssertEqual(expectedCheckoutAttemptId, sut.checkoutAttemptId, "The received checkoutAttemptId is not the expected one.") - - waitForExpectations(timeout: 10) + wait(until: sut, at: \.checkoutAttemptId, is: expectedCheckoutAttemptId) } func testFetchCheckoutAttemptIdWhenAnalyticsIsEnabledGivenFailureShouldCallCompletionWithNilValue() throws { @@ -122,19 +106,12 @@ class AnalyticsProviderTests: XCTestCase { let checkoutAttemptIdResponse = CheckoutAttemptIdResponse(identifier: expectedCheckoutAttemptId) let checkoutAttemptIdResult: Result = .success(checkoutAttemptIdResponse) apiClient.mockedResults = [checkoutAttemptIdResult] - - let fetchCheckoutAttemptIdExpection = expectation(description: "checkoutAttemptId completion") // When sut.sendInitialAnalytics(with: .components(type: .atome), additionalFields: nil) - fetchCheckoutAttemptIdExpection.fulfill() - - wait(for: .milliseconds(200)) // Then - XCTAssertEqual(expectedCheckoutAttemptId, sut.checkoutAttemptId) - - waitForExpectations(timeout: 1) + wait(until: sut, at: \.checkoutAttemptId, is: expectedCheckoutAttemptId) } func testFetchCheckoutAttemptIdWhenAnalyticsIsDisabledShouldNotSetCheckoutAttemptIdProperty() throws { diff --git a/Tests/Adyen Tests/Analytics/TelemetryTrackerTests.swift b/Tests/Adyen Tests/Analytics/TelemetryTrackerTests.swift index 5e6fcc7f5a..a056d8ce36 100644 --- a/Tests/Adyen Tests/Analytics/TelemetryTrackerTests.swift +++ b/Tests/Adyen Tests/Analytics/TelemetryTrackerTests.swift @@ -30,7 +30,7 @@ class TelemetryTrackerTests: XCTestCase { try super.tearDownWithError() } - private func sendInitialTelemetry(flavor: TelemetryFlavor = .components(type: .achDirectDebit)) { + private func sendInitialAnalytics(flavor: TelemetryFlavor = .components(type: .achDirectDebit)) { sut.sendInitialAnalytics(with: flavor, additionalFields: nil) } @@ -44,7 +44,7 @@ class TelemetryTrackerTests: XCTestCase { let expectedRequestCalls = 0 // When - sendInitialTelemetry() + sendInitialAnalytics() // Then XCTAssertEqual(expectedRequestCalls, apiClient.counter, "One or more telemetry requests were sent.") @@ -59,7 +59,7 @@ class TelemetryTrackerTests: XCTestCase { let expectedRequestCalls = 0 // When - sendInitialTelemetry() + sendInitialAnalytics() // Then XCTAssertEqual(expectedRequestCalls, apiClient.counter, "One or more telemetry requests were sent.") @@ -76,7 +76,7 @@ class TelemetryTrackerTests: XCTestCase { let expectedRequestCalls = 0 // When - sendInitialTelemetry(flavor: flavor) + sendInitialAnalytics(flavor: flavor) // Then XCTAssertEqual(expectedRequestCalls, apiClient.counter, "One or more telemetry requests were sent.") @@ -96,7 +96,7 @@ class TelemetryTrackerTests: XCTestCase { apiClient.mockedResults = [checkoutAttemptIdResult] // When - sendInitialTelemetry(flavor: flavor) + sendInitialAnalytics(flavor: flavor) // Then wait(for: .milliseconds(1)) @@ -117,7 +117,7 @@ class TelemetryTrackerTests: XCTestCase { apiClient.mockedResults = [checkoutAttemptIdResult] // When - sendInitialTelemetry(flavor: flavor) + sendInitialAnalytics(flavor: flavor) // Then wait(for: .milliseconds(1)) diff --git a/Tests/Components Tests/BACS Direct Debit/Mocks/BACSDirectDebitComponentTrackerProtocolMock.swift b/Tests/Components Tests/BACS Direct Debit/Mocks/BACSDirectDebitComponentTrackerProtocolMock.swift index 4fb1097c12..14d611ee64 100644 --- a/Tests/Components Tests/BACS Direct Debit/Mocks/BACSDirectDebitComponentTrackerProtocolMock.swift +++ b/Tests/Components Tests/BACS Direct Debit/Mocks/BACSDirectDebitComponentTrackerProtocolMock.swift @@ -16,7 +16,7 @@ class BACSDirectDebitComponentTrackerProtocolMock: BACSDirectDebitComponentTrack var initialTelemetryEventCallsCount = 0 - func fetchCheckoutAttemptId() { + func sendInitialAnalytics() { initialTelemetryEventCallsCount += 1 } } diff --git a/Tests/Components Tests/BACS Direct Debit/Trackers/BACSDirectDebitComponentTrackerTests.swift b/Tests/Components Tests/BACS Direct Debit/Trackers/BACSDirectDebitComponentTrackerTests.swift index 4b168da402..38f7a3b9ef 100644 --- a/Tests/Components Tests/BACS Direct Debit/Trackers/BACSDirectDebitComponentTrackerTests.swift +++ b/Tests/Components Tests/BACS Direct Debit/Trackers/BACSDirectDebitComponentTrackerTests.swift @@ -33,7 +33,7 @@ class BACSDirectDebitComponentTrackerTests: XCTestCase { func testSendTelemetryEventShouldCallAnalyticsProviderSendTelemetryEvent() throws { // When - sut.fetchCheckoutAttemptId() + sut.sendInitialAnalytics() // Then XCTAssertEqual(analyticsProvider.initialTelemetryEventCallsCount, 1)