1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
import Foundation
import UIKit
extension MockBlueskyService {
func loadModerationPreferences() async throws -> ModerationPolicy.Preferences {
let arguments = ProcessInfo.processInfo.arguments
loadState.preferenceLoadCount += 1
if arguments.contains("-ui-testing-preferences-fail")
|| (arguments.contains("-ui-testing-preferences-refresh-fail") && loadState.preferenceLoadCount > 1) {
throw URLError(.notConnectedToInternet)
}
let adult = arguments.contains("-ui-testing-adult-media")
let setting: ModerationPolicy.LabelSetting =
arguments.contains("-ui-testing-adult-hide")
? .hide : (arguments.contains("-ui-testing-adult-warn") ? .warn : .ignore)
return .init(
userDID: account.id, adultContentEnabled: adult && !arguments.contains("-ui-testing-adult-disabled"),
labels: adult ? ["porn": setting] : (arguments.contains("-ui-testing-info-label") ? ["scam": .warn] : [:]),
labelers: arguments.contains("-ui-testing-content-warnings") || adult
? [.init(did: ModerationPolicy.defaultLabelerDID)] : [],
labelDefinitions: ModerationPolicy.builtInDefinitions,
mutedWords: arguments.contains("-ui-testing-muted-word") ? [.init(value: "water")] : [])
}
func restoreAccount() async throws -> Account? {
if ProcessInfo.processInfo.arguments.contains("-ui-testing-restore-delay") {
try await Task.sleep(nanoseconds: 3_000_000_000)
}
return restoresAccount ? account : nil
}
func signIn(handle: String, appPassword: String, authFactorToken: String?) async throws -> Account {
if requiresAuthFactorToken && authFactorToken == nil {
throw ServiceError.authFactorTokenRequired
}
if requiresAuthFactorToken && authFactorToken != "aB12c3" {
throw ServiceError.authFactorTokenRejected
}
return account
}
func signOut() async throws {}
}