Skip to content
This repository was archived by the owner on Jan 30, 2021. It is now read-only.
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
46 changes: 0 additions & 46 deletions PRODUCTNAME/app/PRODUCTNAMETests/OAuth/APIClientTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -26,52 +26,6 @@ class APIClientTests: XCTestCase {
OHHTTPStubs.removeAllStubs()
}

func testAuthenticatedRequestWithNoCredentials() {
var authorized: Bool = false
stub(condition: pathStartsWith("/oauth/refresh")) { _ in
authorized = false
return OHHTTPStubsResponse(data: Payloads.oauth, statusCode: 400, headers: nil)
}
stub(condition: pathStartsWith("/test")) { _ in
return OHHTTPStubsResponse(data: Payloads.test, statusCode: authorized ? 200 : 401, headers: nil)
}

let expectation = self.expectation(description: "Test Endpoint")
client.request(TestEndpoint()) { _, error in
XCTAssertNotNil(error)
expectation.fulfill()
}
waitForExpectations(timeout: timeout, handler: nil)
XCTAssert(authorized == false, "client made a refresh request")
}

func testAuthenticatedRequestWithCredentials() {
client.oauthClient.credentials = OAuthClient.Credentials(
refreshToken: "INITIAL_REFRESH_TOKEN",
accessToken: "INVALID_TOKEN",
expirationDate: Date.distantFuture
)

var authorized: Bool = false
stub(condition: pathStartsWith("/oauth/refresh")) { _ in
authorized = true
return OHHTTPStubsResponse(data: Payloads.oauth, statusCode: 200, headers: nil)
}
stub(condition: pathStartsWith("/test")) { _ in
return OHHTTPStubsResponse(data: Payloads.test, statusCode: authorized ? 200 : 401, headers: nil)
}

let expectation = self.expectation(description: "Test Endpoint")
client.request(TestEndpoint()) { (response, error) in
XCTAssertNil(error)
XCTAssertNotNil(response)
XCTAssert(response?.count == 1)
expectation.fulfill()
}
waitForExpectations(timeout: timeout, handler: nil)
XCTAssert(authorized, "client did not make a refresh request")
}

func testManyAuthenticatedRequestWithCredentials() {
client.oauthClient.credentials = OAuthClient.Credentials(
refreshToken: "INITIAL_REFRESH_TOKEN",
Expand Down