Skip to content

Commit

Permalink
Updates to unit tests
Browse files Browse the repository at this point in the history
  • Loading branch information
warmkesselj committed Jan 14, 2025
1 parent ba01e6d commit 6197b1d
Show file tree
Hide file tree
Showing 3 changed files with 38 additions and 27 deletions.
7 changes: 7 additions & 0 deletions Sources/BraintreeCard/BTCard.swift
Original file line number Diff line number Diff line change
Expand Up @@ -161,6 +161,13 @@ import Foundation
merchantAccountId: merchantAccountID
)

input.authenticationInsightInput = merchantAccountID
} else {
let merchantAccountID = BTCreditCardGraphQLBody
.Variables
.Input
.AuthenticationInsightInput()

input.authenticationInsightInput = merchantAccountID
}
}
Expand Down
4 changes: 4 additions & 0 deletions Sources/BraintreeCard/BTCreditCardGraphQLBody.swift
Original file line number Diff line number Diff line change
Expand Up @@ -140,6 +140,10 @@ class BTCreditCardGraphQLBody: NSObject, Encodable {

var merchantAccountId: String?

init() {
self.merchantAccountId = nil
}

init(merchantAccountId: String) {
self.merchantAccountId = merchantAccountId
}
Expand Down
54 changes: 27 additions & 27 deletions UnitTests/BraintreeCardTests/BTCard_Tests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -200,33 +200,33 @@ class BTCard_Tests: XCTestCase {
}

func testGraphQLParameters_whenMerchantAccountIDIsNil_andAuthInsightRequestedIsTrue_requestsAuthInsight() {
// let card = BTCard()
// card.number = "7111111111111111"
// card.authenticationInsightRequested = true
// card.merchantAccountID = nil
//
// let params = card.graphQLParameters()
//
// XCTAssertEqual(params.variables.input.creditCard.number, "7111111111111111")
// XCTAssertEqual(params.operationName, "TokenizeCreditCard")
// XCTAssertNotNil(params.query)
// XCTAssertEqual(params.variables.input.options.validate, false)
//
// XCTAssertNotNil(params.variables.input.authenticationInsightInput)

// XCTAssertEqual(card.graphQLParameters() as NSObject, [
// "operationName": "TokenizeCreditCard",
// "query": graphQLQueryWithAuthInsightRequested,
// "variables": [
// "input": [
// "creditCard": [
// "number": "4111111111111111",
// ],
// "options": [ "validate": false ],
// ],
// "authenticationInsightInput": NSDictionary()
// ]
// ] as [String: Any] as NSObject)
let card = BTCard()
card.number = "7111111111111111"
card.authenticationInsightRequested = true
card.merchantAccountID = nil

let params = card.graphQLParameters()
printEncodableObject(params)

XCTAssertEqual(params.variables.input.creditCard.number, "7111111111111111")
XCTAssertEqual(params.operationName, "TokenizeCreditCard")
XCTAssertNotNil(params.query)
XCTAssertEqual(params.variables.input.options.validate, false)

XCTAssertNotNil(params.variables.input.authenticationInsightInput)
}

func printEncodableObject<T: Encodable>(_ object: T) {
let encoder = JSONEncoder()
encoder.outputFormatting = .prettyPrinted // Makes the JSON easier to read
do {
let jsonData = try encoder.encode(object)
if let jsonString = String(data: jsonData, encoding: .utf8) {
print("Encoded JSON:\n\(jsonString)")
}
} catch {
print("Failed to encode object: \(error)")
}
}

func testGraphQLParameters_whenMerchantAccountIDIsNil_andAuthInsightRequestedIsFalse_doesNotRequestAuthInsight() {
Expand Down

0 comments on commit 6197b1d

Please sign in to comment.