diff --git a/CHANGELOG.md b/CHANGELOG.md index 3f004c79..1e5998f2 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,5 +1,8 @@ Changelog ========= +[1.0.0-beta14](https://github.com/hyperwallet/hyperwallet-ios-sdk/releases/tag/1.0.0-beta14) +------------------- +- Performance update for Add Transfer Method GraphQL [1.0.0-beta13](https://github.com/hyperwallet/hyperwallet-ios-sdk/releases/tag/1.0.0-beta13) ------------------- diff --git a/HyperwalletSDK.podspec b/HyperwalletSDK.podspec index 92c777b3..4ea36714 100644 --- a/HyperwalletSDK.podspec +++ b/HyperwalletSDK.podspec @@ -1,6 +1,6 @@ Pod::Spec.new do |spec| spec.name = 'HyperwalletSDK' - spec.version = '1.0.0-beta13' + spec.version = '1.0.0-beta14' spec.summary = 'Hyperwallet Core SDK for iOS to integrate with Hyperwallet Platform' spec.homepage = 'https://github.com/hyperwallet/hyperwallet-ios-sdk' spec.license = { :type => 'MIT', :file => 'LICENSE' } diff --git a/HyperwalletSDK.xcodeproj/project.pbxproj b/HyperwalletSDK.xcodeproj/project.pbxproj index 65f9a12f..392e5826 100644 --- a/HyperwalletSDK.xcodeproj/project.pbxproj +++ b/HyperwalletSDK.xcodeproj/project.pbxproj @@ -140,9 +140,11 @@ E8438CA7F43C3CB6FD545187 /* VenmoAccountResponse.json in Resources */ = {isa = PBXBuildFile; fileRef = E843856BD0D7E5295973780D /* VenmoAccountResponse.json */; }; E8438DB98656EB3F69DE0776 /* VenmoAccountWrongFormatAccountId.json in Resources */ = {isa = PBXBuildFile; fileRef = E84381CE41DDB491C2F2B63D /* VenmoAccountWrongFormatAccountId.json */; }; FD1208CC2581FE3200A8D8B2 /* TransferMethodUpdateConfigurationFieldsVenmoResponse.json in Resources */ = {isa = PBXBuildFile; fileRef = FD1208CB2581FE3200A8D8B2 /* TransferMethodUpdateConfigurationFieldsVenmoResponse.json */; }; + FD2B6ECB2670D6980021078B /* TransferMethodConfigurationFeeAndProcessingTimeResponse.json in Resources */ = {isa = PBXBuildFile; fileRef = FD2B6ECA2670D6980021078B /* TransferMethodConfigurationFeeAndProcessingTimeResponse.json */; }; FD536D072579F98B0056DC2D /* HyperwalletTransferMethodUpdateConfigurationQueries.swift in Sources */ = {isa = PBXBuildFile; fileRef = FD536D062579F98B0056DC2D /* HyperwalletTransferMethodUpdateConfigurationQueries.swift */; }; FD536D09257A3C610056DC2D /* HyperwalletTransferMethodUpdateConfigurationField.swift in Sources */ = {isa = PBXBuildFile; fileRef = FD536D08257A3C610056DC2D /* HyperwalletTransferMethodUpdateConfigurationField.swift */; }; FD536D0C257A60CE0056DC2D /* HyperwalletTransferMethodUpdateConfigurationTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = FD536D0A257A60920056DC2D /* HyperwalletTransferMethodUpdateConfigurationTests.swift */; }; + FDBCC62A26725217002CEF55 /* HyperwalletTransferMethodConfigurationFeeAndProcessingTimeQueryTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = FDBCC62926725217002CEF55 /* HyperwalletTransferMethodConfigurationFeeAndProcessingTimeQueryTests.swift */; }; FDD2F4CF2580AFB0008E4CFC /* TransferMethodUpdateConfigurationFieldsPaypalResponse.json in Resources */ = {isa = PBXBuildFile; fileRef = FDD2F4CE2580AFB0008E4CFC /* TransferMethodUpdateConfigurationFieldsPaypalResponse.json */; }; FDD2F4D12580B1D0008E4CFC /* TransferMethodUpdateConfigurationFieldsBankCardResponse.json in Resources */ = {isa = PBXBuildFile; fileRef = FDD2F4D02580B1D0008E4CFC /* TransferMethodUpdateConfigurationFieldsBankCardResponse.json */; }; FDF2E7A6257E06D600589076 /* TransferMethodUpdateConfigurationFieldsResponse.json in Resources */ = {isa = PBXBuildFile; fileRef = FDF2E7A5257E06D600589076 /* TransferMethodUpdateConfigurationFieldsResponse.json */; }; @@ -292,10 +294,12 @@ E8438F714A2ED30BE185DE8C /* HyperwalletVenmoQueryParam.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = HyperwalletVenmoQueryParam.swift; sourceTree = ""; }; E8438FACD77368B4A83CCA41 /* HyperwalletVenmoAccount.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = HyperwalletVenmoAccount.swift; sourceTree = ""; }; FD1208CB2581FE3200A8D8B2 /* TransferMethodUpdateConfigurationFieldsVenmoResponse.json */ = {isa = PBXFileReference; lastKnownFileType = text.json; path = TransferMethodUpdateConfigurationFieldsVenmoResponse.json; sourceTree = ""; }; + FD2B6ECA2670D6980021078B /* TransferMethodConfigurationFeeAndProcessingTimeResponse.json */ = {isa = PBXFileReference; lastKnownFileType = text.json; path = TransferMethodConfigurationFeeAndProcessingTimeResponse.json; sourceTree = ""; }; FD536D062579F98B0056DC2D /* HyperwalletTransferMethodUpdateConfigurationQueries.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = HyperwalletTransferMethodUpdateConfigurationQueries.swift; sourceTree = ""; }; FD536D08257A3C610056DC2D /* HyperwalletTransferMethodUpdateConfigurationField.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = HyperwalletTransferMethodUpdateConfigurationField.swift; sourceTree = ""; }; FD536D0A257A60920056DC2D /* HyperwalletTransferMethodUpdateConfigurationTests.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = HyperwalletTransferMethodUpdateConfigurationTests.swift; sourceTree = ""; }; FD8C499225E014E30062A440 /* Hippolyte.xcframework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.xcframework; name = Hippolyte.xcframework; path = Carthage/Build/Hippolyte.xcframework; sourceTree = ""; }; + FDBCC62926725217002CEF55 /* HyperwalletTransferMethodConfigurationFeeAndProcessingTimeQueryTests.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = HyperwalletTransferMethodConfigurationFeeAndProcessingTimeQueryTests.swift; sourceTree = ""; }; FDD2F4CE2580AFB0008E4CFC /* TransferMethodUpdateConfigurationFieldsPaypalResponse.json */ = {isa = PBXFileReference; lastKnownFileType = text.json; path = TransferMethodUpdateConfigurationFieldsPaypalResponse.json; sourceTree = ""; }; FDD2F4D02580B1D0008E4CFC /* TransferMethodUpdateConfigurationFieldsBankCardResponse.json */ = {isa = PBXFileReference; lastKnownFileType = text.json; path = TransferMethodUpdateConfigurationFieldsBankCardResponse.json; sourceTree = ""; }; FDF2E7A5257E06D600589076 /* TransferMethodUpdateConfigurationFieldsResponse.json */ = {isa = PBXFileReference; lastKnownFileType = text.json; path = TransferMethodUpdateConfigurationFieldsResponse.json; sourceTree = ""; }; @@ -628,6 +632,7 @@ isa = PBXGroup; children = ( DB45190E22DD00A00022BD1F /* HyperwalletTransferMethodConfigurationFieldQueryTests.swift */, + FDBCC62926725217002CEF55 /* HyperwalletTransferMethodConfigurationFeeAndProcessingTimeQueryTests.swift */, ); path = Query; sourceTree = ""; @@ -675,6 +680,7 @@ DBCA37A9225D6D1700CD4137 /* TransferMethodConfigurationFieldsResponse.json */, DBCA37A4225D6D1600CD4137 /* TransferMethodConfigurationGraphQlResponse.json */, DBCA37AD225D6D1700CD4137 /* TransferMethodConfigurationKeysResponse.json */, + FD2B6ECA2670D6980021078B /* TransferMethodConfigurationFeeAndProcessingTimeResponse.json */, FDF2E7A5257E06D600589076 /* TransferMethodUpdateConfigurationFieldsResponse.json */, FDD2F4D02580B1D0008E4CFC /* TransferMethodUpdateConfigurationFieldsBankCardResponse.json */, FDD2F4CE2580AFB0008E4CFC /* TransferMethodUpdateConfigurationFieldsPaypalResponse.json */, @@ -843,6 +849,7 @@ 64278CAF22C0CE0D00B8736B /* CreateTransferResponseInvalidDestinationToken.json in Resources */, DBCA37B8225D6D1700CD4137 /* TransferMethodConfigurationKeysWithoutFeeResponse.json in Resources */, DBCA37B7225D6D1700CD4137 /* BankAccountErrorResponseWithMissingBankId.json in Resources */, + FD2B6ECB2670D6980021078B /* TransferMethodConfigurationFeeAndProcessingTimeResponse.json in Resources */, DBCA37AE225D6D1700CD4137 /* BankAccountIndividualResponse.json in Resources */, 644A69C122B0F7640058E77E /* WireAccountBusinessResponse.json in Resources */, DBCA37B2225D6D1700CD4137 /* BankCardErrorResponseWithInvalidCardNumber.json in Resources */, @@ -962,6 +969,7 @@ DB1A0422225D571B0080C8D6 /* AuthenticationTokenGeneratorMock.swift in Sources */, DBCA3775225D6A8D00CD4137 /* HyperwalletTransferMethodConfigurationTests.swift in Sources */, 07B1FE6822C2C71200F461D0 /* HyperwalletPrepaidCardTests.swift in Sources */, + FDBCC62A26725217002CEF55 /* HyperwalletTransferMethodConfigurationFeeAndProcessingTimeQueryTests.swift in Sources */, DB0AFDF62277869500ABEFFD /* HyperwalletUserTests.swift in Sources */, DB1A0414225D4D8B0080C8D6 /* ConfigurationTests.swift in Sources */, DB1A0416225D4D8B0080C8D6 /* AuthenticationTokenDecoderTests.swift in Sources */, diff --git a/README.md b/README.md index 845ba249..c0a4781e 100644 --- a/README.md +++ b/README.md @@ -27,13 +27,13 @@ Use [Carthage](https://github.com/Carthage/Carthage) or [CocoaPods](https://coco ### Carthage Specify it in your Cartfile: ```ogdl -github "hyperwallet/hyperwallet-ios-sdk" "1.0.0-beta13" +github "hyperwallet/hyperwallet-ios-sdk" "1.0.0-beta14" ``` ### CocoaPods Specify it in your Podfile: ```ruby -pod 'HyperwalletSDK', '~> 1.0.0-beta13' +pod 'HyperwalletSDK', '~> 1.0.0-beta14' ``` ## Initialization @@ -660,7 +660,7 @@ Hyperwallet.shared.listPrepaidCardBalances(prepaidCardToken: "trm-1234", queryPa ## Transfer Method Configurations -### Get countries, currencies and transfer method types +### Get countries, currencies ```swift let keysQuery = HyperwalletTransferMethodConfigurationKeysQuery() @@ -681,14 +681,32 @@ Hyperwallet.shared.retrieveTransferMethodConfigurationKeys(request: keysQuery) { currencies = result.currencies(from: countries.first!.code) } - // Get transfer method types based on the first country code and its first currency code - if let countryCode = countries?.first?.code, let currencyCode = currencies?.first?.code { - transferMethodTypes = result.transferMethodTypes(countryCode: countryCode, currencyCode: currencyCode) - } - print(countries) print(currencies) +} +``` + +### Get transfer method types, fees and processing times for Country and Currency +```swift +let country = "CA" +let currency = "CAD" +let keysQuery = HyperwalletTransferMethodTypesFeesAndProcessingTimesQuery(country: country, currency: currency) + +Hyperwallet + .shared + .retrieveTransferMethodTypesFeesAndProcessingTimes(request: keysQuery) { (result, error) in + guard error == nil else { + print(error?.getHyperwalletErrors()?.errorList?) + return + } + + guard let result = result else { return } + + // Get transfer method types based on the first country code and its first currency code + transferMethodTypes = result.transferMethodTypes(countryCode: country, currencyCode: currency) print(transferMethodTypes) + print(transferMethodTypes?.first?.fees) + print(transferMethodTypes?.first?.processingTimes) } ``` diff --git a/Sources/HTTPTransaction.swift b/Sources/HTTPTransaction.swift index a90ac5d6..1ecbe5db 100644 --- a/Sources/HTTPTransaction.swift +++ b/Sources/HTTPTransaction.swift @@ -276,7 +276,7 @@ final class HTTPTransaction { /// Returns the default timeout - 5 seconds private static let defaultTimeout: Double = { - 10.0 + 5.0 }() /// Returns `Accept-Language` header, generated by querying `Locale` for the user's `preferredLanguages`. diff --git a/Sources/Hyperwallet.swift b/Sources/Hyperwallet.swift index 33a49929..fb646682 100644 --- a/Sources/Hyperwallet.swift +++ b/Sources/Hyperwallet.swift @@ -929,7 +929,7 @@ public final class Hyperwallet: NSObject { transferMethodUpdateConfigurationFiledResponseHandler(completion)) } - /// Returns the transfer method configuration key set, processing times, and fees for the User that is associated + /// Returns the transfer method configuration key set for the User that is associated /// with the authentication token returned from /// `HyperwalletAuthenticationTokenProvider.retrieveAuthenticationToken(_ : @escaping CompletionHandler)`. /// @@ -951,6 +951,30 @@ public final class Hyperwallet: NSObject { completionHandler: transferMethodConfigurationKeyResponseHandler(completion)) } + /// Returns the transfer method types, processing times, and fees for the User that is associated + /// with the authentication token returned from + /// `HyperwalletAuthenticationTokenProvider.retrieveAuthenticationToken(_ : @escaping CompletionHandler)`. + /// + /// The `completion: @escaping (HyperwalletTransferMethodConfigurationKey?, HyperwalletErrorType?) -> Void` + /// that is passed in to this method invocation will receive the successful + /// response(HyperwalletTransferMethodConfigurationKey) or + /// error(HyperwalletErrorType) from processing the + /// request. + /// + /// This function will request a new authentication token via `HyperwalletAuthenticationTokenProvider` + /// if the current one is expired or is about to expire. + /// + /// - Parameters: + /// - request: containing the transfer method configuration key query + /// - completion: the callback handler of responses from the Hyperwallet platform + public func retrieveTransferMethodTypesFeesAndProcessingTimes( + request: HyperwalletTransferMethodTypesFeesAndProcessingTimesQuery, + completion: @escaping (HyperwalletTransferMethodConfigurationKey?, + HyperwalletErrorType?) -> Void) { + httpTransaction.performGraphQl(request, + completionHandler: transferMethodConfigurationKeyResponseHandler(completion)) + } + /// Updates the `HyperwalletBankAccount` for the User associated with the authentication token returned from /// `HyperwalletAuthenticationTokenProvider.retrieveAuthenticationToken(_ : @escaping CompletionHandler)`. /// diff --git a/Sources/Info.plist b/Sources/Info.plist index 72c00ee9..af2a8e29 100644 --- a/Sources/Info.plist +++ b/Sources/Info.plist @@ -21,6 +21,6 @@ CFBundleVersion $(CURRENT_PROJECT_VERSION) TAG_VERSION - 1.0.0-beta13 + 1.0.0-beta14 diff --git a/Sources/Model/GraphQL/Query/HyperwalletTransferMethodConfigurationQueries.swift b/Sources/Model/GraphQL/Query/HyperwalletTransferMethodConfigurationQueries.swift index b74fab07..c7795b6e 100644 --- a/Sources/Model/GraphQL/Query/HyperwalletTransferMethodConfigurationQueries.swift +++ b/Sources/Model/GraphQL/Query/HyperwalletTransferMethodConfigurationQueries.swift @@ -168,29 +168,6 @@ public struct HyperwalletTransferMethodConfigurationKeysQuery: GraphQlQuery { nodes { code name - transferMethodTypes { - nodes { - code - name - processingTimes { - nodes { - country - currency - transferMethodType - value - } - } - fees { - nodes { - currency - value - feeRateType - maximum - minimum - } - } - } - } } } } @@ -209,3 +186,70 @@ public struct HyperwalletTransferMethodConfigurationKeysQuery: GraphQlQuery { String(format: query, userToken, limit) } } + +/// The 'HyperwalletTransferMethodTypesFeesAndProcessingTimesQuery' struct defines +/// and builds a query to retrieve the processing time and fees associated with each country, currency +/// and transfer method type tuple. +/// that is required to construct a `HyperwalletTransferMethodConfigurationFieldQuery`. +public struct HyperwalletTransferMethodTypesFeesAndProcessingTimesQuery: GraphQlQuery, Hashable { + private var country: String = "" + private var currency: String = "" + + private var query = """ + query QueryFeeAndProcessing( + $idToken: String = "%@", + $country: Country = %@, + $currency: Currency = %@ + ) { + countries (idToken: $idToken,code: $country){ + nodes { + code + name + currencies (code: $currency){ + nodes { + code + name + transferMethodTypes { + nodes { + code + name + processingTimes { + nodes { + country + currency + transferMethodType + value + } + } + fees { + nodes { + currency + feeRateType + value + minimum + maximum + } + } + } + } + } + } + } + } + } + """ + + public init(country: String, currency: String) { + self.country = country + self.currency = currency + } + + public func toGraphQl(userToken: String) -> String { + String(format: query, userToken, country, currency) + } + + public func hash(into hasher: inout Hasher) { + hasher.combine(country) + hasher.combine(currency) + } +} diff --git a/Tests/GraphQL/HyperwalletTransferMethodConfigurationTests.swift b/Tests/GraphQL/HyperwalletTransferMethodConfigurationTests.swift index b76ba05b..bbda2405 100644 --- a/Tests/GraphQL/HyperwalletTransferMethodConfigurationTests.swift +++ b/Tests/GraphQL/HyperwalletTransferMethodConfigurationTests.swift @@ -24,11 +24,6 @@ class HyperwalletTransferMethodConfigurationTests: XCTestCase { var graphQlResponse: HyperwalletTransferMethodConfigurationKey? var errorResponse: HyperwalletErrorType? - var fees: [HyperwalletFee]? - var flatFee: HyperwalletFee? - var percentFee: HyperwalletFee? - var bankAccountProcessingTime: HyperwalletProcessingTime? - var payPalAccountProcessingTime: HyperwalletProcessingTime? // When let keysQuery = HyperwalletTransferMethodConfigurationKeysQuery() @@ -45,56 +40,6 @@ class HyperwalletTransferMethodConfigurationTests: XCTestCase { XCTAssertNil(errorResponse, "The `errorResponse` should be nil") XCTAssertEqual(graphQlResponse?.countries()?.count, 4, "countries()` should be 4") XCTAssertEqual(graphQlResponse?.currencies(from: "CA")?.count, 2, "currencies(...)` should be 2") - XCTAssertEqual(graphQlResponse?.transferMethodTypes(countryCode: "CA", currencyCode: "CAD")? - .count, 2, "`transferMethodTypes(...)` should be 2") - fees = graphQlResponse?.transferMethodTypes(countryCode: "CA", currencyCode: "CAD")? - .first(where: { $0.code == "BANK_ACCOUNT" }) - .flatMap { $0.fees?.nodes } - flatFee = fees?.first - percentFee = fees?.last - - XCTAssertNotNil(fees) - XCTAssertEqual(fees?.count, 2) - XCTAssertEqual(flatFee?.value, "2.20") - XCTAssertEqual(flatFee?.feeRateType, "FLAT") - XCTAssertEqual(percentFee?.value, "8.9") - XCTAssertEqual(percentFee?.feeRateType, "PERCENT") - XCTAssertEqual(percentFee?.minimum, "0.05") - XCTAssertEqual(percentFee?.maximum, "1.00") - - bankAccountProcessingTime = graphQlResponse?.transferMethodTypes(countryCode: "CA", currencyCode: "CAD")? - .first(where: { $0.code == "BANK_ACCOUNT" }) - .flatMap { $0.processingTimes?.nodes?.first } - XCTAssertNotNil(bankAccountProcessingTime, "The bankAccountProcessingTime should not be nil") - XCTAssertEqual(bankAccountProcessingTime!.value, - "1-3 business days", - "Type should be 1-3 business days") - XCTAssertEqual(bankAccountProcessingTime!.country, - "CA", - "The country should be CA") - XCTAssertEqual(bankAccountProcessingTime!.currency, - "CAD", - "The currency should be CAD") - XCTAssertEqual(bankAccountProcessingTime!.transferMethodType, - "BANK_ACCOUNT", - "The transferMethodType should be BANK_ACCOUNT") - - payPalAccountProcessingTime = graphQlResponse?.transferMethodTypes(countryCode: "CA", currencyCode: "CAD")? - .first(where: { $0.code == "PAYPAL_ACCOUNT" }) - .flatMap { $0.processingTimes?.nodes?.first } - XCTAssertNotNil(payPalAccountProcessingTime, "The payPalAccountProcessingTime should not be nil") - XCTAssertEqual(payPalAccountProcessingTime!.value, - "IMMEDIATE", - "The value should be IMMEDIATE") - XCTAssertEqual(payPalAccountProcessingTime!.country, - "CA", - "The country should be CA") - XCTAssertEqual(payPalAccountProcessingTime!.currency, - "CAD", - "The currency should be CAD") - XCTAssertEqual(payPalAccountProcessingTime!.transferMethodType, - "PAYPAL_ACCOUNT", - "The transferMethodType should be PAYPAL_ACCOUNT") } func testRetrieveTransferMethodConfigurationKeys_withoutFees() { @@ -127,8 +72,6 @@ class HyperwalletTransferMethodConfigurationTests: XCTestCase { XCTAssertNil(fees, "Fees should be nil" ) XCTAssertEqual(graphQlResponse?.countries()?.count, 1, "`countries()` should be 1") XCTAssertEqual(graphQlResponse?.currencies(from: "HR")?.count, 1, "currencies(...)` should be 1") - XCTAssertEqual(graphQlResponse?.transferMethodTypes(countryCode: "HR", currencyCode: "HRK")? - .count, 1, "transferMethodTypes(...)` should be 1") } func testRetrieveTransferMethodConfigurationFields_success() { @@ -183,6 +126,91 @@ class HyperwalletTransferMethodConfigurationTests: XCTestCase { XCTAssertEqual(branchIdMask?.scrubRegex, "\\s") } + func testRetrieveTransferMethodTypesFeesAndProcessingTimes() { + // Given + let request = setUpTransferMethodConfigurationRequest("TransferMethodConfigurationFeeAndProcessingTimeResponse") + HyperwalletTestHelper.setUpMockServer(request: request) + + let expectation = self.expectation(description: "Retrieve transfer method configuration keys") + + var graphQlResponse: HyperwalletTransferMethodConfigurationKey? + var errorResponse: HyperwalletErrorType? + var fees: [HyperwalletFee]? + var flatFee: HyperwalletFee? + var percentFee: HyperwalletFee? + var bankAccountProcessingTime: HyperwalletProcessingTime? + var paperCheckProcessingTime: HyperwalletProcessingTime? + + // When + let keysQuery = HyperwalletTransferMethodTypesFeesAndProcessingTimesQuery(country: "CA", currency: "CAD") + + Hyperwallet + .shared + .retrieveTransferMethodTypesFeesAndProcessingTimes(request: keysQuery) { (result, error) in + graphQlResponse = result + errorResponse = error + expectation.fulfill() + } + wait(for: [expectation], timeout: 1) + + print(graphQlResponse?.transferMethodTypes(countryCode: "CA", currencyCode: "CAD") ?? "") + + // Then + XCTAssertNil(errorResponse, "The `errorResponse` should be nil") + XCTAssertEqual(graphQlResponse?.countries()?.count, 1, "countries()` should be 1") + XCTAssertEqual(graphQlResponse?.currencies(from: "CA")?.count, 1, "currencies(...)` should be 1") + XCTAssertEqual(graphQlResponse?.transferMethodTypes(countryCode: "CA", currencyCode: "CAD")? + .count, 2, "`transferMethodTypes(...)` should be 2") + fees = graphQlResponse?.transferMethodTypes(countryCode: "CA", currencyCode: "CAD")? + .first(where: { $0.code == "BANK_ACCOUNT" }) + .flatMap { $0.fees?.nodes } + flatFee = fees?.first + percentFee = fees?.last + + XCTAssertNotNil(fees) + XCTAssertEqual(fees?.count, 2) + XCTAssertEqual(flatFee?.value, "2.20") + XCTAssertEqual(flatFee?.feeRateType, "FLAT") + XCTAssertEqual(percentFee?.value, "8.9") + XCTAssertEqual(percentFee?.feeRateType, "PERCENT") + XCTAssertEqual(percentFee?.minimum, "0.05") + XCTAssertEqual(percentFee?.maximum, "1.00") + + bankAccountProcessingTime = graphQlResponse?.transferMethodTypes(countryCode: "CA", currencyCode: "CAD")? + .first(where: { $0.code == "BANK_ACCOUNT" }) + .flatMap { $0.processingTimes?.nodes?.first } + XCTAssertNotNil(bankAccountProcessingTime, "The bankAccountProcessingTime should not be nil") + XCTAssertEqual(bankAccountProcessingTime!.value, + "1 - 3 Business days", + "Type should be 1 - 3 Business days") + XCTAssertEqual(bankAccountProcessingTime!.country, + "CA", + "The country should be CA") + XCTAssertEqual(bankAccountProcessingTime!.currency, + "CAD", + "The currency should be CAD") + XCTAssertEqual(bankAccountProcessingTime!.transferMethodType, + "BANK_ACCOUNT", + "The transferMethodType should be BANK_ACCOUNT") + + paperCheckProcessingTime = graphQlResponse?.transferMethodTypes(countryCode: "CA", currencyCode: "CAD")? + .first(where: { $0.code == "PAPER_CHECK" }) + .flatMap { $0.processingTimes?.nodes?.first } + XCTAssertNotNil(paperCheckProcessingTime, "The payPalAccountProcessingTime should not be nil") + XCTAssertEqual(paperCheckProcessingTime!.value, + "5 - 7 Business days", + "The value should be 5 - 7 Business days") + XCTAssertEqual(paperCheckProcessingTime!.country, + "CA", + "The country should be CA") + XCTAssertEqual(paperCheckProcessingTime!.currency, + "CAD", + "The currency should be CAD") + XCTAssertEqual(paperCheckProcessingTime!.transferMethodType, + "PAPER_CHECK", + "The transferMethodType should be PAPER_CHECK") + } + private func setUpTransferMethodConfigurationRequest(_ responseFile: String, _ error: NSError? = nil) -> StubRequest { let data = HyperwalletTestHelper.getDataFromJson(responseFile) diff --git a/Tests/GraphQL/Query/HyperwalletTransferMethodConfigurationFeeAndProcessingTimeQueryTests.swift b/Tests/GraphQL/Query/HyperwalletTransferMethodConfigurationFeeAndProcessingTimeQueryTests.swift new file mode 100644 index 00000000..8c10c9af --- /dev/null +++ b/Tests/GraphQL/Query/HyperwalletTransferMethodConfigurationFeeAndProcessingTimeQueryTests.swift @@ -0,0 +1,36 @@ +// +// Copyright 2018 - Present Hyperwallet +// +// Permission is hereby granted, free of charge, to any person obtaining a copy of this software +// and associated documentation files (the "Software"), to deal in the Software without restriction, +// including without limitation the rights to use, copy, modify, merge, publish, distribute, +// sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is +// furnished to do so, subject to the following conditions: +// +// The above copyright notice and this permission notice shall be included in all copies or +// substantial portions of the Software. +// +// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING +// BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND +// NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, +// DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. + +@testable import HyperwalletSDK +import XCTest + +// swiftlint:disable type_name +class HyperwalletTransferMethodConfigurationFeeAndProcessingTimeQueryTests: XCTestCase { + func testHashable_fieldQueryNotEqual() { + let usUsdFieldQuery = + HyperwalletTransferMethodTypesFeesAndProcessingTimesQuery(country: "US", + currency: "USD") + + let usCadQuery = + HyperwalletTransferMethodTypesFeesAndProcessingTimesQuery(country: "US", + currency: "CAD") + + XCTAssertNotEqual(usUsdFieldQuery, usCadQuery) + XCTAssertNotEqual(usUsdFieldQuery.hashValue, usCadQuery.hashValue) + } +} diff --git a/Tests/HTTPTransactionTests.swift b/Tests/HTTPTransactionTests.swift index 35759f8f..edfd3491 100644 --- a/Tests/HTTPTransactionTests.swift +++ b/Tests/HTTPTransactionTests.swift @@ -16,7 +16,7 @@ class HTTPTransactionTests: XCTestCase { let configuration = HTTPTransaction.urlSessionConfiguration let header = configuration.httpAdditionalHeaders - XCTAssertEqual(configuration.timeoutIntervalForRequest, 10.0) + XCTAssertEqual(configuration.timeoutIntervalForRequest, 5.0) XCTAssertEqual(header?["Content-Type"] as? String, "application/json") XCTAssertTrue((header?["Accept-Language"] as? String ?? "").contains("en")) XCTAssertNotNil(header?["x-sdk-version"]) diff --git a/Tests/Responses/TransferMethodConfigurationFeeAndProcessingTimeResponse.json b/Tests/Responses/TransferMethodConfigurationFeeAndProcessingTimeResponse.json new file mode 100644 index 00000000..14f2b692 --- /dev/null +++ b/Tests/Responses/TransferMethodConfigurationFeeAndProcessingTimeResponse.json @@ -0,0 +1,81 @@ +{ + "data": { + "countries": { + "nodes": [ + { + "code": "CA", + "name": "Canada", + "currencies": { + "nodes": [ + { + "code": "CAD", + "name": "CAD", + "transferMethodTypes": { + "nodes": [ + { + "code": "BANK_ACCOUNT", + "name": "Bank Account", + "processingTimes": { + "nodes": [ + { + "country": "CA", + "currency": "CAD", + "transferMethodType": "BANK_ACCOUNT", + "value": "1 - 3 Business days" + } + ] + }, + "fees": { + "nodes": [ + { + "value": "2.20", + "feeRateType": "FLAT", + "currency": "CAD" + }, + { + "value":"8.9", + "feeRateType":"PERCENT", + "currency": "CAD", + "minimum":"0.05", + "maximum":"1.00" + } + ] + } + }, + { + "code": "PAPER_CHECK", + "name": "Paper Check", + "processingTimes": { + "nodes": [ + { + "country": "CA", + "currency": "CAD", + "transferMethodType": "PAPER_CHECK", + "value": "5 - 7 Business days" + } + ] + }, + "fees": { + "nodes": [ + { + "currency": "CAD", + "feeRateType": "FLAT", + "value": "3.50" + }, + { + "currency": "CAD", + "feeRateType": "PERCENT" + } + ] + } + } + ] + } + } + ] + } + } + ] + } + } +}