forked from mapbox/mapbox-directions-swift
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathCredentialsTests.swift
60 lines (51 loc) · 2 KB
/
CredentialsTests.swift
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
import XCTest
@testable import MapboxDirections
class CredentialsTests: XCTestCase {
func testCredentialsCreation() {
let testURL = URL(string: "https://example.com")!
let subject = Credentials(accessToken: "test", host: testURL)
XCTAssertEqual(subject.accessToken, "test")
XCTAssertEqual(subject.host, testURL)
}
func testDefaultConfiguration() {
let credentials = Credentials(accessToken: BogusToken)
XCTAssertEqual(credentials.accessToken, BogusToken)
XCTAssertEqual(credentials.host.absoluteString, "https://api.mapbox.com")
}
func testCustomConfiguration() {
let token = "deadbeefcafebebe"
let host = URL(string: "https://example.com")!
let credentials = Credentials(accessToken: token, host: host)
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)
}
#if !os(Linux)
func testSkuToken() {
let expectedToken = "a token"
MBXAccounts.serviceSkuToken = expectedToken
MBXAccounts.serviceAccessToken = Directions.shared.credentials.accessToken
XCTAssertEqual(Directions.shared.credentials.skuToken, expectedToken)
MBXAccounts.serviceSkuToken = nil
MBXAccounts.serviceAccessToken = nil
}
func testSkuTokenWithMismatchedAccessToken() {
MBXAccounts.serviceSkuToken = "a token"
MBXAccounts.serviceAccessToken = UUID().uuidString
XCTAssertEqual(Directions.shared.credentials.skuToken, nil)
MBXAccounts.serviceSkuToken = nil
MBXAccounts.serviceAccessToken = nil
}
#endif
}
#if !os(Linux)
@objc(MBXAccounts)
final class MBXAccounts: NSObject {
@objc static var serviceSkuToken: String?
@objc static var serviceAccessToken: String?
}
#endif