gte/internal/process/recur_test.go

73 lines
1.8 KiB
Go
Raw Normal View History

2021-05-13 08:15:14 +02:00
package process_test
import (
2022-06-06 11:07:03 +02:00
"fmt"
2021-05-13 08:15:14 +02:00
"testing"
2022-06-06 11:07:03 +02:00
"time"
2021-05-13 08:15:14 +02:00
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/msend"
"ewintr.nl/gte/pkg/mstore"
2021-05-13 08:15:14 +02:00
)
func TestRecurProcess(t *testing.T) {
2022-06-06 11:07:03 +02:00
strFormat := "2006-01-02"
todayStr := time.Now().Format(strFormat)
nextMonthStr := time.Now().Add(30 * 24 * time.Hour).Format(strFormat)
tomorrowStr := task.Today().Add(1).String()
2021-05-13 08:15:14 +02:00
for _, tc := range []struct {
name string
recurMsgs []*mstore.Message
2021-05-15 11:46:03 +02:00
expCount int
2021-05-13 08:15:14 +02:00
expMsgs []*msend.Message
}{
{
2021-05-15 11:46:03 +02:00
name: "empty",
expMsgs: []*msend.Message{},
2021-05-13 08:15:14 +02:00
},
{
name: "one of two recurring",
recurMsgs: []*mstore.Message{
{
2022-06-06 11:07:03 +02:00
Subject: "recurring",
Body: fmt.Sprintf("recur: %s, daily\nid: xxx-xxx\nversion: 1", todayStr),
2021-05-13 08:15:14 +02:00
},
{
2022-06-06 11:07:03 +02:00
Subject: "not recurring",
Body: fmt.Sprintf("recur: %s, daily\nid: xxx-xxx\nversion: 1", nextMonthStr),
2021-05-13 08:15:14 +02:00
},
},
2021-05-15 11:46:03 +02:00
expCount: 1,
2021-05-13 08:15:14 +02:00
expMsgs: []*msend.Message{
2022-06-06 11:07:03 +02:00
{Subject: fmt.Sprintf("%s - recurring", tomorrowStr)},
2021-05-13 08:15:14 +02:00
},
},
} {
t.Run(tc.name, func(t *testing.T) {
mstorer, err := mstore.NewMemory([]string{
task.FOLDER_INBOX,
task.FOLDER_NEW,
task.FOLDER_RECURRING,
task.FOLDER_PLANNED,
task.FOLDER_UNPLANNED,
})
test.OK(t, err)
for _, m := range tc.recurMsgs {
test.OK(t, mstorer.Add(task.FOLDER_RECURRING, m.Subject, m.Body))
}
msender := msend.NewMemory()
2021-06-25 09:14:27 +02:00
recurProc := process.NewRecur(storage.NewRemoteRepository(mstorer), storage.NewDispatcher(msender), 1)
2021-05-13 08:15:14 +02:00
actResult, err := recurProc.Process()
test.OK(t, err)
2021-05-15 11:46:03 +02:00
test.Equals(t, tc.expCount, actResult.Count)
2021-05-13 08:15:14 +02:00
for i, expMsg := range tc.expMsgs {
test.Equals(t, expMsg.Subject, msender.Messages[i].Subject)
}
})
}
}