Merge pull request #1086 from kielgillard/master

Make Account framework tests compile and pass.
This commit is contained in:
Maurice Parker 2019-09-30 02:24:50 -05:00 committed by GitHub
commit 2756da00e1
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
5 changed files with 45 additions and 28 deletions

View File

@ -26,12 +26,12 @@ class AccountCredentialsTest: XCTestCase {
// Make sure any left over from failed tests are gone
do {
try account.removeBasicCredentials()
try account.removeCredentials(type: .basic)
} catch {
XCTFail(error.localizedDescription)
}
var credentials: Credentials? = Credentials.basic(username: "maurice", password: "hardpasswd")
var credentials: Credentials? = Credentials(type: .basic, username: "maurice", secret: "hardpasswd")
// Store the credentials
do {
@ -43,19 +43,21 @@ class AccountCredentialsTest: XCTestCase {
// Retrieve them
credentials = nil
do {
credentials = try account.retrieveBasicCredentials()
credentials = try account.retrieveCredentials(type: .basic)
} catch {
XCTFail(error.localizedDescription)
}
switch credentials! {
case .basic(let username, let password):
XCTAssertEqual("maurice", username)
XCTAssertEqual("hardpasswd", password)
switch credentials!.type {
case .basic:
XCTAssertEqual("maurice", credentials?.username)
XCTAssertEqual("hardpasswd", credentials?.secret)
default:
XCTFail("Expected \(CredentialsType.basic), received \(credentials!.type)")
}
// Update them
credentials = Credentials.basic(username: "maurice", password: "easypasswd")
credentials = Credentials(type: .basic, username: "maurice", secret: "easypasswd")
do {
try account.storeCredentials(credentials!)
} catch {
@ -65,27 +67,29 @@ class AccountCredentialsTest: XCTestCase {
// Retrieve them again
credentials = nil
do {
credentials = try account.retrieveBasicCredentials()
credentials = try account.retrieveCredentials(type: .basic)
} catch {
XCTFail(error.localizedDescription)
}
switch credentials! {
case .basic(let username, let password):
XCTAssertEqual("maurice", username)
XCTAssertEqual("easypasswd", password)
switch credentials!.type {
case .basic:
XCTAssertEqual("maurice", credentials?.username)
XCTAssertEqual("easypasswd", credentials?.secret)
default:
XCTFail("Expected \(CredentialsType.basic), received \(credentials!.type)")
}
// Delete them
do {
try account.removeBasicCredentials()
try account.removeCredentials(type: .basic)
} catch {
XCTFail(error.localizedDescription)
}
// Make sure they are gone
do {
try credentials = account.retrieveBasicCredentials()
try credentials = account.retrieveCredentials(type: .basic)
} catch {
XCTFail(error.localizedDescription)
}

View File

@ -27,7 +27,7 @@ class AccountFeedSyncTest: XCTestCase {
// Test initial folders
let initialExpection = self.expectation(description: "Initial feeds")
account.refreshAll() {
account.refreshAll() { _ in
initialExpection.fulfill()
}
waitForExpectations(timeout: 5, handler: nil)
@ -44,7 +44,7 @@ class AccountFeedSyncTest: XCTestCase {
testTransport.testFiles["https://api.feedbin.com/v2/subscriptions.json"] = "subscriptions_add.json"
let addExpection = self.expectation(description: "Add feeds")
account.refreshAll() {
account.refreshAll() { _ in
addExpection.fulfill()
}
waitForExpectations(timeout: 5, handler: nil)

View File

@ -28,7 +28,7 @@ class AccountFolderContentsSyncTest: XCTestCase {
// Test initial folders
let initialExpection = self.expectation(description: "Initial contents")
account.refreshAll() {
account.refreshAll() { _ in
initialExpection.fulfill()
}
waitForExpectations(timeout: 5, handler: nil)
@ -41,7 +41,7 @@ class AccountFolderContentsSyncTest: XCTestCase {
testTransport.testFiles["https://api.feedbin.com/v2/taggings.json"] = "taggings_add.json"
let addExpection = self.expectation(description: "Add contents")
account.refreshAll() {
account.refreshAll() { _ in
addExpection.fulfill()
}
waitForExpectations(timeout: 5, handler: nil)
@ -53,7 +53,7 @@ class AccountFolderContentsSyncTest: XCTestCase {
testTransport.testFiles["https://api.feedbin.com/v2/taggings.json"] = "taggings_delete.json"
let deleteExpection = self.expectation(description: "Delete contents")
account.refreshAll() {
account.refreshAll() { _ in
deleteExpection.fulfill()
}
waitForExpectations(timeout: 5, handler: nil)

View File

@ -25,7 +25,7 @@ class AccountFolderSyncTest: XCTestCase {
// Test initial folders
let initialExpection = self.expectation(description: "Initial tags")
account.refreshAll() {
account.refreshAll() { _ in
initialExpection.fulfill()
}
waitForExpectations(timeout: 5, handler: nil)
@ -43,7 +43,7 @@ class AccountFolderSyncTest: XCTestCase {
testTransport.testFiles["https://api.feedbin.com/v2/tags.json"] = "tags_delete.json"
let deleteExpection = self.expectation(description: "Delete tags")
account.refreshAll() {
account.refreshAll() { _ in
deleteExpection.fulfill()
}
waitForExpectations(timeout: 5, handler: nil)
@ -62,7 +62,7 @@ class AccountFolderSyncTest: XCTestCase {
testTransport.testFiles["https://api.feedbin.com/v2/tags.json"] = "tags_add.json"
let addExpection = self.expectation(description: "Add tags")
account.refreshAll() {
account.refreshAll() { _ in
addExpection.fulfill()
}
waitForExpectations(timeout: 5, handler: nil)

View File

@ -16,30 +16,43 @@ final class TestTransport: Transport {
}
var testFiles = [String: String]()
var testStatusCodes = [String: Int]()
func send(request: URLRequest, completion: @escaping (Result<(HTTPHeaders, Data?), Error>) -> Void) {
private func httpResponse(for request: URLRequest, statusCode: Int = 200) -> HTTPURLResponse {
guard let url = request.url else {
fatalError("Attempting to mock a http response for a request without a URL \(request).")
}
return HTTPURLResponse(url: url, statusCode: statusCode, httpVersion: "HTTP/1.1", headerFields: nil)!
}
func send(request: URLRequest, completion: @escaping (Result<(HTTPURLResponse, Data?), Error>) -> Void) {
guard let urlString = request.url?.absoluteString else {
completion(.failure(TestTransportError.invalidState))
return
}
let response = httpResponse(for: request, statusCode: testStatusCodes[urlString] ?? 200)
if let testFileName = testFiles[urlString] {
let testFileURL = Bundle(for: TestTransport.self).resourceURL!.appendingPathComponent(testFileName)
let data = try! Data(contentsOf: testFileURL)
DispatchQueue.global(qos: .background).async {
completion(.success((HTTPHeaders(), data)))
completion(.success((response, data)))
}
} else {
DispatchQueue.global(qos: .background).async {
completion(.success((HTTPHeaders(), nil)))
completion(.success((response, nil)))
}
}
}
func send(request: URLRequest, payload: Data, completion: @escaping (Result<(HTTPHeaders, Data?), Error>) -> Void) {
func send(request: URLRequest, method: String, completion: @escaping (Result<Void, Error>) -> Void) {
fatalError("Unimplemented.")
}
func send(request: URLRequest, method: String, payload: Data, completion: @escaping (Result<(HTTPURLResponse, Data?), Error>) -> Void) {
fatalError("Unimplemented.")
}
}