Skip to content

Commit

Permalink
Update unit tests
Browse files Browse the repository at this point in the history
  • Loading branch information
nauaros committed Oct 25, 2024
1 parent ceae25f commit 9bd40ca
Show file tree
Hide file tree
Showing 4 changed files with 48 additions and 37 deletions.
4 changes: 4 additions & 0 deletions Adyen.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -496,6 +496,7 @@
C9454C37276A340B0086C218 /* BACSDirectDebitPresentationDelegate.swift in Sources */ = {isa = PBXBuildFile; fileRef = C9454C35276A33A00086C218 /* BACSDirectDebitPresentationDelegate.swift */; };
C9454C38276A34150086C218 /* BACSDirectDebitPresentationDelegate.swift in Sources */ = {isa = PBXBuildFile; fileRef = C9454C35276A33A00086C218 /* BACSDirectDebitPresentationDelegate.swift */; };
C94632BE27BA6985003DD81F /* AnalyticsProvider.swift in Sources */ = {isa = PBXBuildFile; fileRef = C94632BD27BA6985003DD81F /* AnalyticsProvider.swift */; };
C958E9AD2CCBC63B005F2C69 /* NativeRedirectAction.swift in Sources */ = {isa = PBXBuildFile; fileRef = C958E9AC2CCBC63B005F2C69 /* NativeRedirectAction.swift */; };
C95903DE275A48D000E7D3BC /* BACSDirectDebitComponentTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = C95903DD275A48D000E7D3BC /* BACSDirectDebitComponentTests.swift */; };
C96688BF26A6FC1C00DC7297 /* AffirmComponentTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = C96688BE26A6FC1C00DC7297 /* AffirmComponentTests.swift */; };
C96E07A3283B92E300345732 /* BACSDirectDebitComponentTrackerTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = C96E07A1283B92D500345732 /* BACSDirectDebitComponentTrackerTests.swift */; };
Expand Down Expand Up @@ -1806,6 +1807,7 @@
C93B01B82760B06300D311A1 /* BACSConfirmationPresenter.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = BACSConfirmationPresenter.swift; sourceTree = "<group>"; };
C9454C35276A33A00086C218 /* BACSDirectDebitPresentationDelegate.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = BACSDirectDebitPresentationDelegate.swift; sourceTree = "<group>"; };
C94632BD27BA6985003DD81F /* AnalyticsProvider.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = AnalyticsProvider.swift; sourceTree = "<group>"; };
C958E9AC2CCBC63B005F2C69 /* NativeRedirectAction.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = NativeRedirectAction.swift; sourceTree = "<group>"; };
C95903DD275A48D000E7D3BC /* BACSDirectDebitComponentTests.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = BACSDirectDebitComponentTests.swift; sourceTree = "<group>"; };
C95C89312BF63A3500C47296 /* Info.plist */ = {isa = PBXFileReference; lastKnownFileType = text.plist.xml; path = Info.plist; sourceTree = "<group>"; };
C96688BE26A6FC1C00DC7297 /* AffirmComponentTests.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = AffirmComponentTests.swift; sourceTree = "<group>"; };
Expand Down Expand Up @@ -3741,6 +3743,7 @@
5A988B7A2653F1750007F4C0 /* BoletoVoucherAction.swift */,
F99D2F6F2664EDC900BB5B2F /* AnyVoucherAction.swift */,
A02AF3E9275A3A5100E1636C /* DocumentAction.swift */,
C958E9AC2CCBC63B005F2C69 /* NativeRedirectAction.swift */,
);
path = Actions;
sourceTree = "<group>";
Expand Down Expand Up @@ -7495,6 +7498,7 @@
F96757C327CF909900A16FB6 /* AnyWeChatPaySDKActionComponent.swift in Sources */,
F9175FD22594999600D653BE /* RedirectComponent.swift in Sources */,
00165FE02C05DA8600347399 /* RedireactableAwaitAction.swift in Sources */,
C958E9AD2CCBC63B005F2C69 /* NativeRedirectAction.swift in Sources */,
F9237D3D28CB470E004F9929 /* ThreeDS2ClassicActionHandler+Initializers.swift in Sources */,
81E4231B2C74DC3600349A5E /* String+QRCode.swift in Sources */,
8182AAB72B95D3560087568E /* Twint+Injectable.swift in Sources */,
Expand Down
41 changes: 41 additions & 0 deletions AdyenActions/Actions/NativeRedirectAction.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
//
// Copyright (c) 2024 Adyen N.V.
//
// This file is open source and available under the MIT license. See the LICENSE file for more info.
//

