2021-02-19 04:56:51 +01:00
|
|
|
//
|
|
|
|
// MastodonSDK+API+OnboardingTests.swift
|
|
|
|
//
|
|
|
|
//
|
|
|
|
// Created by MainasuK Cirno on 2021-2-18.
|
|
|
|
//
|
|
|
|
|
|
|
|
import os.log
|
|
|
|
import XCTest
|
|
|
|
import Combine
|
|
|
|
@testable import MastodonSDK
|
|
|
|
|
|
|
|
extension MastodonSDKTests {
|
|
|
|
|
|
|
|
func testServers() throws {
|
|
|
|
try _testServers(query: Mastodon.API.Onboarding.ServersQuery(language: nil, category: nil))
|
|
|
|
try _testServers(query: Mastodon.API.Onboarding.ServersQuery(language: "en", category: "tech"))
|
|
|
|
}
|
|
|
|
|
|
|
|
func _testServers(query: Mastodon.API.Onboarding.ServersQuery) throws {
|
|
|
|
let theExpectation = expectation(description: "Fetch Server List")
|
|
|
|
Mastodon.API.Onboarding.servers(
|
|
|
|
session: session,
|
|
|
|
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-02-19 05:17:12 +01:00
|
|
|
func testCategories() throws {
|
|
|
|
let theExpectation = expectation(description: "Fetch Server Categories")
|
2021-02-19 04:56:51 +01:00
|
|
|
Mastodon.API.Onboarding.categories(
|
|
|
|
session: session
|
|
|
|
)
|
|
|
|
.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-02-19 05:17:12 +01:00
|
|
|
func testCategoryKind() {
|
|
|
|
XCTAssertEqual(Mastodon.Entity.Category.Kind.allCases.count, 12)
|
|
|
|
}
|
|
|
|
|
2021-02-19 04:56:51 +01:00
|
|
|
|
|
|
|
}
|