Skip to content

Commit

Permalink
chore: review updates
Browse files Browse the repository at this point in the history
  • Loading branch information
erenbesel committed Jan 25, 2024
1 parent 842fb79 commit d8f5325
Show file tree
Hide file tree
Showing 14 changed files with 25 additions and 53 deletions.
8 changes: 4 additions & 4 deletions Adyen.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -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 */; };
Expand Down Expand Up @@ -1699,7 +1699,7 @@
E71E8F3D257921D10054B03D /* StoredBLIKPaymentMethod.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = StoredBLIKPaymentMethod.swift; sourceTree = "<group>"; };
E72521ED25517EB100533E35 /* BLIKComponentTests.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = BLIKComponentTests.swift; sourceTree = "<group>"; };
E7275BF8255012F600907CF9 /* FormLabelItem.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = FormLabelItem.swift; sourceTree = "<group>"; };
E72D9BA926A6E66800FBDA48 /* Dimentions.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = Dimentions.swift; sourceTree = "<group>"; };
E72D9BA926A6E66800FBDA48 /* Dimensions.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = Dimensions.swift; sourceTree = "<group>"; };
E72DA33C23E19DE300707638 /* PreselectedPaymentMethodComponent.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = PreselectedPaymentMethodComponent.swift; sourceTree = "<group>"; };
E72DA34023E1BE5300707638 /* DropInNavigationController.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = DropInNavigationController.swift; sourceTree = "<group>"; };
E736497E25277B6500AB76AE /* StringExtension.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = StringExtension.swift; sourceTree = "<group>"; };
Expand Down Expand Up @@ -3540,7 +3540,7 @@
E28098B9220DB9E70087928F /* List */,
E2C0E0BF220D7E53008616F6 /* Views */,
F9175F7625948EDF00D653BE /* View Controllers */,
E72D9BA926A6E66800FBDA48 /* Dimentions.swift */,
E72D9BA926A6E66800FBDA48 /* Dimensions.swift */,
);
path = UI;
sourceTree = "<group>";
Expand Down Expand Up @@ -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 */,
Expand Down
5 changes: 0 additions & 5 deletions Adyen/Analytics/Models/AdyenAnalytics.swift
Original file line number Diff line number Diff line change
Expand Up @@ -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 }
//}
Original file line number Diff line number Diff line change
Expand Up @@ -258,7 +258,7 @@ extension AbstractPersonalInformationComponent: ViewControllerDelegate {
// MARK: - ViewControllerDelegate

public func viewWillAppear(viewController: UIViewController) {
fetchCheckoutAttemptId()
sendInitialAnalytics()
populateFields()
}
}
2 changes: 1 addition & 1 deletion Adyen/Core/Components/StoredPaymentMethodComponent.swift
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
6 changes: 3 additions & 3 deletions Adyen/Core/Core Protocols/PresentableComponent.swift
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand All @@ -82,6 +82,6 @@ extension TrackableComponent where Self: PaymentMethodAware {
extension TrackableComponent where Self: ViewControllerDelegate {

public func viewWillAppear(viewController: UIViewController) {
fetchCheckoutAttemptId()
sendInitialAnalytics()
}
}
File renamed without changes.
2 changes: 1 addition & 1 deletion AdyenCard/Components/Stored Card/StoredCardComponent.swift
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ internal class BACSInputPresenter: BACSInputPresenterProtocol {
// MARK: - BACSInputPresenterProtocol

internal func viewDidLoad() {
tracker.fetchCheckoutAttemptId()
tracker.sendInitialAnalytics()
createItems()
setupView()
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
import Foundation

internal protocol BACSDirectDebitComponentTrackerProtocol: AnyObject {
func fetchCheckoutAttemptId()
func sendInitialAnalytics()
}

internal class BACSDirectDebitComponentTracker: BACSDirectDebitComponentTrackerProtocol {
Expand All @@ -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)
Expand Down
2 changes: 1 addition & 1 deletion AdyenComponents/Boleto/BoletoComponent.swift
Original file line number Diff line number Diff line change
Expand Up @@ -188,7 +188,7 @@ extension BoletoComponent: ViewControllerDelegate {
public func viewDidAppear(viewController: UIViewController) {}

public func viewWillAppear(viewController: UIViewController) {
fetchCheckoutAttemptId()
sendInitialAnalytics()
prefillFields(for: formComponent)
}
}
Expand Down
29 changes: 3 additions & 26 deletions Tests/Adyen Tests/Analytics/AnalyticsProviderTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -35,19 +35,11 @@ class AnalyticsProviderTests: XCTestCase {
let checkoutAttemptIdResponse = CheckoutAttemptIdResponse(identifier: expectedCheckoutAttemptId)
let checkoutAttemptIdResult: Result<Response, Error> = .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 {
Expand Down Expand Up @@ -75,20 +67,12 @@ class AnalyticsProviderTests: XCTestCase {
let checkoutAttemptIdResponse = CheckoutAttemptIdResponse(identifier: expectedCheckoutAttemptId)
let checkoutAttemptIdResult: Result<Response, Error> = .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 {
Expand Down Expand Up @@ -122,19 +106,12 @@ class AnalyticsProviderTests: XCTestCase {
let checkoutAttemptIdResponse = CheckoutAttemptIdResponse(identifier: expectedCheckoutAttemptId)
let checkoutAttemptIdResult: Result<Response, Error> = .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 {
Expand Down
12 changes: 6 additions & 6 deletions Tests/Adyen Tests/Analytics/TelemetryTrackerTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -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)
}

Expand All @@ -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.")
Expand All @@ -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.")
Expand All @@ -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.")
Expand All @@ -96,7 +96,7 @@ class TelemetryTrackerTests: XCTestCase {
apiClient.mockedResults = [checkoutAttemptIdResult]

// When
sendInitialTelemetry(flavor: flavor)
sendInitialAnalytics(flavor: flavor)

// Then
wait(for: .milliseconds(1))
Expand All @@ -117,7 +117,7 @@ class TelemetryTrackerTests: XCTestCase {
apiClient.mockedResults = [checkoutAttemptIdResult]

// When
sendInitialTelemetry(flavor: flavor)
sendInitialAnalytics(flavor: flavor)

// Then
wait(for: .milliseconds(1))
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ class BACSDirectDebitComponentTrackerProtocolMock: BACSDirectDebitComponentTrack

var initialTelemetryEventCallsCount = 0

func fetchCheckoutAttemptId() {
func sendInitialAnalytics() {
initialTelemetryEventCallsCount += 1
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ class BACSDirectDebitComponentTrackerTests: XCTestCase {

func testSendTelemetryEventShouldCallAnalyticsProviderSendTelemetryEvent() throws {
// When
sut.fetchCheckoutAttemptId()
sut.sendInitialAnalytics()

// Then
XCTAssertEqual(analyticsProvider.initialTelemetryEventCallsCount, 1)
Expand Down

0 comments on commit d8f5325

Please sign in to comment.