2021-06-25 09:14:27 +02:00
|
|
|
package storage_test
|
2021-06-24 06:56:00 +02:00
|
|
|
|
|
|
|
import (
|
|
|
|
"fmt"
|
|
|
|
"testing"
|
|
|
|
|
2024-03-08 09:20:40 +01:00
|
|
|
"code.ewintr.nl/go-kit/test"
|
|
|
|
"code.ewintr.nl/gte/internal/storage"
|
|
|
|
"code.ewintr.nl/gte/internal/task"
|
|
|
|
"code.ewintr.nl/gte/pkg/msend"
|
2021-06-24 06:56:00 +02:00
|
|
|
)
|
|
|
|
|
|
|
|
func TestDispatcherDispatch(t *testing.T) {
|
|
|
|
mem := msend.NewMemory()
|
2021-06-25 09:14:27 +02:00
|
|
|
disp := storage.NewDispatcher(mem)
|
2021-06-24 06:56:00 +02:00
|
|
|
tsk := &task.Task{
|
|
|
|
Id: "id",
|
|
|
|
Version: 3,
|
|
|
|
Action: "action",
|
|
|
|
Project: "project",
|
|
|
|
Due: task.NewDate(2021, 6, 24),
|
|
|
|
}
|
|
|
|
|
|
|
|
t.Run("err", func(t *testing.T) {
|
|
|
|
expErr := fmt.Errorf("not good")
|
|
|
|
mem.Err = expErr
|
|
|
|
actErr := disp.Dispatch(tsk)
|
|
|
|
|
|
|
|
test.Equals(t, expErr, actErr)
|
|
|
|
})
|
|
|
|
|
|
|
|
t.Run("success", func(t *testing.T) {
|
|
|
|
mem.Err = nil
|
|
|
|
|
|
|
|
test.OK(t, disp.Dispatch(tsk))
|
|
|
|
test.Equals(t, 1, len(mem.Messages))
|
|
|
|
|
|
|
|
actMsg := mem.Messages[0]
|
|
|
|
test.Equals(t, tsk.FormatSubject(), actMsg.Subject)
|
|
|
|
test.Equals(t, tsk.FormatBody(), actMsg.Body)
|
|
|
|
})
|
|
|
|
}
|