Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,9 @@ extension MainContentCoordinator {
if #available(macOS 14.0, *) {
FeatureTipSignals.editorQueryRan()
}
if request.wasSuccessful {
MacAnalyticsProvider.shared.markFirstQueryExecuted()
}
}
let recorder = services.queryHistoryManager
return Task(priority: .utility) {
Expand Down
41 changes: 41 additions & 0 deletions apple/TableProTests/Views/Main/FirstQueryAnalyticsTests.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
import Foundation
import Testing

@testable import TablePro

/// The heartbeat's first-query timestamp lost its only caller when `DatabaseManager.execute(query:)`
/// was removed, so it stayed nil on every Mac. Recording an editor run's history is where it is set now.
@MainActor
struct FirstQueryAnalyticsTests {
private func request(_ source: QueryHistorySource, succeeded: Bool, connectionId: UUID) -> QueryHistoryRecordRequest {
QueryHistoryRecordRequest(
query: "SELECT 1",
connectionId: connectionId,
databaseName: "db",
databaseType: .postgresql,
source: source,
executionTime: 0.01,
rowCount: 1,
wasSuccessful: succeeded,
errorMessage: succeeded ? nil : "syntax error"
)
}

// The mark is written before recordHistory returns its task, so every assertion runs before the
// first suspension and no other suite can touch the shared defaults in between.
@Test("Only a successful editor query records the first-query timestamp")
func successfulEditorQueryMarksFirstQuery() async {
AppStorageEnvironment.shared.defaults.removeObject(forKey: MacAnalyticsProvider.Keys.firstQueryExecutedAt)
let fixture = CoordinatorFixture()
let connectionId = fixture.connection.id

let failed = fixture.coordinator.recordHistory(request(.editor, succeeded: false, connectionId: connectionId))
let browsed = fixture.coordinator.recordHistory(request(.tableBrowse, succeeded: true, connectionId: connectionId))
#expect(MacAnalyticsProvider.shared.firstQueryExecutedAt == nil)

let ran = fixture.coordinator.recordHistory(request(.editor, succeeded: true, connectionId: connectionId))
#expect(MacAnalyticsProvider.shared.firstQueryExecutedAt != nil)

_ = await (failed.value, browsed.value, ran.value)
}
}
Loading