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

63 lines
2.0 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>()
let domain = "mstdn.jp"
let session = URLSession(configuration: .ephemeral)
func testCreateAnAnpplication() throws {
let theExpectation = expectation(description: "Create An Application")
let query = Mastodon.API.App.CreateQuery(
clientName: "XCTest",
website: nil
)
2021-01-27 11:46:14 +01:00
Mastodon.API.App.create(session: session, domain: domain, query: query)
2021-01-27 09:01:20 +01:00
.receive(on: DispatchQueue.main)
.sink { completion in
2021-01-27 11:46:14 +01:00
switch completion {
case .failure(let error):
XCTFail(error.localizedDescription)
case .finished:
break
}
2021-01-27 09:01:20 +01:00
} receiveValue: { response in
2021-01-27 11:46:14 +01:00
XCTAssertEqual(response.value.name, "XCTest")
XCTAssertEqual(response.value.website, nil)
XCTAssertEqual(response.value.redirectURI, "urn:ietf:wg:oauth:2.0:oob")
2021-01-27 09:01:20 +01:00
theExpectation.fulfill()
}
.store(in: &disposeBag)
2021-01-22 07:27:37 +01:00
2021-01-27 09:01:20 +01:00
wait(for: [theExpectation], timeout: 10.0)
}
2021-01-27 11:52:01 +01:00
func testPublicTimeline() throws {
let theExpectation = expectation(description: "Create An Application")
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
}