Skip to content

Commit

Permalink
Do not consider deprecated scans in the scan UI (#2729)
Browse files Browse the repository at this point in the history
Task/Issue URL:
https://app.asana.com/0/1203581873609357/1207208737318475/f

**Description**:
Do not consider deprecated scans in the scan UI
  • Loading branch information
Bunn authored May 2, 2024
1 parent 9ef6a4c commit 0c616cc
Show file tree
Hide file tree
Showing 4 changed files with 30 additions and 17 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ protocol DataBrokerOperationsCollectionErrorDelegate: AnyObject {
final class DataBrokerOperationsCollection: Operation {

enum OperationType {
case scan
case manualScan
case optOut
case all
}
Expand Down Expand Up @@ -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 }
}
Expand Down Expand Up @@ -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 }
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
}

Expand Down Expand Up @@ -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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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),
Expand Down

0 comments on commit 0c616cc

Please sign in to comment.