From 0c616cc6812b95a4cafc468e803da45cd8d2f5da Mon Sep 17 00:00:00 2001 From: Fernando Bunn Date: Thu, 2 May 2024 16:53:20 +0100 Subject: [PATCH] Do not consider deprecated scans in the scan UI (#2729) Task/Issue URL: https://app.asana.com/0/1203581873609357/1207208737318475/f **Description**: Do not consider deprecated scans in the scan UI --- .../DataBrokerOperationsCollection.swift | 8 +++---- .../DataBrokerProtectionProcessor.swift | 2 +- .../DataBrokerProtection/UI/UIMapper.swift | 21 ++++++++----------- .../MapperToUITests.swift | 16 ++++++++++++++ 4 files changed, 30 insertions(+), 17 deletions(-) diff --git a/LocalPackages/DataBrokerProtection/Sources/DataBrokerProtection/Operations/DataBrokerOperationsCollection.swift b/LocalPackages/DataBrokerProtection/Sources/DataBrokerProtection/Operations/DataBrokerOperationsCollection.swift index cbe22fe8fe..eeae49e168 100644 --- a/LocalPackages/DataBrokerProtection/Sources/DataBrokerProtection/Operations/DataBrokerOperationsCollection.swift +++ b/LocalPackages/DataBrokerProtection/Sources/DataBrokerProtection/Operations/DataBrokerOperationsCollection.swift @@ -31,7 +31,7 @@ protocol DataBrokerOperationsCollectionErrorDelegate: AnyObject { final class DataBrokerOperationsCollection: Operation { enum OperationType { - case scan + case manualScan case optOut case all } @@ -119,8 +119,8 @@ final class DataBrokerOperationsCollection: Operation { switch operationType { case .optOut: operationsData = brokerProfileQueriesData.flatMap { $0.optOutOperationsData } - case .scan: - operationsData = brokerProfileQueriesData.compactMap { $0.scanOperationData } + case .manualScan: + operationsData = brokerProfileQueriesData.filter { $0.profileQuery.deprecated == false }.compactMap { $0.scanOperationData } case .all: operationsData = brokerProfileQueriesData.flatMap { $0.operationsData } } @@ -181,7 +181,7 @@ final class DataBrokerOperationsCollection: Operation { runner: runner, pixelHandler: pixelHandler, showWebView: showWebView, - isManualScan: operationType == .scan, + isManualScan: operationType == .manualScan, userNotificationService: userNotificationService, shouldRunNextStep: { [weak self] in guard let self = self else { return false } diff --git a/LocalPackages/DataBrokerProtection/Sources/DataBrokerProtection/Scheduler/DataBrokerProtectionProcessor.swift b/LocalPackages/DataBrokerProtection/Sources/DataBrokerProtection/Scheduler/DataBrokerProtectionProcessor.swift index 74b381eb3e..dee4d346e2 100644 --- a/LocalPackages/DataBrokerProtection/Sources/DataBrokerProtection/Scheduler/DataBrokerProtectionProcessor.swift +++ b/LocalPackages/DataBrokerProtection/Sources/DataBrokerProtection/Scheduler/DataBrokerProtectionProcessor.swift @@ -59,7 +59,7 @@ final class DataBrokerProtectionProcessor { completion: ((DataBrokerProtectionSchedulerErrorCollection?) -> Void)? = nil) { operationQueue.cancelAllOperations() - runOperations(operationType: .scan, + runOperations(operationType: .manualScan, priorityDate: nil, showWebView: showWebView) { errors in os_log("Scans done", log: .dataBrokerProtection) diff --git a/LocalPackages/DataBrokerProtection/Sources/DataBrokerProtection/UI/UIMapper.swift b/LocalPackages/DataBrokerProtection/Sources/DataBrokerProtection/UI/UIMapper.swift index 87ccad2494..ee89f641f2 100644 --- a/LocalPackages/DataBrokerProtection/Sources/DataBrokerProtection/UI/UIMapper.swift +++ b/LocalPackages/DataBrokerProtection/Sources/DataBrokerProtection/UI/UIMapper.swift @@ -56,10 +56,15 @@ struct MapperToUI { // not by the total real cans that the app is doing. let profileQueriesGroupedByBroker = Dictionary(grouping: brokerProfileQueryData, by: { $0.dataBroker.name }) - let totalScans = profileQueriesGroupedByBroker.reduce(0) { accumulator, element in + // We don't want to consider deprecated queries when reporting manual scans to the UI + let filteredProfileQueriesGroupedByBroker = profileQueriesGroupedByBroker.mapValues { queries in + queries.filter { !$0.profileQuery.deprecated } + } + + let totalScans = filteredProfileQueriesGroupedByBroker.reduce(0) { accumulator, element in return accumulator + element.value.totalScans } - let currentScans = profileQueriesGroupedByBroker.reduce(0) { accumulator, element in + let currentScans = filteredProfileQueriesGroupedByBroker.reduce(0) { accumulator, element in return accumulator + element.value.currentScans } @@ -333,23 +338,15 @@ fileprivate extension Array where Element == BrokerProfileQueryData { var totalScans: Int { guard let broker = self.first?.dataBroker else { return 0 } - - let areAllQueriesDeprecated = allSatisfy { $0.profileQuery.deprecated } - - if areAllQueriesDeprecated { - return 0 - } else { - return 1 + broker.mirrorSites.filter { $0.shouldWeIncludeMirrorSite() }.count - } + return 1 + broker.mirrorSites.filter { $0.shouldWeIncludeMirrorSite() }.count } var currentScans: Int { guard let broker = self.first?.dataBroker else { return 0 } - let areAllQueriesDeprecated = allSatisfy { $0.profileQuery.deprecated } let didAllQueriesFinished = allSatisfy { $0.scanOperationData.lastRunDate != nil } - if areAllQueriesDeprecated || !didAllQueriesFinished { + if !didAllQueriesFinished { return 0 } else { return 1 + broker.mirrorSites.filter { $0.shouldWeIncludeMirrorSite() }.count diff --git a/LocalPackages/DataBrokerProtection/Tests/DataBrokerProtectionTests/MapperToUITests.swift b/LocalPackages/DataBrokerProtection/Tests/DataBrokerProtectionTests/MapperToUITests.swift index 6629f5c0be..b7fc620d08 100644 --- a/LocalPackages/DataBrokerProtection/Tests/DataBrokerProtectionTests/MapperToUITests.swift +++ b/LocalPackages/DataBrokerProtection/Tests/DataBrokerProtectionTests/MapperToUITests.swift @@ -105,6 +105,22 @@ final class MapperToUITests: XCTestCase { XCTAssertEqual(result.resultsFound.count, 1) } + func testWhenScansHaveDeprecatedProfileQueriesThatDidNotRun_thenThoseAreNotTakenIntoAccount() { + let brokerProfileQueryData: [BrokerProfileQueryData] = [ + .mock(dataBrokerName: "Broker #1", lastRunDate: Date(), extractedProfile: .mockWithRemovedDate), + .mock(dataBrokerName: "Broker #1", lastRunDate: Date()), + .mock(dataBrokerName: "Broker #1", lastRunDate: nil, deprecated: true), + .mock(dataBrokerName: "Broker #2", lastRunDate: Date()), + .mock(dataBrokerName: "Broker #3", lastRunDate: Date(), extractedProfile: .mockWithRemovedDate, deprecated: true) + ] + + let result = sut.initialScanState(brokerProfileQueryData) + + XCTAssertEqual(result.scanProgress.totalScans, 2) + XCTAssertEqual(result.scanProgress.currentScans, 2) + XCTAssertEqual(result.resultsFound.count, 1) + } + func testInProgressAndCompletedOptOuts_areMappedCorrectly() { let brokerProfileQueryData: [BrokerProfileQueryData] = [ .mock(extractedProfile: .mockWithRemovedDate),