metatext-app-ios-iphone-ipad/ViewModels/Sources/PreviewViewModels/PreviewViewModels.swift

54 lines
1.6 KiB
Swift
Raw Normal View History

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 url = URL(string: "https://mastodon.social")!
let db = try! IdentityDatabase(inMemory: true, keychain: MockKeychain.self)
let decoder = MastodonDecoder()
let instance = try! decoder.decode(Instance.self, from: StubData.instance)
let account = try! decoder.decode(Account.self, from: StubData.account)
let secrets = Secrets(identityID: id, keychain: MockKeychain.self)
try! secrets.setInstanceURL(url)
try! secrets.setAccessToken(UUID().uuidString)
2020-09-09 07:40:49 +02:00
_ = db.createIdentity(id: id, url: url, authenticated: true)
2020-09-08 04:12:38 +02:00
.receive(on: ImmediateScheduler.shared)
.sink { _ in } receiveValue: { _ in }
_ = db.updateInstance(instance, forIdentityID: id)
.receive(on: ImmediateScheduler.shared)
.sink { _ in } receiveValue: { _ in }
_ = db.updateAccount(account, forIdentityID: id)
.receive(on: ImmediateScheduler.shared)
.sink { _ in } receiveValue: { _ in }
return db
}()
let environment = AppEnvironment.mock(fixtureDatabase: db)
public extension RootViewModel {
static let preview = try! RootViewModel(environment: environment) { Empty().eraseToAnyPublisher() }
}
public extension Identification {
static let preview = RootViewModel.preview.identification!
}
// swiftlint:enable force_try