import XCTest
@testable import HealthProbe

final class LocalOperationLogTests: XCTestCase {
    override func tearDown() {
        LocalOperationLogStore.removeAll()
        super.tearDown()
    }

    func testAppendsLogsNewestFirst() {
        var older = LocalOperationLog(
            operationType: "delete",
            summary: "Older",
            deviceID: "device-a",
            appBuildVersion: "1"
        )
        older.timestamp = Date(timeIntervalSince1970: 1)

        var newer = LocalOperationLog(
            operationType: "delete",
            summary: "Newer",
            deviceID: "device-a",
            appBuildVersion: "1"
        )
        newer.timestamp = Date(timeIntervalSince1970: 2)
        newer.affectedSnapshotIDs = ["snapshot-a"]

        LocalOperationLogStore.append(older)
        LocalOperationLogStore.append(newer)

        let logs = LocalOperationLogStore.allLogs()
        XCTAssertEqual(logs.map(\.summary), ["Newer", "Older"])
        XCTAssertEqual(logs.first?.affectedSnapshotIDs, ["snapshot-a"])
    }
}
