tests
This commit is contained in:
parent
abf3d7291d
commit
e03618efec
|
@ -48,6 +48,11 @@ func TestNewEvent(t *testing.T) {
|
|||
it: item.Item{
|
||||
ID: "a",
|
||||
Kind: item.KindEvent,
|
||||
Recurrer: &item.Recur{
|
||||
Start: time.Date(2024, 12, 8, 9, 0, 0, 0, time.UTC),
|
||||
Period: item.PeriodDay,
|
||||
Count: 1,
|
||||
},
|
||||
Body: `{
|
||||
"title":"title",
|
||||
"start":"2024-09-20T08:00:00Z",
|
||||
|
@ -56,6 +61,11 @@ func TestNewEvent(t *testing.T) {
|
|||
},
|
||||
expEvent: item.Event{
|
||||
ID: "a",
|
||||
Recurrer: &item.Recur{
|
||||
Start: time.Date(2024, 12, 8, 9, 0, 0, 0, time.UTC),
|
||||
Period: item.PeriodDay,
|
||||
Count: 1,
|
||||
},
|
||||
EventBody: item.EventBody{
|
||||
Title: "title",
|
||||
Start: time.Date(2024, 9, 20, 8, 0, 0, 0, time.UTC),
|
||||
|
|
|
@ -4,6 +4,7 @@ import (
|
|||
"testing"
|
||||
"time"
|
||||
|
||||
"go-mod.ewintr.nl/planner/item"
|
||||
"go-mod.ewintr.nl/planner/plan/command"
|
||||
)
|
||||
|
||||
|
@ -52,6 +53,15 @@ func TestArgSet(t *testing.T) {
|
|||
setValue: "2h30m",
|
||||
exp: 2*time.Hour + 30*time.Minute,
|
||||
},
|
||||
{
|
||||
name: "recur period flag success",
|
||||
flags: map[string]command.Flag{
|
||||
"period": &command.FlagPeriod{Name: "period"},
|
||||
},
|
||||
flagName: "period",
|
||||
setValue: "month",
|
||||
exp: item.PeriodMonth,
|
||||
},
|
||||
{
|
||||
name: "unknown flag error",
|
||||
flags: map[string]command.Flag{},
|
||||
|
|
|
@ -4,6 +4,7 @@ import (
|
|||
"testing"
|
||||
"time"
|
||||
|
||||
"go-mod.ewintr.nl/planner/item"
|
||||
"go-mod.ewintr.nl/planner/plan/command"
|
||||
)
|
||||
|
||||
|
@ -113,3 +114,30 @@ func TestFlagDurationTime(t *testing.T) {
|
|||
t.Errorf("exp %v, got %v", valid, act)
|
||||
}
|
||||
}
|
||||
|
||||
func TestFlagPeriod(t *testing.T) {
|
||||
t.Parallel()
|
||||
|
||||
valid := item.PeriodMonth
|
||||
validStr := "month"
|
||||
f := command.FlagPeriod{}
|
||||
if f.IsSet() {
|
||||
t.Errorf("exp false, got true")
|
||||
}
|
||||
|
||||
if err := f.Set(validStr); err != nil {
|
||||
t.Errorf("exp nil, got %v", err)
|
||||
}
|
||||
|
||||
if !f.IsSet() {
|
||||
t.Errorf("exp true, got false")
|
||||
}
|
||||
|
||||
act, ok := f.Get().(item.RecurPeriod)
|
||||
if !ok {
|
||||
t.Errorf("exp true, got false")
|
||||
}
|
||||
if act != valid {
|
||||
t.Errorf("exp %v, got %v", valid, act)
|
||||
}
|
||||
}
|
||||
|
|
|
@ -149,6 +149,58 @@ func TestUpdateExecute(t *testing.T) {
|
|||
},
|
||||
},
|
||||
},
|
||||
{
|
||||
name: "invalid rec start",
|
||||
main: []string{"update", fmt.Sprintf("%d", lid)},
|
||||
flags: map[string]string{
|
||||
"rec-start": "invalud",
|
||||
},
|
||||
expErr: true,
|
||||
},
|
||||
{
|
||||
name: "valid rec start",
|
||||
main: []string{"update", fmt.Sprintf("%d", lid)},
|
||||
flags: map[string]string{
|
||||
"rec-start": "2024-12-08",
|
||||
},
|
||||
expEvent: item.Event{
|
||||
ID: eid,
|
||||
Recurrer: &item.Recur{
|
||||
Start: time.Date(2024, 12, 8, 0, 0, 0, 0, time.UTC),
|
||||
},
|
||||
EventBody: item.EventBody{
|
||||
Title: title,
|
||||
Start: start,
|
||||
Duration: oneHour,
|
||||
},
|
||||
},
|
||||
},
|
||||
{
|
||||
name: "invalid rec period",
|
||||
main: []string{"update", fmt.Sprintf("%d", lid)},
|
||||
flags: map[string]string{
|
||||
"rec-period": "invalid",
|
||||
},
|
||||
expErr: true,
|
||||
},
|
||||
{
|
||||
name: "valid rec period",
|
||||
main: []string{"update", fmt.Sprintf("%d", lid)},
|
||||
flags: map[string]string{
|
||||
"rec-period": "month",
|
||||
},
|
||||
expEvent: item.Event{
|
||||
ID: eid,
|
||||
Recurrer: &item.Recur{
|
||||
Period: item.PeriodMonth,
|
||||
},
|
||||
EventBody: item.EventBody{
|
||||
Title: title,
|
||||
Start: start,
|
||||
Duration: oneHour,
|
||||
},
|
||||
},
|
||||
},
|
||||
} {
|
||||
t.Run(tc.name, func(t *testing.T) {
|
||||
eventRepo := memory.NewEvent()
|
||||
|
@ -182,7 +234,7 @@ func TestUpdateExecute(t *testing.T) {
|
|||
t.Errorf("exp nil, got %v", err)
|
||||
}
|
||||
if diff := cmp.Diff(tc.expEvent, actEvent); diff != "" {
|
||||
t.Errorf("(exp +, got -)\n%s", diff)
|
||||
t.Errorf("(exp -, got +)\n%s", diff)
|
||||
}
|
||||
updated, err := syncRepo.FindAll()
|
||||
if err != nil {
|
||||
|
|
Loading…
Reference in New Issue