Skip to content

Commit

Permalink
Fix tests
Browse files Browse the repository at this point in the history
  • Loading branch information
SlayterDev committed Aug 30, 2024
1 parent 0106b03 commit 636d565
Show file tree
Hide file tree
Showing 8 changed files with 120 additions and 40 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -91,7 +91,7 @@ final class MockPrivacyConfigurationManager: NSObject, PrivacyConfigurationManag
}

func reload(etag: String?, data: Data?) -> BrowserServicesKit.PrivacyConfigurationManager.ReloadResult {
fatalError("not implemented")
return .embedded
}

var updatesPublisher: AnyPublisher<Void, Never> = Just(()).eraseToAnyPublisher()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,6 @@ class HTTPSUpgradeIntegrationTests: XCTestCase {
window = WindowsManager.openNewWindow(with: .none)!

XCTAssertTrue(AppPrivacyFeatures.shared.contentBlocking.privacyConfigurationManager.privacyConfig.isFeature(.httpsUpgrade, enabledForDomain: "privacy-test-pages.site"))
await ConfigurationManager.shared.refreshIfNeeded()?.value
}

@MainActor
Expand Down
2 changes: 2 additions & 0 deletions LocalPackages/DataBrokerProtection/Package.swift
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,8 @@ let package = Package(
.product(name: "SwiftUIExtensions", package: "SwiftUIExtensions"),
.byName(name: "XPCHelper"),
.product(name: "PixelKit", package: "BrowserServicesKit"),
.product(name: "Configuration", package: "BrowserServicesKit"),
.product(name: "Persistence", package: "BrowserServicesKit")
],
resources: [.process("Resources")],
swiftSettings: [
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -116,7 +116,7 @@ public final class DataBrokerProtectionAgentManager {
private let operationDependencies: DataBrokerOperationDependencies
private let pixelHandler: EventMapping<DataBrokerProtectionPixels>
private let agentStopper: DataBrokerProtectionAgentStopper
private let configurationManger: ConfigurationManager
private let configurationManger: DefaultConfigurationManager

// Used for debug functions only, so not injected
private lazy var browserWindowManager = BrowserWindowManager()
Expand All @@ -131,7 +131,7 @@ public final class DataBrokerProtectionAgentManager {
operationDependencies: DataBrokerOperationDependencies,
pixelHandler: EventMapping<DataBrokerProtectionPixels>,
agentStopper: DataBrokerProtectionAgentStopper,
configurationManager: ConfigurationManager
configurationManager: DefaultConfigurationManager
) {
self.userNotificationService = userNotificationService
self.activityScheduler = activityScheduler
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,8 @@
//

import XCTest
import Configuration
import Persistence
@testable import DataBrokerProtection

final class DataBrokerProtectionAgentManagerTests: XCTestCase {
Expand All @@ -32,13 +34,15 @@ final class DataBrokerProtectionAgentManagerTests: XCTestCase {
private var mockDependencies: DefaultDataBrokerOperationDependencies!
private var mockProfile: DataBrokerProtectionProfile!
private var mockAgentStopper: MockAgentStopper!
private var mockConfigurationManager: MockConfigurationManager!

override func setUpWithError() throws {

mockPixelHandler = MockPixelHandler()
mockActivityScheduler = MockDataBrokerProtectionBackgroundActivityScheduler()
mockNotificationService = MockUserNotificationService()
mockAgentStopper = MockAgentStopper()
mockConfigurationManager = MockConfigurationManager()

let mockDatabase = MockDatabase()
let mockMismatchCalculator = MockMismatchCalculator(database: mockDatabase, pixelHandler: mockPixelHandler)
Expand Down Expand Up @@ -78,7 +82,8 @@ final class DataBrokerProtectionAgentManagerTests: XCTestCase {
dataManager: mockDataManager,
operationDependencies: mockDependencies,
pixelHandler: mockPixelHandler,
agentStopper: mockAgentStopper)
agentStopper: mockAgentStopper,
configurationManager: mockConfigurationManager)

mockDataManager.profileToReturn = mockProfile

Expand Down Expand Up @@ -121,7 +126,8 @@ final class DataBrokerProtectionAgentManagerTests: XCTestCase {
dataManager: mockDataManager,
operationDependencies: mockDependencies,
pixelHandler: mockPixelHandler,
agentStopper: agentStopper)
agentStopper: agentStopper,
configurationManager: mockConfigurationManager)

mockDataManager.profileToReturn = nil

Expand Down Expand Up @@ -153,7 +159,8 @@ final class DataBrokerProtectionAgentManagerTests: XCTestCase {
dataManager: mockDataManager,
operationDependencies: mockDependencies,
pixelHandler: mockPixelHandler,
agentStopper: mockAgentStopper)
agentStopper: mockAgentStopper,
configurationManager: mockConfigurationManager)

mockDataManager.profileToReturn = nil

Expand Down Expand Up @@ -190,7 +197,8 @@ final class DataBrokerProtectionAgentManagerTests: XCTestCase {
dataManager: mockDataManager,
operationDependencies: mockDependencies,
pixelHandler: mockPixelHandler,
agentStopper: mockAgentStopper)
agentStopper: mockAgentStopper,
configurationManager: mockConfigurationManager)

mockDataManager.profileToReturn = mockProfile

Expand All @@ -216,7 +224,8 @@ final class DataBrokerProtectionAgentManagerTests: XCTestCase {
dataManager: mockDataManager,
operationDependencies: mockDependencies,
pixelHandler: mockPixelHandler,
agentStopper: mockAgentStopper)
agentStopper: mockAgentStopper,
configurationManager: mockConfigurationManager)

mockDataManager.profileToReturn = mockProfile

Expand All @@ -242,7 +251,8 @@ final class DataBrokerProtectionAgentManagerTests: XCTestCase {
dataManager: mockDataManager,
operationDependencies: mockDependencies,
pixelHandler: mockPixelHandler,
agentStopper: mockAgentStopper)
agentStopper: mockAgentStopper,
configurationManager: mockConfigurationManager)

