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

63 lines
1.7 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 = {
2020-10-06 00:50:05 +02:00
let id = Identity.Id()
2020-09-08 04:12:38 +02:00
let db = try! IdentityDatabase(inMemory: true, keychain: MockKeychain.self)
2020-10-06 00:50:05 +02:00
let secrets = Secrets(identityId: id, keychain: MockKeychain.self)
2020-09-08 04:12:38 +02:00
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-10-06 00:50:05 +02:00
_ = db.updateInstance(.preview, id: id)
2020-09-08 04:12:38 +02:00
.receive(on: ImmediateScheduler.shared)
.sink { _ in } receiveValue: { _ in }
2020-10-06 00:50:05 +02:00
_ = db.updateAccount(.preview, id: 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