Skip to content

Commit

Permalink
Dev 64080: Revisit public interface of delegate authentication flow (#…
Browse files Browse the repository at this point in the history
…1546)

As per our discussions during the code review we wanted to update the
public interface of the ThreeDSComponent.
  • Loading branch information
goergisn authored Mar 13, 2024
2 parents 3d5f181 + e07910b commit af740ea
Show file tree
Hide file tree
Showing 3 changed files with 24 additions and 41 deletions.
6 changes: 3 additions & 3 deletions AdyenActions/AdyenActionComponent.swift
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
//
// Copyright (c) 2023 Adyen N.V.
// Copyright (c) 2024 Adyen N.V.
//
// This file is open source and available under the MIT license. See the LICENSE file for more info.
//
Expand Down Expand Up @@ -154,8 +154,8 @@ public final class AdyenActionComponent: ActionComponent, ActionHandlingComponen
requestorAppURL: configuration.threeDS.requestorAppURL,
delegateAuthentication: configuration.threeDS.delegateAuthentication)
let component = ThreeDS2Component(context: context,
configuration: threeDS2Configuration,
presentationDelegate: presentationDelegate)
configuration: threeDS2Configuration)
component.presentationDelegate = presentationDelegate
component._isDropIn = _isDropIn
component.delegate = delegate

