/
AuthenticationLiveTest.swift
62 lines (57 loc) · 2.45 KB
/
AuthenticationLiveTest.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
61
62
//
// AuthenticationLiveTest.swift
// OmiseGOTests
//
// Created by Mederic Petit on 6/11/2017.
// Copyright © 2017-2018 Omise Go Pte. Ltd. All rights reserved.
//
import XCTest
import OmiseGO
class AuthenticationLiveTest: LiveTestCase {
func testInvalidAuthenticationToken() {
let expectation = self.expectation(description: "Error token not found")
let config = ClientConfiguration(baseURL: self.validBaseURL,
apiKey: self.validAPIKey,
authenticationToken: self.invalidAuthenticationToken)
let client = HTTPClient(config: config)
let request = User.getCurrent(using: client) { (response) in
defer { expectation.fulfill() }
switch response {
case .success(data: _):
XCTFail("Call shouldn't succeed with an invalid authentication token")
case .fail(error: let error):
switch error {
case .api(apiError: let apiError) where apiError.isAuthorizationError():
XCTAssertEqual(apiError.code, .authenticationTokenNotFound)
default:
XCTFail("Error should be an authorization error")
}
}
}
XCTAssertNotNil(request)
waitForExpectations(timeout: 15.0, handler: nil)
}
func testInvalidAPIKey() {
let expectation = self.expectation(description: "Invalid API key")
let config = ClientConfiguration(baseURL: self.validBaseURL,
apiKey: self.invalidAPIKey,
authenticationToken: self.validAuthenticationToken)
let client = HTTPClient(config: config)
let request = User.getCurrent(using: client) { (response) in
defer { expectation.fulfill() }
switch response {
case .success(data: _):
XCTFail("Call shouldn't succeed with an invalid authentication token")
case .fail(error: let error):
switch error {
case .api(apiError: let apiError) where apiError.isAuthorizationError():
XCTAssertEqual(apiError.code, .invalidAPIKey)
default:
XCTFail("Error should be an authorization error")
}
}
}
XCTAssertNotNil(request)
waitForExpectations(timeout: 15.0, handler: nil)
}
}