Skip to content

Commit

Permalink
Fixing some warnings + failure flow tests
Browse files Browse the repository at this point in the history
  • Loading branch information
goergisn committed Mar 7, 2024
1 parent 56b1c98 commit e7a1777
Show file tree
Hide file tree
Showing 13 changed files with 251 additions and 54 deletions.
12 changes: 8 additions & 4 deletions Adyen.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -151,6 +151,8 @@
8109FF4F2AD84496000748C8 /* MapkitAddressLookupProvider.swift in Sources */ = {isa = PBXBuildFile; fileRef = 81AA3B372AD040D800F5719D /* MapkitAddressLookupProvider.swift */; };
8109FF502AD84498000748C8 /* MapkitAddressLookupProvider.swift in Sources */ = {isa = PBXBuildFile; fileRef = 81AA3B372AD040D800F5719D /* MapkitAddressLookupProvider.swift */; };
81129AE62A4EEF8600E63EBE /* SearchViewController+InterfaceState.swift in Sources */ = {isa = PBXBuildFile; fileRef = 81129AE52A4EEF8600E63EBE /* SearchViewController+InterfaceState.swift */; };
8122B9BB2B9A09D0002FC4D6 /* TwintSDKActionTests+Flows.swift in Sources */ = {isa = PBXBuildFile; fileRef = 8122B9BA2B9A09D0002FC4D6 /* TwintSDKActionTests+Flows.swift */; };
8122B9BD2B9A0FF3002FC4D6 /* ErrorMock.swift in Sources */ = {isa = PBXBuildFile; fileRef = 8122B9BC2B9A0FF3002FC4D6 /* ErrorMock.swift */; };
813BF1122B2365400096940E /* XCTestCase+FirstResponder.swift in Sources */ = {isa = PBXBuildFile; fileRef = 813BF1102B2364E00096940E /* XCTestCase+FirstResponder.swift */; };
813BF1132B2365400096940E /* XCTestCase+FirstResponder.swift in Sources */ = {isa = PBXBuildFile; fileRef = 813BF1102B2364E00096940E /* XCTestCase+FirstResponder.swift */; };
813EF9DE2A5DA0BC00C65D15 /* FormPickerItem.swift in Sources */ = {isa = PBXBuildFile; fileRef = 813EF9DD2A5DA0BC00C65D15 /* FormPickerItem.swift */; };
Expand All @@ -166,7 +168,6 @@
8140A3762A3327B500896403 /* AdyenComponents.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = F9175E55259393E800D653BE /* AdyenComponents.framework */; };
814276622A7145F50081E896 /* AddressInputFormViewController+ViewModel.swift in Sources */ = {isa = PBXBuildFile; fileRef = 814276612A7145F50081E896 /* AddressInputFormViewController+ViewModel.swift */; };
8149CCB62B0B855F007235E2 /* ThreeDS2PlusDACoreActionHandlerTests+Constants.swift in Sources */ = {isa = PBXBuildFile; fileRef = 8149CCB52B0B855F007235E2 /* ThreeDS2PlusDACoreActionHandlerTests+Constants.swift */; };
815175612B986871008A9601 /* TwintSDKActionTests+Success.swift in Sources */ = {isa = PBXBuildFile; fileRef = 815175602B986871008A9601 /* TwintSDKActionTests+Success.swift */; };
815175632B986B6D008A9601 /* TwintSDKActionTests+Convenience.swift in Sources */ = {isa = PBXBuildFile; fileRef = 815175622B986B6D008A9601 /* TwintSDKActionTests+Convenience.swift */; };
8169B9EC2A0506CC00AAC9F8 /* Adyen.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = E2C0E03322097917008616F6 /* Adyen.framework */; };
817F6D8C2B62A6110010D248 /* (null) in Sources */ = {isa = PBXBuildFile; };
Expand Down Expand Up @@ -1488,6 +1489,8 @@
8109FF4B2AD5AD0C000748C8 /* OpenExternalAppDetector+DependencyKey.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = "OpenExternalAppDetector+DependencyKey.swift"; sourceTree = "<group>"; };
8109FF4D2AD6D8A9000748C8 /* MockAddressLookupProvider.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = MockAddressLookupProvider.swift; sourceTree = "<group>"; };
81129AE52A4EEF8600E63EBE /* SearchViewController+InterfaceState.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = "SearchViewController+InterfaceState.swift"; sourceTree = "<group>"; };
8122B9BA2B9A09D0002FC4D6 /* TwintSDKActionTests+Flows.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = "TwintSDKActionTests+Flows.swift"; sourceTree = "<group>"; };
8122B9BC2B9A0FF3002FC4D6 /* ErrorMock.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = ErrorMock.swift; sourceTree = "<group>"; };
813BF1102B2364E00096940E /* XCTestCase+FirstResponder.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = "XCTestCase+FirstResponder.swift"; sourceTree = "<group>"; };
813EF9DD2A5DA0BC00C65D15 /* FormPickerItem.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = FormPickerItem.swift; sourceTree = "<group>"; };
813EF9E12A5DA2D400C65D15 /* FormPickerItemView.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = FormPickerItemView.swift; sourceTree = "<group>"; };
Expand All @@ -1501,7 +1504,6 @@
814044302B62BDBB00EB7FBA /* SecuredViewControllerUITests.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = SecuredViewControllerUITests.swift; sourceTree = "<group>"; };
814276612A7145F50081E896 /* AddressInputFormViewController+ViewModel.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = "AddressInputFormViewController+ViewModel.swift"; sourceTree = "<group>"; };
8149CCB52B0B855F007235E2 /* ThreeDS2PlusDACoreActionHandlerTests+Constants.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = "ThreeDS2PlusDACoreActionHandlerTests+Constants.swift"; sourceTree = "<group>"; };
815175602B986871008A9601 /* TwintSDKActionTests+Success.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = "TwintSDKActionTests+Success.swift"; sourceTree = "<group>"; };
815175622B986B6D008A9601 /* TwintSDKActionTests+Convenience.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = "TwintSDKActionTests+Convenience.swift"; sourceTree = "<group>"; };
81825CB72AC59C3300F91912 /* UIView+Search.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = "UIView+Search.swift"; sourceTree = "<group>"; };
81825CBA2AC59C4000F91912 /* UIViewController+Search.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = "UIViewController+Search.swift"; sourceTree = "<group>"; };
Expand Down Expand Up @@ -2853,7 +2855,7 @@
isa = PBXGroup;
children = (
8182AAB82B95FEA10087568E /* TwintSDKActionTests.swift */,
815175602B986871008A9601 /* TwintSDKActionTests+Success.swift */,
8122B9BA2B9A09D0002FC4D6 /* TwintSDKActionTests+Flows.swift */,
815175622B986B6D008A9601 /* TwintSDKActionTests+Convenience.swift */,
8182AABA2B974D160087568E /* Twint+Spy.swift */,
);
Expand Down Expand Up @@ -3130,6 +3132,7 @@
813BF1102B2364E00096940E /* XCTestCase+FirstResponder.swift */,
81B505782A7BE209009B4CB3 /* UIBarButtonItem+XCTest.swift */,
819CC3332B14C53200D2EEE9 /* PaymentMethods+Equatable.swift */,
8122B9BC2B9A0FF3002FC4D6 /* ErrorMock.swift */,
);
path = Helpers;
sourceTree = "<group>";
Expand Down Expand Up @@ -6982,6 +6985,7 @@
F99F08582383EA2A00EBB948 /* ValidatorMock.swift in Sources */,
F9EDB78B2395608D00CFB3C9 /* SEPADirectDebitComponentTests.swift in Sources */,
E74D918325AF3FE600743B0C /* CardBrandProviderTests.swift in Sources */,
8122B9BB2B9A09D0002FC4D6 /* TwintSDKActionTests+Flows.swift in Sources */,
813BF1122B2365400096940E /* XCTestCase+FirstResponder.swift in Sources */,
E773EA3C2523432B00119499 /* CardTypeProviderMock.swift in Sources */,
C97C16AC280702B200534419 /* AnalyticsFlavorTests.swift in Sources */,
Expand Down Expand Up @@ -7018,6 +7022,7 @@
E7768BDC26B416C3000851B3 /* DateValidationTests.swift in Sources */,
F97BC2CE2668EB4500F1D242 /* VoucherViewDelegateMock.swift in Sources */,
F9AC61C2243751A70062A00D /* ActionComponentDelegateMock.swift in Sources */,
8122B9BD2B9A0FF3002FC4D6 /* ErrorMock.swift in Sources */,
C9C0005F280474DF00CE2EEC /* AnalyticsProviderTests.swift in Sources */,
F9F1A98726CCFD1F0005CB1D /* JWAA256CBCHS512AlgorithmTests.swift in Sources */,
81EA6C122A44836E0071A141 /* FormAddressItemTests.swift in Sources */,
Expand Down Expand Up @@ -7049,7 +7054,6 @@
F9D5750E237475DB009C18B5 /* CardEncryptorCardTests.swift in Sources */,
F9C5F0DD25CAB8FC005A6E54 /* VoucherComponentTests.swift in Sources */,
5AD40F4F263157D50090E01C /* UIButtonHelpersTests.swift in Sources */,
815175612B986871008A9601 /* TwintSDKActionTests+Success.swift in Sources */,
E7E8343C24F3C81700EC3844 /* PublicKeyProviderMock.swift in Sources */,
F9838D0126318EBD00963483 /* ReadyToSubmitPaymentComponentDelegateMock.swift in Sources */,
F919DF9924EA64680027976E /* CardPublicKeyProviderTests.swift in Sources */,
Expand Down
2 changes: 2 additions & 0 deletions Adyen/Core/Payment Methods/Abstract/AnyPaymentMethod.swift
Original file line number Diff line number Diff line change
Expand Up @@ -78,9 +78,11 @@ internal enum AnyPaymentMethod: Codable {
case let .onlineBanking(paymentMethod): return paymentMethod
case let .upi(paymentMethod): return paymentMethod
case let .cashAppPay(paymentMethod): return paymentMethod
// swiftlint:disable switch_case_alignment
#if canImport(TwintSDK)
case let .twint(paymentMethod): return paymentMethod
#endif
// swiftlint:enable switch_case_alignment
case .none: return nil
}
}
Expand Down
3 changes: 1 addition & 2 deletions Adyen/Core/ToolBar/CancellableToolBar.swift
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
//
// Copyright (c) 2022 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 @@ -40,4 +40,3 @@ public final class CancellingToolBar: ModalToolbar {
}
}
}

