MCPcopy Create free account
hub / github.com/Facets-cloud/flow / TestCmdEditTaskBumpsUpdatedAt

Function TestCmdEditTaskBumpsUpdatedAt

internal/app/edit_test.go:30–78  ·  view source on GitHub ↗
(t *testing.T)

Source from the content-addressed store, hash-verified

28}
29
30func TestCmdEditTaskBumpsUpdatedAt(t *testing.T) {
31 root, db := showListEditDB(t)
32 insertTask(t, db, "authfix", "Auth", "backlog", "high", filepath.Join(root, "x"), nil)
33 // Back-date so we can verify the bump is forward.
34 if _, err := db.Exec(`UPDATE tasks SET updated_at = '2020-01-01T00:00:00Z' WHERE slug = ?`, "authfix"); err != nil {
35 t.Fatal(err)
36 }
37
38 // Pre-create brief so the fake editor has something to append to.
39 briefPath := filepath.Join(root, "tasks", "authfix", "brief.md")
40 if err := os.MkdirAll(filepath.Dir(briefPath), 0o755); err != nil {
41 t.Fatal(err)
42 }
43 if err := os.WriteFile(briefPath, []byte("original\n"), 0o644); err != nil {
44 t.Fatal(err)
45 }
46
47 script := writeFakeEditor(t, t.TempDir())
48 oldEditor := os.Getenv("EDITOR")
49 os.Setenv("EDITOR", script)
50 t.Cleanup(func() { os.Setenv("EDITOR", oldEditor) })
51
52 out := captureStdout(t, func() {
53 if rc := cmdEdit([]string{"authfix"}); rc != 0 {
54 t.Errorf("rc=%d", rc)
55 }
56 })
57 if !strings.Contains(out, "Edited task authfix") {
58 t.Errorf("missing confirmation; out=%q", out)
59 }
60
61 // Verify the fake editor ran (file mutated).
62 data, err := os.ReadFile(briefPath)
63 if err != nil {
64 t.Fatalf("read brief: %v", err)
65 }
66 if !strings.Contains(string(data), "edited by test") {
67 t.Errorf("brief not edited: %q", string(data))
68 }
69
70 // Verify updated_at moved.
71 task, err := flowdb.GetTask(db, "authfix")
72 if err != nil {
73 t.Fatal(err)
74 }
75 if task.UpdatedAt == "2020-01-01T00:00:00Z" {
76 t.Errorf("updated_at not bumped: %q", task.UpdatedAt)
77 }
78}
79
80func TestCmdEditProjectBumpsUpdatedAt(t *testing.T) {
81 root, db := showListEditDB(t)

Callers

nothing calls this directly

Calls 6

GetTaskFunction · 0.92
showListEditDBFunction · 0.85
writeFakeEditorFunction · 0.85
captureStdoutFunction · 0.85
cmdEditFunction · 0.85
insertTaskFunction · 0.70

Tested by

no test coverage detected