Skip to content

Commit

Permalink
Update test cases
Browse files Browse the repository at this point in the history
  • Loading branch information
quanganhdo committed Dec 2, 2024
1 parent f629dbf commit e6b3bdd
Show file tree
Hide file tree
Showing 3 changed files with 32 additions and 26 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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)
}
}

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

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -513,7 +513,7 @@ final class OperationPreferredDateCalculatorTests: XCTestCase {
schedulingConfig: schedulingConfig,
attemptCount: 0)

XCTAssertTrue(proposedOptOutDate!.isInDistantFuture())
XCTAssertNil(proposedOptOutDate)
}

func testOptOutConfirmedWithoutCurrentPreferredDate_thenOptOutIsNotScheduled() throws {
Expand All @@ -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,
Expand All @@ -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,
Expand All @@ -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 {
Expand Down Expand Up @@ -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,
Expand All @@ -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 {
Expand Down Expand Up @@ -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,
Expand All @@ -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 {
Expand Down Expand Up @@ -894,9 +904,3 @@ struct MockDate: DateProtocol {
return Date(timeIntervalSince1970: 0)
}
}

extension Date {
func isInDistantFuture() -> Bool {
self > Date(timeIntervalSinceNow: .days(365_000))
}
}

0 comments on commit e6b3bdd

Please sign in to comment.