gte/internal/process/update_test.go

58 lines
1.3 KiB
Go
Raw Normal View History

2021-07-10 12:30:38 +02:00
package process_test
import (
"testing"
"git.ewintr.nl/go-kit/test"
"git.ewintr.nl/gte/internal/process"
"git.ewintr.nl/gte/internal/storage"
"git.ewintr.nl/gte/internal/task"
)
func TestUpdate(t *testing.T) {
2021-07-29 07:01:24 +02:00
for _, tc := range []struct {
name string
2021-08-22 13:29:04 +02:00
updates *task.LocalUpdate
2021-07-29 07:01:24 +02:00
}{
{
name: "done",
2021-08-22 13:29:04 +02:00
updates: &task.LocalUpdate{
ForVersion: 2,
Fields: []string{task.FIELD_DONE},
Done: true,
2021-07-29 07:01:24 +02:00
},
},
{
name: "fields",
2021-08-22 13:29:04 +02:00
updates: &task.LocalUpdate{
ForVersion: 2,
Fields: []string{task.FIELD_ACTION, task.FIELD_PROJECT, task.FIELD_DUE},
Project: "project2",
Action: "action2",
Due: task.NewDate(2021, 8, 1),
2021-07-29 07:01:24 +02:00
},
},
} {
t.Run(tc.name, func(t *testing.T) {
2021-09-03 10:02:08 +02:00
task1 := &task.Task{
Id: "id-1",
Version: 2,
Project: "project1",
Action: "action1",
Due: task.NewDate(2021, 7, 29),
Folder: task.FOLDER_PLANNED,
}
local := storage.NewMemory()
allTasks := []*task.Task{task1}
2021-07-10 12:30:38 +02:00
2021-09-03 10:02:08 +02:00
test.OK(t, local.SetTasks(allTasks))
update := process.NewUpdate(local, task1.Id, tc.updates)
2021-07-29 07:01:24 +02:00
test.OK(t, update.Process())
2021-09-03 10:02:08 +02:00
lt, err := local.FindById(task1.Id)
test.OK(t, err)
test.Equals(t, task.STATUS_UPDATED, lt.LocalStatus)
test.Equals(t, tc.updates, lt.LocalUpdate)
2021-07-29 07:01:24 +02:00
})
}
2021-07-10 12:30:38 +02:00
}