gte/internal/process/fetch_test.go

55 lines
1.4 KiB
Go
Raw Normal View History

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"
2021-09-19 11:59:26 +02:00
"ewintr.nl/go-kit/test"
"ewintr.nl/gte/internal/process"
"ewintr.nl/gte/internal/storage"
"ewintr.nl/gte/internal/task"
"ewintr.nl/gte/pkg/mstore"
2021-06-25 09:14:27 +02:00
)
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
}