2020-09-08 02:12:38 +00: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 = {
|
2020-10-05 22:50:05 +00:00
|
|
|
let id = Identity.Id()
|
2020-09-08 02:12:38 +00:00
|
|
|
let db = try! IdentityDatabase(inMemory: true, keychain: MockKeychain.self)
|
2020-10-05 22:50:05 +00:00
|
|
|
let secrets = Secrets(identityId: id, keychain: MockKeychain.self)
|
2020-09-08 02:12:38 +00:00
|
|
|
|
2020-09-11 09:55:06 +00:00
|
|
|
try! secrets.setInstanceURL(.previewInstanceURL)
|
2020-09-08 02:12:38 +00:00
|
|
|
try! secrets.setAccessToken(UUID().uuidString)
|
|
|
|
|
2020-09-13 08:03:08 +00:00
|
|
|
_ = db.createIdentity(id: id, url: .previewInstanceURL, authenticated: true, pending: false)
|
2020-09-08 02:12:38 +00:00
|
|
|
.receive(on: ImmediateScheduler.shared)
|
|
|
|
.sink { _ in } receiveValue: { _ in }
|
|
|
|
|
2020-10-05 22:50:05 +00:00
|
|
|
_ = db.updateInstance(.preview, id: id)
|
2020-09-08 02:12:38 +00:00
|
|
|
.receive(on: ImmediateScheduler.shared)
|
|
|
|
.sink { _ in } receiveValue: { _ in }
|
|
|
|
|
2020-10-05 22:50:05 +00:00
|
|
|
_ = db.updateAccount(.preview, id: id)
|
2020-09-08 02:12:38 +00:00
|
|
|
.receive(on: ImmediateScheduler.shared)
|
|
|
|
.sink { _ in } receiveValue: { _ in }
|
|
|
|
|
|
|
|
return db
|
|
|
|
}()
|
|
|
|
|
|
|
|
let environment = AppEnvironment.mock(fixtureDatabase: db)
|
2020-09-11 09:55:06 +00: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 02:12:38 +00:00
|
|
|
|
|
|
|
public extension RootViewModel {
|
|
|
|
static let preview = try! RootViewModel(environment: environment) { Empty().eraseToAnyPublisher() }
|
|
|
|
}
|
|
|
|
|
|
|
|
public extension Identification {
|
2020-09-09 22:48:56 +00:00
|
|
|
static let preview = RootViewModel.preview.navigationViewModel!.identification
|
2020-09-08 02:12:38 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// swiftlint:enable force_try
|