gte/internal/process/update_test.go

82 lines
1.8 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"
"git.ewintr.nl/gte/pkg/msend"
)
func TestUpdate(t *testing.T) {
task1 := &task.Task{
Id: "id-1",
2021-08-22 13:29:04 +02:00
Version: 2,
2021-07-10 12:30:38 +02:00
Project: "project1",
Action: "action1",
2021-07-29 07:01:24 +02:00
Due: task.NewDate(2021, 7, 29),
2021-07-10 12:30:38 +02:00
Folder: task.FOLDER_PLANNED,
}
local := storage.NewMemory()
allTasks := []*task.Task{task1}
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
exp *task.Task
}{
{
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
},
exp: &task.Task{
Id: "id-1",
2021-08-22 13:29:04 +02:00
Version: 2,
2021-07-29 07:01:24 +02:00
Project: "project1",
Action: "action1",
Due: task.NewDate(2021, 7, 29),
Folder: task.FOLDER_PLANNED,
Done: true,
},
},
{
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
},
exp: &task.Task{
Id: "id-1",
2021-08-22 13:29:04 +02:00
Version: 2,
2021-07-29 07:01:24 +02:00
Project: "project2",
Action: "action2",
Due: task.NewDate(2021, 8, 1),
Folder: task.FOLDER_PLANNED,
},
},
} {
t.Run(tc.name, func(t *testing.T) {
2021-09-03 09:19:36 +02:00
test.OK(t, local.SetTasks(allTasks))
2021-07-29 07:01:24 +02:00
out := msend.NewMemory()
disp := storage.NewDispatcher(out)
2021-07-10 12:30:38 +02:00
2021-07-29 07:01:24 +02:00
update := process.NewUpdate(local, disp, task1.Id, tc.updates)
test.OK(t, update.Process())
expMsg := &msend.Message{
Subject: tc.exp.FormatSubject(),
Body: tc.exp.FormatBody(),
}
test.Assert(t, len(out.Messages) == 1, "amount of messages was not one")
test.Equals(t, expMsg, out.Messages[0])
})
}
2021-07-10 12:30:38 +02:00
}