Something went wrong. Try again.
cli + tui to publish to leaflet (wip) & manage tasks, notes & watch/read lists 🍃
charm leaflet readability golang
Something went wrong. Try again.
12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097package main
import ( "context" "os" "path/filepath" "slices" "strings" "testing"
"github.com/stormlightlabs/noteleaf/internal/handlers" "github.com/stormlightlabs/noteleaf/internal/services" "github.com/stormlightlabs/noteleaf/internal/shared")
func setupCommandTest(t *testing.T) func() { tempDir, err := os.MkdirTemp("", "noteleaf-cmd-test-*") if err != nil { t.Fatalf("Failed to create temp dir: %v", err) }
oldNoteleafConfig := os.Getenv("NOTELEAF_CONFIG") oldNoteleafDataDir := os.Getenv("NOTELEAF_DATA_DIR") os.Setenv("NOTELEAF_CONFIG", filepath.Join(tempDir, ".noteleaf.conf.toml")) os.Setenv("NOTELEAF_DATA_DIR", tempDir)
cleanup := func() { os.Setenv("NOTELEAF_CONFIG", oldNoteleafConfig) os.Setenv("NOTELEAF_DATA_DIR", oldNoteleafDataDir) os.RemoveAll(tempDir) }
ctx := context.Background() err = handlers.Setup(ctx, []string{}) if err != nil { cleanup() t.Fatalf("Failed to setup database: %v", err) }
return cleanup}
func createTestTaskHandler(t *testing.T) (*handlers.TaskHandler, func()) { cleanup := setupCommandTest(t) handler, err := handlers.NewTaskHandler() if err != nil { cleanup() t.Fatalf("Failed to create test task handler: %v", err) } return handler, func() { handler.Close() cleanup() }}
func createTestMovieHandler(t *testing.T) (*handlers.MovieHandler, func()) { cleanup := setupCommandTest(t) handler, err := handlers.NewMovieHandler() if err != nil { cleanup() t.Fatalf("Failed to create test movie handler: %v", err) } return handler, func() { handler.Close() cleanup() }}
func createTestTVHandler(t *testing.T) (*handlers.TVHandler, func()) { cleanup := setupCommandTest(t) handler, err := handlers.NewTVHandler() if err != nil { cleanup() t.Fatalf("Failed to create test TV handler: %v", err) } return handler, func() { handler.Close() cleanup() }}
func createTestNoteHandler(t *testing.T) (*handlers.NoteHandler, func()) { cleanup := setupCommandTest(t) handler, err := handlers.NewNoteHandler() if err != nil { cleanup() t.Fatalf("Failed to create test note handler: %v", err) } return handler, func() { handler.Close() cleanup() }}
func createTestBookHandler(t *testing.T) (*handlers.BookHandler, func()) { cleanup := setupCommandTest(t) handler, err := handlers.NewBookHandler() if err != nil { cleanup() t.Fatalf("Failed to create test book handler: %v", err) } return handler, func() { handler.Close() cleanup() }}
func createTestArticleHandler(t *testing.T) (*handlers.ArticleHandler, func()) { cleanup := setupCommandTest(t) handler, err := handlers.NewArticleHandler() if err != nil { cleanup() t.Fatalf("Failed to create test article handler: %v", err) } return handler, func() { handler.Close() cleanup() }}
func createTestConfigHandler(t *testing.T) (*handlers.ConfigHandler, func()) { cleanup := setupCommandTest(t) handler, err := handlers.NewConfigHandler() if err != nil { cleanup() t.Fatalf("failed to create test config handler: %v", err) } return handler, cleanup}
func findSubcommand(commands []string, target string) bool { return slices.Contains(commands, target)}
func TestCommandGroup(t *testing.T) { t.Run("Interface Implementations", func(t *testing.T) { taskHandler, taskCleanup := createTestTaskHandler(t) defer taskCleanup()
movieHandler, movieCleanup := createTestMovieHandler(t) defer movieCleanup()
tvHandler, tvCleanup := createTestTVHandler(t) defer tvCleanup()
noteHandler, noteCleanup := createTestNoteHandler(t) defer noteCleanup()
bookHandler, bookCleanup := createTestBookHandler(t) defer bookCleanup()
articleHandler, articleCleanup := createTestArticleHandler(t) defer articleCleanup()
var _ CommandGroup = NewTaskCommand(taskHandler) var _ CommandGroup = NewMovieCommand(movieHandler) var _ CommandGroup = NewTVCommand(tvHandler) var _ CommandGroup = NewNoteCommand(noteHandler) var _ CommandGroup = NewBookCommand(bookHandler) var _ CommandGroup = NewArticleCommand(articleHandler) })
t.Run("Create", func(t *testing.T) { t.Run("TaskCommand", func(t *testing.T) { handler, cleanup := createTestTaskHandler(t) defer cleanup()
commands := NewTaskCommand(handler) cmd := commands.Create()
if cmd == nil { t.Fatal("Create returned nil") } if cmd.Use != "todo" { t.Errorf("Expected Use to be 'todo', got '%s'", cmd.Use) } if len(cmd.Aliases) != 1 || cmd.Aliases[0] != "task" { t.Errorf("Expected aliases to be ['task'], got %v", cmd.Aliases) } if cmd.Short != "task management" { t.Errorf("Expected Short to be 'task management', got '%s'", cmd.Short) } if !cmd.HasSubCommands() { t.Error("Expected command to have subcommands") } })
t.Run("MovieCommand", func(t *testing.T) { handler, cleanup := createTestMovieHandler(t) defer cleanup()
commands := NewMovieCommand(handler) cmd := commands.Create()
if cmd == nil { t.Fatal("Create returned nil") } if cmd.Use != "movie" { t.Errorf("Expected Use to be 'movie', got '%s'", cmd.Use) } if cmd.Short != "Manage movie watch queue" { t.Errorf("Expected Short to be 'Manage movie watch queue', got '%s'", cmd.Short) } if !cmd.HasSubCommands() { t.Error("Expected command to have subcommands") }
subcommands := cmd.Commands() subcommandNames := make([]string, len(subcommands)) for i, subcmd := range subcommands { subcommandNames[i] = subcmd.Use }
expectedSubcommands := []string{ "add [search query...]", "list [--all|--watched|--queued]", "watched [id]", "remove [id]", }
for _, expected := range expectedSubcommands { if !findSubcommand(subcommandNames, expected) { t.Errorf("Expected subcommand '%s' not found in %v", expected, subcommandNames) } } })
t.Run("TVCommand", func(t *testing.T) { handler, cleanup := createTestTVHandler(t) defer cleanup()
commands := NewTVCommand(handler) cmd := commands.Create()
if cmd == nil { t.Fatal("Create returned nil") } if cmd.Use != "tv" { t.Errorf("Expected Use to be 'tv', got '%s'", cmd.Use) } if cmd.Short != "Manage TV show watch queue" { t.Errorf("Expected Short to be 'Manage TV show watch queue', got '%s'", cmd.Short) } if !cmd.HasSubCommands() { t.Error("Expected command to have subcommands") }
subcommands := cmd.Commands() subcommandNames := make([]string, len(subcommands)) for i, subcmd := range subcommands { subcommandNames[i] = subcmd.Use }
expectedSubcommands := []string{ "add [search query...]", "list [--all|--queued|--watching|--watched]", "watching [id]", "watched [id]", "remove [id]", }
for _, expected := range expectedSubcommands { if !findSubcommand(subcommandNames, expected) { t.Errorf("Expected subcommand '%s' not found in %v", expected, subcommandNames) } } })
t.Run("NoteCommand", func(t *testing.T) { handler, cleanup := createTestNoteHandler(t) defer cleanup()
commands := NewNoteCommand(handler) cmd := commands.Create()
if cmd == nil { t.Fatal("Create returned nil") } if cmd.Use != "note" { t.Errorf("Expected Use to be 'note', got '%s'", cmd.Use) } if cmd.Short != "Manage notes" { t.Errorf("Expected Short to be 'Manage notes', got '%s'", cmd.Short) } if !cmd.HasSubCommands() { t.Error("Expected command to have subcommands") }
subcommands := cmd.Commands() subcommandNames := make([]string, len(subcommands)) for i, subcmd := range subcommands { subcommandNames[i] = subcmd.Use }
expectedSubcommands := []string{ "create [title] [content...]", "list [--archived] [--static] [--tags=tag1,tag2]", "read [note-id]", "edit [note-id]", "remove [note-id]", }
for _, expected := range expectedSubcommands { if !findSubcommand(subcommandNames, expected) { t.Errorf("Expected subcommand '%s' not found in %v", expected, subcommandNames) } } })
t.Run("BookCommand", func(t *testing.T) { handler, cleanup := createTestBookHandler(t) defer cleanup()
commands := NewBookCommand(handler) cmd := commands.Create()
if cmd == nil { t.Fatal("Create returned nil") } if cmd.Use != "book" { t.Errorf("Expected Use to be 'book', got '%s'", cmd.Use) } if cmd.Short != "Manage reading list" { t.Errorf("Expected Short to be 'Manage reading list', got '%s'", cmd.Short) } if !cmd.HasSubCommands() { t.Error("Expected command to have subcommands") }
subcommands := cmd.Commands() subcommandNames := make([]string, len(subcommands)) for i, subcmd := range subcommands { subcommandNames[i] = subcmd.Use }
expectedSubcommands := []string{ "add [search query...]", "list [--all|--reading|--finished|--queued]", "reading <id>", "finished <id>", "remove <id>", "progress <id> <percentage>", "update <id> <status>", }
for _, expected := range expectedSubcommands { if !findSubcommand(subcommandNames, expected) { t.Errorf("Expected subcommand '%s' not found in %v", expected, subcommandNames) } } })
t.Run("ArticleCommand", func(t *testing.T) { handler, cleanup := createTestArticleHandler(t) defer cleanup()
commands := NewArticleCommand(handler) cmd := commands.Create()
if cmd == nil { t.Fatal("Create returned nil") } if cmd.Use != "article" { t.Errorf("Expected Use to be 'article', got '%s'", cmd.Use) } if cmd.Short != "Manage saved articles" { t.Errorf("Expected Short to be 'Manage saved articles', got '%s'", cmd.Short) } if !cmd.HasSubCommands() { t.Error("Expected command to have subcommands") }
subcommands := cmd.Commands() subcommandNames := make([]string, len(subcommands)) for i, subcmd := range subcommands { subcommandNames[i] = subcmd.Use }
for _, expected := range []string{"add <url>", "list [query]", "view <id>", "remove <id>"} { if !findSubcommand(subcommandNames, expected) { t.Errorf("Expected subcommand '%s' not found in %v", expected, subcommandNames) } } })
t.Run("all command groups implement Create", func(t *testing.T) { taskHandler, taskCleanup := createTestTaskHandler(t) defer taskCleanup()
movieHandler, movieCleanup := createTestMovieHandler(t) defer movieCleanup()
tvHandler, tvCleanup := createTestTVHandler(t) defer tvCleanup()
noteHandler, noteCleanup := createTestNoteHandler(t) defer noteCleanup()
bookHandler, bookCleanup := createTestBookHandler(t) defer bookCleanup()
articleHandler, articleCleanup := createTestArticleHandler(t) defer articleCleanup()
groups := []CommandGroup{ NewTaskCommand(taskHandler), NewMovieCommand(movieHandler), NewTVCommand(tvHandler), NewNoteCommand(noteHandler), NewBookCommand(bookHandler), NewArticleCommand(articleHandler), }
for i, group := range groups { cmd := group.Create() if cmd == nil { t.Errorf("CommandGroup %d returned nil from Create()", i) continue } if cmd.Use == "" { t.Errorf("CommandGroup %d returned command with empty Use", i) } } }) })
}
func TestCommandExecution(t *testing.T) { t.Run("Movie Commands", func(t *testing.T) { handler, cleanup := createTestMovieHandler(t) defer cleanup()
t.Run("list command - default", func(t *testing.T) { cmd := NewMovieCommand(handler).Create() cmd.SetArgs([]string{"list"}) err := cmd.Execute() if err != nil { t.Errorf("movie list command failed: %v", err) } })
t.Run("add command with empty args", func(t *testing.T) { cmd := NewMovieCommand(handler).Create() cmd.SetArgs([]string{"add"}) err := cmd.Execute() if err == nil { t.Error("expected movie add command to fail with empty args") } })
t.Run("add command with valid args - successful search", func(t *testing.T) { cleanup := services.SetupSuccessfulMovieMocks(t) defer cleanup()
cmd := NewMovieCommand(handler).Create() cmd.SetArgs([]string{"add", "Fantastic Four"}) err := cmd.Execute()
// NOTE: The command will find results but fail due to no user input in test environment if err == nil { t.Error("expected movie add command to fail due to no user input in test environment") } if !strings.Contains(err.Error(), "invalid input") { t.Errorf("expected 'invalid input' error, got: %v", err) } })
t.Run("add command with valid args - search failure", func(t *testing.T) { cleanup := services.SetupFailureMocks(t, "search failed") defer cleanup()
cmd := NewMovieCommand(handler).Create() cmd.SetArgs([]string{"add", "some movie"}) err := cmd.Execute() if err == nil { t.Error("expected movie add command to fail when search fails") } shared.AssertErrorContains(t, err, "search failed", "") })
t.Run("remove command with non-existent movie ID", func(t *testing.T) { cmd := NewMovieCommand(handler).Create() cmd.SetArgs([]string{"remove", "999"}) err := cmd.Execute() if err == nil { t.Error("expected movie remove command to fail with non-existent ID") } })
t.Run("remove command with non-numeric ID", func(t *testing.T) { cmd := NewMovieCommand(handler).Create() cmd.SetArgs([]string{"remove", "invalid"}) err := cmd.Execute() if err == nil { t.Error("expected movie remove command to fail with non-numeric ID") } })
t.Run("watched command", func(t *testing.T) { handler, cleanup := createTestMovieHandler(t) defer cleanup()
cmd := NewMovieCommand(handler).Create() cmd.SetArgs([]string{"watched", "1"}) err := cmd.Execute() if err == nil { t.Error("expected movie watched command to fail with non-existent ID") } }) })
t.Run("TV Commands", func(t *testing.T) { handler, cleanup := createTestTVHandler(t) defer cleanup()
t.Run("list command - default", func(t *testing.T) { cmd := NewTVCommand(handler).Create() cmd.SetArgs([]string{"list"}) err := cmd.Execute() if err != nil { t.Errorf("tv list command failed: %v", err) } })
t.Run("add command with empty args", func(t *testing.T) { cmd := NewTVCommand(handler).Create() cmd.SetArgs([]string{"add"}) err := cmd.Execute() if err == nil { t.Error("expected tv add command to fail with empty args") } })
t.Run("add command with valid args - successful search", func(t *testing.T) { cleanup := services.SetupSuccessfulTVMocks(t) defer cleanup()
cmd := NewTVCommand(handler).Create() cmd.SetArgs([]string{"add", "Peacemaker"}) err := cmd.Execute()
// NOTE: The command will find results but fail due to no user input in test environment if err == nil { t.Error("expected tv add command to fail due to no user input in test environment") } if !strings.Contains(err.Error(), "invalid input") { t.Errorf("expected 'invalid input' error, got: %v", err) } })
t.Run("add command with valid args - search failure", func(t *testing.T) { cleanup := services.SetupFailureMocks(t, "tv search failed") defer cleanup()
cmd := NewTVCommand(handler).Create() cmd.SetArgs([]string{"add", "some show"}) err := cmd.Execute() if err == nil { t.Error("expected tv add command to fail when search fails") } shared.AssertErrorContains(t, err, "tv search failed", "") })
t.Run("remove command with non-existent TV show ID", func(t *testing.T) { cmd := NewTVCommand(handler).Create() cmd.SetArgs([]string{"remove", "999"}) err := cmd.Execute() if err == nil { t.Error("expected tv remove command to fail with non-existent ID") } })
t.Run("remove command with non-numeric ID", func(t *testing.T) { cmd := NewTVCommand(handler).Create() cmd.SetArgs([]string{"remove", "invalid"}) err := cmd.Execute() if err == nil { t.Error("expected tv remove command to fail with non-numeric ID") } })
t.Run("watching command", func(t *testing.T) { handler, cleanup := createTestTVHandler(t) defer cleanup()
cmd := NewTVCommand(handler).Create() cmd.SetArgs([]string{"watching", "1"}) err := cmd.Execute() if err == nil { t.Error("expected tv watching command to fail with non-existent ID") } })
t.Run("watched command", func(t *testing.T) { handler, cleanup := createTestTVHandler(t) defer cleanup()
cmd := NewTVCommand(handler).Create() cmd.SetArgs([]string{"watched", "1"}) err := cmd.Execute() if err == nil { t.Error("expected tv watched command to fail with non-existent ID") } }) })
t.Run("Book Commands", func(t *testing.T) { handler, cleanup := createTestBookHandler(t) defer cleanup()
t.Run("list command - default", func(t *testing.T) { cmd := NewBookCommand(handler).Create() cmd.SetArgs([]string{"list"}) err := cmd.Execute() if err != nil { t.Errorf("book list command failed: %v", err) } })
t.Run("remove command with non-existent book ID", func(t *testing.T) { cmd := NewBookCommand(handler).Create() cmd.SetArgs([]string{"remove", "999"}) err := cmd.Execute() if err == nil { t.Error("expected book remove command to fail with non-existent ID") } })
t.Run("remove command with non-numeric ID", func(t *testing.T) { cmd := NewBookCommand(handler).Create() cmd.SetArgs([]string{"remove", "invalid"}) err := cmd.Execute() if err == nil { t.Error("expected book remove command to fail with non-numeric ID") } })
t.Run("update command with removed status", func(t *testing.T) { cmd := NewBookCommand(handler).Create() cmd.SetArgs([]string{"update", "999", "removed"}) err := cmd.Execute() if err == nil { t.Error("expected book update command to fail with non-existent ID") } })
t.Run("update command with invalid status", func(t *testing.T) { cmd := NewBookCommand(handler).Create() cmd.SetArgs([]string{"update", "1", "invalid_status"}) err := cmd.Execute() if err == nil { t.Error("expected book update command to fail with invalid status") } })
t.Run("reading command", func(t *testing.T) { cmd := NewBookCommand(handler).Create() cmd.SetArgs([]string{"reading", "1"}) err := cmd.Execute() if err == nil { t.Error("expected book reading command to fail with non-existent ID") } })
t.Run("finished command", func(t *testing.T) { cmd := NewBookCommand(handler).Create() cmd.SetArgs([]string{"finished", "1"}) err := cmd.Execute() if err == nil { t.Error("expected book finished command to fail with non-existent ID") } })
t.Run("progress command", func(t *testing.T) { cmd := NewBookCommand(handler).Create() cmd.SetArgs([]string{"progress", "1", "50"}) err := cmd.Execute() if err == nil { t.Error("expected book progress command to fail with non-existent ID") } })
t.Run("progress command with invalid percentage", func(t *testing.T) { cmd := NewBookCommand(handler).Create() cmd.SetArgs([]string{"progress", "1", "invalid"}) err := cmd.Execute() if err == nil { t.Error("expected book progress command to fail with invalid percentage") } }) })
t.Run("Article Commands", func(t *testing.T) { handler, cleanup := createTestArticleHandler(t) defer cleanup()
t.Run("list command - default", func(t *testing.T) { cmd := NewArticleCommand(handler).Create() cmd.SetArgs([]string{"list"}) err := cmd.Execute() if err != nil { t.Errorf("article list command failed: %v", err) } })
t.Run("help command", func(t *testing.T) { cmd := NewArticleCommand(handler).Create() cmd.SetArgs([]string{"help"}) err := cmd.Execute() if err != nil { t.Errorf("article help command failed: %v", err) } })
t.Run("add command with empty args", func(t *testing.T) { cmd := NewArticleCommand(handler).Create() cmd.SetArgs([]string{"add"}) err := cmd.Execute() if err == nil { t.Error("expected article add command to fail with empty args") } })
t.Run("add command with invalid URL", func(t *testing.T) { cmd := NewArticleCommand(handler).Create() cmd.SetArgs([]string{"add", "not-a-url"}) err := cmd.Execute() if err == nil { t.Error("expected article add command to fail with invalid URL") } })
t.Run("view command with non-existent article ID", func(t *testing.T) { cmd := NewArticleCommand(handler).Create() cmd.SetArgs([]string{"view", "999"}) err := cmd.Execute() if err == nil { t.Error("expected article view command to fail with non-existent ID") } })
t.Run("view command with non-numeric ID", func(t *testing.T) { cmd := NewArticleCommand(handler).Create() cmd.SetArgs([]string{"view", "invalid"}) err := cmd.Execute() if err == nil { t.Error("expected article view command to fail with non-numeric ID") } })
t.Run("read command with non-existent article ID", func(t *testing.T) { cmd := NewArticleCommand(handler).Create() cmd.SetArgs([]string{"read", "999"}) err := cmd.Execute() if err == nil { t.Error("expected article read command to fail with non-existent ID") } })
t.Run("read command with non-numeric ID", func(t *testing.T) { cmd := NewArticleCommand(handler).Create() cmd.SetArgs([]string{"read", "invalid"}) err := cmd.Execute() if err == nil { t.Error("expected article read command to fail with non-numeric ID") } })
t.Run("remove command with non-existent article ID", func(t *testing.T) { cmd := NewArticleCommand(handler).Create() cmd.SetArgs([]string{"remove", "999"}) err := cmd.Execute() if err == nil { t.Error("expected article remove command to fail with non-existent ID") } })
t.Run("remove command with non-numeric ID", func(t *testing.T) { cmd := NewArticleCommand(handler).Create() cmd.SetArgs([]string{"remove", "invalid"}) err := cmd.Execute() if err == nil { t.Error("expected article remove command to fail with non-numeric ID") } }) })
t.Run("Note Commands", func(t *testing.T) { t.Run("create command - non-interactive", func(t *testing.T) { handler, cleanup := createTestNoteHandler(t) defer cleanup()
cmd := NewNoteCommand(handler).Create() cmd.SetArgs([]string{"create", "test title", "test content"}) err := cmd.Execute() if err != nil { t.Errorf("note create command failed: %v", err) } })
t.Run("list command - static mode", func(t *testing.T) { handler, cleanup := createTestNoteHandler(t) defer cleanup()
cmd := NewNoteCommand(handler).Create() cmd.SetArgs([]string{"list", "--static"}) err := cmd.Execute() if err != nil { t.Errorf("note list command failed: %v", err) } })
t.Run("read command with valid note ID", func(t *testing.T) { handler, cleanup := createTestNoteHandler(t) defer cleanup()
err := handler.CreateWithOptions(context.Background(), "test note", "test content", "", false, false) if err != nil { t.Fatalf("failed to create test note: %v", err) }
cmd := NewNoteCommand(handler).Create() cmd.SetArgs([]string{"read", "1"}) err = cmd.Execute() if err != nil { t.Errorf("note read command failed: %v", err) } })
t.Run("edit command with valid note ID", func(t *testing.T) { t.Skip("edit command requires interactive editor") })
t.Run("remove command with valid note ID", func(t *testing.T) { handler, cleanup := createTestNoteHandler(t) defer cleanup()
err := handler.CreateWithOptions(context.Background(), "test note", "test content", "", false, false) if err != nil { t.Fatalf("failed to create test note: %v", err) }
cmd := NewNoteCommand(handler).Create() cmd.SetArgs([]string{"remove", "1"}) err = cmd.Execute() if err != nil { t.Errorf("note remove command failed: %v", err) } })
t.Run("edit command with invalid ID", func(t *testing.T) { handler, cleanup := createTestNoteHandler(t) defer cleanup()
cmd := NewNoteCommand(handler).Create() cmd.SetArgs([]string{"edit", "invalid"}) err := cmd.Execute() if err == nil { t.Error("expected note edit command to fail with invalid ID") } })
t.Run("remove command with invalid ID", func(t *testing.T) { handler, cleanup := createTestNoteHandler(t) defer cleanup()
cmd := NewNoteCommand(handler).Create() cmd.SetArgs([]string{"remove", "invalid"}) err := cmd.Execute() if err == nil { t.Error("expected note remove command to fail with invalid ID") } })
t.Run("list command with static flag", func(t *testing.T) { handler, cleanup := createTestNoteHandler(t) defer cleanup()
cmd := NewNoteCommand(handler).Create() cmd.SetArgs([]string{"list", "--static", "test query"}) err := cmd.Execute() if err != nil { t.Errorf("note list command with query failed: %v", err) } }) })
t.Run("Task Commands", func(t *testing.T) { t.Run("list command - static", func(t *testing.T) { handler, cleanup := createTestTaskHandler(t) defer cleanup()
cmd := NewTaskCommand(handler).Create() cmd.SetArgs([]string{"list", "--static"}) err := cmd.Execute() if err != nil { t.Errorf("task list command failed: %v", err) } })
t.Run("add command with valid args", func(t *testing.T) { handler, cleanup := createTestTaskHandler(t) defer cleanup()
cmd := NewTaskCommand(handler).Create() cmd.SetArgs([]string{"add", "test task"}) err := cmd.Execute() if err != nil { t.Errorf("task add command failed: %v", err) } })
t.Run("projects command - static", func(t *testing.T) { handler, cleanup := createTestTaskHandler(t) defer cleanup()
cmd := NewTaskCommand(handler).Create() cmd.SetArgs([]string{"projects", "--static"}) err := cmd.Execute() if err != nil { t.Errorf("task projects command failed: %v", err) } })
t.Run("tags command - static", func(t *testing.T) { handler, cleanup := createTestTaskHandler(t) defer cleanup()
cmd := NewTaskCommand(handler).Create() cmd.SetArgs([]string{"tags", "--static"}) err := cmd.Execute() if err != nil { t.Errorf("task tags command failed: %v", err) } })
t.Run("contexts command - static", func(t *testing.T) { handler, cleanup := createTestTaskHandler(t) defer cleanup()
cmd := NewTaskCommand(handler).Create() cmd.SetArgs([]string{"contexts", "--static"}) err := cmd.Execute() if err != nil { t.Errorf("task contexts command failed: %v", err) } })
t.Run("timesheet command", func(t *testing.T) { handler, cleanup := createTestTaskHandler(t) defer cleanup()
cmd := NewTaskCommand(handler).Create() cmd.SetArgs([]string{"timesheet"}) err := cmd.Execute() if err != nil { t.Errorf("task timesheet command failed: %v", err) } })
t.Run("view command", func(t *testing.T) { handler, cleanup := createTestTaskHandler(t) defer cleanup()
cmd := NewTaskCommand(handler).Create() cmd.SetArgs([]string{"view", "1"}) err := cmd.Execute() if err == nil { t.Error("expected task view command to fail with non-existent ID") } })
t.Run("update command", func(t *testing.T) { handler, cleanup := createTestTaskHandler(t) defer cleanup()
cmd := NewTaskCommand(handler).Create() cmd.SetArgs([]string{"update", "1"}) err := cmd.Execute() if err == nil { t.Error("expected task update command to fail with non-existent ID") } })
t.Run("start command", func(t *testing.T) { handler, cleanup := createTestTaskHandler(t) defer cleanup()
cmd := NewTaskCommand(handler).Create() cmd.SetArgs([]string{"start", "1"}) err := cmd.Execute() if err == nil { t.Error("expected task start command to fail with non-existent ID") } })
t.Run("stop command", func(t *testing.T) { handler, cleanup := createTestTaskHandler(t) defer cleanup()
cmd := NewTaskCommand(handler).Create() cmd.SetArgs([]string{"stop", "1"}) err := cmd.Execute() if err == nil { t.Error("expected task stop command to fail with non-existent ID") } })
t.Run("edit command", func(t *testing.T) { handler, cleanup := createTestTaskHandler(t) defer cleanup()
cmd := NewTaskCommand(handler).Create() cmd.SetArgs([]string{"edit", "1"}) err := cmd.Execute() if err == nil { t.Error("expected task edit command to fail with non-existent ID") } })
t.Run("delete command", func(t *testing.T) { handler, cleanup := createTestTaskHandler(t) defer cleanup()
cmd := NewTaskCommand(handler).Create() cmd.SetArgs([]string{"delete", "1"}) err := cmd.Execute() if err == nil { t.Error("expected task delete command to fail with non-existent ID") } })
t.Run("done command", func(t *testing.T) { handler, cleanup := createTestTaskHandler(t) defer cleanup()
cmd := NewTaskCommand(handler).Create() cmd.SetArgs([]string{"done", "1"}) err := cmd.Execute() if err == nil { t.Error("expected task done command to fail with non-existent ID") } }) })
t.Run("Config Command", func(t *testing.T) { handler, cleanup := createTestConfigHandler(t) defer cleanup()
cmd := NewConfigCommand(handler).Create()
if cmd.Use != "config" { t.Errorf("expected Use 'config', got %s", cmd.Use) } if cmd.Short == "" { t.Errorf("expected Short description to be set") } if len(cmd.Commands()) == 0 { t.Errorf("expected subcommands to be registered") }
t.Run("path command", func(t *testing.T) { cmd.SetArgs([]string{"path"}) if err := cmd.Execute(); err != nil { t.Errorf("config path failed: %v", err) } })
t.Run("get with no args", func(t *testing.T) { cmd.SetArgs([]string{"get"}) if err := cmd.Execute(); err != nil { t.Errorf("config get with no args failed: %v", err) } })
t.Run("set and get roundtrip", func(t *testing.T) { cmd.SetArgs([]string{"set", "editor", "vim"}) if err := cmd.Execute(); err != nil { t.Fatalf("config set failed: %v", err) }
cmd.SetArgs([]string{"get", "editor"}) if err := cmd.Execute(); err != nil { t.Errorf("config get after set failed: %v", err) } })
t.Run("reset command", func(t *testing.T) { cmd.SetArgs([]string{"reset"}) if err := cmd.Execute(); err != nil { t.Errorf("config reset failed: %v", err) } }) })}