2024-10-29 07:22:04 +01:00
|
|
|
package command_test
|
|
|
|
|
|
|
|
import (
|
|
|
|
"testing"
|
|
|
|
|
|
|
|
"go-mod.ewintr.nl/planner/item"
|
|
|
|
"go-mod.ewintr.nl/planner/plan/command"
|
|
|
|
"go-mod.ewintr.nl/planner/plan/storage/memory"
|
|
|
|
)
|
|
|
|
|
|
|
|
func TestList(t *testing.T) {
|
|
|
|
t.Parallel()
|
|
|
|
|
2024-12-24 08:00:23 +01:00
|
|
|
taskRepo := memory.NewTask()
|
2024-10-29 07:22:04 +01:00
|
|
|
localRepo := memory.NewLocalID()
|
2024-12-24 08:00:23 +01:00
|
|
|
e := item.Task{
|
2024-12-19 12:06:03 +01:00
|
|
|
ID: "id",
|
|
|
|
Date: item.NewDate(2024, 10, 7),
|
2024-12-24 08:00:23 +01:00
|
|
|
TaskBody: item.TaskBody{
|
2024-10-29 07:22:04 +01:00
|
|
|
Title: "name",
|
|
|
|
},
|
|
|
|
}
|
2024-12-24 08:00:23 +01:00
|
|
|
if err := taskRepo.Store(e); err != nil {
|
2024-10-29 07:22:04 +01:00
|
|
|
t.Errorf("exp nil, got %v", err)
|
|
|
|
}
|
|
|
|
if err := localRepo.Store(e.ID, 1); err != nil {
|
|
|
|
t.Errorf("exp nil, got %v", err)
|
|
|
|
}
|
|
|
|
|
|
|
|
for _, tc := range []struct {
|
|
|
|
name string
|
|
|
|
main []string
|
2024-12-29 09:32:49 +01:00
|
|
|
expRes bool
|
2024-10-29 07:22:04 +01:00
|
|
|
expErr bool
|
|
|
|
}{
|
|
|
|
{
|
2024-12-29 09:32:49 +01:00
|
|
|
name: "empty",
|
|
|
|
main: []string{},
|
|
|
|
expRes: true,
|
2024-10-29 07:22:04 +01:00
|
|
|
},
|
|
|
|
{
|
2024-12-29 09:32:49 +01:00
|
|
|
name: "list",
|
|
|
|
main: []string{"list"},
|
|
|
|
expRes: true,
|
|
|
|
},
|
|
|
|
{
|
|
|
|
name: "empty list",
|
|
|
|
main: []string{"list", "recur"},
|
2024-10-29 07:22:04 +01:00
|
|
|
},
|
|
|
|
{
|
|
|
|
name: "wrong",
|
|
|
|
main: []string{"delete"},
|
|
|
|
expErr: true,
|
|
|
|
},
|
|
|
|
} {
|
|
|
|
t.Run(tc.name, func(t *testing.T) {
|
2024-12-29 09:32:49 +01:00
|
|
|
// parse
|
2024-12-27 11:20:32 +01:00
|
|
|
cmd, actErr := command.NewListArgs().Parse(tc.main, nil)
|
|
|
|
if tc.expErr != (actErr != nil) {
|
2024-10-29 07:22:04 +01:00
|
|
|
t.Errorf("exp %v, got %v", tc.expErr, actErr)
|
|
|
|
}
|
2024-12-27 11:20:32 +01:00
|
|
|
if tc.expErr {
|
|
|
|
return
|
|
|
|
}
|
2024-12-29 09:32:49 +01:00
|
|
|
|
|
|
|
// do
|
|
|
|
res, err := cmd.Do(command.Dependencies{
|
2024-12-27 11:20:32 +01:00
|
|
|
TaskRepo: taskRepo,
|
|
|
|
LocalIDRepo: localRepo,
|
2024-12-29 09:32:49 +01:00
|
|
|
})
|
|
|
|
if err != nil {
|
2024-12-27 11:20:32 +01:00
|
|
|
t.Errorf("exp nil, got %v", err)
|
|
|
|
}
|
2024-12-29 09:32:49 +01:00
|
|
|
|
|
|
|
// check
|
|
|
|
listRes := res.(command.ListResult)
|
|
|
|
actRes := len(listRes.Tasks) > 0
|
|
|
|
if tc.expRes != actRes {
|
|
|
|
t.Errorf("exp %v, got %v", tc.expRes, actRes)
|
|
|
|
}
|
2024-10-29 07:22:04 +01:00
|
|
|
})
|
|
|
|
}
|
|
|
|
}
|