-
Notifications
You must be signed in to change notification settings - Fork 296
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Fix Bug where
fetchPaymentMethodNonces
Return Incorrect Type (#1100)
* We were never parsing out the type from the nonce as expected * In Objective-C we did this in the load method, we can instead just parse it out from the JSON and return the type as we were in v5
- Loading branch information
1 parent
eadb707
commit 2559fa8
Showing
7 changed files
with
168 additions
and
37 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -2,7 +2,7 @@ import XCTest | |
@testable import BraintreeCore | ||
|
||
class BTPaymentMethodNonceParser_Tests: XCTestCase { | ||
var parser : BTPaymentMethodNonceParser = BTPaymentMethodNonceParser() | ||
var parser: BTPaymentMethodNonceParser = BTPaymentMethodNonceParser() | ||
|
||
func testRegisterType_addsTypeToTypes() { | ||
parser.registerType("MyType") { _ -> BTPaymentMethodNonce? in return nil} | ||
|
@@ -67,4 +67,86 @@ class BTPaymentMethodNonceParser_Tests: XCTestCase { | |
XCTAssertEqual(unknownNonce.type, "Unknown") | ||
XCTAssertTrue(unknownNonce.isDefault) | ||
} | ||
|
||
func testSharedParser_whenTypeIsApplePayCard_returnsApplePayType() { | ||
let sharedParser = BTPaymentMethodNonceParser.shared | ||
let applePayCard = BTJSON(value: [ | ||
"consumed": false, | ||
"details": ["cardType": "American Express"], | ||
"isLocked": false, | ||
"nonce": "a-nonce", | ||
"securityQuestions": [] as [Any], | ||
"type": "ApplePayCard", | ||
] as [String: Any]) | ||
|
||
let applePayCardNonce = sharedParser.parseJSON(applePayCard, withParsingBlockForType: "ApplePayCard") | ||
|
||
XCTAssertEqual(applePayCardNonce?.nonce, "a-nonce") | ||
XCTAssertEqual(applePayCardNonce?.type, "American Express") | ||
} | ||
|
||
func testSharedParser_whenTypeIsCreditCard_returnsCardType() { | ||
let sharedParser = BTPaymentMethodNonceParser.shared | ||
|
||
let creditCardJSON = BTJSON(value: [ | ||
"consumed": false, | ||
"description": "ending in 31", | ||
"details": [ | ||
"cardType": "American Express", | ||
"lastTwo": "31", | ||
], | ||
"isLocked": false, | ||
"nonce": "0099b1d0-7a1c-44c3-b1e4-297082290bb9", | ||
"securityQuestions": ["cvv"], | ||
"threeDSecureInfo": NSNull(), | ||
"type": "CreditCard", | ||
"default": true | ||
] as [String: Any]) | ||
|
||
let cardNonce = sharedParser.parseJSON(creditCardJSON, withParsingBlockForType:"CreditCard")! | ||
|
||
XCTAssertEqual(cardNonce.nonce, "0099b1d0-7a1c-44c3-b1e4-297082290bb9") | ||
XCTAssertEqual(cardNonce.type, "AMEX") | ||
XCTAssertTrue(cardNonce.isDefault) | ||
} | ||
|
||
func testSharedParser_whenTypeIsVenmo_returnsVenmoType() { | ||
let sharedParser = BTPaymentMethodNonceParser.shared | ||
|
||
let venmoAccountJSON = BTJSON(value: [ | ||
"consumed": false, | ||
"description": "VenmoAccount", | ||
"details": ["username": "[email protected]"], | ||
"isLocked": false, | ||
"nonce": "a-nonce", | ||
"securityQuestions": [] as [Any], | ||
"type": "VenmoAccount", | ||
"default": true | ||
] as [String: Any]) | ||
|
||
let venmoAccountNonce = sharedParser.parseJSON(venmoAccountJSON, withParsingBlockForType: "VenmoAccount") | ||
|
||
XCTAssertEqual(venmoAccountNonce?.nonce, "a-nonce") | ||
XCTAssertEqual(venmoAccountNonce?.type, "Venmo") | ||
} | ||
|
||
func testSharedParser_whenTypeIsPayPal_returnsPayPalType() { | ||
let sharedParser = BTPaymentMethodNonceParser.shared | ||
|
||
let payPalAccountJSON = BTJSON(value: [ | ||
"consumed": false, | ||
"description": "[email protected]", | ||
"details": ["email": "[email protected]"], | ||
"isLocked": false, | ||
"nonce": "a-nonce", | ||
"securityQuestions": [] as [Any], | ||
"type": "PayPalAccount", | ||
"default": true | ||
] as [String: Any]) | ||
|
||
let payPalAccountNonce = sharedParser.parseJSON(payPalAccountJSON, withParsingBlockForType: "PayPalAccount") | ||
|
||
XCTAssertEqual(payPalAccountNonce?.nonce, "a-nonce") | ||
XCTAssertEqual(payPalAccountNonce?.type, "PayPal") | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,33 +1,9 @@ | ||
import XCTest | ||
@testable import BraintreePayPal | ||
|
||
class BTPaymentMethodNonceParser_PayPal_Tests: XCTestCase { | ||
func testSharedParser_whenTypeIsPayPal_returnsPayPalAccountNonce() { | ||
let payPalAccountNonce = BTPayPalAccountNonce( | ||
json: BTJSON( | ||
value: [ | ||
"consumed": false, | ||
"description": "[email protected]", | ||
"details": [ | ||
"email": "[email protected]", | ||
], | ||
"isLocked": false, | ||
"nonce": "a-nonce", | ||
"securityQuestions": [] as [Any?], | ||
"type": "PayPalAccount", | ||
"default": true | ||
] as [String: Any] | ||
) | ||
) | ||
|
||
XCTAssertEqual(payPalAccountNonce?.nonce, "a-nonce") | ||
XCTAssertEqual(payPalAccountNonce?.type, "PayPal") | ||
XCTAssertEqual(payPalAccountNonce?.email, "[email protected]") | ||
XCTAssertTrue(payPalAccountNonce!.isDefault) | ||
XCTAssertNil(payPalAccountNonce?.creditFinancing) | ||
} | ||
final class BTPayPalAccountNonce_Tests: XCTestCase { | ||
|
||
func testParsePayPalCreditFinancingAmount() { | ||
func testPayPalAccountNonce_returnsPayPalCreditFinancingAmount() { | ||
let payPalCreditFinancingAmount = BTJSON(value: [ | ||
"currency": "USD", | ||
"value": "123.45", | ||
|
@@ -41,7 +17,7 @@ class BTPaymentMethodNonceParser_PayPal_Tests: XCTestCase { | |
XCTAssertEqual(amount.value, "123.45") | ||
} | ||
|
||
func testParsePayPalCreditFinancing() { | ||
func testPayPalAccountNonce_returnsPayPalCreditFinancing() { | ||
let payPalCreditFinancing = BTJSON(value: [ | ||
"cardAmountImmutable": false, | ||
"monthlyPayment": [ | ||
|
@@ -93,7 +69,7 @@ class BTPaymentMethodNonceParser_PayPal_Tests: XCTestCase { | |
XCTAssertEqual(totalInterest.value, "456.78") | ||
} | ||
|
||
func testSharedParser_whenTypeIsPayPal_returnsPayPalAccountNonceWithCreditFinancingOffered() { | ||
func testPayPalAccountNonce_returnsPayPalAccountNonceWithCreditFinancingOffered() { | ||
let payPalAccountNonce = BTPayPalAccountNonce( | ||
json: BTJSON( | ||
value: [ | ||
|