2021-06-25 09:14:27 +02:00
|
|
|
package process_test
|
|
|
|
|
|
|
|
import (
|
2021-08-25 06:52:48 +02:00
|
|
|
"sort"
|
2021-06-25 09:14:27 +02:00
|
|
|
"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/mstore"
|
|
|
|
)
|
|
|
|
|
2021-09-03 07:12:16 +02:00
|
|
|
func TestFetchProcess(t *testing.T) {
|
2021-06-25 09:14:27 +02:00
|
|
|
task1 := &task.Task{
|
|
|
|
Id: "id1",
|
|
|
|
Version: 1,
|
|
|
|
Action: "action1",
|
|
|
|
Folder: task.FOLDER_NEW,
|
|
|
|
}
|
|
|
|
task2 := &task.Task{
|
|
|
|
Id: "id2",
|
|
|
|
Version: 1,
|
|
|
|
Action: "action2",
|
|
|
|
Folder: task.FOLDER_UNPLANNED,
|
|
|
|
}
|
|
|
|
|
2021-09-01 06:52:21 +02:00
|
|
|
localTask1 := &task.LocalTask{Task: *task1, LocalUpdate: &task.LocalUpdate{}, LocalStatus: task.STATUS_FETCHED}
|
|
|
|
localTask2 := &task.LocalTask{Task: *task2, LocalUpdate: &task.LocalUpdate{}, LocalStatus: task.STATUS_FETCHED}
|
2021-08-20 09:06:35 +02:00
|
|
|
|
2021-06-25 09:14:27 +02:00
|
|
|
mstorer, err := mstore.NewMemory(task.KnownFolders)
|
|
|
|
test.OK(t, err)
|
|
|
|
test.OK(t, mstorer.Add(task1.Folder, task1.FormatSubject(), task1.FormatBody()))
|
|
|
|
test.OK(t, mstorer.Add(task2.Folder, task2.FormatSubject(), task2.FormatBody()))
|
|
|
|
remote := storage.NewRemoteRepository(mstorer)
|
|
|
|
local := storage.NewMemory()
|
|
|
|
|
2021-09-03 07:12:16 +02:00
|
|
|
syncer := process.NewFetch(remote, local)
|
2021-06-25 09:14:27 +02:00
|
|
|
actResult, err := syncer.Process()
|
|
|
|
test.OK(t, err)
|
|
|
|
test.Equals(t, 2, actResult.Count)
|
2021-08-25 06:52:48 +02:00
|
|
|
actTasks, err := local.FindAll()
|
2021-06-25 09:14:27 +02:00
|
|
|
test.OK(t, err)
|
2021-08-25 06:52:48 +02:00
|
|
|
for _, a := range actTasks {
|
|
|
|
a.LocalId = 0
|
|
|
|
a.Message = nil
|
|
|
|
}
|
|
|
|
exp := task.ById([]*task.LocalTask{localTask1, localTask2})
|
|
|
|
sExp := task.ById(exp)
|
|
|
|
sAct := task.ById(actTasks)
|
|
|
|
sort.Sort(sAct)
|
|
|
|
sort.Sort(sExp)
|
|
|
|
test.Equals(t, sExp, sAct)
|
2021-06-25 09:14:27 +02:00
|
|
|
}
|