diff --git a/packages/example/ios/example_0_70_6.xcodeproj/project.pbxproj b/packages/example/ios/example_0_70_6.xcodeproj/project.pbxproj index aea29e9d5..1db052f7d 100644 --- a/packages/example/ios/example_0_70_6.xcodeproj/project.pbxproj +++ b/packages/example/ios/example_0_70_6.xcodeproj/project.pbxproj @@ -16,6 +16,17 @@ A17A44A32BF7A57F00433548 /* UIImageExtensionTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = A17A44A02BF7A57F00433548 /* UIImageExtensionTests.swift */; }; A17A44A42BF7A57F00433548 /* CodableExtensionsTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = A17A44A12BF7A57F00433548 /* CodableExtensionsTests.swift */; }; A17A44A52BF7A57F00433548 /* ErrorExtensionTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = A17A44A22BF7A57F00433548 /* ErrorExtensionTests.swift */; }; + A17A44A72BFB7A6200433548 /* PrimerCheckoutPaymentMethodTypeTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = A17A44A62BFB7A6200433548 /* PrimerCheckoutPaymentMethodTypeTests.swift */; }; + A17A44A92BFB7D3800433548 /* RNTPrimerTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = A17A44A82BFB7D3800433548 /* RNTPrimerTests.swift */; }; + A17A44AD2BFB843F00433548 /* ImplementedRNCallbacksTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = A17A44AC2BFB843F00433548 /* ImplementedRNCallbacksTests.swift */; }; + A17A44B02BFB851900433548 /* PrimerBancontactCardRedirectData+ExtensionTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = A17A44AF2BFB851900433548 /* PrimerBancontactCardRedirectData+ExtensionTests.swift */; }; + A17A44B22BFB858D00433548 /* PrimerCardData+ExtensionTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = A17A44B12BFB858D00433548 /* PrimerCardData+ExtensionTests.swift */; }; + A17A44B42BFB865300433548 /* PrimerPhoneNumberData+ExtensionTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = A17A44B32BFB865300433548 /* PrimerPhoneNumberData+ExtensionTests.swift */; }; + A17A44B62BFB86D700433548 /* PrimerRawRetailerData+ExtensionTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = A17A44B52BFB86D700433548 /* PrimerRawRetailerData+ExtensionTests.swift */; }; + A17A44B82BFB874600433548 /* PrimerSettings+ExtensionsTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = A17A44B72BFB874600433548 /* PrimerSettings+ExtensionsTests.swift */; }; + A17A44BA2BFB8AD200433548 /* PrimerThemeRNTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = A17A44B92BFB8AD200433548 /* PrimerThemeRNTests.swift */; }; + A17A44BC2BFB8C7B00433548 /* RNTNativeErrorTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = A17A44BB2BFB8C7B00433548 /* RNTNativeErrorTests.swift */; }; + A17A44C02BFF650A00433548 /* RNTBanksCollectableDataTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = A17A44BF2BFF650A00433548 /* RNTBanksCollectableDataTests.swift */; }; C010C35792AF87095495BFED /* (null) in Frameworks */ = {isa = PBXBuildFile; }; CA8BCC075C44D2D84D0763C5 /* libPods-example_0_70_6-example_0_70_6Tests.a in Frameworks */ = {isa = PBXBuildFile; fileRef = 1CD0A4D74B8ACFC62D6A65A1 /* libPods-example_0_70_6-example_0_70_6Tests.a */; }; EBD12C17BEFC44D84D486A26 /* libPods-example_0_70_6.a in Frameworks */ = {isa = PBXBuildFile; fileRef = 80FB55FEE50456A2CC839A71 /* libPods-example_0_70_6.a */; }; @@ -55,6 +66,17 @@ A17A44A02BF7A57F00433548 /* UIImageExtensionTests.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = UIImageExtensionTests.swift; sourceTree = ""; }; A17A44A12BF7A57F00433548 /* CodableExtensionsTests.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = CodableExtensionsTests.swift; sourceTree = ""; }; A17A44A22BF7A57F00433548 /* ErrorExtensionTests.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = ErrorExtensionTests.swift; sourceTree = ""; }; + A17A44A62BFB7A6200433548 /* PrimerCheckoutPaymentMethodTypeTests.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = PrimerCheckoutPaymentMethodTypeTests.swift; sourceTree = ""; }; + A17A44A82BFB7D3800433548 /* RNTPrimerTests.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = RNTPrimerTests.swift; sourceTree = ""; }; + A17A44AC2BFB843F00433548 /* ImplementedRNCallbacksTests.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = ImplementedRNCallbacksTests.swift; sourceTree = ""; }; + A17A44AF2BFB851900433548 /* PrimerBancontactCardRedirectData+ExtensionTests.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = "PrimerBancontactCardRedirectData+ExtensionTests.swift"; sourceTree = ""; }; + A17A44B12BFB858D00433548 /* PrimerCardData+ExtensionTests.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = "PrimerCardData+ExtensionTests.swift"; sourceTree = ""; }; + A17A44B32BFB865300433548 /* PrimerPhoneNumberData+ExtensionTests.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = "PrimerPhoneNumberData+ExtensionTests.swift"; sourceTree = ""; }; + A17A44B52BFB86D700433548 /* PrimerRawRetailerData+ExtensionTests.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = "PrimerRawRetailerData+ExtensionTests.swift"; sourceTree = ""; }; + A17A44B72BFB874600433548 /* PrimerSettings+ExtensionsTests.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = "PrimerSettings+ExtensionsTests.swift"; sourceTree = ""; }; + A17A44B92BFB8AD200433548 /* PrimerThemeRNTests.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = PrimerThemeRNTests.swift; sourceTree = ""; }; + A17A44BB2BFB8C7B00433548 /* RNTNativeErrorTests.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = RNTNativeErrorTests.swift; sourceTree = ""; }; + A17A44BF2BFF650A00433548 /* RNTBanksCollectableDataTests.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = RNTBanksCollectableDataTests.swift; sourceTree = ""; }; B7FC3B6D8BEFAD7734A2FDC8 /* Pods-example_0_70_6-ios_sdk_tests.debug.xcconfig */ = {isa = PBXFileReference; includeInIndex = 1; lastKnownFileType = text.xcconfig; name = "Pods-example_0_70_6-ios_sdk_tests.debug.xcconfig"; path = "Target Support Files/Pods-example_0_70_6-ios_sdk_tests/Pods-example_0_70_6-ios_sdk_tests.debug.xcconfig"; sourceTree = ""; }; C15C82089BBDB7EBFE153BBA /* Pods-example_0_70_6.release.xcconfig */ = {isa = PBXFileReference; includeInIndex = 1; lastKnownFileType = text.xcconfig; name = "Pods-example_0_70_6.release.xcconfig"; path = "Target Support Files/Pods-example_0_70_6/Pods-example_0_70_6.release.xcconfig"; sourceTree = ""; }; ED297162215061F000B7C4FE /* JavaScriptCore.framework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.framework; name = JavaScriptCore.framework; path = System/Library/Frameworks/JavaScriptCore.framework; sourceTree = SDKROOT; }; @@ -89,10 +111,9 @@ children = ( 00E356F01AD99517003FC87E /* Supporting Files */, F004EDB42BF6091A006F3CAA /* example_0_70_6Tests-Bridging-Header.h */, - F004EDB72BF60A4E006F3CAA /* UIColorExtensionTests.swift */, - A17A44A12BF7A57F00433548 /* CodableExtensionsTests.swift */, - A17A44A22BF7A57F00433548 /* ErrorExtensionTests.swift */, - A17A44A02BF7A57F00433548 /* UIImageExtensionTests.swift */, + A17A44AB2BFB825B00433548 /* HelpersTests */, + A17A44A82BFB7D3800433548 /* RNTPrimerTests.swift */, + A17A44AE2BFB844800433548 /* DataModelsTests */, ); path = example_0_70_6Tests; sourceTree = ""; @@ -162,6 +183,42 @@ name = Products; sourceTree = ""; }; + A17A44AB2BFB825B00433548 /* HelpersTests */ = { + isa = PBXGroup; + children = ( + F004EDB72BF60A4E006F3CAA /* UIColorExtensionTests.swift */, + A17A44A12BF7A57F00433548 /* CodableExtensionsTests.swift */, + A17A44A22BF7A57F00433548 /* ErrorExtensionTests.swift */, + A17A44A02BF7A57F00433548 /* UIImageExtensionTests.swift */, + A17A44A62BFB7A6200433548 /* PrimerCheckoutPaymentMethodTypeTests.swift */, + ); + path = HelpersTests; + sourceTree = ""; + }; + A17A44AE2BFB844800433548 /* DataModelsTests */ = { + isa = PBXGroup; + children = ( + A17A44AC2BFB843F00433548 /* ImplementedRNCallbacksTests.swift */, + A17A44AF2BFB851900433548 /* PrimerBancontactCardRedirectData+ExtensionTests.swift */, + A17A44B12BFB858D00433548 /* PrimerCardData+ExtensionTests.swift */, + A17A44B32BFB865300433548 /* PrimerPhoneNumberData+ExtensionTests.swift */, + A17A44B52BFB86D700433548 /* PrimerRawRetailerData+ExtensionTests.swift */, + A17A44B72BFB874600433548 /* PrimerSettings+ExtensionsTests.swift */, + A17A44B92BFB8AD200433548 /* PrimerThemeRNTests.swift */, + A17A44BB2BFB8C7B00433548 /* RNTNativeErrorTests.swift */, + A17A44C12BFF650F00433548 /* Banks Component */, + ); + path = DataModelsTests; + sourceTree = ""; + }; + A17A44C12BFF650F00433548 /* Banks Component */ = { + isa = PBXGroup; + children = ( + A17A44BF2BFF650A00433548 /* RNTBanksCollectableDataTests.swift */, + ); + path = "Banks Component"; + sourceTree = ""; + }; BBD78D7AC51CEA395F1C20DB /* Pods */ = { isa = PBXGroup; children = ( @@ -456,10 +513,21 @@ isa = PBXSourcesBuildPhase; buildActionMask = 2147483647; files = ( + A17A44BC2BFB8C7B00433548 /* RNTNativeErrorTests.swift in Sources */, F004EDB82BF60A4E006F3CAA /* UIColorExtensionTests.swift in Sources */, + A17A44AD2BFB843F00433548 /* ImplementedRNCallbacksTests.swift in Sources */, + A17A44B22BFB858D00433548 /* PrimerCardData+ExtensionTests.swift in Sources */, + A17A44A92BFB7D3800433548 /* RNTPrimerTests.swift in Sources */, A17A44A32BF7A57F00433548 /* UIImageExtensionTests.swift in Sources */, A17A44A52BF7A57F00433548 /* ErrorExtensionTests.swift in Sources */, + A17A44C02BFF650A00433548 /* RNTBanksCollectableDataTests.swift in Sources */, + A17A44B02BFB851900433548 /* PrimerBancontactCardRedirectData+ExtensionTests.swift in Sources */, + A17A44A72BFB7A6200433548 /* PrimerCheckoutPaymentMethodTypeTests.swift in Sources */, + A17A44B42BFB865300433548 /* PrimerPhoneNumberData+ExtensionTests.swift in Sources */, + A17A44B82BFB874600433548 /* PrimerSettings+ExtensionsTests.swift in Sources */, + A17A44BA2BFB8AD200433548 /* PrimerThemeRNTests.swift in Sources */, A17A44A42BF7A57F00433548 /* CodableExtensionsTests.swift in Sources */, + A17A44B62BFB86D700433548 /* PrimerRawRetailerData+ExtensionTests.swift in Sources */, ); runOnlyForDeploymentPostprocessing = 0; }; diff --git a/packages/example/ios/example_0_70_6/Project.swift b/packages/example/ios/example_0_70_6/Project.swift index d58d6007c..1dac615ed 100644 --- a/packages/example/ios/example_0_70_6/Project.swift +++ b/packages/example/ios/example_0_70_6/Project.swift @@ -69,8 +69,8 @@ let project = Project( LaunchArgument(name: "-PrimerDebugEnabled", isEnabled: true), LaunchArgument(name: "-PrimerAnalyticsDebugEnabled", isEnabled: true) ] - ) - ) - ) + ) + ) + ) ] ) diff --git a/packages/example/ios/example_0_70_6Tests/CodableExtensionsTests.swift b/packages/example/ios/example_0_70_6Tests/CodableExtensionsTests.swift deleted file mode 100644 index 72f90fc5e..000000000 --- a/packages/example/ios/example_0_70_6Tests/CodableExtensionsTests.swift +++ /dev/null @@ -1,55 +0,0 @@ -// -// CodableExtensionsTests.swift -// example_0_70_6Tests -// -// Created by Boris on 17.5.24.. -// - -import XCTest -@testable import primer_io_react_native - -// Define test structs conforming to Encodable and Decodable for testing purposes -struct TestStruct: Codable, Equatable { - let id: Int - let name: String -} - -// Unit test class for the extensions -class CodableExtensionsTests: XCTestCase { - - func testEncodableToJsonObject() { - let testObject = TestStruct(id: 1, name: "Test") - - do { - let jsonObject = try testObject.toJsonObject() - XCTAssertNotNil(jsonObject) - if let jsonDict = jsonObject as? [String: Any] { - XCTAssertEqual(jsonDict["id"] as? Int, 1) - XCTAssertEqual(jsonDict["name"] as? String, "Test") - } else { - XCTFail("Encoded object is not a valid JSON dictionary") - } - } catch { - XCTFail("Encoding to JSON object failed with error: \(error)") - } - } - - func testDecodableFromJsonString() { - let jsonString = "{\"id\":1,\"name\":\"Test\"}" - - do { - let testObject = try TestStruct.from(jsonString: jsonString) - XCTAssertEqual(testObject, TestStruct(id: 1, name: "Test")) - } catch { - XCTFail("Decoding from JSON string failed with error: \(error)") - } - } - - func testDecodableFromInvalidJsonString() { - let invalidJsonString = "{\"id\":1,\"name\":}" - - XCTAssertThrowsError(try TestStruct.from(jsonString: invalidJsonString)) { error in - XCTAssertTrue(error is DecodingError) - } - } -} diff --git a/packages/example/ios/example_0_70_6Tests/DataModelsTests/Banks Component/RNTBanksCollectableDataTests.swift b/packages/example/ios/example_0_70_6Tests/DataModelsTests/Banks Component/RNTBanksCollectableDataTests.swift new file mode 100644 index 000000000..686ee9a37 --- /dev/null +++ b/packages/example/ios/example_0_70_6Tests/DataModelsTests/Banks Component/RNTBanksCollectableDataTests.swift @@ -0,0 +1,105 @@ +// +// RNTBanksCollectableDataTests.swift +// example_0_70_6Tests +// +// Created by Boris on 23.5.24.. +// + +import XCTest +@testable import primer_io_react_native +import PrimerSDK + +class BanksCollectableDataRNTests: XCTestCase { + + func testFilterRNInitialization() { + let filter = FilterRN(text: "filterText") + XCTAssertEqual(filter.validatableDataName, "bankListFilter") + XCTAssertEqual(filter.text, "filterText") + } + + func testBankIdRNInitialization() { + let bankId = BankIdRN(id: "bankId123") + XCTAssertEqual(bankId.validatableDataName, "bankId") + XCTAssertEqual(bankId.id, "bankId123") + } + + func testBanksCollectableDataToBankIdRN() { + let bankData = BanksCollectableData.bankId(bankId: "bankId123") + let bankIdRN: BankIdRN? + + switch bankData { + case .bankId(let bankId): + bankIdRN = BankIdRN(id: bankId) + default: + bankIdRN = nil + } + + if let bankIdRN = bankIdRN { + XCTAssertEqual(bankIdRN.validatableDataName, "bankId") + XCTAssertEqual(bankIdRN.id, "bankId123") + } else { + XCTFail("Conversion to BankIdRN failed") + } + } + + func testBanksCollectableDataToFilterRN() { + let filterData = BanksCollectableData.bankFilterText(text: "filterText") + let filterRN: FilterRN? + + switch filterData { + case .bankFilterText(let text): + filterRN = FilterRN(text: text) + default: + filterRN = nil + } + + if let filterRN = filterRN { + XCTAssertEqual(filterRN.validatableDataName, "bankListFilter") + XCTAssertEqual(filterRN.text, "filterText") + } else { + XCTFail("Conversion to FilterRN failed") + } + } + + func testFilterRNEncoding() { + let filter = FilterRN(text: "filterText") + let encoder = JSONEncoder() + do { + let data = try encoder.encode(filter) + let jsonString = String(data: data, encoding: .utf8) + XCTAssertNotNil(jsonString) + } catch { + XCTFail("Encoding failed: \(error)") + } + } + + func testBankIdRNEncoding() { + let bankId = BankIdRN(id: "bankId123") + let encoder = JSONEncoder() + do { + let data = try encoder.encode(bankId) + let jsonString = String(data: data, encoding: .utf8) + XCTAssertNotNil(jsonString) + } catch { + XCTFail("Encoding failed: \(error)") + } + } + + func testBanksCollectableDataEncoding() { + let bankIdData = BanksCollectableData.bankId(bankId: "bankId123") + let filterData = BanksCollectableData.bankFilterText(text: "filterText") + let encoder = JSONEncoder() + + do { + let bankIdDataEncoded = try encoder.encode(bankIdData) + let bankIdJsonString = String(data: bankIdDataEncoded, encoding: .utf8) + XCTAssertNotNil(bankIdJsonString) + + let filterDataEncoded = try encoder.encode(filterData) + let filterJsonString = String(data: filterDataEncoded, encoding: .utf8) + XCTAssertNotNil(filterJsonString) + } catch { + XCTFail("Encoding failed: \(error)") + } + } +} diff --git a/packages/example/ios/example_0_70_6Tests/DataModelsTests/ImplementedRNCallbacksTests.swift b/packages/example/ios/example_0_70_6Tests/DataModelsTests/ImplementedRNCallbacksTests.swift new file mode 100644 index 000000000..05615929b --- /dev/null +++ b/packages/example/ios/example_0_70_6Tests/DataModelsTests/ImplementedRNCallbacksTests.swift @@ -0,0 +1,116 @@ +// +// ImplementedRNCallbacksTests.swift +// example_0_70_6Tests +// +// Created by Boris on 20.5.24.. +// + +import XCTest +@testable import primer_io_react_native + +class ImplementedRNCallbacksTests: XCTestCase { + + func testDecodingWithAllFields() { + let jsonString = """ + { + "onAvailablePaymentMethodsLoad": true, + "onTokenizationStart": true, + "onTokenizationSuccess": true, + "onCheckoutResume": true, + "onCheckoutPending": true, + "onCheckoutAdditionalInfo": true, + "onError": true, + "onCheckoutComplete": true, + "onBeforeClientSessionUpdate": true, + "onClientSessionUpdate": true, + "onBeforePaymentCreate": true, + "onPreparationStart": true, + "onPaymentMethodShow": true, + "onDismiss": true + } + """ + let jsonData = jsonString.data(using: .utf8)! + let decoder = JSONDecoder() + + do { + let callbacks = try decoder.decode(ImplementedRNCallbacks.self, from: jsonData) + + XCTAssertTrue(callbacks.isOnAvailablePaymentMethodsLoadImplemented) + XCTAssertTrue(callbacks.isOnTokenizationStartImplemented) + XCTAssertTrue(callbacks.isOnTokenizationSuccessImplemented) + XCTAssertTrue(callbacks.isOnCheckoutResumeImplemented) + XCTAssertTrue(callbacks.isOnCheckoutPendingImplemented) + XCTAssertTrue(callbacks.isOnCheckoutAdditionalInfoImplemented) + XCTAssertTrue(callbacks.isOnErrorImplemented) + XCTAssertTrue(callbacks.isOnCheckoutCompleteImplemented) + XCTAssertTrue(callbacks.isOnBeforeClientSessionUpdateImplemented) + XCTAssertTrue(callbacks.isOnClientSessionUpdateImplemented) + XCTAssertTrue(callbacks.isOnBeforePaymentCreateImplemented) + XCTAssertTrue(callbacks.isOnPreparationStartImplemented) + XCTAssertTrue(callbacks.isOnPaymentMethodShowImplemented) + XCTAssertTrue(callbacks.isOnDismissImplemented) + } catch { + XCTFail("Decoding failed: \(error)") + } + } + + func testDecodingWithMissingFields() { + let jsonString = """ + { + "onTokenizationSuccess": true, + "onCheckoutComplete": true, + "onBeforeClientSessionUpdate": true + } + """ + let jsonData = jsonString.data(using: .utf8)! + let decoder = JSONDecoder() + + do { + let callbacks = try decoder.decode(ImplementedRNCallbacks.self, from: jsonData) + + XCTAssertFalse(callbacks.isOnAvailablePaymentMethodsLoadImplemented) + XCTAssertFalse(callbacks.isOnTokenizationStartImplemented) + XCTAssertTrue(callbacks.isOnTokenizationSuccessImplemented) + XCTAssertFalse(callbacks.isOnCheckoutResumeImplemented) + XCTAssertFalse(callbacks.isOnCheckoutPendingImplemented) + XCTAssertFalse(callbacks.isOnCheckoutAdditionalInfoImplemented) + XCTAssertFalse(callbacks.isOnErrorImplemented) + XCTAssertTrue(callbacks.isOnCheckoutCompleteImplemented) + XCTAssertTrue(callbacks.isOnBeforeClientSessionUpdateImplemented) + XCTAssertFalse(callbacks.isOnClientSessionUpdateImplemented) + XCTAssertFalse(callbacks.isOnBeforePaymentCreateImplemented) + XCTAssertFalse(callbacks.isOnPreparationStartImplemented) + XCTAssertFalse(callbacks.isOnPaymentMethodShowImplemented) + XCTAssertFalse(callbacks.isOnDismissImplemented) + } catch { + XCTFail("Decoding failed: \(error)") + } + } + + func testDecodingWithEmptyJSON() { + let jsonString = "{}" + let jsonData = jsonString.data(using: .utf8)! + let decoder = JSONDecoder() + + do { + let callbacks = try decoder.decode(ImplementedRNCallbacks.self, from: jsonData) + + XCTAssertFalse(callbacks.isOnAvailablePaymentMethodsLoadImplemented) + XCTAssertFalse(callbacks.isOnTokenizationStartImplemented) + XCTAssertFalse(callbacks.isOnTokenizationSuccessImplemented) + XCTAssertFalse(callbacks.isOnCheckoutResumeImplemented) + XCTAssertFalse(callbacks.isOnCheckoutPendingImplemented) + XCTAssertFalse(callbacks.isOnCheckoutAdditionalInfoImplemented) + XCTAssertFalse(callbacks.isOnErrorImplemented) + XCTAssertFalse(callbacks.isOnCheckoutCompleteImplemented) + XCTAssertFalse(callbacks.isOnBeforeClientSessionUpdateImplemented) + XCTAssertFalse(callbacks.isOnClientSessionUpdateImplemented) + XCTAssertFalse(callbacks.isOnBeforePaymentCreateImplemented) + XCTAssertFalse(callbacks.isOnPreparationStartImplemented) + XCTAssertFalse(callbacks.isOnPaymentMethodShowImplemented) + XCTAssertFalse(callbacks.isOnDismissImplemented) + } catch { + XCTFail("Decoding failed: \(error)") + } + } +} diff --git a/packages/example/ios/example_0_70_6Tests/DataModelsTests/PrimerBancontactCardRedirectData+ExtensionTests.swift b/packages/example/ios/example_0_70_6Tests/DataModelsTests/PrimerBancontactCardRedirectData+ExtensionTests.swift new file mode 100644 index 000000000..47e4b6f1a --- /dev/null +++ b/packages/example/ios/example_0_70_6Tests/DataModelsTests/PrimerBancontactCardRedirectData+ExtensionTests.swift @@ -0,0 +1,70 @@ +// +// PrimerBancontactCardRedirectData+ExtensionTests.swift +// example_0_70_6Tests +// +// Created by Boris on 20.5.24.. +// + +import XCTest +import PrimerSDK +@testable import primer_io_react_native + +class PrimerBancontactCardRedirectData: XCTestCase { + + func testConvenienceInitWithValidJSON() { + let jsonString = """ + { + "cardNumber": "1234567812345678", + "expiryDate": "12/24", + "cardholderName": "John Doe" + } + """ + + guard let cardData = PrimerBancontactCardData(bankcontactCardDataStr: jsonString) else { + return XCTFail("Initialization should succeed with valid JSON") + } + + XCTAssertEqual(cardData.cardNumber, "1234567812345678") + XCTAssertEqual(cardData.expiryDate, "12/24") + XCTAssertEqual(cardData.cardholderName, "John Doe") + } + + func testConvenienceInitWithMissingFields() { + let jsonString = """ + { + "cardNumber": "1234567812345678", + "expiryDate": "12/24" + } + """ + + let cardData = PrimerBancontactCardData(bankcontactCardDataStr: jsonString) + XCTAssertNil(cardData, "Initialization should fail if any required field is missing") + } + + func testConvenienceInitWithEmptyJSON() { + let jsonString = "{}" + + let cardData = PrimerBancontactCardData(bankcontactCardDataStr: jsonString) + XCTAssertNil(cardData, "Initialization should fail with empty JSON") + } + + func testConvenienceInitWithInvalidJSON() { + let jsonString = """ + { + "cardNumber": 1234567812345678, + "expiryDate": 12/24, + "cardholderName": "John Doe" + } + """ + + let cardData = PrimerBancontactCardData(bankcontactCardDataStr: jsonString) + XCTAssertNil(cardData, "Initialization should fail with invalid JSON format") + } + + func testConvenienceInitWithNonJSONString() { + let nonJSONString = "This is not a JSON string" + + let cardData = PrimerBancontactCardData(bankcontactCardDataStr: nonJSONString) + XCTAssertNil(cardData, "Initialization should fail with non-JSON string") + } +} diff --git a/packages/example/ios/example_0_70_6Tests/DataModelsTests/PrimerCardData+ExtensionTests.swift b/packages/example/ios/example_0_70_6Tests/DataModelsTests/PrimerCardData+ExtensionTests.swift new file mode 100644 index 000000000..64a3a0688 --- /dev/null +++ b/packages/example/ios/example_0_70_6Tests/DataModelsTests/PrimerCardData+ExtensionTests.swift @@ -0,0 +1,72 @@ +// +// PrimerCardData+ExtensionTests.swift +// example_0_70_6Tests +// +// Created by Boris on 20.5.24.. +// + +import XCTest +import PrimerSDK +@testable import primer_io_react_native + +class PrimerCardDataTests: XCTestCase { + + func testConvenienceInitWithValidJSON() { + let jsonString = """ + { + "cardNumber": "1234567812345678", + "cvv": "123", + "expiryDate": "12/24", + "cardholderName": "John Doe" + } + """ + + guard let cardData = PrimerCardData(cardDataStr: jsonString) else { + return XCTFail("Initialization should succeed with valid JSON") + } + + XCTAssertEqual(cardData.cardNumber, "1234567812345678") + XCTAssertEqual(cardData.cvv, "123") + XCTAssertEqual(cardData.expiryDate, "12/24") + XCTAssertEqual(cardData.cardholderName, "John Doe") + } + + func testConvenienceInitWithMissingFields() { + let jsonString = """ + { + "cardNumber": "1234567812345678", + "cvv": "123" + } + """ + + let cardData = PrimerCardData(cardDataStr: jsonString) + XCTAssertNil(cardData, "Initialization should fail if any required field is missing") + } + + func testConvenienceInitWithEmptyJSON() { + let jsonString = "{}" + + let cardData = PrimerCardData(cardDataStr: jsonString) + XCTAssertNil(cardData, "Initialization should fail with empty JSON") + } + + func testConvenienceInitWithInvalidJSON() { + let jsonString = """ + { + "cardNumber": 1234567812345678, + "cvv": 123, + "expiryDate": 12/24 + } + """ + + let cardData = PrimerCardData(cardDataStr: jsonString) + XCTAssertNil(cardData, "Initialization should fail with invalid JSON format") + } + + func testConvenienceInitWithNonJSONString() { + let nonJSONString = "This is not a JSON string" + + let cardData = PrimerCardData(cardDataStr: nonJSONString) + XCTAssertNil(cardData, "Initialization should fail with non-JSON string") + } +} diff --git a/packages/example/ios/example_0_70_6Tests/DataModelsTests/PrimerPhoneNumberData+ExtensionTests.swift b/packages/example/ios/example_0_70_6Tests/DataModelsTests/PrimerPhoneNumberData+ExtensionTests.swift new file mode 100644 index 000000000..6a30c9bfd --- /dev/null +++ b/packages/example/ios/example_0_70_6Tests/DataModelsTests/PrimerPhoneNumberData+ExtensionTests.swift @@ -0,0 +1,63 @@ +// +// PrimerPhoneNumberData+ExtensionTests.swift +// example_0_70_6Tests +// +// Created by Boris on 20.5.24.. +// + +import PrimerSDK +import XCTest +@testable import primer_io_react_native + +class PrimerPhoneNumberDataTests: XCTestCase { + + func testConvenienceInitWithValidJSON() { + let jsonString = """ + { + "phoneNumber": "+1234567890" + } + """ + + guard let phoneNumberData = PrimerPhoneNumberData(phoneNumbeDatarStr: jsonString) else { + return XCTFail("Initialization should succeed with valid JSON") + } + + XCTAssertEqual(phoneNumberData.phoneNumber, "+1234567890") + } + + func testConvenienceInitWithMissingPhoneNumber() { + let jsonString = """ + { + "anotherField": "value" + } + """ + + let phoneNumberData = PrimerPhoneNumberData(phoneNumbeDatarStr: jsonString) + XCTAssertNil(phoneNumberData, "Initialization should fail if phoneNumber field is missing") + } + + func testConvenienceInitWithEmptyJSON() { + let jsonString = "{}" + + let phoneNumberData = PrimerPhoneNumberData(phoneNumbeDatarStr: jsonString) + XCTAssertNil(phoneNumberData, "Initialization should fail with empty JSON") + } + + func testConvenienceInitWithInvalidJSON() { + let jsonString = """ + { + "phoneNumber": 1234567890 + } + """ + + let phoneNumberData = PrimerPhoneNumberData(phoneNumbeDatarStr: jsonString) + XCTAssertNil(phoneNumberData, "Initialization should fail with invalid JSON format") + } + + func testConvenienceInitWithNonJSONString() { + let nonJSONString = "This is not a JSON string" + + let phoneNumberData = PrimerPhoneNumberData(phoneNumbeDatarStr: nonJSONString) + XCTAssertNil(phoneNumberData, "Initialization should fail with non-JSON string") + } +} diff --git a/packages/example/ios/example_0_70_6Tests/DataModelsTests/PrimerRawRetailerData+ExtensionTests.swift b/packages/example/ios/example_0_70_6Tests/DataModelsTests/PrimerRawRetailerData+ExtensionTests.swift new file mode 100644 index 000000000..1a4868435 --- /dev/null +++ b/packages/example/ios/example_0_70_6Tests/DataModelsTests/PrimerRawRetailerData+ExtensionTests.swift @@ -0,0 +1,63 @@ +// +// PrimerRawRetailerData+ExtensionTests.swift +// example_0_70_6Tests +// +// Created by Boris on 20.5.24.. +// + +import XCTest +import PrimerSDK +@testable import primer_io_react_native + +class PrimerRawRetailerDataTests: XCTestCase { + + func testConvenienceInitWithValidJSON() { + let jsonString = """ + { + "id": "retailer123" + } + """ + + guard let retailerData = PrimerRetailerData(primerRetailerDataStr: jsonString) else { + return XCTFail("Initialization should succeed with valid JSON") + } + + XCTAssertEqual(retailerData.id, "retailer123") + } + + func testConvenienceInitWithMissingId() { + let jsonString = """ + { + "anotherField": "value" + } + """ + + let retailerData = PrimerRetailerData(primerRetailerDataStr: jsonString) + XCTAssertNil(retailerData, "Initialization should fail if id field is missing") + } + + func testConvenienceInitWithEmptyJSON() { + let jsonString = "{}" + + let retailerData = PrimerRetailerData(primerRetailerDataStr: jsonString) + XCTAssertNil(retailerData, "Initialization should fail with empty JSON") + } + + func testConvenienceInitWithInvalidJSON() { + let jsonString = """ + { + "id": 123 + } + """ + + let retailerData = PrimerRetailerData(primerRetailerDataStr: jsonString) + XCTAssertNil(retailerData, "Initialization should fail with invalid JSON format") + } + + func testConvenienceInitWithNonJSONString() { + let nonJSONString = "This is not a JSON string" + + let retailerData = PrimerRetailerData(primerRetailerDataStr: nonJSONString) + XCTAssertNil(retailerData, "Initialization should fail with non-JSON string") + } +} diff --git a/packages/example/ios/example_0_70_6Tests/DataModelsTests/PrimerSettings+ExtensionsTests.swift b/packages/example/ios/example_0_70_6Tests/DataModelsTests/PrimerSettings+ExtensionsTests.swift new file mode 100644 index 000000000..b3ffebbcb --- /dev/null +++ b/packages/example/ios/example_0_70_6Tests/DataModelsTests/PrimerSettings+ExtensionsTests.swift @@ -0,0 +1,45 @@ +// +// PrimerSettings+ExtensionsTests.swift +// example_0_70_6Tests +// +// Created by Boris on 20.5.24.. +// + +import XCTest +@testable import primer_io_react_native +import PrimerSDK + +class PrimerSettingsTests: XCTestCase { + + func testConvenienceInitWithMissingFields() { + let jsonString = """ + { + "paymentHandling": "AUTO" + } + """ + + do { + let settings = try PrimerSettings(settingsStr: jsonString) + XCTAssertEqual(settings.paymentHandling, .auto) + } catch { + XCTFail("Initialization should succeed with missing optional fields") + } + } + + func testConvenienceInitWithEmptyJSON() { + let jsonString = "{}" + + do { + let settings = try PrimerSettings(settingsStr: jsonString) + XCTAssertEqual(settings.paymentHandling, .auto) + } catch { + XCTFail("Initialization should succeed with empty JSON") + } + } + + func testConvenienceInitWithNonJSONString() { + let nonJSONString = "This is not a JSON string" + + XCTAssertThrowsError(try PrimerSettings(settingsStr: nonJSONString), "Initialization should fail with non-JSON string") + } +} diff --git a/packages/example/ios/example_0_70_6Tests/DataModelsTests/PrimerThemeRNTests.swift b/packages/example/ios/example_0_70_6Tests/DataModelsTests/PrimerThemeRNTests.swift new file mode 100644 index 000000000..09c71a0ab --- /dev/null +++ b/packages/example/ios/example_0_70_6Tests/DataModelsTests/PrimerThemeRNTests.swift @@ -0,0 +1,84 @@ +// +// PrimerThemeRNTests.swift +// example_0_70_6Tests +// +// Created by Boris on 20.5.24.. +// + +import XCTest +@testable import primer_io_react_native +import PrimerSDK + +class PrimerThemeRNTests: XCTestCase { + + func testAsPrimerTheme() { + let jsonString = """ + { + "colors": { + "mainColor": { + "red": 255, + "green": 0, + "blue": 0, + "alpha": 255 + }, + "contrastingColor": { + "red": 0, + "green": 255, + "blue": 0, + "alpha": 255 + }, + "background": { + "red": 0, + "green": 0, + "blue": 255, + "alpha": 255 + }, + "text": { + "red": 0, + "green": 0, + "blue": 0, + "alpha": 255 + }, + "contrastingText": { + "red": 255, + "green": 255, + "blue": 255, + "alpha": 255 + }, + "borders": { + "red": 128, + "green": 128, + "blue": 128, + "alpha": 255 + }, + "disabled": { + "red": 192, + "green": 192, + "blue": 192, + "alpha": 255 + }, + "error": { + "red": 255, + "green": 0, + "blue": 0, + "alpha": 255 + } + } + } + """ + + guard let data = jsonString.data(using: .utf8) else { + return XCTFail("Failed to convert JSON string to data") + } + + do { + let primerThemeRN = try JSONDecoder().decode(PrimerThemeRN.self, from: data) + let primerTheme = primerThemeRN.asPrimerTheme() + + // Add assertions to verify the conversion to PrimerTheme + XCTAssertNotNil(primerTheme) + } catch { + XCTFail("Decoding or conversion failed: \(error)") + } + } +} diff --git a/packages/example/ios/example_0_70_6Tests/DataModelsTests/RNTNativeErrorTests.swift b/packages/example/ios/example_0_70_6Tests/DataModelsTests/RNTNativeErrorTests.swift new file mode 100644 index 000000000..a01a9f133 --- /dev/null +++ b/packages/example/ios/example_0_70_6Tests/DataModelsTests/RNTNativeErrorTests.swift @@ -0,0 +1,40 @@ +// +// RNTNativeErrorTests.swift +// example_0_70_6Tests +// +// Created by Boris on 20.5.24.. +// + +import XCTest +@testable import primer_io_react_native + +class RNTNativeErrorTests: XCTestCase { + + func testRnErrorWithRecoverySuggestion() { + let error = RNTNativeError(errorId: "testId", errorDescription: "Test description", recoverySuggestion: "Try again") + let expected = [ + "errorId": "testId", + "description": "Test description", + "recoverySuggestion": "Try again" + ] + XCTAssertEqual(error.rnError, expected) + } + + func testRnErrorWithoutRecoverySuggestion() { + let error = RNTNativeError(errorId: "testId", errorDescription: "Test description", recoverySuggestion: nil) + let expected = [ + "errorId": "testId", + "description": "Test description" + ] + XCTAssertEqual(error.rnError, expected) + } + + func testRnErrorWithNilDescription() { + let error = RNTNativeError(errorId: "testId", errorDescription: nil, recoverySuggestion: nil) + let expected = [ + "errorId": "testId", + "description": "Something went wrong" + ] + XCTAssertEqual(error.rnError, expected) + } +} diff --git a/packages/example/ios/example_0_70_6Tests/ErrorExtensionTests.swift b/packages/example/ios/example_0_70_6Tests/ErrorExtensionTests.swift deleted file mode 100644 index e50e35a14..000000000 --- a/packages/example/ios/example_0_70_6Tests/ErrorExtensionTests.swift +++ /dev/null @@ -1,71 +0,0 @@ -// -// ErrorExtensionTests.swift -// example_0_70_6Tests -// -// Created by Boris on 17.5.24.. -// - -import XCTest -import PrimerSDK -@testable import primer_io_react_native - -class ErrorExtensionTests: XCTestCase { - - func testRNErrorForPrimerValidationError() { - let error = PrimerValidationError.invalidCardnumber(message: "Invalid card number", userInfo: ["key": "value"], diagnosticsId: "12345") - - let expected: [String: String] = [ - "description": "[invalid-card-number] Invalid card number", - "errorId": "invalid-card-number", - "diagnosticsId": "12345", - "inputElementType": "CARD_NUMBER" - ] - - XCTAssertEqual(error.rnError, expected) - } - - func testRNErrorForPrimerError() { - let error = PrimerError.generic(message: "message", userInfo: ["test1": "test2"], diagnosticsId: "diagnosticsId123") - - let expected: [String: String] = [ - "errorId": "primer-generic", - "diagnosticsId": "diagnosticsId123", - "description": "[primer-generic] Generic error | Message: message | Data: {\n \"test1\" : \"test2\"\n}) (diagnosticsId: diagnosticsId123)" - ] - XCTAssertEqual(error.rnError, expected) - } - - func testRNErrorForNSError() { - let userInfo: [String: Any] = [ - NSLocalizedDescriptionKey: "An error occurred", - "inputElementType": "TEXT_FIELD", - NSLocalizedRecoverySuggestionErrorKey: "Try again" - ] - let error = NSError(domain: "com.example.error", code: 1001, userInfo: userInfo) - - let expected: [String: String] = [ - "description": "An error occurred", - "errorId": "com.example.error", - "inputElementType": "TEXT_FIELD", - "recoverySuggestion": "Try again" - ] - - XCTAssertEqual(error.rnError, expected) - } - - func testRNErrorForNSErrorWithoutRecoverySuggestion() { - let userInfo: [String: Any] = [ - NSLocalizedDescriptionKey: "Another error occurred", - "inputElementType": "BUTTON" - ] - let error = NSError(domain: "com.example.anotherError", code: 1002, userInfo: userInfo) - - let expected: [String: String] = [ - "description": "Another error occurred", - "errorId": "com.example.anotherError", - "inputElementType": "BUTTON" - ] - - XCTAssertEqual(error.rnError, expected) - } -} diff --git a/packages/example/ios/example_0_70_6Tests/HelpersTests/CodableExtensionsTests.swift b/packages/example/ios/example_0_70_6Tests/HelpersTests/CodableExtensionsTests.swift new file mode 100644 index 000000000..3d9d616ba --- /dev/null +++ b/packages/example/ios/example_0_70_6Tests/HelpersTests/CodableExtensionsTests.swift @@ -0,0 +1,55 @@ +// +// CodableExtensionsTests.swift +// example_0_70_6Tests +// +// Created by Boris on 17.5.24.. +// + +import XCTest +@testable import primer_io_react_native + +// Define test structs conforming to Encodable and Decodable for testing purposes +fileprivate struct TestStruct: Codable, Equatable { + let id: Int + let name: String +} + +// Unit test class for the extensions +class CodableExtensionsTests: XCTestCase { + + func testEncodableToJsonObject() { + let testObject = TestStruct(id: 1, name: "Test") + + do { + let jsonObject = try testObject.toJsonObject() + XCTAssertNotNil(jsonObject) + if let jsonDict = jsonObject as? [String: Any] { + XCTAssertEqual(jsonDict["id"] as? Int, 1) + XCTAssertEqual(jsonDict["name"] as? String, "Test") + } else { + XCTFail("Encoded object is not a valid JSON dictionary") + } + } catch { + XCTFail("Encoding to JSON object failed with error: \(error)") + } + } + + func testDecodableFromJsonString() { + let jsonString = "{\"id\":1,\"name\":\"Test\"}" + + do { + let testObject = try TestStruct.from(jsonString: jsonString) + XCTAssertEqual(testObject, TestStruct(id: 1, name: "Test")) + } catch { + XCTFail("Decoding from JSON string failed with error: \(error)") + } + } + + func testDecodableFromInvalidJsonString() { + let invalidJsonString = "{\"id\":1,\"name\":}" + + XCTAssertThrowsError(try TestStruct.from(jsonString: invalidJsonString)) { error in + XCTAssertTrue(error is DecodingError) + } + } +} diff --git a/packages/example/ios/example_0_70_6Tests/HelpersTests/ErrorExtensionTests.swift b/packages/example/ios/example_0_70_6Tests/HelpersTests/ErrorExtensionTests.swift new file mode 100644 index 000000000..4a78a7392 --- /dev/null +++ b/packages/example/ios/example_0_70_6Tests/HelpersTests/ErrorExtensionTests.swift @@ -0,0 +1,71 @@ +// +// ErrorExtensionTests.swift +// example_0_70_6Tests +// +// Created by Boris on 17.5.24.. +// + +import XCTest +import PrimerSDK +@testable import primer_io_react_native + +class ErrorExtensionTests: XCTestCase { + + func testRNErrorForPrimerValidationError() { + let error = PrimerValidationError.invalidCardnumber(message: "Invalid card number", userInfo: ["key": "value"], diagnosticsId: "12345") + + let expected: [String: String] = [ + "description": "[invalid-card-number] Invalid card number", + "errorId": "invalid-card-number", + "diagnosticsId": "12345", + "inputElementType": "CARD_NUMBER" + ] + + XCTAssertEqual(error.rnError, expected) + } + + func testRNErrorForPrimerError() { + let error = PrimerError.generic(message: "message", userInfo: ["test1": "test2"], diagnosticsId: "diagnosticsId123") + + let expected: [String: String] = [ + "errorId": "primer-generic", + "diagnosticsId": "diagnosticsId123", + "description": "[primer-generic] Generic error | Message: message | Data: {\n \"test1\" : \"test2\"\n}) (diagnosticsId: diagnosticsId123)" + ] + XCTAssertEqual(error.rnError, expected) + } + + func testRNErrorForNSError() { + let userInfo: [String: Any] = [ + NSLocalizedDescriptionKey: "An error occurred", + "inputElementType": "TEXT_FIELD", + NSLocalizedRecoverySuggestionErrorKey: "Try again" + ] + let error = NSError(domain: "com.example.error", code: 1001, userInfo: userInfo) + + let expected: [String: String] = [ + "description": "An error occurred", + "errorId": "com.example.error", + "inputElementType": "TEXT_FIELD", + "recoverySuggestion": "Try again" + ] + + XCTAssertEqual(error.rnError, expected) + } + + func testRNErrorForNSErrorWithoutRecoverySuggestion() { + let userInfo: [String: Any] = [ + NSLocalizedDescriptionKey: "Another error occurred", + "inputElementType": "BUTTON" + ] + let error = NSError(domain: "com.example.anotherError", code: 1002, userInfo: userInfo) + + let expected: [String: String] = [ + "description": "Another error occurred", + "errorId": "com.example.anotherError", + "inputElementType": "BUTTON" + ] + + XCTAssertEqual(error.rnError, expected) + } +} diff --git a/packages/example/ios/example_0_70_6Tests/HelpersTests/PrimerCheckoutPaymentMethodTypeTests.swift b/packages/example/ios/example_0_70_6Tests/HelpersTests/PrimerCheckoutPaymentMethodTypeTests.swift new file mode 100644 index 000000000..ed1e92268 --- /dev/null +++ b/packages/example/ios/example_0_70_6Tests/HelpersTests/PrimerCheckoutPaymentMethodTypeTests.swift @@ -0,0 +1,72 @@ +// +// PrimerCheckoutPaymentMethodTypeTests.swift +// example_0_70_6Tests +// +// Created by Boris on 20.5.24.. +// + +import XCTest +import PrimerSDK +@testable import primer_io_react_native + +class PrimerCheckoutPaymentMethodDataTests: XCTestCase { + + func testInitialization() { + let paymentMethodType = PrimerCheckoutPaymentMethodType(type: "credit_card") + let paymentMethodData = PrimerCheckoutPaymentMethodData(type: paymentMethodType) + + XCTAssertEqual(paymentMethodData.paymentMethodType.type, "credit_card") + } + + func testToPrimerCheckoutPaymentMethodDataRN() { + let paymentMethodType = PrimerCheckoutPaymentMethodType(type: "credit_card") + let paymentMethodData = PrimerCheckoutPaymentMethodData(type: paymentMethodType) + + let paymentMethodDataRN = paymentMethodData.toPrimerCheckoutPaymentMethodDataRN() + + XCTAssertEqual(paymentMethodDataRN.paymentMethodType.type, "credit_card") + XCTAssertEqual(paymentMethodDataRN.paymentMethod, "credit_card") + } + + func testCodableConformance() { + let paymentMethodType = PrimerCheckoutPaymentMethodType(type: "credit_card") + let paymentMethodData = PrimerCheckoutPaymentMethodData(type: paymentMethodType) + + let encoder = JSONEncoder() + let decoder = JSONDecoder() + + do { + let data = try encoder.encode(paymentMethodData) + let decodedPaymentMethodData = try decoder.decode(PrimerCheckoutPaymentMethodData.self, from: data) + + XCTAssertEqual(decodedPaymentMethodData.paymentMethodType.type, "credit_card") + } catch { + XCTFail("Encoding or decoding failed: \(error)") + } + } +} + +class PrimerCheckoutPaymentMethodTypeTests: XCTestCase { + + func testInitialization() { + let paymentMethodType = PrimerCheckoutPaymentMethodType(type: "credit_card") + + XCTAssertEqual(paymentMethodType.type, "credit_card") + } + + func testCodableConformance() { + let paymentMethodType = PrimerCheckoutPaymentMethodType(type: "credit_card") + + let encoder = JSONEncoder() + let decoder = JSONDecoder() + + do { + let data = try encoder.encode(paymentMethodType) + let decodedPaymentMethodType = try decoder.decode(PrimerCheckoutPaymentMethodType.self, from: data) + + XCTAssertEqual(decodedPaymentMethodType.type, "credit_card") + } catch { + XCTFail("Encoding or decoding failed: \(error)") + } + } +} diff --git a/packages/example/ios/example_0_70_6Tests/HelpersTests/UIColorExtensionTests.swift b/packages/example/ios/example_0_70_6Tests/HelpersTests/UIColorExtensionTests.swift new file mode 100644 index 000000000..2aa714750 --- /dev/null +++ b/packages/example/ios/example_0_70_6Tests/HelpersTests/UIColorExtensionTests.swift @@ -0,0 +1,35 @@ +// +// UIColorExtensionTests.swift +// example_0_70_6Tests +// +// Created by Niall Quinn on 16/05/24. +// + +import XCTest +@testable import primer_io_react_native + +final class UIColorExtensionTests: XCTestCase { + + func test_toHex() throws { + // Tesddt case 1: RGB color without alpha + let color1 = UIColor(red: 0, green: 0, blue: 0, alpha: 1.0) + XCTAssertEqual(color1.toHex(), "000000") + + let color2 = UIColor(red: 1, green: 1, blue: 1, alpha: 1.0) + XCTAssertEqual(color2.toHex(), "FFFFFF") + + let color3 = UIColor(red: 1, green: 0, blue: 0, alpha: 1.0) + XCTAssertEqual(color3.toHex(), "FF0000") + + let color4 = UIColor(red: 0, green: 1, blue: 0, alpha: 1.0) + XCTAssertEqual(color4.toHex(), "00FF00") + + let color5 = UIColor(red: 0, green: 0, blue: 1, alpha: 1.0) + XCTAssertEqual(color5.toHex(), "0000FF") + + let noAlpha = UIColor(red: 0, green: 0, blue: 1, alpha: 1.0) + XCTAssertEqual(noAlpha.toHex(alpha: true), "0000FFFF") + + } + +} diff --git a/packages/example/ios/example_0_70_6Tests/UIImageExtensionTests.swift b/packages/example/ios/example_0_70_6Tests/HelpersTests/UIImageExtensionTests.swift similarity index 100% rename from packages/example/ios/example_0_70_6Tests/UIImageExtensionTests.swift rename to packages/example/ios/example_0_70_6Tests/HelpersTests/UIImageExtensionTests.swift diff --git a/packages/example/ios/example_0_70_6Tests/RNTPrimerTests.swift b/packages/example/ios/example_0_70_6Tests/RNTPrimerTests.swift new file mode 100644 index 000000000..cae152827 --- /dev/null +++ b/packages/example/ios/example_0_70_6Tests/RNTPrimerTests.swift @@ -0,0 +1,171 @@ +// +// RNTPrimerTests.swift +// example_0_70_6Tests +// +// Created by Boris on 20.5.24.. +// + +import XCTest +import PrimerSDK +@testable import primer_io_react_native + +class RNTPrimerTests: XCTestCase { + + var rnPrimer: RNTPrimer! + + override func setUp() { + super.setUp() + rnPrimer = RNTPrimer() + } + + override func tearDown() { + rnPrimer = nil + super.tearDown() + } + + // MARK: - INITIALIZATION & REACT NATIVE SUPPORT + + func testInitialization() { + XCTAssertNotNil(rnPrimer) + XCTAssertTrue(RNTPrimer.requiresMainQueueSetup()) + } + + func testSupportedEvents() { + let expectedEvents = PrimerEvents.allCases.map { $0.stringValue } + XCTAssertEqual(rnPrimer.supportedEvents(), expectedEvents) + } + + // MARK: - SDK API + + func testConfigure() { + let expectation = self.expectation(description: "Configure completes") + + rnPrimer.configure("{\"setting\":\"value\"}", resolver: { _ in + expectation.fulfill() + }, rejecter: { _, _, _ in + XCTFail("Configure failed") + }) + + waitForExpectations(timeout: 2.0, handler: nil) + } + + func testDismiss() { + rnPrimer.dismiss() + // No specific assertion as dismiss method doesn't return a value + } + + func testCleanUp() { + rnPrimer.cleanUp() + // No specific assertion as cleanUp method doesn't return a value + } + + // MARK: - DECISION HANDLERS + + func testHandleTokenizationNewClientToken() { + let expectation = self.expectation(description: "HandleTokenizationNewClientToken completes") + + rnPrimer.handleTokenizationNewClientToken("newClientToken", resolver: { _ in + expectation.fulfill() + }, rejecter: { _, _, _ in + XCTFail("HandleTokenizationNewClientToken failed") + }) + + waitForExpectations(timeout: 2.0, handler: nil) + } + + func testHandleTokenizationSuccess() { + let expectation = self.expectation(description: "HandleTokenizationSuccess completes") + + rnPrimer.handleTokenizationSuccess({ _ in + expectation.fulfill() + }, rejecter: { _, _, _ in + XCTFail("HandleTokenizationSuccess failed") + }) + + waitForExpectations(timeout: 2.0, handler: nil) + } + + func testHandleTokenizationFailure() { + let expectation = self.expectation(description: "HandleTokenizationFailure completes") + + rnPrimer.handleTokenizationFailure("errorMessage", resolver: { _ in + expectation.fulfill() + }, rejecter: { _, _, _ in + XCTFail("HandleTokenizationFailure failed") + }) + + waitForExpectations(timeout: 2.0, handler: nil) + } + + func testHandleResumeWithNewClientToken() { + let expectation = self.expectation(description: "HandleResumeWithNewClientToken completes") + + rnPrimer.handleResumeWithNewClientToken("newClientToken", resolver: { _ in + expectation.fulfill() + }, rejecter: { _, _, _ in + XCTFail("HandleResumeWithNewClientToken failed") + }) + + waitForExpectations(timeout: 2.0, handler: nil) + } + + func testHandleResumeSuccess() { + let expectation = self.expectation(description: "HandleResumeSuccess completes") + + rnPrimer.handleResumeSuccess({ _ in + expectation.fulfill() + }, rejecter: { _, _, _ in + XCTFail("HandleResumeSuccess failed") + }) + + waitForExpectations(timeout: 2.0, handler: nil) + } + + func testHandleResumeFailure() { + let expectation = self.expectation(description: "HandleResumeFailure completes") + + rnPrimer.handleResumeFailure("errorMessage", resolver: { _ in + expectation.fulfill() + }, rejecter: { _, _, _ in + XCTFail("HandleResumeFailure failed") + }) + + waitForExpectations(timeout: 2.0, handler: nil) + } + + func testHandlePaymentCreationAbort() { + let expectation = self.expectation(description: "HandlePaymentCreationAbort completes") + + rnPrimer.handlePaymentCreationAbort("errorMessage", resolver: { _ in + expectation.fulfill() + }, rejecter: { _, _, _ in + XCTFail("HandlePaymentCreationAbort failed") + }) + + waitForExpectations(timeout: 2.0, handler: nil) + } + + func testHandlePaymentCreationContinue() { + let expectation = self.expectation(description: "HandlePaymentCreationContinue completes") + + rnPrimer.handlePaymentCreationContinue({ _ in + expectation.fulfill() + }, rejecter: { _, _, _ in + XCTFail("HandlePaymentCreationContinue failed") + }) + + waitForExpectations(timeout: 2.0, handler: nil) + } + + func testShowErrorMessage() { + let expectation = self.expectation(description: "ShowErrorMessage completes") + + rnPrimer.showErrorMessage("errorMessage", resolver: { _ in + expectation.fulfill() + }, rejecter: { _, _, _ in + XCTFail("ShowErrorMessage failed") + }) + + waitForExpectations(timeout: 2.0, handler: nil) + } +} diff --git a/packages/example/ios/example_0_70_6Tests/UIColorExtensionTests.swift b/packages/example/ios/example_0_70_6Tests/UIColorExtensionTests.swift deleted file mode 100644 index 7bb01cc30..000000000 --- a/packages/example/ios/example_0_70_6Tests/UIColorExtensionTests.swift +++ /dev/null @@ -1,35 +0,0 @@ -// -// UIColorExtensionTests.swift -// example_0_70_6Tests -// -// Created by Niall Quinn on 16/05/24. -// - -import XCTest -@testable import primer_io_react_native - -final class UIColorExtensionTests: XCTestCase { - - func test_toHex() throws { - // Tesddt case 1: RGB color without alpha - let color1 = UIColor(red: 0, green: 0, blue: 0, alpha: 1.0) - XCTAssertEqual(color1.toHex(), "000000") - - let color2 = UIColor(red: 1, green: 1, blue: 1, alpha: 1.0) - XCTAssertEqual(color2.toHex(), "FFFFFF") - - let color3 = UIColor(red: 1, green: 0, blue: 0, alpha: 1.0) - XCTAssertEqual(color3.toHex(), "FF0000") - - let color4 = UIColor(red: 0, green: 1, blue: 0, alpha: 1.0) - XCTAssertEqual(color4.toHex(), "00FF00") - - let color5 = UIColor(red: 0, green: 0, blue: 1, alpha: 1.0) - XCTAssertEqual(color5.toHex(), "0000FF") - - let noAlpha = UIColor(red: 0, green: 0, blue: 1, alpha: 1.0) - XCTAssertEqual(noAlpha.toHex(alpha: true), "0000FFFF") - - } - -} diff --git a/packages/sdk/ios/Sources/RNTPrimer.swift b/packages/sdk/ios/Sources/RNTPrimer.swift index 851277908..7fcb98574 100644 --- a/packages/sdk/ios/Sources/RNTPrimer.swift +++ b/packages/sdk/ios/Sources/RNTPrimer.swift @@ -291,13 +291,17 @@ class RNTPrimer: RCTEventEmitter { var body: [String: Any] = ["error": error.rnError] if let checkoutData = checkoutData, let data = try? JSONEncoder().encode(checkoutData), - let json = try? JSONSerialization.jsonObject(with: data){ + let json = try? JSONSerialization.jsonObject(with: data) { body["checkoutData"] = json } - print(body) - self.sendEvent(withName: PrimerEvents.onError.stringValue, body: body) + if self.bridge != nil { + self.sendEvent(withName: PrimerEvents.onError.stringValue, body: body) + } else { + print("Bridge is not set") + } } } + } // MARK: - PRIMER DELEGATE