Skip to content

Commit

Permalink
Update unit tests
Browse files Browse the repository at this point in the history
  • Loading branch information
warmkesselj committed Jan 30, 2025
1 parent d2d1c28 commit c56dd73
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 22 deletions.
16 changes: 3 additions & 13 deletions Sources/BraintreeCard/CreditCardGraphQLBody.swift
Original file line number Diff line number Diff line change
Expand Up @@ -42,23 +42,13 @@ struct CreditCardGraphQLBody: Encodable {
var expirationYear: String?
var cardholderName: String?

init(
card: BTCard,
//billingAddress: BillingAddress? = nil,
number: String? = nil,
expirationMonth: String? = nil,
cvv: String? = nil,
options: Options? = nil,
expirationYear: String? = nil,
cardHolderName: String? = nil
) {
init(card: BTCard) {
self.billingAddress = BillingAddress(card: card)
self.number = card.number
self.expirationMonth = card.expirationMonth
self.cvv = card.cvv
self.options = options
self.expirationYear = expirationYear
self.cardholderName = cardHolderName
self.expirationYear = card.expirationYear
self.cardholderName = card.cardholderName
}

func encode(to encoder: any Encoder) throws {
Expand Down
18 changes: 9 additions & 9 deletions UnitTests/BraintreeCardTests/BTCard_Tests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -153,7 +153,7 @@ class BTCard_Tests: XCTestCase {
}

func testGraphQLParameters_whenDoingCVVOnly_returnsExpectedValue() {
let card = BTCard(cvv: "123")
let card = BTCard(cvv: "321")

let params = card.parameters()

Expand All @@ -169,7 +169,7 @@ class BTCard_Tests: XCTestCase {

func testGraphQLParameters_whenMerchantAccountIDIsPresent_andAuthInsightRequestedIsTrue_requestsAuthInsight() {
let card = BTCard(
number: "4111111111111111",
number: "5111111111111111",
expirationMonth: "12",
expirationYear: "2038",
cvv: "1234",
Expand All @@ -183,15 +183,14 @@ class BTCard_Tests: XCTestCase {
XCTAssertEqual(params.variables.input.creditCard.number, "5111111111111111")
XCTAssertEqual(params.variables.input.options.validate, false)
XCTAssertEqual(params.variables.input.authenticationInsightInput?.merchantAccountId, "some id")

XCTAssertNil(params.variables.input.creditCard.cvv)

XCTAssertNil(params.variables.input.creditCard.billingAddress?.firstName)
XCTAssertNil(params.variables.input.creditCard.cardholderName)
}

func testGraphQLParameters_whenMerchantAccountIDIsPresent_andAuthInsightRequestedIsFalse_doesNotRequestAuthInsight() {
let card = BTCard(
number: "4111111111111111",
number: "6111111111111111",
expirationMonth: "12",
expirationYear: "2038",
cvv: "1234",
Expand All @@ -211,7 +210,7 @@ class BTCard_Tests: XCTestCase {

func testGraphQLParameters_whenMerchantAccountIDIsNil_andAuthInsightRequestedIsTrue_requestsAuthInsight() {
let card = BTCard(
number: "4111111111111111",
number: "7111111111111111",
expirationMonth: "12",
expirationYear: "2038",
cvv: "1234",
Expand Down Expand Up @@ -245,7 +244,7 @@ class BTCard_Tests: XCTestCase {

func testGraphQLParameters_whenMerchantAccountIDIsNil_andAuthInsightRequestedIsFalse_doesNotRequestAuthInsight() {
let card = BTCard(
number: "4111111111111111",
number: "8111111111111111",
expirationMonth: "12",
expirationYear: "2038",
cvv: "123",
Expand All @@ -259,7 +258,8 @@ class BTCard_Tests: XCTestCase {
XCTAssertEqual(params.operationName, "TokenizeCreditCard")
XCTAssertNotNil(params.query)
XCTAssertEqual(params.variables.input.options.validate, false)

XCTAssertNil(params.variables.input.authenticationInsightInput)

XCTAssertNotNil(params.variables.input.authenticationInsightInput)
XCTAssertNil(params.variables.input.authenticationInsightInput?.merchantAccountId)
}
}

0 comments on commit c56dd73

Please sign in to comment.