2 changes: 2 additions & 0 deletions AdyenActions/Actions/SDKAction.swift
Original file line number Diff line number Diff line change
Expand Up @@ -24,10 +24,12 @@ public enum SDKAction: Decodable {
switch type {
case .weChatPay:
self = try .weChatPay(WeChatPaySDKAction(from: decoder))
// swiftlint:disable switch_case_alignment
#if canImport(TwintSDK)
case .twint:
self = try .twint(TwintSDKAction(from: decoder))
#endif
// swiftlint:enable switch_case_alignment
}
}

Expand Down
2 changes: 1 addition & 1 deletion AdyenActions/Actions/TwintSDKAction.swift
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ public final class TwintSDKAction: Decodable {
// The payment method subtype
public let type: String

enum CodingKeys: CodingKey {
internal enum CodingKeys: CodingKey {
case sdkData
case paymentData
case paymentMethodType
Expand Down
4 changes: 3 additions & 1 deletion AdyenActions/AdyenActionComponent.swift
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,7 @@ public final class AdyenActionComponent: ActionComponent, ActionHandlingComponen
/// without a host/path/... (e.g. "my-app", not a url "my-app://...")
public init(callbackAppScheme: String) {
if !Self.isCallbackSchemeValid(callbackAppScheme) {
assertionFailure("Format of provided callbackAppScheme '\(callbackAppScheme)' is incorrect.")
AdyenAssertion.assertionFailure(message: "Format of provided callbackAppScheme '\(callbackAppScheme)' is incorrect.")
}

self.callbackAppScheme = callbackAppScheme
Expand Down Expand Up @@ -213,10 +213,12 @@ public final class AdyenActionComponent: ActionComponent, ActionHandlingComponen
switch sdkAction {
case let .weChatPay(weChatPaySDKAction):
handle(weChatPaySDKAction)
// swiftlint:disable switch_case_alignment
#if canImport(TwintSDK)
case let .twint(twintSDKAction):
handle(twintSDKAction)
#endif
// swiftlint:enable switch_case_alignment
}
}

Expand Down
8 changes: 5 additions & 3 deletions AdyenActions/Components/SDK/TwintSDKActionComponent.swift
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ import Foundation
#endif

#if canImport(TwintSDK)
struct TwintActionDetails: AdditionalDetails {}
internal struct TwintActionDetails: AdditionalDetails {}

/// A component that handles Twint SDK action's.
public final class TwintSDKActionComponent: ActionComponent {
Expand All @@ -38,7 +38,8 @@ import Foundation

/// The callback app scheme invoked once the Twint app is done with the payment
///
/// - Important: This value is required to only provide the scheme, without a host/path/.... (e.g. "my-app", not a url "my-app://...")
/// - Important: This value is required to only provide the scheme,
/// without a host/path/.... (e.g. "my-app", not a url "my-app://...")
public let callbackAppScheme: String

/// Initializes an instance of `Configuration`
Expand All @@ -48,7 +49,8 @@ import Foundation
/// - callbackAppScheme: The callback app scheme invoked once the Twint app is done with the payment
/// - localizationParameters: The localization parameters, leave it nil to use the default parameters.
///
/// - Important: The value of ``callbackAppScheme`` is required to only provide the scheme, without a host/path/... (e.g. "my-app", not a url "my-app://...")
/// - Important: The value of ``callbackAppScheme`` is required to only provide the scheme,
/// without a host/path/... (e.g. "my-app", not a url "my-app://...")
public init(
style: AwaitComponentStyle = .init(),
callbackAppScheme: String,
Expand Down
2 changes: 2 additions & 0 deletions AdyenDropIn/DropInComponent.swift
Original file line number Diff line number Diff line change
Expand Up @@ -238,10 +238,12 @@ public final class DropInComponent: NSObject,
navigationController.present(asModal: component)
case let component as InstantPaymentComponent:
component.initiatePayment()
// swiftlint:disable switch_case_alignment
#if canImport(AdyenTwint)
case let component as TwintComponent:
component.initiatePayment()
#endif
// swiftlint:enable switch_case_alignment
default:
break
}
Expand Down
2 changes: 1 addition & 1 deletion AdyenDropIn/Models/DropInConfiguration.swift
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,7 @@ public extension DropInComponent {
public var threeDS: AdyenActionComponent.Configuration.ThreeDS = .init()

/// Twint configurations
public var twint: AdyenActionComponent.Configuration.Twint? = nil
public var twint: AdyenActionComponent.Configuration.Twint?
}

/// Boleto component configuration.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,20 +8,44 @@ import XCTest
@testable @_spi(AdyenInternal) import Adyen
@testable @_spi(AdyenInternal) import AdyenActions

extension TwintSDKActionTests {

/// PresentationDelegateMock that fails when `doPresent` is called
static func failingPresentationDelegateMock() -> PresentationDelegateMock {
let presentationDelegateMock = PresentationDelegateMock()
presentationDelegateMock.doPresent = { _ in
XCTFail("Nothing should have been displayed")
}
return presentationDelegateMock
#if canImport(TwintSDK)
import TwintSDK
#endif

#if canImport(TwintSDK)

extension TWAppConfiguration {
static var dummy: TWAppConfiguration {
let twintAppConfiguration = TWAppConfiguration()
twintAppConfiguration.appDisplayName = "Test App"
twintAppConfiguration.appURLScheme = "scheme://"
return twintAppConfiguration
}
}

extension TwintSDKActionComponent.Configuration {
static var dummy: Self {
.init(callbackAppScheme: "ui-host")
}
}

extension TwintSDKAction {
static var dummy: TwintSDKAction {
.init(
sdkData: .init(token: "token"),
paymentData: "paymentData",
paymentMethodType: "paymentMethodType",
type: "type"
)
}
}

extension TwintSDKActionTests {

static func actionComponent(
with twintSpy: TwintSpy,
presentationDelegate: PresentationDelegate?
presentationDelegate: PresentationDelegate?,
delegate: ActionComponentDelegate?
) -> TwintSDKActionComponent {

let component = TwintSDKActionComponent(
Expand All @@ -31,7 +55,53 @@ extension TwintSDKActionTests {
)

component.presentationDelegate = presentationDelegate
component.delegate = delegate

return component
}

// MARK: PresentationDelegateMock

/// PresentationDelegateMock that fails when `doPresent` is called
static func failingPresentationDelegateMock() -> PresentationDelegateMock {
let presentationDelegateMock = PresentationDelegateMock()
presentationDelegateMock.doPresent = { _ in
XCTFail("Nothing should have been displayed")
}
return presentationDelegateMock
}

/// ActionComponentDelegateMock that fails when `onDidFail` is called
static func successFlowActionComponentDelegateMock(
onProvide: @escaping (ActionComponentData) -> Void
) -> ActionComponentDelegateMock {

let actonComponentDelegateMock = ActionComponentDelegateMock()
actonComponentDelegateMock.onDidFail = { error, component in
XCTFail("delegate.onDidFail should not have been called")
}
actonComponentDelegateMock.onDidProvide = { data, component in
onProvide(data)
}

return actonComponentDelegateMock
}

/// ActionComponentDelegateMock that fails when `onDidFail` is called
static func failureFlowActionComponentDelegateMock(
onDidFail: @escaping (Error) -> Void
) -> ActionComponentDelegateMock {

let actonComponentDelegateMock = ActionComponentDelegateMock()
actonComponentDelegateMock.onDidFail = { error, component in
onDidFail(error)
}
actonComponentDelegateMock.onDidProvide = { data, component in
XCTFail("delegate.onDidProvide should not have been called")
}

return actonComponentDelegateMock
}
}

#endif
Loading

0 comments on commit e7a1777

Please sign in to comment.