Skip to content

Commit

Permalink
Update ThreeDS2ClassicActionHandlerTests
Browse files Browse the repository at this point in the history
  • Loading branch information
nauaros committed Jan 21, 2025
1 parent fafc0d0 commit 4bc54e4
Showing 1 changed file with 2 additions and 27 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ class ThreeDS2ClassicActionHandlerTests: XCTestCase {
let fingerprint = try ThreeDS2Component.Fingerprint(
authenticationRequestParameters: authenticationRequestParameters
)
let expectedFingerprintJSON = try Coder.encode(fingerprint) as String
let expectedFingerprint = try Coder.encodeBase64(fingerprint)

let resultExpectation = expectation(description: "Expect ThreeDS2ActionHandler completion closure to be called.")
let sut = ThreeDS2ClassicActionHandler(apiContext: Dummy.context, service: service)
Expand All @@ -75,12 +75,7 @@ class ThreeDS2ClassicActionHandlerTests: XCTestCase {
let details = details as! ThreeDS2Details
switch details {
case let .fingerprint(fingerprint):
if let data = Data(base64Encoded: fingerprint),
let receivedFingerprintJSON = String(data: data, encoding: .utf8) {
XCTAssertTrue(self.compareJSONStrings(expectedFingerprintJSON, receivedFingerprintJSON))
} else {
XCTFail()
}
XCTAssertEqual(fingerprint, expectedFingerprint)
default:
XCTFail()
}
Expand Down Expand Up @@ -273,24 +268,4 @@ class ThreeDS2ClassicActionHandlerTests: XCTestCase {

waitForExpectations(timeout: 2, handler: nil)
}

// MARK: - Private

func compareJSONStrings(_ jsonString1: String, _ jsonString2: String) -> Bool {
guard let data1 = jsonString1.data(using: .utf8),
let data2 = jsonString2.data(using: .utf8) else {
print("Invalid data.")
return false
}

do {
let dict1 = try JSONSerialization.jsonObject(with: data1, options: [.allowFragments]) as? [String: Any]
let dict2 = try JSONSerialization.jsonObject(with: data2, options: [.allowFragments]) as? [String: Any]

return NSDictionary(dictionary: dict1 ?? [:]).isEqual(to: dict2 ?? [:])
} catch {
print("Error decoding JSON: \(error)")
return false
}
}
}

0 comments on commit 4bc54e4

Please sign in to comment.