Skip to content

Commit

Permalink
PIR: Improve sorting logic and related test (#3049)
Browse files Browse the repository at this point in the history
Task/Issue URL: https://app.asana.com/0/1206488453854252/1207903506922077/f

**Description**: Improve sorting logic, which was not fully deterministic, and also
improve related test
  • Loading branch information
aataraxiaa authored Jul 31, 2024
1 parent 00df0d5 commit 116efba
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 7 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -373,7 +373,14 @@ private extension Array where Element == [BrokerProfileQueryData] {
/// - Returns: An array of `[BrokerProfileQueryData]` values sorted by the first `lastRunDate` of each element
func sortedByLastRunDate() -> Self {
self.sorted { lhs, rhs in
lhs.first?.scanJobData.lastRunDate < rhs.first?.scanJobData.lastRunDate
let lhsDate = lhs.first?.scanJobData.lastRunDate
let rhsDate = rhs.first?.scanJobData.lastRunDate

if lhsDate == rhsDate {
return lhs.first?.dataBroker.name ?? "" < rhs.first?.dataBroker.name ?? ""
} else {
return lhsDate < rhsDate
}
}
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -362,26 +362,28 @@ final class MapperToUITests: XCTestCase {
func testBrokersWithMixedScanProgress_areOrderedByLastRunDate_andHaveCorrectStatus() {

// Given
let minusTwoHours = Date.minusTwoHours
let minusThreeHours = Date.minusThreeHours
let brokerProfileQueryData: [BrokerProfileQueryData] = [
.mock(dataBrokerName: "Broker #1", lastRunDate: Date()),
.mock(dataBrokerName: "Broker #1", lastRunDate: Date()),
.mock(dataBrokerName: "Broker #1", lastRunDate: .minusTwoHours),
.mock(dataBrokerName: "Broker #1", lastRunDate: minusTwoHours),
.mock(dataBrokerName: "Broker #2"),
.mock(dataBrokerName: "Broker #2", lastRunDate: .minusOneHour),
.mock(dataBrokerName: "Broker #2", lastRunDate: .minusThreeHours),
.mock(dataBrokerName: "Broker #3", lastRunDate: .minusTwoHours),
.mock(dataBrokerName: "Broker #2", lastRunDate: minusThreeHours),
.mock(dataBrokerName: "Broker #3", lastRunDate: minusTwoHours),
.mock(dataBrokerName: "Broker #3"),
.mock(dataBrokerName: "Broker #3", lastRunDate: Date()),
.mock(dataBrokerName: "Broker #4"),
.mock(dataBrokerName: "Broker #5"),
.mock(dataBrokerName: "Broker #7", lastRunDate: .minusThreeHours),
.mock(dataBrokerName: "Broker #6", lastRunDate: .minusThreeHours)
.mock(dataBrokerName: "Broker #7", lastRunDate: minusThreeHours),
.mock(dataBrokerName: "Broker #6", lastRunDate: minusThreeHours)
]

let expected: [DBPUIScanProgress.ScannedBroker] = [
.mock("Broker #2", status: .inProgress),
.mock("Broker #7", status: .completed),
.mock("Broker #6", status: .completed),
.mock("Broker #7", status: .completed),
.mock("Broker #1", status: .completed),
.mock("Broker #3", status: .inProgress)
]
Expand Down

0 comments on commit 116efba

Please sign in to comment.