add
This commit is contained in:
parent
e03618efec
commit
a2c7a81136
|
@ -24,9 +24,11 @@ func NewAdd(localRepo storage.LocalID, eventRepo storage.Event, syncRepo storage
|
|||
syncRepo: syncRepo,
|
||||
argSet: &ArgSet{
|
||||
Flags: map[string]Flag{
|
||||
FlagOn: &FlagDate{},
|
||||
FlagAt: &FlagTime{},
|
||||
FlagFor: &FlagDuration{},
|
||||
FlagOn: &FlagDate{},
|
||||
FlagAt: &FlagTime{},
|
||||
FlagFor: &FlagDuration{},
|
||||
FlagRecStart: &FlagDate{},
|
||||
FlagRecPeriod: &FlagPeriod{},
|
||||
},
|
||||
},
|
||||
}
|
||||
|
@ -68,6 +70,9 @@ func (add *Add) Execute(main []string, flags map[string]string) error {
|
|||
return fmt.Errorf("could not set duration to 24 hours")
|
||||
}
|
||||
}
|
||||
if as.IsSet(FlagRecStart) != as.IsSet(FlagRecPeriod) {
|
||||
return fmt.Errorf("rec-start required rec-period and vice versa")
|
||||
}
|
||||
|
||||
return add.do()
|
||||
}
|
||||
|
@ -93,6 +98,13 @@ func (add *Add) do() error {
|
|||
if as.IsSet(FlagFor) {
|
||||
e.Duration = as.GetDuration(FlagFor)
|
||||
}
|
||||
if as.IsSet(FlagRecStart) {
|
||||
e.Recurrer = &item.Recur{
|
||||
Start: as.GetTime(FlagRecStart),
|
||||
Period: as.GetRecurPeriod(FlagRecPeriod),
|
||||
}
|
||||
}
|
||||
|
||||
if err := add.eventRepo.Store(e); err != nil {
|
||||
return fmt.Errorf("could not store event: %v", err)
|
||||
}
|
||||
|
|
|
@ -102,6 +102,46 @@ func TestAdd(t *testing.T) {
|
|||
},
|
||||
expErr: true,
|
||||
},
|
||||
{
|
||||
name: "rec-start without rec-period",
|
||||
main: []string{"add", "title"},
|
||||
flags: map[string]string{
|
||||
command.FlagOn: aDateStr,
|
||||
command.FlagRecStart: "2024-12-08",
|
||||
},
|
||||
expErr: true,
|
||||
},
|
||||
{
|
||||
name: "rec-period without rec-start",
|
||||
main: []string{"add", "title"},
|
||||
flags: map[string]string{
|
||||
command.FlagOn: aDateStr,
|
||||
command.FlagRecPeriod: "day",
|
||||
},
|
||||
expErr: true,
|
||||
},
|
||||
{
|
||||
name: "rec-start with rec-period",
|
||||
main: []string{"add", "title"},
|
||||
flags: map[string]string{
|
||||
command.FlagOn: aDateStr,
|
||||
command.FlagRecStart: "2024-12-08",
|
||||
command.FlagRecPeriod: "day",
|
||||
},
|
||||
expEvent: item.Event{
|
||||
ID: "title",
|
||||
Recurrer: &item.Recur{
|
||||
Start: time.Date(2024, 12, 8, 0, 0, 0, 0, time.UTC),
|
||||
Period: item.PeriodDay,
|
||||
},
|
||||
RecurNext: time.Time{},
|
||||
EventBody: item.EventBody{
|
||||
Title: "title",
|
||||
Start: aDate,
|
||||
Duration: aDay,
|
||||
},
|
||||
},
|
||||
},
|
||||
} {
|
||||
t.Run(tc.name, func(t *testing.T) {
|
||||
eventRepo := memory.NewEvent()
|
||||
|
@ -140,7 +180,7 @@ func TestAdd(t *testing.T) {
|
|||
}
|
||||
tc.expEvent.ID = actEvents[0].ID
|
||||
if diff := cmp.Diff(tc.expEvent, actEvents[0]); diff != "" {
|
||||
t.Errorf("(exp +, got -)\n%s", diff)
|
||||
t.Errorf("(exp -, got +)\n%s", diff)
|
||||
}
|
||||
|
||||
updated, err := syncRepo.FindAll()
|
||||
|
|
Loading…
Reference in New Issue