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 24, 2024
1 parent 4b17818 commit a6fefee
Show file tree
Hide file tree
Showing 2 changed files with 64 additions and 64 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -222,8 +222,8 @@ extension Array where Element == BrokerJobData {
/// - Jobs with a preferred run date on or before the priority date are included.
///
/// Note: Opt-out jobs without a preferred run date may be:
/// 1. From child brokers (skipped during runOptOutOperation)
/// 2. From former child brokers now acting as parent brokers (processed if extractedProfile hasn't been removed)
/// 1. From child brokers (will be skipped during runOptOutOperation).
/// 2. From former child brokers now acting as parent brokers (will be processed if extractedProfile hasn't been removed).
func filtered(using priorityDate: Date) -> [BrokerJobData] {
filter { jobData in
guard let preferredRunDate = jobData.preferredRunDate else {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -507,13 +507,13 @@ final class OperationPreferredDateCalculatorTests: XCTestCase {

let calculator = OperationPreferredDateCalculator()

let proposedOptOutDate = try calculator.dateForOptOutOperation(currentPreferredRunDate: Date(),
historyEvents: historyEvents,
extractedProfileID: nil,
schedulingConfig: schedulingConfig,
attemptCount: 0)
let actualOptOutDate = try calculator.dateForOptOutOperation(currentPreferredRunDate: Date(),
historyEvents: historyEvents,
extractedProfileID: nil,
schedulingConfig: schedulingConfig,
attemptCount: 0)

XCTAssertNil(proposedOptOutDate)
XCTAssertNil(actualOptOutDate)
}

func testOptOutConfirmedWithoutCurrentPreferredDate_thenOptOutIsNotScheduled() throws {
Expand All @@ -525,13 +525,13 @@ final class OperationPreferredDateCalculatorTests: XCTestCase {

let calculator = OperationPreferredDateCalculator()

let proposedOptOutDate = try calculator.dateForOptOutOperation(currentPreferredRunDate: Date(),
historyEvents: historyEvents,
extractedProfileID: nil,
schedulingConfig: schedulingConfig,
attemptCount: 0)
let actualOptOutDate = try calculator.dateForOptOutOperation(currentPreferredRunDate: Date(),
historyEvents: historyEvents,
extractedProfileID: nil,
schedulingConfig: schedulingConfig,
attemptCount: 0)

XCTAssertNil(proposedOptOutDate)
XCTAssertNil(actualOptOutDate)
}

func testOptOutRequestedWithCurrentPreferredDate_thenOptOutIsNotScheduled() throws {
Expand All @@ -545,14 +545,14 @@ final class OperationPreferredDateCalculatorTests: XCTestCase {

let calculator = OperationPreferredDateCalculator()

let proposedOptOutDate = try calculator.dateForOptOutOperation(currentPreferredRunDate: Date(),
historyEvents: historyEvents,
extractedProfileID: nil,
schedulingConfig: schedulingConfig,
attemptCount: 0,
date: MockDate())
let actualOptOutDate = try calculator.dateForOptOutOperation(currentPreferredRunDate: Date(),
historyEvents: historyEvents,
extractedProfileID: nil,
schedulingConfig: schedulingConfig,
attemptCount: 0,
date: MockDate())

XCTAssertTrue(areDatesEqualIgnoringSeconds(date1: proposedOptOutDate, date2: expectedOptOutDate))
XCTAssertTrue(areDatesEqualIgnoringSeconds(date1: actualOptOutDate, date2: expectedOptOutDate))
}

func testOptOutRequestedWithoutCurrentPreferredDate_thenOptOutIsNotScheduled() throws {
Expand All @@ -566,14 +566,14 @@ final class OperationPreferredDateCalculatorTests: XCTestCase {

let calculator = OperationPreferredDateCalculator()

let proposedOptOutDate = try calculator.dateForOptOutOperation(currentPreferredRunDate: nil,
historyEvents: historyEvents,
extractedProfileID: nil,
schedulingConfig: schedulingConfig,
attemptCount: 0,
date: MockDate())
let actualOptOutDate = try calculator.dateForOptOutOperation(currentPreferredRunDate: nil,
historyEvents: historyEvents,
extractedProfileID: nil,
schedulingConfig: schedulingConfig,
attemptCount: 0,
date: MockDate())

XCTAssertTrue(areDatesEqualIgnoringSeconds(date1: proposedOptOutDate, date2: expectedOptOutDate))
XCTAssertTrue(areDatesEqualIgnoringSeconds(date1: actualOptOutDate, date2: expectedOptOutDate))
}

func testScanStarted_thenOptOutDoesNotChange() throws {
Expand Down Expand Up @@ -608,10 +608,10 @@ final class OperationPreferredDateCalculatorTests: XCTestCase {
let calculator = OperationPreferredDateCalculator()

let actualOptOutDate = try calculator.dateForOptOutOperation(currentPreferredRunDate: nil,
historyEvents: historyEvents,
extractedProfileID: nil,
schedulingConfig: schedulingConfig,
attemptCount: 0)
historyEvents: historyEvents,
extractedProfileID: nil,
schedulingConfig: schedulingConfig,
attemptCount: 0)

XCTAssertTrue(areDatesEqualIgnoringSeconds(date1: expectedOptOutDate, date2: actualOptOutDate))
}
Expand Down Expand Up @@ -766,14 +766,14 @@ final class OperationPreferredDateCalculatorTests: XCTestCase {
type: .optOutRequested),
]
let calculator = OperationPreferredDateCalculator()
let proposedOptOutDate = try calculator.dateForOptOutOperation(currentPreferredRunDate: nil,
historyEvents: historyEvents,
extractedProfileID: 1,
schedulingConfig: schedulingConfig,
attemptCount: 1,
date: MockDate())
let actualOptOutDate = try calculator.dateForOptOutOperation(currentPreferredRunDate: nil,
historyEvents: historyEvents,
extractedProfileID: 1,
schedulingConfig: schedulingConfig,
attemptCount: 1,
date: MockDate())

XCTAssertTrue(areDatesEqualIgnoringSeconds(date1: proposedOptOutDate, date2: expectedOptOutDate))
XCTAssertTrue(areDatesEqualIgnoringSeconds(date1: actualOptOutDate, date2: expectedOptOutDate))
}

func testChildBrokerTurnsParentBroker_whenFirstOptOutFails_thenOptOutIsScheduled() throws {
Expand All @@ -786,13 +786,13 @@ final class OperationPreferredDateCalculatorTests: XCTestCase {
type: .error(error: .malformedURL)),
]
let calculator = OperationPreferredDateCalculator()
let proposedOptOutDate = try calculator.dateForOptOutOperation(currentPreferredRunDate: nil,
historyEvents: historyEvents,
extractedProfileID: 1,
schedulingConfig: schedulingConfig,
attemptCount: 1)
let actualOptOutDate = try calculator.dateForOptOutOperation(currentPreferredRunDate: nil,
historyEvents: historyEvents,
extractedProfileID: 1,
schedulingConfig: schedulingConfig,
attemptCount: 1)

XCTAssertTrue(areDatesEqualIgnoringSeconds(date1: expectedOptOutDate, date2: proposedOptOutDate))
XCTAssertTrue(areDatesEqualIgnoringSeconds(date1: expectedOptOutDate, date2: actualOptOutDate))
}

func testRequestedOptOut_whenProfileReappears_thenOptOutIsScheduled() throws {
Expand All @@ -810,13 +810,13 @@ final class OperationPreferredDateCalculatorTests: XCTestCase {
type: .reAppearence),
]
let calculator = OperationPreferredDateCalculator()
let proposedOptOutDate = try calculator.dateForOptOutOperation(currentPreferredRunDate: .distantFuture,
historyEvents: historyEvents,
extractedProfileID: 1,
schedulingConfig: schedulingConfig,
attemptCount: 1)
let actualOptOutDate = try calculator.dateForOptOutOperation(currentPreferredRunDate: .distantFuture,
historyEvents: historyEvents,
extractedProfileID: 1,
schedulingConfig: schedulingConfig,
attemptCount: 1)

XCTAssertTrue(areDatesEqualIgnoringSeconds(date1: expectedOptOutDate, date2: proposedOptOutDate))
XCTAssertTrue(areDatesEqualIgnoringSeconds(date1: expectedOptOutDate, date2: actualOptOutDate))
}

func testOptOutStartedWithRecentDate_thenOptOutDateDoesNotChange() throws {
Expand Down Expand Up @@ -848,13 +848,13 @@ final class OperationPreferredDateCalculatorTests: XCTestCase {

let calculator = OperationPreferredDateCalculator()

let proposedOptOutDate = try calculator.dateForOptOutOperation(currentPreferredRunDate: nil,
historyEvents: historyEvents,
extractedProfileID: nil,
schedulingConfig: schedulingConfig,
attemptCount: 0)
let actualOptOutDate = try calculator.dateForOptOutOperation(currentPreferredRunDate: nil,
historyEvents: historyEvents,
extractedProfileID: nil,
schedulingConfig: schedulingConfig,
attemptCount: 0)

XCTAssertNil(proposedOptOutDate)
XCTAssertNil(actualOptOutDate)
}

func testOptOutRequestedWithRecentDate_thenOutOutIsNotScheduled() throws {
Expand All @@ -868,14 +868,14 @@ final class OperationPreferredDateCalculatorTests: XCTestCase {

let calculator = OperationPreferredDateCalculator()

let proposedOptOutDate = try calculator.dateForOptOutOperation(currentPreferredRunDate: nil,
historyEvents: historyEvents,
extractedProfileID: nil,
schedulingConfig: schedulingConfig,
attemptCount: 0,
date: MockDate())
let actualOptOutDate = try calculator.dateForOptOutOperation(currentPreferredRunDate: nil,
historyEvents: historyEvents,
extractedProfileID: nil,
schedulingConfig: schedulingConfig,
attemptCount: 0,
date: MockDate())

XCTAssertTrue(areDatesEqualIgnoringSeconds(date1: proposedOptOutDate, date2: expectedOptOutDate))
XCTAssertTrue(areDatesEqualIgnoringSeconds(date1: actualOptOutDate, date2: expectedOptOutDate))
}

func testScanStartedWithRecentDate_thenOptOutDateDoesNotChange() throws {
Expand Down

0 comments on commit a6fefee

Please sign in to comment.