2024-11-04 22:34:22 +00:00
|
|
|
//
|
|
|
|
// AppContext+Mock.swift
|
|
|
|
// Passepartout
|
|
|
|
//
|
|
|
|
// Created by Davide De Rosa on 6/22/24.
|
|
|
|
// Copyright (c) 2024 Davide De Rosa. All rights reserved.
|
|
|
|
//
|
|
|
|
// https://github.com/passepartoutvpn
|
|
|
|
//
|
|
|
|
// This file is part of Passepartout.
|
|
|
|
//
|
|
|
|
// Passepartout is free software: you can redistribute it and/or modify
|
|
|
|
// it under the terms of the GNU General Public License as published by
|
|
|
|
// the Free Software Foundation, either version 3 of the License, or
|
|
|
|
// (at your option) any later version.
|
|
|
|
//
|
|
|
|
// Passepartout is distributed in the hope that it will be useful,
|
|
|
|
// but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
// GNU General Public License for more details.
|
|
|
|
//
|
|
|
|
// You should have received a copy of the GNU General Public License
|
|
|
|
// along with Passepartout. If not, see <http://www.gnu.org/licenses/>.
|
|
|
|
//
|
|
|
|
|
|
|
|
import Combine
|
|
|
|
import CommonLibrary
|
|
|
|
import CommonUtils
|
|
|
|
import Foundation
|
|
|
|
import PassepartoutKit
|
|
|
|
|
|
|
|
extension AppContext {
|
|
|
|
public static let mock: AppContext = .mock(withRegistry: Registry())
|
|
|
|
|
|
|
|
public static func mock(withRegistry registry: Registry) -> AppContext {
|
|
|
|
let iapManager = IAPManager(
|
2024-11-20 17:05:47 +00:00
|
|
|
inAppHelper: FakeAppProductHelper(),
|
|
|
|
receiptReader: FakeAppReceiptReader(),
|
2024-11-21 17:57:32 +00:00
|
|
|
betaChecker: TestFlightChecker(),
|
2024-11-04 22:34:22 +00:00
|
|
|
unrestrictedFeatures: [
|
|
|
|
.interactiveLogin,
|
2024-11-05 09:03:54 +00:00
|
|
|
.onDemand
|
2024-11-04 22:34:22 +00:00
|
|
|
],
|
|
|
|
productsAtBuild: { _ in
|
|
|
|
[]
|
|
|
|
}
|
|
|
|
)
|
2024-11-21 15:03:57 +00:00
|
|
|
let processor = InAppProcessor(
|
2024-11-04 22:34:22 +00:00
|
|
|
iapManager: iapManager,
|
|
|
|
title: {
|
|
|
|
"Passepartout.Mock: \($0.name)"
|
|
|
|
},
|
|
|
|
isIncluded: { _, _ in
|
|
|
|
true
|
|
|
|
},
|
2024-11-21 15:03:57 +00:00
|
|
|
willRebuild: { _, builder in
|
2024-11-04 22:34:22 +00:00
|
|
|
builder
|
|
|
|
},
|
2024-11-21 15:48:12 +00:00
|
|
|
willInstall: { _, profile in
|
2024-11-04 22:34:22 +00:00
|
|
|
try profile.withProviderModules()
|
2024-11-19 07:55:41 +00:00
|
|
|
},
|
|
|
|
verify: { _, _ in
|
|
|
|
nil
|
2024-11-04 22:34:22 +00:00
|
|
|
}
|
|
|
|
)
|
|
|
|
let profileManager = {
|
|
|
|
let profiles: [Profile] = (0..<20)
|
|
|
|
.reduce(into: []) { list, _ in
|
|
|
|
list.append(.newMockProfile())
|
|
|
|
}
|
|
|
|
return ProfileManager(profiles: profiles)
|
|
|
|
}()
|
|
|
|
let tunnelEnvironment = InMemoryEnvironment()
|
|
|
|
let tunnel = ExtendedTunnel(
|
|
|
|
tunnel: Tunnel(strategy: FakeTunnelStrategy(environment: tunnelEnvironment)),
|
|
|
|
environment: tunnelEnvironment,
|
|
|
|
processor: processor,
|
|
|
|
interval: Constants.shared.tunnel.refreshInterval
|
|
|
|
)
|
|
|
|
let providerManager = ProviderManager(
|
|
|
|
repository: InMemoryProviderRepository()
|
|
|
|
)
|
2024-11-14 10:02:26 +00:00
|
|
|
let migrationManager = MigrationManager()
|
2024-11-04 22:34:22 +00:00
|
|
|
return AppContext(
|
|
|
|
iapManager: iapManager,
|
2024-11-14 10:02:26 +00:00
|
|
|
migrationManager: migrationManager,
|
2024-11-04 22:34:22 +00:00
|
|
|
profileManager: profileManager,
|
2024-11-14 10:02:26 +00:00
|
|
|
providerManager: providerManager,
|
|
|
|
registry: registry,
|
2024-11-17 10:34:43 +00:00
|
|
|
tunnel: tunnel,
|
|
|
|
tunnelReceiptURL: BundleConfiguration.urlForBetaReceipt
|
2024-11-04 22:34:22 +00:00
|
|
|
)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// MARK: - Shortcuts
|
|
|
|
|
|
|
|
extension IAPManager {
|
|
|
|
public static var mock: IAPManager {
|
|
|
|
AppContext.mock.iapManager
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
extension ProfileManager {
|
|
|
|
public static var mock: ProfileManager {
|
|
|
|
AppContext.mock.profileManager
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
extension ExtendedTunnel {
|
|
|
|
public static var mock: ExtendedTunnel {
|
|
|
|
AppContext.mock.tunnel
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
extension ProviderManager {
|
|
|
|
public static var mock: ProviderManager {
|
|
|
|
AppContext.mock.providerManager
|
|
|
|
}
|
|
|
|
}
|