Skip to content

Commit

Permalink
Adds means of injecting accessToken from SPM tests
Browse files Browse the repository at this point in the history
SPM tests can't contain Info.plist which is used for injecting default
access token into the library.

With this addition SPM tests can set access token using `MBXAccessToken`
key in NSUserDefaults which will be used in `defaultAccessToken`
initialization.
  • Loading branch information
S2Ler committed Jun 15, 2021
1 parent 0c6ae5c commit ff79925
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 3 deletions.
5 changes: 3 additions & 2 deletions Sources/MapboxDirections/DirectionsCredentials.swift
Original file line number Diff line number Diff line change
@@ -1,9 +1,10 @@
import Foundation

/// The Mapbox access token specified in the main application bundle’s Info.plist.
let defaultAccessToken =
let defaultAccessToken: String? =
Bundle.main.object(forInfoDictionaryKey: "MBXAccessToken") as? String ??
Bundle.main.object(forInfoDictionaryKey: "MGLMapboxAccessToken") as? String
Bundle.main.object(forInfoDictionaryKey: "MGLMapboxAccessToken") as? String ??
UserDefaults.standard.string(forKey: "MBXAccessToken")
let defaultApiEndPointURLString = Bundle.main.object(forInfoDictionaryKey: "MGLMapboxAPIBaseURL") as? String

public struct DirectionsCredentials: Equatable {
Expand Down
6 changes: 6 additions & 0 deletions Tests/MapboxDirectionsTests/DirectionsCredentialsTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -15,4 +15,10 @@ class DirectionsCredentialsTests: XCTestCase {
XCTAssertEqual(credentials.accessToken, token)
XCTAssertEqual(credentials.host, host)
}

func testAccessTokenInjection() {
let expected = "injected"
UserDefaults.standard.set(expected, forKey: "MBXAccessToken")
XCTAssertEqual(Directions.shared.credentials.accessToken, expected)
}
}
1 change: 0 additions & 1 deletion Tests/MapboxDirectionsTests/QuickLookTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@ class QuickLookTests: XCTestCase {
LocationCoordinate2D(latitude: 0, longitude: 0),
LocationCoordinate2D(latitude: 1, longitude: 1),
])
XCTAssertNil(debugQuickLookURL(illustrating: lineString))
XCTAssertEqual(debugQuickLookURL(illustrating: lineString, accessToken: BogusToken), URL(string: "https://api.mapbox.com/styles/v1/mapbox/streets-v11/static/path-10+3802DA-0.6(%3F%3F_ibE_ibE)/auto/680x360@2x?before_layer=building-number-label&access_token=\(BogusToken)"))
XCTAssertEqual(debugQuickLookURL(illustrating: lineString, profileIdentifier: .automobileAvoidingTraffic, accessToken: BogusToken), URL(string: "https://api.mapbox.com/styles/v1/mapbox/navigation-preview-day-v4/static/path-10+3802DA-0.6(%3F%3F_ibE_ibE)/auto/680x360@2x?before_layer=waterway-label&access_token=\(BogusToken)"))
XCTAssertEqual(debugQuickLookURL(illustrating: lineString, profileIdentifier: .cycling, accessToken: BogusToken), URL(string: "https://api.mapbox.com/styles/v1/mapbox/outdoors-v11/static/path-10+3802DA-0.6(%3F%3F_ibE_ibE)/auto/680x360@2x?before_layer=contour-label&access_token=\(BogusToken)"))
Expand Down

0 comments on commit ff79925

Please sign in to comment.