feat: make Unit Test works

This commit is contained in:
CMK 2021-01-27 18:52:01 +08:00
parent 7ecbcec077
commit 27a7ccbd88
4 changed files with 46 additions and 4 deletions

View File

@ -14,7 +14,7 @@ extension Mastodon.API.Timeline {
return Mastodon.API.endpointURL(domain: domain).appendingPathComponent("timelines/public") return Mastodon.API.endpointURL(domain: domain).appendingPathComponent("timelines/public")
} }
public static func create( public static func `public`(
session: URLSession, session: URLSession,
domain: String, domain: String,
query: PublicTimelineQuery query: PublicTimelineQuery
@ -45,7 +45,15 @@ extension Mastodon.API.Timeline {
public let minID: Mastodon.Entity.Toot.ID? public let minID: Mastodon.Entity.Toot.ID?
public let limit: Int? public let limit: Int?
public init(local: Bool?, remote: Bool?, onlyMedia: Bool?, maxID: Mastodon.Entity.Toot.ID?, sinceID: Mastodon.Entity.Toot.ID?, minID: Mastodon.Entity.Toot.ID?, limit: Int?) { public init(
local: Bool? = nil,
remote: Bool? = nil,
onlyMedia: Bool? = nil,
maxID: Mastodon.Entity.Toot.ID? = nil,
sinceID: Mastodon.Entity.Toot.ID? = nil,
minID: Mastodon.Entity.Toot.ID? = nil,
limit: Int? = nil
) {
self.local = local self.local = local
self.remote = remote self.remote = remote
self.onlyMedia = onlyMedia self.onlyMedia = onlyMedia

View File

@ -19,7 +19,18 @@ extension Mastodon.API {
}() }()
static let decoder: JSONDecoder = { static let decoder: JSONDecoder = {
let decoder = JSONDecoder() let decoder = JSONDecoder()
decoder.dateDecodingStrategy = .iso8601 decoder.dateDecodingStrategy = JSONDecoder.DateDecodingStrategy.custom { decoder throws -> Date in
let container = try decoder.singleValueContainer()
let string = try container.decode(String.self)
let formatter = ISO8601DateFormatter()
formatter.formatOptions.insert(.withFractionalSeconds)
if let date = formatter.date(from: string) {
return date
}
throw DecodingError.dataCorruptedError(in: container, debugDescription: "Invalid date: \(string)")
}
return decoder return decoder
}() }()

View File

@ -14,7 +14,7 @@ extension Mastodon.Entity {
public let id: ID public let id: ID
public let username: Date public let username: String
public let acct: String public let acct: String
public let displayName: String? public let displayName: String?
public let avatar: String? public let avatar: String?

View File

@ -36,4 +36,27 @@ final class MastodonSDKTests: XCTestCase {
wait(for: [theExpectation], timeout: 10.0) wait(for: [theExpectation], timeout: 10.0)
} }
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)
}
} }