Skip to content

Commit

Permalink
Fixing tests
Browse files Browse the repository at this point in the history
  • Loading branch information
Alex Guretzki committed Nov 28, 2024
1 parent 0e3367f commit 9dd3f31
Show file tree
Hide file tree
Showing 4 changed files with 25 additions and 10 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ import Foundation

internal class TwintSpy: Twint {

internal typealias HandleFetchBlock = (@escaping ([TWAppConfiguration]) -> Void) -> Void
internal typealias HandleFetchBlock = (Int, @escaping ([TWAppConfiguration]) -> Void) -> Void

internal typealias HandlePayBlock = (
_ code: String,
Expand Down Expand Up @@ -62,9 +62,10 @@ import Foundation
}

@objc override internal func fetchInstalledAppConfigurations(
maxIssuerNumber: Int,
completion: @escaping ([TWAppConfiguration]) -> Void
) {
handleFetchInstalledAppConfigurations(completion)
handleFetchInstalledAppConfigurations(maxIssuerNumber, completion)
}

@objc override internal func pay(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,10 @@ import XCTest
static var dummy: Self {
.init(callbackAppScheme: "ui-host")
}

static func dummy(maxIssuerNumber: Int) -> Self {
.init(callbackAppScheme: "ui-host", maxIssuerNumber: maxIssuerNumber)
}
}

extension TwintSDKAction {
Expand All @@ -45,6 +49,7 @@ import XCTest

static func actionComponent(
with twintSpy: TwintSpy,
configuration: TwintSDKActionComponent.Configuration = .dummy,
presentationDelegate: PresentationDelegate?,
delegate: ActionComponentDelegate?,
shouldFailPolling: Bool = false
Expand All @@ -60,7 +65,7 @@ import XCTest

let component = TwintSDKActionComponent(
context: Dummy.context,
configuration: .dummy,
configuration: configuration,
twint: twintSpy,
pollingComponentBuilder: pollingBuilder
)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -103,7 +103,8 @@ import XCTest

var twintResponseHandler: ((Error?) -> Void)?

let twintSpy = TwintSpy { configurationsBlock in
let twintSpy = TwintSpy { maxIssuerNumber, configurationsBlock in
XCTAssertEqual(maxIssuerNumber, .max)
fetchBlockExpectation.fulfill()
configurationsBlock([.dummy])
} handlePay: { code, appConfiguration, callbackAppScheme, completionHandler in
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,8 @@ import XCTest

let expectedAlertMessage = "No or an outdated version of TWINT is installed on this device. Please update or install the TWINT app."

let twintSpy = TwintSpy { configurationsBlock in
let twintSpy = TwintSpy { maxIssuerNumber, configurationsBlock in
XCTAssertEqual(maxIssuerNumber, .max)
fetchBlockExpectation.fulfill()
configurationsBlock([])
} handlePay: { code, appConfiguration, callbackAppScheme, completionHandler in
Expand Down Expand Up @@ -80,10 +81,12 @@ import XCTest

func testSingleAppFound() throws {

let expectedMaxIssuerNumber = 5
let fetchBlockExpectation = expectation(description: "Fetch was called")
let payBlockExpectation = expectation(description: "Pay was called")

let twintSpy = TwintSpy { configurationsBlock in
let twintSpy = TwintSpy { maxIssuerNumber, configurationsBlock in
XCTAssertEqual(maxIssuerNumber, expectedMaxIssuerNumber)
fetchBlockExpectation.fulfill()
configurationsBlock([.dummy])
} handlePay: { code, appConfiguration, callbackAppScheme, completionHandler in
Expand All @@ -108,6 +111,7 @@ import XCTest

let twintActionComponent = Self.actionComponent(
with: twintSpy,
configuration: .dummy(maxIssuerNumber: expectedMaxIssuerNumber),
presentationDelegate: presentationDelegate,
delegate: nil
)
Expand Down Expand Up @@ -136,7 +140,8 @@ import XCTest
var appSelectionHandler: ((TWAppConfiguration?) -> Void)? = nil
var appCancelHandler: (() -> Void)? = nil

let twintSpy = TwintSpy { configurationsBlock in
let twintSpy = TwintSpy { maxIssuerNumber, configurationsBlock in
XCTAssertEqual(maxIssuerNumber, .max)
fetchBlockExpectation.fulfill()
configurationsBlock(expectedAppConfigurations)
} handlePay: { code, appConfiguration, callbackAppScheme, completionHandler in
Expand Down Expand Up @@ -219,7 +224,8 @@ import XCTest

let expectedAlertMessage = "Error Message"

let twintSpy = TwintSpy { configurationsBlock in
let twintSpy = TwintSpy { maxIssuerNumber, configurationsBlock in
XCTAssertEqual(maxIssuerNumber, .max)
fetchBlockExpectation.fulfill()
configurationsBlock([.dummy])
} handlePay: { code, appConfiguration, callbackAppScheme, completionHandler in
Expand Down Expand Up @@ -268,7 +274,8 @@ import XCTest
let fetchBlockExpectation = expectation(description: "Fetch was called")
let registerForUFO = expectation(description: "registerForUFO was called")

let twintSpy = TwintSpy { configurationsBlock in
let twintSpy = TwintSpy { maxIssuerNumber, configurationsBlock in
XCTAssertEqual(maxIssuerNumber, .max)
fetchBlockExpectation.fulfill()
configurationsBlock([.dummy])
} handlePay: { _, _, _, completionHandler in
Expand Down Expand Up @@ -325,7 +332,8 @@ import XCTest
var appSelectionHandler: ((TWAppConfiguration?) -> Void)? = nil
var appCancelHandler: (() -> Void)? = nil

let twintSpy = TwintSpy { configurationsBlock in
let twintSpy = TwintSpy { maxIssuerNumber, configurationsBlock in
XCTAssertEqual(maxIssuerNumber, .max)
fetchBlockExpectation.fulfill()
configurationsBlock(expectedAppConfigurations)
} handlePay: { _, _, _, completionHandler in
Expand Down

0 comments on commit 9dd3f31

Please sign in to comment.