feat: make Unit Test works
This commit is contained in:
parent
7ecbcec077
commit
27a7ccbd88
|
@ -14,7 +14,7 @@ extension Mastodon.API.Timeline {
|
|||
return Mastodon.API.endpointURL(domain: domain).appendingPathComponent("timelines/public")
|
||||
}
|
||||
|
||||
public static func create(
|
||||
public static func `public`(
|
||||
session: URLSession,
|
||||
domain: String,
|
||||
query: PublicTimelineQuery
|
||||
|
@ -45,7 +45,15 @@ extension Mastodon.API.Timeline {
|
|||
public let minID: Mastodon.Entity.Toot.ID?
|
||||
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.remote = remote
|
||||
self.onlyMedia = onlyMedia
|
||||
|
|
|
@ -19,7 +19,18 @@ extension Mastodon.API {
|
|||
}()
|
||||
static 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
|
||||
}()
|
||||
|
|
|
@ -14,7 +14,7 @@ extension Mastodon.Entity {
|
|||
|
||||
public let id: ID
|
||||
|
||||
public let username: Date
|
||||
public let username: String
|
||||
public let acct: String
|
||||
public let displayName: String?
|
||||
public let avatar: String?
|
||||
|
|
|
@ -36,4 +36,27 @@ final class MastodonSDKTests: XCTestCase {
|
|||
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)
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue