Skip to content

Commit

Permalink
PR Feedback - prefer payPal camelcase syntax & add unit test for PayP…
Browse files Browse the repository at this point in the history
…al API prod env setting
  • Loading branch information
scannillo committed Jan 18, 2024
1 parent c446f79 commit 335b594
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 6 deletions.
4 changes: 2 additions & 2 deletions Sources/BraintreeCore/BTAPIClient.swift
Original file line number Diff line number Diff line change
Expand Up @@ -181,7 +181,7 @@ import Foundation
}

if payPalHTTP == nil {
let paypalBaseURL: URL? = paypalAPIURL(forEnvironment: configuration?.environment ?? "")
let paypalBaseURL: URL? = payPalAPIURL(forEnvironment: configuration?.environment ?? "")

if let clientToken, let paypalBaseURL {
payPalHTTP = BTHTTP(url: paypalBaseURL, authorizationFingerprint: clientToken.authorizationFingerprint)
Expand Down Expand Up @@ -481,7 +481,7 @@ import Foundation
return components.url
}

func paypalAPIURL(forEnvironment environment: String) -> URL? {
func payPalAPIURL(forEnvironment environment: String) -> URL? {
if environment.caseInsensitiveCompare("sandbox") == .orderedSame ||
environment.caseInsensitiveCompare("development") == .orderedSame {
return URL(string: "https://api-m.sandbox.paypal.com")
Expand Down
14 changes: 10 additions & 4 deletions UnitTests/BraintreeCoreTests/BTAPIClient_Tests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -586,19 +586,25 @@ class BTAPIClient_Tests: XCTestCase {
XCTAssertEqual(sandboxURL?.absoluteString, "https://payments.braintree-api.com/graphql")
}

func testPayPalBaseURLForEnvironment_returnsSandbox() {
func testPayPalBaseURLForEnvironment_returnsSandboxURL() {
let apiClientSand = BTAPIClient(authorization: "development_tokenization_key")
let baseURLSand: URL? = apiClientSand?.paypalAPIURL(forEnvironment: "sandbox")
let baseURLSand: URL? = apiClientSand?.payPalAPIURL(forEnvironment: "sandbox")
XCTAssertEqual(baseURLSand?.absoluteString, "https://api-m.sandbox.paypal.com")

let apiClientDev = BTAPIClient(authorization: "development_tokenization_key")
let baseURLDev: URL? = apiClientDev?.paypalAPIURL(forEnvironment: "development")
let baseURLDev: URL? = apiClientDev?.payPalAPIURL(forEnvironment: "development")
XCTAssertEqual(baseURLDev?.absoluteString, "https://api-m.sandbox.paypal.com")
}

func testPayPalBaseURLForEnvironment_returnsProductionURL() {
let apiClientSand = BTAPIClient(authorization: "development_tokenization_key")
let baseURLSand: URL? = apiClientSand?.payPalAPIURL(forEnvironment: "production")
XCTAssertEqual(baseURLSand?.absoluteString, "https://api-m.paypal.com")
}

func testPayPalBaseURLForEnvironment_returnsProductionURL_asDefault() {
let apiClient = BTAPIClient(authorization: "development_tokenization_key")
let baseURL: URL? = apiClient?.paypalAPIURL(forEnvironment: "unknown")
let baseURL: URL? = apiClient?.payPalAPIURL(forEnvironment: "unknown")
XCTAssertEqual(baseURL?.absoluteString, "https://api-m.paypal.com")
}
}

0 comments on commit 335b594

Please sign in to comment.