2020-07-31 23:40:57 +02:00
|
|
|
// Copyright © 2020 Metabolist. All rights reserved.
|
|
|
|
|
|
|
|
import Foundation
|
|
|
|
import Combine
|
|
|
|
|
|
|
|
// swiftlint:disable force_try
|
|
|
|
private let decoder = MastodonDecoder()
|
|
|
|
private var cancellables = Set<AnyCancellable>()
|
2020-08-03 00:23:01 +02:00
|
|
|
private let devInstanceURL = URL(string: "https://mastodon.social")!
|
2020-08-08 01:19:13 +02:00
|
|
|
private let devIdentityID = UUID(uuidString: "E621E1F8-C36C-495A-93FC-0C247A3E6E5F")!
|
2020-08-03 00:23:01 +02:00
|
|
|
private let devAccessToken = "DEVELOPMENT_ACCESS_TOKEN"
|
2020-07-31 23:40:57 +02:00
|
|
|
|
|
|
|
extension Secrets {
|
2020-08-03 00:23:01 +02:00
|
|
|
static func fresh() -> Secrets { Secrets(keychain: FakeKeychain()) }
|
|
|
|
|
2020-07-31 23:40:57 +02:00
|
|
|
static let development: Secrets = {
|
2020-08-03 00:23:01 +02:00
|
|
|
let secrets = Secrets.fresh()
|
2020-07-31 23:40:57 +02:00
|
|
|
|
|
|
|
try! secrets.set("DEVELOPMENT_CLIENT_ID", forItem: .clientID, forIdentityID: devIdentityID)
|
|
|
|
try! secrets.set("DEVELOPMENT_CLIENT_SECRET", forItem: .clientSecret, forIdentityID: devIdentityID)
|
2020-08-03 00:23:01 +02:00
|
|
|
try! secrets.set(devAccessToken, forItem: .accessToken, forIdentityID: devIdentityID)
|
2020-07-31 23:40:57 +02:00
|
|
|
|
|
|
|
return secrets
|
|
|
|
}()
|
|
|
|
}
|
|
|
|
|
2020-08-06 08:45:57 +02:00
|
|
|
extension Defaults {
|
|
|
|
static func fresh() -> Defaults { Defaults(userDefaults: FakeUserDefaults()) }
|
2020-08-03 00:23:01 +02:00
|
|
|
|
2020-08-06 08:45:57 +02:00
|
|
|
static let development: Defaults = {
|
|
|
|
let preferences = Defaults.fresh()
|
2020-08-03 00:23:01 +02:00
|
|
|
|
2020-08-08 03:16:04 +02:00
|
|
|
// Do future setup here
|
2020-08-03 00:23:01 +02:00
|
|
|
|
|
|
|
return preferences
|
|
|
|
}()
|
|
|
|
}
|
|
|
|
|
2020-07-31 23:40:57 +02:00
|
|
|
extension Account {
|
|
|
|
static let development = try! decoder.decode(Account.self, from: Data(officialAccountJSON.utf8))
|
|
|
|
}
|
|
|
|
|
|
|
|
extension Instance {
|
|
|
|
static let development = try! decoder.decode(Instance.self, from: Data(officialInstanceJSON.utf8))
|
|
|
|
}
|
|
|
|
|
|
|
|
extension IdentityDatabase {
|
2020-08-03 00:23:01 +02:00
|
|
|
static func fresh() -> IdentityDatabase { try! IdentityDatabase(inMemory: true) }
|
|
|
|
|
2020-07-31 23:40:57 +02:00
|
|
|
static var development: IdentityDatabase = {
|
2020-08-03 00:23:01 +02:00
|
|
|
let db = IdentityDatabase.fresh()
|
2020-07-31 23:40:57 +02:00
|
|
|
|
2020-08-03 00:23:01 +02:00
|
|
|
db.createIdentity(id: devIdentityID, url: devInstanceURL)
|
2020-07-31 23:40:57 +02:00
|
|
|
.receive(on: ImmediateScheduler.shared)
|
|
|
|
.sink(receiveCompletion: { _ in }, receiveValue: { _ in })
|
|
|
|
.store(in: &cancellables)
|
|
|
|
|
|
|
|
db.updateAccount(.development, forIdentityID: devIdentityID)
|
|
|
|
.receive(on: ImmediateScheduler.shared)
|
|
|
|
.sink(receiveCompletion: { _ in }, receiveValue: { _ in })
|
|
|
|
.store(in: &cancellables)
|
|
|
|
|
|
|
|
db.updateInstance(.development, forIdentityID: devIdentityID)
|
|
|
|
.receive(on: ImmediateScheduler.shared)
|
|
|
|
.sink(receiveCompletion: { _ in }, receiveValue: { _ in })
|
|
|
|
.store(in: &cancellables)
|
|
|
|
|
|
|
|
return db
|
|
|
|
}()
|
|
|
|
}
|
|
|
|
|
2020-08-03 00:23:01 +02:00
|
|
|
extension AppEnvironment {
|
|
|
|
static func fresh(
|
2020-08-03 17:20:51 +02:00
|
|
|
URLSessionConfiguration: URLSessionConfiguration = .stubbing,
|
2020-08-03 00:23:01 +02:00
|
|
|
identityDatabase: IdentityDatabase = .fresh(),
|
2020-08-06 08:45:57 +02:00
|
|
|
defaults: Defaults = .fresh(),
|
2020-08-03 00:23:01 +02:00
|
|
|
secrets: Secrets = .fresh(),
|
|
|
|
webAuthSessionType: WebAuthSession.Type = SuccessfulStubbingWebAuthSession.self) -> AppEnvironment {
|
|
|
|
AppEnvironment(
|
2020-08-03 17:20:51 +02:00
|
|
|
URLSessionConfiguration: URLSessionConfiguration,
|
2020-08-03 00:23:01 +02:00
|
|
|
identityDatabase: identityDatabase,
|
2020-08-06 08:45:57 +02:00
|
|
|
defaults: defaults,
|
2020-08-03 00:23:01 +02:00
|
|
|
secrets: secrets,
|
|
|
|
webAuthSessionType: webAuthSessionType)
|
|
|
|
}
|
|
|
|
|
|
|
|
static let development = AppEnvironment(
|
2020-08-03 17:20:51 +02:00
|
|
|
URLSessionConfiguration: .stubbing,
|
2020-07-31 23:40:57 +02:00
|
|
|
identityDatabase: .development,
|
2020-08-06 08:45:57 +02:00
|
|
|
defaults: .development,
|
2020-08-03 00:23:01 +02:00
|
|
|
secrets: .development,
|
|
|
|
webAuthSessionType: SuccessfulStubbingWebAuthSession.self)
|
|
|
|
}
|
|
|
|
|
2020-08-08 00:18:54 +02:00
|
|
|
extension IdentityRepository {
|
|
|
|
static let development = try! IdentityRepository(identityID: devIdentityID, appEnvironment: .development)
|
2020-08-07 03:41:59 +02:00
|
|
|
}
|
|
|
|
|
2020-08-03 17:20:51 +02:00
|
|
|
extension RootViewModel {
|
|
|
|
static let development = RootViewModel(environment: .development)
|
|
|
|
}
|
|
|
|
|
|
|
|
extension MainNavigationViewModel {
|
2020-08-08 00:18:54 +02:00
|
|
|
static let development = MainNavigationViewModel(identityRepository: .development)
|
2020-08-03 17:20:51 +02:00
|
|
|
}
|
|
|
|
|
2020-08-07 05:57:52 +02:00
|
|
|
extension SecondaryNavigationViewModel {
|
2020-08-03 17:20:51 +02:00
|
|
|
static let development = MainNavigationViewModel.development.settingsViewModel()
|
2020-07-31 23:40:57 +02:00
|
|
|
}
|
|
|
|
|
2020-08-04 22:26:09 +02:00
|
|
|
extension IdentitiesViewModel {
|
2020-08-07 05:57:52 +02:00
|
|
|
static let development = SecondaryNavigationViewModel.development.identitiesViewModel()
|
2020-08-04 22:26:09 +02:00
|
|
|
}
|
|
|
|
|
2020-08-07 12:59:48 +02:00
|
|
|
extension PreferencesViewModel {
|
|
|
|
static let development = SecondaryNavigationViewModel.development.preferencesViewModel()
|
|
|
|
}
|
|
|
|
|
|
|
|
extension PostingReadingPreferencesViewModel {
|
|
|
|
static let development = PreferencesViewModel.development.postingReadingPreferencesViewModel()
|
2020-08-07 12:14:14 +02:00
|
|
|
}
|
|
|
|
|
2020-07-31 23:40:57 +02:00
|
|
|
// swiftlint:enable force_try
|