This repository was archived by the owner on Feb 24, 2025. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 15
Handle child to parent broker migration #3596
Merged
Merged
Changes from all commits
Commits
Show all changes
32 commits
Select commit
Hold shift + click to select a range
348bf3e
Handle child broker to parent broker migration
quanganhdo 4853c58
Merge branch 'main' into anh/pir/child-to-parent-broker
quanganhdo 9dfa64d
Fix operation data sorting
quanganhdo 56a777b
Update kwold JSON
quanganhdo ee69d21
Refactor
quanganhdo 70551e0
Add test cases
quanganhdo 24a8136
Update comments
quanganhdo 0a9a5b5
Merge branch 'main' into anh/pir/child-to-parent-broker
quanganhdo 2ffca99
Use distantFuture for preferred run date
quanganhdo 01ad2c2
Merge branch 'main' into anh/pir/child-to-parent-broker
quanganhdo 173ffef
Fix SwiftLint
quanganhdo f629dbf
Add tests
quanganhdo e6b3bdd
Update test cases
quanganhdo f4f4636
Add optOutReattempt
quanganhdo 4b17818
Merge branch 'main' into anh/pir/child-to-parent-broker
quanganhdo a6fefee
Update test cases
quanganhdo d776ea0
Oops
quanganhdo 12de525
Convert Verecor child sites to be parent sites
brianhall bef9931
Add missing property
quanganhdo 80df190
Fix corrupted JSON
quanganhdo 418b810
Merge branch 'main' into anh/pir/child-to-parent-broker
quanganhdo c00eedf
Revert to old currentScans calculation logic
quanganhdo f7cd5ed
Merge branch 'main' into anh/pir/child-to-parent-broker
quanganhdo 2af7e21
Merge branch 'main' into anh/pir/child-to-parent-broker
quanganhdo 09e8f87
Refactor and update tests
quanganhdo e60fa60
Add comments
quanganhdo 8b0111a
Merge branch 'main' into anh/pir/child-to-parent-broker
quanganhdo 1ccfc6d
Address PR comments
quanganhdo 44350a3
Rename optOutReattempt to hoursUntilNextOptOutAttempt
quanganhdo e7098de
Merge branch 'main' into anh/pir/child-to-parent-broker
quanganhdo 44bb2aa
Merge branch 'main' into anh/pir/child-to-parent-broker
quanganhdo e19a0ae
Use kwold from main
quanganhdo File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
99 changes: 99 additions & 0 deletions
99
...kages/DataBrokerProtection/Tests/DataBrokerProtectionTests/DataBrokerOperationTests.swift
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,99 @@ | ||
// | ||
// DataBrokerOperationTests.swift | ||
// | ||
// Copyright © 2024 DuckDuckGo. All rights reserved. | ||
// | ||
// Licensed under the Apache License, Version 2.0 (the "License"); | ||
// you may not use this file except in compliance with the License. | ||
// You may obtain a copy of the License at | ||
// | ||
// http://www.apache.org/licenses/LICENSE-2.0 | ||
// | ||
// Unless required by applicable law or agreed to in writing, software | ||
// distributed under the License is distributed on an "AS IS" BASIS, | ||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
// See the License for the specific language governing permissions and | ||
// limitations under the License. | ||
// | ||
|
||
@testable import DataBrokerProtection | ||
import XCTest | ||
|
||
final class DataBrokerOperationTests: XCTestCase { | ||
lazy var mockOptOutQueryData: [BrokerProfileQueryData] = { | ||
let brokerId: Int64 = 1 | ||
|
||
let mockNilPreferredRunDateQueryData = Array(1...10).map { | ||
BrokerProfileQueryData.mock(preferredRunDate: nil, optOutJobData: [BrokerProfileQueryData.createOptOutJobData(extractedProfileId: Int64($0), brokerId: brokerId, profileQueryId: Int64($0), preferredRunDate: nil)]) | ||
} | ||
let mockPastQueryData = Array(1...10).map { | ||
BrokerProfileQueryData.mock(preferredRunDate: .nowMinus(hours: $0), optOutJobData: [BrokerProfileQueryData.createOptOutJobData(extractedProfileId: Int64($0), brokerId: brokerId, profileQueryId: Int64($0), preferredRunDate: .nowMinus(hours: $0))]) | ||
} | ||
let mockFutureQueryData = Array(1...10).map { | ||
BrokerProfileQueryData.mock(preferredRunDate: .nowPlus(hours: $0), optOutJobData: [BrokerProfileQueryData.createOptOutJobData(extractedProfileId: Int64($0), brokerId: brokerId, profileQueryId: Int64($0), preferredRunDate: .nowPlus(hours: $0))]) | ||
} | ||
|
||
return mockNilPreferredRunDateQueryData + mockPastQueryData + mockFutureQueryData | ||
}() | ||
|
||
lazy var mockScanQueryData: [BrokerProfileQueryData] = { | ||
let mockNilPreferredRunDateQueryData = Array(1...10).map { _ in | ||
BrokerProfileQueryData.mock(preferredRunDate: nil) | ||
} | ||
let mockPastQueryData = Array(1...10).map { | ||
BrokerProfileQueryData.mock(preferredRunDate: .nowMinus(hours: $0)) | ||
} | ||
let mockFutureQueryData = Array(1...10).map { | ||
BrokerProfileQueryData.mock(preferredRunDate: .nowPlus(hours: $0)) | ||
} | ||
|
||
return mockNilPreferredRunDateQueryData + mockPastQueryData + mockFutureQueryData | ||
}() | ||
|
||
func testWhenFilteringOptOutOperationData_thenAllButFuturePreferredRunDateIsReturned() { | ||
let operationData1 = MockDataBrokerOperation.filterAndSortOperationsData(brokerProfileQueriesData: mockOptOutQueryData, operationType: .optOut, priorityDate: nil) | ||
let operationData2 = MockDataBrokerOperation.filterAndSortOperationsData(brokerProfileQueriesData: mockOptOutQueryData, operationType: .optOut, priorityDate: .now) | ||
let operationData3 = MockDataBrokerOperation.filterAndSortOperationsData(brokerProfileQueriesData: mockOptOutQueryData, operationType: .optOut, priorityDate: .distantPast) | ||
let operationData4 = MockDataBrokerOperation.filterAndSortOperationsData(brokerProfileQueriesData: mockOptOutQueryData, operationType: .optOut, priorityDate: .distantFuture) | ||
|
||
XCTAssertEqual(operationData1.count, 30) // all jobs | ||
XCTAssertEqual(operationData2.count, 20) // nil preferred run date + past jobs | ||
XCTAssertEqual(operationData3.count, 10) // nil preferred run date jobs | ||
XCTAssertEqual(operationData4.count, 30) // all jobs | ||
} | ||
|
||
func testWhenFilteringScanOperationData_thenPreferredRunDatePriorToPriorityDateIsReturned() { | ||
let operationData1 = MockDataBrokerOperation.filterAndSortOperationsData(brokerProfileQueriesData: mockScanQueryData, operationType: .scheduledScan, priorityDate: nil) | ||
let operationData2 = MockDataBrokerOperation.filterAndSortOperationsData(brokerProfileQueriesData: mockScanQueryData, operationType: .manualScan, priorityDate: .now) | ||
let operationData3 = MockDataBrokerOperation.filterAndSortOperationsData(brokerProfileQueriesData: mockScanQueryData, operationType: .scheduledScan, priorityDate: .distantPast) | ||
let operationData4 = MockDataBrokerOperation.filterAndSortOperationsData(brokerProfileQueriesData: mockScanQueryData, operationType: .manualScan, priorityDate: .distantFuture) | ||
|
||
XCTAssertEqual(operationData1.count, 30) // all jobs | ||
XCTAssertEqual(operationData2.count, 10) // past jobs | ||
XCTAssertEqual(operationData3.count, 0) // no jobs | ||
XCTAssertEqual(operationData4.count, 20) // past + future jobs | ||
} | ||
|
||
func testFilteringAllOperationData() { | ||
let operationData1 = MockDataBrokerOperation.filterAndSortOperationsData(brokerProfileQueriesData: mockOptOutQueryData, operationType: .all, priorityDate: nil) | ||
let operationData2 = MockDataBrokerOperation.filterAndSortOperationsData(brokerProfileQueriesData: mockOptOutQueryData, operationType: .all, priorityDate: .now) | ||
let operationData3 = MockDataBrokerOperation.filterAndSortOperationsData(brokerProfileQueriesData: mockOptOutQueryData, operationType: .all, priorityDate: .distantPast) | ||
let operationData4 = MockDataBrokerOperation.filterAndSortOperationsData(brokerProfileQueriesData: mockOptOutQueryData, operationType: .all, priorityDate: .distantFuture) | ||
|
||
XCTAssertEqual(operationData1.filter { $0 is ScanJobData }.count, 30) // all jobs | ||
XCTAssertEqual(operationData1.filter { $0 is OptOutJobData }.count, 30) // all jobs | ||
XCTAssertEqual(operationData1.count, 30+30) | ||
|
||
XCTAssertEqual(operationData2.filter { $0 is ScanJobData }.count, 10) // past jobs | ||
XCTAssertEqual(operationData2.filter { $0 is OptOutJobData }.count, 20) // nil preferred run date + past jobs | ||
XCTAssertEqual(operationData2.count, 10+20) | ||
|
||
XCTAssertEqual(operationData3.filter { $0 is ScanJobData }.count, 0) // no jobs | ||
XCTAssertEqual(operationData3.filter { $0 is OptOutJobData }.count, 10) // nil preferred run date jobs | ||
XCTAssertEqual(operationData3.count, 0+10) | ||
|
||
XCTAssertEqual(operationData4.filter { $0 is ScanJobData }.count, 20) // past + future jobs | ||
XCTAssertEqual(operationData4.filter { $0 is OptOutJobData }.count, 30) // all jobs | ||
XCTAssertEqual(operationData4.count, 20+30) | ||
} | ||
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.