Expand Down
15 changes: 5 additions & 10 deletions AdyenActions/Components/3DS2/ThreeDS2Component.swift
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
//
// Copyright (c) 2023 Adyen N.V.
// Copyright (c) 2024 Adyen N.V.
//
// This file is open source and available under the MIT license. See the LICENSE file for more info.
//
Expand All @@ -22,7 +22,7 @@ public final class ThreeDS2Component: ActionComponent {
/// The delegate of the component.
public weak var delegate: ActionComponentDelegate?

/// Delegates `PresentableComponent`'s presentation.
/// Delegates `PresentableComponent`'s presentation. This property must be set if you wish to use delegated authentication.
public weak var presentationDelegate: PresentationDelegate?

/// Three DS2 component configurations.
Expand Down Expand Up @@ -106,13 +106,10 @@ public final class ThreeDS2Component: ActionComponent {
///
/// - Parameter context: The context object for this component.
/// - Parameter configuration: The component's configuration.
/// - Parameter presentationDelegate: Delegates `PresentableComponent`'s presentation.
public init(context: AdyenContext,
configuration: Configuration = Configuration(),
presentationDelegate: PresentationDelegate?) {
configuration: Configuration = Configuration()) {
self.context = context
self.configuration = configuration
self.presentationDelegate = presentationDelegate

self.updateConfiguration()
}
Expand All @@ -129,11 +126,9 @@ public final class ThreeDS2Component: ActionComponent {
threeDS2CompactFlowHandler: AnyThreeDS2ActionHandler,
threeDS2ClassicFlowHandler: AnyThreeDS2ActionHandler,
redirectComponent: AnyRedirectComponent,
configuration: Configuration = Configuration(),
presentationDelegate: PresentationDelegate?) {
configuration: Configuration = Configuration()) {
self.init(context: context,
configuration: configuration,
presentationDelegate: presentationDelegate)
configuration: configuration)
self.threeDS2CompactFlowHandler = threeDS2CompactFlowHandler
self.threeDS2ClassicFlowHandler = threeDS2ClassicFlowHandler
self.redirectComponent = redirectComponent
Expand Down
44 changes: 16 additions & 28 deletions Tests/Card Tests/3DS2 Component/ThreeDS2ComponentTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -35,8 +35,7 @@ class ThreeDS2ComponentTests: XCTestCase {
let sut = ThreeDS2Component(context: Dummy.context,
threeDS2CompactFlowHandler: threeDSActionHandler,
threeDS2ClassicFlowHandler: AnyThreeDS2ActionHandlerMock(),
redirectComponent: redirectComponent,
presentationDelegate: nil)
redirectComponent: redirectComponent)
redirectComponent.delegate = sut

let delegate = ActionComponentDelegateMock()
Expand Down Expand Up @@ -75,8 +74,7 @@ class ThreeDS2ComponentTests: XCTestCase {
let sut = ThreeDS2Component(context: Dummy.context,
threeDS2CompactFlowHandler: threeDS2ActionHandler,
threeDS2ClassicFlowHandler: AnyThreeDS2ActionHandlerMock(),
redirectComponent: redirectComponent,
presentationDelegate: nil)
redirectComponent: redirectComponent)
redirectComponent.delegate = sut

let delegate = ActionComponentDelegateMock()
Expand Down Expand Up @@ -114,8 +112,7 @@ class ThreeDS2ComponentTests: XCTestCase {
let sut = ThreeDS2Component(context: Dummy.context,
threeDS2CompactFlowHandler: threeDS2ActionHandler,
threeDS2ClassicFlowHandler: AnyThreeDS2ActionHandlerMock(),
redirectComponent: redirectComponent,
presentationDelegate: nil)
redirectComponent: redirectComponent)
redirectComponent.delegate = sut

let delegate = ActionComponentDelegateMock()
Expand Down Expand Up @@ -154,8 +151,7 @@ class ThreeDS2ComponentTests: XCTestCase {
let sut = ThreeDS2Component(context: Dummy.context,
threeDS2CompactFlowHandler: threeDS2ActionHandler,
threeDS2ClassicFlowHandler: AnyThreeDS2ActionHandlerMock(),
redirectComponent: redirectComponent,
presentationDelegate: nil)
redirectComponent: redirectComponent)
redirectComponent.delegate = sut

let delegate = ActionComponentDelegateMock()
Expand Down Expand Up @@ -199,8 +195,7 @@ class ThreeDS2ComponentTests: XCTestCase {
let sut = ThreeDS2Component(context: Dummy.context,
threeDS2CompactFlowHandler: threeDS2ActionHandler,
threeDS2ClassicFlowHandler: AnyThreeDS2ActionHandlerMock(),
redirectComponent: redirectComponent,
presentationDelegate: nil)
redirectComponent: redirectComponent)
redirectComponent.delegate = sut

let delegate = ActionComponentDelegateMock()
Expand Down Expand Up @@ -231,8 +226,7 @@ class ThreeDS2ComponentTests: XCTestCase {
let sut = ThreeDS2Component(context: Dummy.context,
threeDS2CompactFlowHandler: threeDS2ActionHandler,
threeDS2ClassicFlowHandler: AnyThreeDS2ActionHandlerMock(),
redirectComponent: redirectComponent,
presentationDelegate: nil)
redirectComponent: redirectComponent)
redirectComponent.delegate = sut

let delegate = ActionComponentDelegateMock()
Expand Down Expand Up @@ -266,8 +260,7 @@ class ThreeDS2ComponentTests: XCTestCase {
let sut = ThreeDS2Component(context: Dummy.context,
threeDS2CompactFlowHandler: AnyThreeDS2ActionHandlerMock(),
threeDS2ClassicFlowHandler: threeDS2ActionHandler,
redirectComponent: redirectComponent,
presentationDelegate: nil)
redirectComponent: redirectComponent)
redirectComponent.delegate = sut

let delegate = ActionComponentDelegateMock()
Expand Down Expand Up @@ -295,7 +288,7 @@ class ThreeDS2ComponentTests: XCTestCase {
}

func testSettingRequestorAppURL() throws {
let sut = ThreeDS2Component(context: Dummy.context, presentationDelegate: nil)
let sut = ThreeDS2Component(context: Dummy.context)
sut.configuration.requestorAppURL = URL(string: "https://google.com")
XCTAssertEqual(sut.threeDS2CompactFlowHandler.threeDSRequestorAppURL, URL(string: "https://google.com"))
XCTAssertEqual(sut.threeDS2ClassicFlowHandler.threeDSRequestorAppURL, URL(string: "https://google.com"))
Expand All @@ -304,8 +297,7 @@ class ThreeDS2ComponentTests: XCTestCase {
func testSettingRequestorAppURLWithInitializer() throws {
let configuration = ThreeDS2Component.Configuration(requestorAppURL: URL(string: "https://google.com"))
let sut = ThreeDS2Component(context: Dummy.context,
configuration: configuration,
presentationDelegate: nil)
configuration: configuration)
XCTAssertEqual(sut.threeDS2CompactFlowHandler.threeDSRequestorAppURL, URL(string: "https://google.com"))
XCTAssertEqual(sut.threeDS2ClassicFlowHandler.threeDSRequestorAppURL, URL(string: "https://google.com"))
}
Expand All @@ -319,8 +311,7 @@ class ThreeDS2ComponentTests: XCTestCase {
threeDS2CompactFlowHandler: threeDS2CompactFlowHandler,
threeDS2ClassicFlowHandler: threeDS2ClassicFlowHandler,
redirectComponent: redirectComponent,
configuration: configuration,
presentationDelegate: nil)
configuration: configuration)
XCTAssertEqual(sut.threeDS2CompactFlowHandler.threeDSRequestorAppURL, URL(string: "https://google.com"))
XCTAssertEqual(sut.threeDS2ClassicFlowHandler.threeDSRequestorAppURL, URL(string: "https://google.com"))
}
Expand All @@ -341,8 +332,7 @@ class ThreeDS2ComponentTests: XCTestCase {
let sut = ThreeDS2Component(context: Dummy.context,
threeDS2CompactFlowHandler: AnyThreeDS2ActionHandlerMock(),
threeDS2ClassicFlowHandler: threeDS2ActionHandler,
redirectComponent: redirectComponent,
presentationDelegate: nil)
redirectComponent: redirectComponent)
redirectComponent.delegate = sut

let delegate = ActionComponentDelegateMock()
Expand Down Expand Up @@ -387,8 +377,7 @@ class ThreeDS2ComponentTests: XCTestCase {
let sut = ThreeDS2Component(context: Dummy.context,
threeDS2CompactFlowHandler: threeDS2ActionHandler,
threeDS2ClassicFlowHandler: AnyThreeDS2ActionHandlerMock(),
redirectComponent: redirectComponent,
presentationDelegate: nil)
redirectComponent: redirectComponent)
redirectComponent.delegate = sut

let delegate = ActionComponentDelegateMock()
Expand Down Expand Up @@ -467,8 +456,8 @@ class ThreeDS2ComponentTests: XCTestCase {
let sut = ThreeDS2Component(context: Dummy.context,
threeDS2CompactFlowHandler: AnyThreeDS2ActionHandlerMock(),
threeDS2ClassicFlowHandler: classicActionHandler,
redirectComponent: redirectComponent,
presentationDelegate: presentationDelegateMock)
redirectComponent: redirectComponent)
sut.presentationDelegate = presentationDelegateMock
let delegateExpectation = expectation(description: "Expect delegate didProvide(_:from:) function to be called.")
delegate.onDidProvide = { data, component in
XCTAssertTrue(component === sut)
Expand Down Expand Up @@ -563,9 +552,8 @@ class ThreeDS2ComponentTests: XCTestCase {
let sut = ThreeDS2Component(context: Dummy.context,
threeDS2CompactFlowHandler: AnyThreeDS2ActionHandlerMock(),
threeDS2ClassicFlowHandler: classicActionHandler,
redirectComponent: redirectComponent,
presentationDelegate: presentationDelegateMock)

redirectComponent: redirectComponent)
sut.presentationDelegate = presentationDelegateMock
// Verify if we get a challengeResult.
let delegateExpectation = expectation(description: "Expect delegate didProvide(_:from:) function to be called.")
delegate.onDidProvide = { data, component in
Expand Down

0 comments on commit af740ea

Please sign in to comment.