diff --git a/LocalPackages/DataBrokerProtection/Sources/DataBrokerProtection/Operations/OperationPreferredDateCalculator.swift b/LocalPackages/DataBrokerProtection/Sources/DataBrokerProtection/Operations/OperationPreferredDateCalculator.swift index acc78af0ac..e787f119b7 100644 --- a/LocalPackages/DataBrokerProtection/Sources/DataBrokerProtection/Operations/OperationPreferredDateCalculator.swift +++ b/LocalPackages/DataBrokerProtection/Sources/DataBrokerProtection/Operations/OperationPreferredDateCalculator.swift @@ -81,8 +81,10 @@ struct OperationPreferredDateCalculator { return date.now.addingTimeInterval(calculateNextRunDateOnError(schedulingConfig: schedulingConfig, historyEvents: historyEvents)) case .optOutStarted, .scanStarted, .noMatchFound: return currentPreferredRunDate - case .optOutConfirmed, .optOutRequested: - return Date.distantFuture + case .optOutConfirmed: + return nil + case .optOutRequested: + return date.now.addingTimeInterval(schedulingConfig.maintenanceScan.hoursToSeconds) } } diff --git a/LocalPackages/DataBrokerProtection/Tests/DataBrokerProtectionTests/DataBrokerProfileQueryOperationManagerTests.swift b/LocalPackages/DataBrokerProtection/Tests/DataBrokerProtectionTests/DataBrokerProfileQueryOperationManagerTests.swift index 9bf5359ab7..869c1e855a 100644 --- a/LocalPackages/DataBrokerProtection/Tests/DataBrokerProtectionTests/DataBrokerProfileQueryOperationManagerTests.swift +++ b/LocalPackages/DataBrokerProtection/Tests/DataBrokerProtectionTests/DataBrokerProfileQueryOperationManagerTests.swift @@ -832,7 +832,7 @@ final class DataBrokerProfileQueryOperationManagerTests: XCTestCase { XCTAssertTrue(areDatesEqualIgnoringSeconds(date1: mockDatabase.lastPreferredRunDateOnScan, date2: Date().addingTimeInterval(schedulingConfig.confirmOptOutScan.hoursToSeconds))) } - func testWhenUpdatingDatesAndLastEventIsOptOutRequested_thenWeSetOptOutPreferredRunDateToDistantFuture() throws { + func testWhenUpdatingDatesAndLastEventIsOptOutRequested_thenWeSetOptOutPreferredRunDateToMaintenance() throws { let brokerId: Int64 = 1 let profileQueryId: Int64 = 1 let extractedProfileId: Int64 = 1 @@ -842,7 +842,7 @@ final class DataBrokerProfileQueryOperationManagerTests: XCTestCase { try sut.updateOperationDataDates(origin: .scan, brokerId: brokerId, profileQueryId: profileQueryId, extractedProfileId: extractedProfileId, schedulingConfig: schedulingConfig, database: mockDatabase) XCTAssertTrue(mockDatabase.wasUpdatedPreferredRunDateForScanCalled) - XCTAssertTrue(mockDatabase.lastPreferredRunDateOnOptOut!.isInDistantFuture()) + XCTAssertTrue(areDatesEqualIgnoringSeconds(date1: mockDatabase.lastPreferredRunDateOnOptOut, date2: Date().addingTimeInterval(schedulingConfig.maintenanceScan.hoursToSeconds))) } func testWhenUpdatingDatesAndLastEventIsMatchesFound_thenWeSetScanPreferredDateToMaintanence() throws { @@ -911,7 +911,7 @@ final class DataBrokerProfileQueryOperationManagerTests: XCTestCase { XCTAssertFalse(mockDatabase.wasUpdatedPreferredRunDateForScanCalled) XCTAssertTrue(mockDatabase.wasUpdatedPreferredRunDateForOptOutCalled) - XCTAssertTrue(mockDatabase.lastPreferredRunDateOnOptOut!.isInDistantFuture()) + XCTAssertTrue(areDatesEqualIgnoringSeconds(date1: mockDatabase.lastPreferredRunDateOnOptOut, date2: Date().addingTimeInterval(config.maintenanceScan.hoursToSeconds))) } func testUpdatingScanDateFromScan_thenScanDoesNotRespectMostRecentDate() throws { @@ -938,7 +938,7 @@ final class DataBrokerProfileQueryOperationManagerTests: XCTestCase { XCTAssertTrue(areDatesEqualIgnoringSeconds(date1: mockDatabase.lastPreferredRunDateOnScan, date2: expectedPreferredRunDate), "\(String(describing: mockDatabase.lastPreferredRunDateOnScan)) is not equal to \(expectedPreferredRunDate)") XCTAssertTrue(mockDatabase.wasUpdatedPreferredRunDateForOptOutCalled) - XCTAssertTrue(mockDatabase.lastPreferredRunDateOnOptOut!.isInDistantFuture()) + XCTAssertTrue(areDatesEqualIgnoringSeconds(date1: mockDatabase.lastPreferredRunDateOnOptOut, date2: Date().addingTimeInterval(config.maintenanceScan.hoursToSeconds))) } } diff --git a/LocalPackages/DataBrokerProtection/Tests/DataBrokerProtectionTests/OperationPreferredDateCalculatorTests.swift b/LocalPackages/DataBrokerProtection/Tests/DataBrokerProtectionTests/OperationPreferredDateCalculatorTests.swift index ad0925ce9c..c569cf2eea 100644 --- a/LocalPackages/DataBrokerProtection/Tests/DataBrokerProtectionTests/OperationPreferredDateCalculatorTests.swift +++ b/LocalPackages/DataBrokerProtection/Tests/DataBrokerProtectionTests/OperationPreferredDateCalculatorTests.swift @@ -513,7 +513,7 @@ final class OperationPreferredDateCalculatorTests: XCTestCase { schedulingConfig: schedulingConfig, attemptCount: 0) - XCTAssertTrue(proposedOptOutDate!.isInDistantFuture()) + XCTAssertNil(proposedOptOutDate) } func testOptOutConfirmedWithoutCurrentPreferredDate_thenOptOutIsNotScheduled() throws { @@ -531,10 +531,12 @@ final class OperationPreferredDateCalculatorTests: XCTestCase { schedulingConfig: schedulingConfig, attemptCount: 0) - XCTAssertTrue(proposedOptOutDate!.isInDistantFuture()) + XCTAssertNil(proposedOptOutDate) } func testOptOutRequestedWithCurrentPreferredDate_thenOptOutIsNotScheduled() throws { + let expectedOptOutDate = MockDate().now.addingTimeInterval(schedulingConfig.maintenanceScan.hoursToSeconds) + let historyEvents = [ HistoryEvent(extractedProfileId: 1, brokerId: 1, @@ -547,12 +549,15 @@ final class OperationPreferredDateCalculatorTests: XCTestCase { historyEvents: historyEvents, extractedProfileID: nil, schedulingConfig: schedulingConfig, - attemptCount: 0) + attemptCount: 0, + date: MockDate()) - XCTAssertTrue(proposedOptOutDate!.isInDistantFuture()) + XCTAssertTrue(areDatesEqualIgnoringSeconds(date1: proposedOptOutDate, date2: expectedOptOutDate)) } - func testOptOutRequestedWithoutCurrentPreferredDate_thenOptOutIsNil() throws { + func testOptOutRequestedWithoutCurrentPreferredDate_thenOptOutIsNotScheduled() throws { + let expectedOptOutDate = MockDate().now.addingTimeInterval(schedulingConfig.maintenanceScan.hoursToSeconds) + let historyEvents = [ HistoryEvent(extractedProfileId: 1, brokerId: 1, @@ -565,9 +570,10 @@ final class OperationPreferredDateCalculatorTests: XCTestCase { historyEvents: historyEvents, extractedProfileID: nil, schedulingConfig: schedulingConfig, - attemptCount: 0) + attemptCount: 0, + date: MockDate()) - XCTAssertTrue(proposedOptOutDate!.isInDistantFuture()) + XCTAssertTrue(areDatesEqualIgnoringSeconds(date1: proposedOptOutDate, date2: expectedOptOutDate)) } func testScanStarted_thenOptOutDoesNotChange() throws { @@ -750,7 +756,9 @@ final class OperationPreferredDateCalculatorTests: XCTestCase { } } - func testChildBrokerTurnsParentBroker_whenFirstOptOutSucceeds_thenOptOutDateIsSetToDistantFuture() throws { + func testChildBrokerTurnsParentBroker_whenFirstOptOutSucceeds_thenOptOutDateIsNotScheduled() throws { + let expectedOptOutDate = MockDate().now.addingTimeInterval(schedulingConfig.maintenanceScan.hoursToSeconds) + let historyEvents = [ HistoryEvent(extractedProfileId: 1, brokerId: 1, @@ -762,9 +770,10 @@ final class OperationPreferredDateCalculatorTests: XCTestCase { historyEvents: historyEvents, extractedProfileID: 1, schedulingConfig: schedulingConfig, - attemptCount: 1) + attemptCount: 1, + date: MockDate()) - XCTAssertTrue(proposedOptOutDate!.isInDistantFuture()) + XCTAssertTrue(areDatesEqualIgnoringSeconds(date1: proposedOptOutDate, date2: expectedOptOutDate)) } func testChildBrokerTurnsParentBroker_whenFirstOptOutFails_thenOptOutIsScheduled() throws { @@ -845,11 +854,11 @@ final class OperationPreferredDateCalculatorTests: XCTestCase { schedulingConfig: schedulingConfig, attemptCount: 0) - XCTAssertTrue(proposedOptOutDate!.isInDistantFuture()) + XCTAssertNil(proposedOptOutDate) } func testOptOutRequestedWithRecentDate_thenOutOutIsNotScheduled() throws { - let expectedOptOutDate: Date? = nil + let expectedOptOutDate = MockDate().now.addingTimeInterval(schedulingConfig.maintenanceScan.hoursToSeconds) let historyEvents = [ HistoryEvent(extractedProfileId: 1, @@ -863,9 +872,10 @@ final class OperationPreferredDateCalculatorTests: XCTestCase { historyEvents: historyEvents, extractedProfileID: nil, schedulingConfig: schedulingConfig, - attemptCount: 0) + attemptCount: 0, + date: MockDate()) - XCTAssertTrue(proposedOptOutDate!.isInDistantFuture()) + XCTAssertTrue(areDatesEqualIgnoringSeconds(date1: proposedOptOutDate, date2: expectedOptOutDate)) } func testScanStartedWithRecentDate_thenOptOutDateDoesNotChange() throws { @@ -894,9 +904,3 @@ struct MockDate: DateProtocol { return Date(timeIntervalSince1970: 0) } } - -extension Date { - func isInDistantFuture() -> Bool { - self > Date(timeIntervalSinceNow: .days(365_000)) - } -}