MCPcopy Create free account
hub / github.com/basecamp/hey-cli / TestTimetracking

Function TestTimetracking

tests/smoke/timetrack_test.go:9–58  ·  view source on GitHub ↗
(t *testing.T)

Source from the content-addressed store, hash-verified

7 "path/filepath"
8 "strings"
9 "testing"
10 "time"
11)
12
13func TestTimetracking(t *testing.T) {
14 // Stop any existing time track to start clean.
15 hey(t, "timetrack", "stop")
16
17 // --- Start ---
18 startOut, startErr, startCode := hey(t, "timetrack", "start", "--json")
19 if startCode != 0 {
20 t.Fatalf("timetrack start failed (exit %d): %s", startCode, startErr)
21 }
22 var startResp Response
23 if err := json.Unmarshal([]byte(startOut), &startResp); err != nil {
24 t.Fatalf("failed to parse start response: %v", err)
25 }
26 assertContains(t, startResp.Summary, "Time tracking started")
27
28 // --- Current (should be active) ---
29 resp := heyJSON(t, "timetrack", "current")
30 currentData := dataAs[map[string]any](t, resp)
31 if currentData == nil {
32 t.Fatal("expected active time track from current, got nil")
33 }
34 if _, ok := currentData["id"]; !ok {
35 t.Error("expected current time track to have an id")
36 }
37
38 // Cross-verify: the calendar page should show the active time track.
39 html := fetchHTML(t, baseURL+"/calendar")
40 if len(html) == 0 {
41 t.Error("calendar page returned empty HTML during active time track")
42 }
43
44 // --- Stop ---
45 // Wait so ends_at > starts_at (sub-second precision can cause validation failure).
46 time.Sleep(1 * time.Second)
47 stopOut, stopErr, stopCode := hey(t, "timetrack", "stop", "--json")
48 if stopCode != 0 {
49 t.Fatalf("timetrack stop failed (exit %d): %s", stopCode, stopErr)
50 }
51 var stopResp Response
52 if err := json.Unmarshal([]byte(stopOut), &stopResp); err != nil {
53 t.Fatalf("failed to parse stop response: %v", err)
54 }
55 assertContains(t, stopResp.Summary, "Time tracking stopped")
56
57 // --- Current (should be inactive) ---
58 resp = heyJSON(t, "timetrack", "current")
59 if resp.Data != nil && string(resp.Data) != "null" {
60 t.Log("Warning: current still returns data after stop (may be expected)")
61 }

Callers

nothing calls this directly

Calls 6

heyFunction · 0.85
assertContainsFunction · 0.85
heyJSONFunction · 0.85
dataAsFunction · 0.85
fetchHTMLFunction · 0.85
ErrorMethod · 0.45

Tested by

no test coverage detected