import Foundation

/// Describes an action in which the user is redirected to an app.
public class NativeRedirectAction: RedirectAction {

/// Native redirect data.
public let nativeRedirectData: String?

/// Initializes a native redirect action.
///
/// - Parameters:
/// - url: The URL to which to redirect the user.
/// - paymentData: The server-generated payment data that should be submitted to the `/payments/details` endpoint.
/// - nativeRedirectData: Native redirect data.
public init(url: URL, paymentData: String?, nativeRedirectData: String? = nil) {
self.nativeRedirectData = nativeRedirectData
super.init(url: url, paymentData: paymentData)
}

public required init(from decoder: any Decoder) throws {
let container = try decoder.container(keyedBy: CodingKeys.self)
let url = try container.decode(URL.self, forKey: CodingKeys.url)
let paymentData = try container.decodeIfPresent(String.self, forKey: CodingKeys.paymentData)
self.nativeRedirectData = try container.decodeIfPresent(String.self, forKey: CodingKeys.nativeRedirectData)
super.init(url: url, paymentData: paymentData)
}

// MARK: - CodingKeys

private enum CodingKeys: CodingKey {
case url
case paymentData
case nativeRedirectData
}
}
34 changes: 0 additions & 34 deletions AdyenActions/Actions/RedirectAction.swift
Original file line number Diff line number Diff line change
Expand Up @@ -25,37 +25,3 @@ public class RedirectAction: Decodable {
self.paymentData = paymentData
}
}

/// Describes an action in which the user is redirected to a URL.
public class NativeRedirectAction: RedirectAction {

/// Native redirect data.
public let nativeRedirectData: String?

/// Initializes a native redirect action.
///
/// - Parameters:
/// - url: The URL to which to redirect the user.
/// - paymentData: The server-generated payment data that should be submitted to the `/payments/details` endpoint.
/// - nativeRedirectData: Native redirect data.
public init(url: URL, paymentData: String?, nativeRedirectData: String? = nil) {
self.nativeRedirectData = nativeRedirectData
super.init(url: url, paymentData: paymentData)
}

public required init(from decoder: any Decoder) throws {
let container = try decoder.container(keyedBy: CodingKeys.self)
let url = try container.decode(URL.self, forKey: CodingKeys.url)
let paymentData = try container.decodeIfPresent(String.self, forKey: CodingKeys.paymentData)
self.nativeRedirectData = try container.decodeIfPresent(String.self, forKey: CodingKeys.nativeRedirectData)
super.init(url: url, paymentData: paymentData)
}

// MARK: - CodingKeys

private enum CodingKeys: CodingKey {
case url
case paymentData
case nativeRedirectData
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -283,7 +283,7 @@ class RedirectComponentTests: XCTestCase {
}
delegate.onDidFail = { _, _ in XCTFail("Should not call onDidFail") }

let action = RedirectAction(url: URL(string: "https://google.com")!, paymentData: nil, nativeRedirectData: "test_nativeRedirectData")
let action = NativeRedirectAction(url: URL(string: "https://google.com")!, paymentData: nil, nativeRedirectData: "test_nativeRedirectData")
sut.handle(action)
XCTAssertTrue(RedirectComponent.applicationDidOpen(from: URL(string: "url://?queryParam=value")!))

Expand Down Expand Up @@ -311,7 +311,7 @@ class RedirectComponentTests: XCTestCase {
XCTFail("Should not call onDidProvide")
}

let action = RedirectAction(url: URL(string: "https://google.com")!, paymentData: nil, nativeRedirectData: "test_nativeRedirectData")
let action = NativeRedirectAction(url: URL(string: "https://google.com")!, paymentData: nil, nativeRedirectData: "test_nativeRedirectData")
sut.handle(action)
XCTAssertFalse(RedirectComponent.applicationDidOpen(from: URL(string: "url://")!))

Expand Down Expand Up @@ -343,7 +343,7 @@ class RedirectComponentTests: XCTestCase {
redirectExpectation.fulfill()
}

let action = RedirectAction(url: URL(string: "https://google.com")!, paymentData: nil, nativeRedirectData: "test_nativeRedirectData")
let action = NativeRedirectAction(url: URL(string: "https://google.com")!, paymentData: nil, nativeRedirectData: "test_nativeRedirectData")
sut.handle(action)
XCTAssertTrue(RedirectComponent.applicationDidOpen(from: URL(string: "url://?queryParam=value")!))

Expand Down

0 comments on commit 9bd40ca

Please sign in to comment.