mockNotificationService.reset()

Expand All @@ -263,7 +273,8 @@ final class DataBrokerProtectionAgentManagerTests: XCTestCase {
dataManager: mockDataManager,
operationDependencies: mockDependencies,
pixelHandler: mockPixelHandler,
agentStopper: mockAgentStopper)
agentStopper: mockAgentStopper,
configurationManager: mockConfigurationManager)

mockNotificationService.reset()

Expand All @@ -284,7 +295,8 @@ final class DataBrokerProtectionAgentManagerTests: XCTestCase {
dataManager: mockDataManager,
operationDependencies: mockDependencies,
pixelHandler: mockPixelHandler,
agentStopper: mockAgentStopper)
agentStopper: mockAgentStopper,
configurationManager: mockConfigurationManager)

mockNotificationService.reset()
mockQueueManager.startImmediateOperationsIfPermittedCompletionError = DataBrokerProtectionAgentErrorCollection(oneTimeError: NSError(domain: "test", code: 10))
Expand All @@ -306,7 +318,8 @@ final class DataBrokerProtectionAgentManagerTests: XCTestCase {
dataManager: mockDataManager,
operationDependencies: mockDependencies,
pixelHandler: mockPixelHandler,
agentStopper: mockAgentStopper)
agentStopper: mockAgentStopper,
configurationManager: mockConfigurationManager)

mockNotificationService.reset()
mockDataManager.shouldReturnHasMatches = true
Expand All @@ -328,7 +341,8 @@ final class DataBrokerProtectionAgentManagerTests: XCTestCase {
dataManager: mockDataManager,
operationDependencies: mockDependencies,
pixelHandler: mockPixelHandler,
agentStopper: mockAgentStopper)
agentStopper: mockAgentStopper,
configurationManager: mockConfigurationManager)

mockNotificationService.reset()
mockDataManager.shouldReturnHasMatches = false
Expand All @@ -350,7 +364,8 @@ final class DataBrokerProtectionAgentManagerTests: XCTestCase {
dataManager: mockDataManager,
operationDependencies: mockDependencies,
pixelHandler: mockPixelHandler,
agentStopper: mockAgentStopper)
agentStopper: mockAgentStopper,
configurationManager: mockConfigurationManager)

var startScheduledScansCalled = false
mockQueueManager.startScheduledOperationsIfPermittedCalledCompletion = { _ in
Expand All @@ -364,3 +379,48 @@ final class DataBrokerProtectionAgentManagerTests: XCTestCase {
XCTAssertTrue(startScheduledScansCalled)
}
}

struct MockConfigurationFetcher: ConfigurationFetching {
func fetch(_ configuration: Configuration, isDebug: Bool) async throws {
return
}

func fetch(all configurations: [Configuration]) async throws {
return
}
}

struct MockConfigurationStore: ConfigurationStoring {
func loadData(for configuration: Configuration) -> Data? {
return nil
}

func loadEtag(for configuration: Configuration) -> String? {
return nil
}

func loadEmbeddedEtag(for configuration: Configuration) -> String? {
return nil
}

mutating func saveData(_ data: Data, for configuration: Configuration) throws {
return
}

mutating func saveEtag(_ etag: String, for configuration: Configuration) throws {
return
}

func fileUrl(for configuration: Configuration) -> URL {
return URL(string: "file:///\(configuration.rawValue)")!
}

}

final class MockConfigurationManager: DefaultConfigurationManager {
override init(fetcher: ConfigurationFetching = MockConfigurationFetcher(),
store: ConfigurationStoring = MockConfigurationStore(),
defaults: KeyValueStoring = UserDefaults()) {
super.init(fetcher: fetcher, store: store)
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
import BrowserServicesKit
import Combine
import Common
import Configuration
import Foundation
import GRDB
import SecureStorage
Expand Down Expand Up @@ -1929,3 +1930,17 @@ struct MockMigrationsProvider: DataBrokerProtectionDatabaseMigrationsProvider {
return { _ in }
}
}

//struct MockConfigurationFetcher: ConfigurationFetching {

Check failure on line 1934 in LocalPackages/DataBrokerProtection/Tests/DataBrokerProtectionTests/Mocks.swift

View workflow job for this annotation

GitHub Actions / SwiftLint

Prefer at least one space after slashes for comments (comment_spacing)
// func fetch(_ configuration: Configuration, isDebug: Bool) async throws {
// return
// }
//
// func fetch(all configurations: [Configuration]) async throws {
// return
// }
//}

Check failure on line 1942 in LocalPackages/DataBrokerProtection/Tests/DataBrokerProtectionTests/Mocks.swift

View workflow job for this annotation

GitHub Actions / SwiftLint

Prefer at least one space after slashes for comments (comment_spacing)
//
//final class MockConfigurationManager: DefaultConfigurationManager {

Check failure on line 1944 in LocalPackages/DataBrokerProtection/Tests/DataBrokerProtectionTests/Mocks.swift

View workflow job for this annotation

GitHub Actions / SwiftLint

Prefer at least one space after slashes for comments (comment_spacing)
//
//}

Check failure on line 1946 in LocalPackages/DataBrokerProtection/Tests/DataBrokerProtectionTests/Mocks.swift

View workflow job for this annotation

GitHub Actions / SwiftLint

Prefer at least one space after slashes for comments (comment_spacing)
Loading

0 comments on commit 636d565

Please sign in to comment.