2020-09-08 04:12:38 +02:00
|
|
|
// Copyright © 2020 Metabolist. All rights reserved.
|
|
|
|
|
|
|
|
import Combine
|
|
|
|
import DB
|
|
|
|
import Foundation
|
|
|
|
import Mastodon
|
|
|
|
import MastodonAPIStubs
|
|
|
|
import MockKeychain
|
|
|
|
import Secrets
|
|
|
|
import ServiceLayer
|
|
|
|
import ServiceLayerMocks
|
|
|
|
import ViewModels
|
|
|
|
|
|
|
|
// swiftlint:disable force_try
|
|
|
|
|
|
|
|
let db: IdentityDatabase = {
|
|
|
|
let id = UUID()
|
|
|
|
let db = try! IdentityDatabase(inMemory: true, keychain: MockKeychain.self)
|
|
|
|
let secrets = Secrets(identityID: id, keychain: MockKeychain.self)
|
|
|
|
|
2020-09-11 11:55:06 +02:00
|
|
|
try! secrets.setInstanceURL(.previewInstanceURL)
|
2020-09-08 04:12:38 +02:00
|
|
|
try! secrets.setAccessToken(UUID().uuidString)
|
|
|
|
|
2020-09-13 10:03:08 +02:00
|
|
|
_ = db.createIdentity(id: id, url: .previewInstanceURL, authenticated: true, pending: false)
|
2020-09-08 04:12:38 +02:00
|
|
|
.receive(on: ImmediateScheduler.shared)
|
|
|
|
.sink { _ in } receiveValue: { _ in }
|
|
|
|
|
2020-09-11 11:55:06 +02:00
|
|
|
_ = db.updateInstance(.preview, forIdentityID: id)
|
2020-09-08 04:12:38 +02:00
|
|
|
.receive(on: ImmediateScheduler.shared)
|
|
|
|
.sink { _ in } receiveValue: { _ in }
|
|
|
|
|
2020-09-11 11:55:06 +02:00
|
|
|
_ = db.updateAccount(.preview, forIdentityID: id)
|
2020-09-08 04:12:38 +02:00
|
|
|
.receive(on: ImmediateScheduler.shared)
|
|
|
|
.sink { _ in } receiveValue: { _ in }
|
|
|
|
|
|
|
|
return db
|
|
|
|
}()
|
|
|
|
|
|
|
|
let environment = AppEnvironment.mock(fixtureDatabase: db)
|
2020-09-11 11:55:06 +02:00
|
|
|
let decoder = MastodonDecoder()
|
|
|
|
|
|
|
|
public extension URL {
|
|
|
|
static let previewInstanceURL = URL(string: "https://mastodon.social")!
|
|
|
|
}
|
|
|
|
|
|
|
|
public extension Account {
|
|
|
|
static let preview = try! decoder.decode(Account.self, from: StubData.account)
|
|
|
|
}
|
|
|
|
|
|
|
|
public extension Instance {
|
|
|
|
static let preview = try! decoder.decode(Instance.self, from: StubData.instance)
|
|
|
|
}
|
2020-09-08 04:12:38 +02:00
|
|
|
|
|
|
|
public extension RootViewModel {
|
|
|
|
static let preview = try! RootViewModel(environment: environment) { Empty().eraseToAnyPublisher() }
|
|
|
|
}
|
|
|
|
|
|
|
|
public extension Identification {
|
2020-09-10 00:48:56 +02:00
|
|
|
static let preview = RootViewModel.preview.navigationViewModel!.identification
|
2020-09-08 04:12:38 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
// swiftlint:enable force_try
|