mastodon-app-ufficiale-ipho.../MastodonSDK/Tests/MastodonSDKTests/MastodonSDKTests.swift

47 lines
1.4 KiB
Swift
Raw Normal View History

2021-01-22 07:27:37 +01:00
import XCTest
2021-01-27 09:01:20 +01:00
import Combine
2021-01-22 07:27:37 +01:00
@testable import MastodonSDK
final class MastodonSDKTests: XCTestCase {
2021-01-27 09:01:20 +01:00
var disposeBag = Set<AnyCancellable>()
2021-01-28 07:52:35 +01:00
2021-01-29 12:38:11 +01:00
let session = URLSession(configuration: .ephemeral)
var domain: String { MastodonSDKTests.environmentVariable(key: "domain") }
2021-01-28 07:52:35 +01:00
2021-01-29 12:38:11 +01:00
static func environmentVariable(key: String) -> String {
return ProcessInfo.processInfo.environment[key]!
2021-01-28 07:52:35 +01:00
}
2021-01-22 07:27:37 +01:00
2021-01-28 07:52:35 +01:00
}
extension MastodonSDKTests {
2021-01-27 09:01:20 +01:00
2021-01-29 12:38:11 +01:00
func testPublicTimeline() throws {
try _testPublicTimeline(domain: domain)
2021-01-28 07:52:35 +01:00
}
private func _testPublicTimeline(domain: String) throws {
let theExpectation = expectation(description: "Fetch Public Timeline")
2021-01-27 11:52:01 +01:00
let query = Mastodon.API.Timeline.PublicTimelineQuery()
Mastodon.API.Timeline.public(session: session, domain: domain, query: query)
.receive(on: DispatchQueue.main)
.sink { completion in
switch completion {
case .failure(let error):
XCTFail(error.localizedDescription)
case .finished:
break
}
} receiveValue: { response in
XCTAssert(!response.value.isEmpty)
theExpectation.fulfill()
}
.store(in: &disposeBag)
wait(for: [theExpectation], timeout: 10.0)
}
2021-01-22 07:27:37 +01:00
}