package store import ( "errors" "testing" ) func TestSetTaskLabels_UpdatesLabels(t *testing.T) { s := newNativeTasksTestStore(t) if err := s.SetTaskLabels("real-1", []string{"chore", "urgent"}); err != nil { t.Fatalf("SetTaskLabels: %v", err) } task, err := s.GetNativeTaskByID("real-1") if err != nil { t.Fatal(err) } if len(task.Labels) != 2 || task.Labels[0] != "chore" || task.Labels[1] != "urgent" { t.Errorf("Labels = %v, want [chore urgent]", task.Labels) } } func TestSetTaskLabels_EmptyList_ClearsLabels(t *testing.T) { s := newNativeTasksTestStore(t) if err := s.SetTaskLabels("real-1", []string{"chore"}); err != nil { t.Fatal(err) } if err := s.SetTaskLabels("real-1", []string{}); err != nil { t.Fatalf("SetTaskLabels (clear): %v", err) } task, err := s.GetNativeTaskByID("real-1") if err != nil { t.Fatal(err) } if len(task.Labels) != 0 { t.Errorf("Labels = %v, want empty", task.Labels) } } func TestSetTaskLabels_UnknownID_ReturnsErrNotFound(t *testing.T) { s := newNativeTasksTestStore(t) err := s.SetTaskLabels("does-not-exist", []string{"chore"}) if !errors.Is(err, ErrNativeTaskNotFound) { t.Fatalf("expected ErrNativeTaskNotFound, got %v", err) } } func TestSetLabelColor_ThenGetLabelColors_ReturnsIt(t *testing.T) { s := newNativeTasksTestStore(t) if err := s.SetLabelColor("chore", "#F59E0B"); err != nil { t.Fatalf("SetLabelColor: %v", err) } colors, err := s.GetLabelColors() if err != nil { t.Fatalf("GetLabelColors: %v", err) } if len(colors) != 1 || colors[0].Name != "chore" || colors[0].Color != "#F59E0B" { t.Fatalf("colors = %+v, want [{chore #F59E0B}]", colors) } } func TestSetLabelColor_SameName_Overwrites(t *testing.T) { s := newNativeTasksTestStore(t) if err := s.SetLabelColor("chore", "#F59E0B"); err != nil { t.Fatal(err) } if err := s.SetLabelColor("chore", "#EF4444"); err != nil { t.Fatalf("SetLabelColor (overwrite): %v", err) } colors, err := s.GetLabelColors() if err != nil { t.Fatal(err) } if len(colors) != 1 || colors[0].Color != "#EF4444" { t.Fatalf("colors = %+v, want a single entry with the overwritten color", colors) } }