2021-07-09 09:42:44 +02:00
|
|
|
package process_test
|
|
|
|
|
|
|
|
import (
|
|
|
|
"errors"
|
2021-08-25 06:52:48 +02:00
|
|
|
"sort"
|
2021-07-09 09:42:44 +02:00
|
|
|
"testing"
|
|
|
|
|
2024-09-17 07:33:26 +02:00
|
|
|
"go-mod.ewintr.nl/go-kit/test"
|
|
|
|
"go-mod.ewintr.nl/gte/internal/process"
|
|
|
|
"go-mod.ewintr.nl/gte/internal/storage"
|
|
|
|
"go-mod.ewintr.nl/gte/internal/task"
|
2021-07-09 09:42:44 +02:00
|
|
|
)
|
|
|
|
|
|
|
|
func TestListProcess(t *testing.T) {
|
|
|
|
date1 := task.NewDate(2021, 7, 9)
|
|
|
|
date2 := task.NewDate(2021, 7, 10)
|
|
|
|
date3 := task.NewDate(2021, 7, 11)
|
|
|
|
|
|
|
|
task1 := &task.Task{
|
|
|
|
Id: "id1",
|
|
|
|
Version: 1,
|
|
|
|
Action: "action1",
|
|
|
|
Folder: task.FOLDER_NEW,
|
2021-08-09 06:46:13 +02:00
|
|
|
Project: "project1",
|
2021-07-09 09:42:44 +02:00
|
|
|
}
|
|
|
|
task2 := &task.Task{
|
|
|
|
Id: "id2",
|
|
|
|
Version: 1,
|
|
|
|
Action: "action2",
|
|
|
|
Due: date1,
|
|
|
|
Folder: task.FOLDER_PLANNED,
|
2021-08-09 06:46:13 +02:00
|
|
|
Project: "project2",
|
2021-07-09 09:42:44 +02:00
|
|
|
}
|
|
|
|
task3 := &task.Task{
|
|
|
|
Id: "id3",
|
|
|
|
Version: 1,
|
|
|
|
Action: "action3",
|
|
|
|
Due: date2,
|
|
|
|
Folder: task.FOLDER_PLANNED,
|
2021-08-09 06:46:13 +02:00
|
|
|
Project: "project1",
|
2021-07-09 09:42:44 +02:00
|
|
|
}
|
|
|
|
task4 := &task.Task{
|
|
|
|
Id: "id4",
|
|
|
|
Version: 1,
|
|
|
|
Action: "action4",
|
|
|
|
Due: date3,
|
|
|
|
Folder: task.FOLDER_PLANNED,
|
2021-08-09 06:46:13 +02:00
|
|
|
Project: "project2",
|
2021-07-09 09:42:44 +02:00
|
|
|
}
|
|
|
|
allTasks := []*task.Task{task1, task2, task3, task4}
|
2021-09-01 06:52:21 +02:00
|
|
|
localTask2 := &task.LocalTask{Task: *task2, LocalUpdate: &task.LocalUpdate{}, LocalStatus: task.STATUS_FETCHED}
|
|
|
|
localTask3 := &task.LocalTask{Task: *task3, LocalUpdate: &task.LocalUpdate{}, LocalStatus: task.STATUS_FETCHED}
|
|
|
|
localTask4 := &task.LocalTask{Task: *task4, LocalUpdate: &task.LocalUpdate{}, LocalStatus: task.STATUS_FETCHED}
|
2021-07-09 09:42:44 +02:00
|
|
|
local := storage.NewMemory()
|
|
|
|
test.OK(t, local.SetTasks(allTasks))
|
|
|
|
|
|
|
|
t.Run("invalid reqs", func(t *testing.T) {
|
|
|
|
list := process.NewList(local, process.ListReqs{})
|
|
|
|
_, actErr := list.Process()
|
|
|
|
test.Assert(t, errors.Is(actErr, process.ErrInvalidReqs), "expected invalid reqs err")
|
|
|
|
})
|
|
|
|
|
|
|
|
for _, tc := range []struct {
|
|
|
|
name string
|
|
|
|
reqs process.ListReqs
|
2021-08-20 09:06:35 +02:00
|
|
|
exp []*task.LocalTask
|
2021-07-09 09:42:44 +02:00
|
|
|
}{
|
|
|
|
{
|
|
|
|
name: "due",
|
|
|
|
reqs: process.ListReqs{
|
|
|
|
Due: date2,
|
|
|
|
},
|
2021-08-20 09:06:35 +02:00
|
|
|
exp: []*task.LocalTask{localTask3},
|
2021-07-09 09:42:44 +02:00
|
|
|
},
|
|
|
|
{
|
|
|
|
name: "due and before",
|
|
|
|
reqs: process.ListReqs{
|
|
|
|
Due: date2,
|
|
|
|
IncludeBefore: true,
|
|
|
|
},
|
2021-08-20 09:06:35 +02:00
|
|
|
exp: []*task.LocalTask{localTask2, localTask3},
|
2021-07-09 09:42:44 +02:00
|
|
|
},
|
2021-08-09 06:46:13 +02:00
|
|
|
{
|
|
|
|
name: "folder",
|
|
|
|
reqs: process.ListReqs{
|
|
|
|
Folder: task.FOLDER_PLANNED,
|
|
|
|
},
|
2021-08-20 09:06:35 +02:00
|
|
|
exp: []*task.LocalTask{localTask2, localTask3, localTask4},
|
2021-08-09 06:46:13 +02:00
|
|
|
},
|
|
|
|
{
|
|
|
|
name: "project",
|
|
|
|
reqs: process.ListReqs{
|
|
|
|
Project: "project2",
|
|
|
|
},
|
2021-08-20 09:06:35 +02:00
|
|
|
exp: []*task.LocalTask{localTask2, localTask4},
|
2021-08-09 06:46:13 +02:00
|
|
|
},
|
2021-07-09 09:42:44 +02:00
|
|
|
} {
|
|
|
|
t.Run(tc.name, func(t *testing.T) {
|
|
|
|
list := process.NewList(local, tc.reqs)
|
2021-08-25 06:52:48 +02:00
|
|
|
actRes, err := list.Process()
|
2021-07-09 09:42:44 +02:00
|
|
|
test.OK(t, err)
|
2021-08-25 06:52:48 +02:00
|
|
|
act := actRes.Tasks
|
|
|
|
for _, a := range act {
|
|
|
|
a.LocalId = 0
|
|
|
|
}
|
|
|
|
sAct := task.ById(act)
|
|
|
|
sExp := task.ById(tc.exp)
|
|
|
|
sort.Sort(sAct)
|
|
|
|
sort.Sort(sExp)
|
|
|
|
|
|
|
|
test.Equals(t, sExp, sAct)
|
2021-07-09 09:42:44 +02:00
|
|
|
})
|
|
|
|
}
|
2021-09-06 07:24:29 +02:00
|
|
|
|
|
|
|
t.Run("applyupdates", func(t *testing.T) {
|
|
|
|
mem := storage.NewMemory()
|
2021-09-07 06:50:30 +02:00
|
|
|
test.OK(t, mem.SetTasks([]*task.Task{task2, task3, task4}))
|
|
|
|
lu3 := &task.LocalUpdate{
|
|
|
|
ForVersion: task3.Version,
|
|
|
|
Fields: []string{task.FIELD_PROJECT, task.FIELD_DONE},
|
|
|
|
Project: "project4",
|
|
|
|
Done: true,
|
|
|
|
}
|
|
|
|
test.OK(t, mem.SetLocalUpdate(task3.Id, lu3))
|
|
|
|
lu4 := &task.LocalUpdate{
|
2021-09-06 07:24:29 +02:00
|
|
|
ForVersion: task4.Version,
|
|
|
|
Fields: []string{task.FIELD_PROJECT},
|
|
|
|
Project: "project4",
|
|
|
|
}
|
2021-09-07 06:50:30 +02:00
|
|
|
test.OK(t, mem.SetLocalUpdate(task4.Id, lu4))
|
2021-09-06 07:24:29 +02:00
|
|
|
|
|
|
|
lr := process.ListReqs{
|
|
|
|
Project: "project4",
|
|
|
|
ApplyUpdates: true,
|
|
|
|
}
|
|
|
|
|
|
|
|
list := process.NewList(mem, lr)
|
|
|
|
actRes, err := list.Process()
|
|
|
|
test.OK(t, err)
|
|
|
|
act := actRes.Tasks
|
|
|
|
test.Equals(t, 1, len(act))
|
|
|
|
test.Equals(t, "project4", act[0].Project)
|
|
|
|
})
|
2021-07-09 09:42:44 +02:00
|
|
|
}
|