From 335b594f5f61bfec610f8897c3fa96aa708c92f1 Mon Sep 17 00:00:00 2001 From: Sammy Cannillo Date: Thu, 18 Jan 2024 09:42:40 -0600 Subject: [PATCH] PR Feedback - prefer payPal camelcase syntax & add unit test for PayPal API prod env setting --- Sources/BraintreeCore/BTAPIClient.swift | 4 ++-- .../BraintreeCoreTests/BTAPIClient_Tests.swift | 14 ++++++++++---- 2 files changed, 12 insertions(+), 6 deletions(-) diff --git a/Sources/BraintreeCore/BTAPIClient.swift b/Sources/BraintreeCore/BTAPIClient.swift index bdf955aa39..6b36cf4d83 100644 --- a/Sources/BraintreeCore/BTAPIClient.swift +++ b/Sources/BraintreeCore/BTAPIClient.swift @@ -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) @@ -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") diff --git a/UnitTests/BraintreeCoreTests/BTAPIClient_Tests.swift b/UnitTests/BraintreeCoreTests/BTAPIClient_Tests.swift index 6249bf6115..70ef8d2a44 100644 --- a/UnitTests/BraintreeCoreTests/BTAPIClient_Tests.swift +++ b/UnitTests/BraintreeCoreTests/BTAPIClient_Tests.swift @@ -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") } }