some tests
This commit is contained in:
parent
06a8f3153a
commit
ff86bab8ba
|
@ -38,6 +38,7 @@ func (u *Update) Process() error {
|
|||
if err := u.local.SetLocalUpdate(tsk); err != nil {
|
||||
return fmt.Errorf("%w: %v", ErrUpdateTask, err)
|
||||
}
|
||||
// create a new version and send it away
|
||||
tsk.ApplyUpdate()
|
||||
if err := u.disp.Dispatch(&tsk.Task); err != nil {
|
||||
return fmt.Errorf("%w: %v", ErrUpdateTask, err)
|
||||
|
|
|
@ -65,3 +65,105 @@ func TestLocalTaskApply(t *testing.T) {
|
|||
})
|
||||
}
|
||||
}
|
||||
|
||||
func TestLocalUpdateAdd(t *testing.T) {
|
||||
for _, tc := range []struct {
|
||||
name string
|
||||
start *task.LocalUpdate
|
||||
add *task.LocalUpdate
|
||||
exp *task.LocalUpdate
|
||||
}{
|
||||
{
|
||||
name: "empty",
|
||||
start: &task.LocalUpdate{},
|
||||
add: &task.LocalUpdate{},
|
||||
exp: &task.LocalUpdate{},
|
||||
},
|
||||
{
|
||||
name: "empty add",
|
||||
start: &task.LocalUpdate{
|
||||
ForVersion: 2,
|
||||
Fields: []string{task.FIELD_ACTION, task.FIELD_PROJECT, task.FIELD_DUE, task.FIELD_RECUR, task.FIELD_DONE},
|
||||
Action: "action",
|
||||
Project: "project",
|
||||
Due: task.NewDate(2021, 8, 22),
|
||||
Recur: task.NewRecurrer("today, daily"),
|
||||
Done: true,
|
||||
},
|
||||
add: &task.LocalUpdate{},
|
||||
exp: &task.LocalUpdate{
|
||||
ForVersion: 2,
|
||||
Fields: []string{task.FIELD_ACTION, task.FIELD_PROJECT, task.FIELD_DUE, task.FIELD_RECUR, task.FIELD_DONE},
|
||||
Action: "action",
|
||||
Project: "project",
|
||||
Due: task.NewDate(2021, 8, 22),
|
||||
Recur: task.NewRecurrer("today, daily"),
|
||||
Done: true,
|
||||
},
|
||||
},
|
||||
{
|
||||
name: "empty start",
|
||||
start: &task.LocalUpdate{},
|
||||
add: &task.LocalUpdate{
|
||||
ForVersion: 2,
|
||||
Fields: []string{task.FIELD_ACTION, task.FIELD_PROJECT, task.FIELD_PROJECT, task.FIELD_DUE, task.FIELD_RECUR, task.FIELD_DONE},
|
||||
Action: "action",
|
||||
Project: "project",
|
||||
Due: task.NewDate(2021, 8, 22),
|
||||
Recur: task.NewRecurrer("today, daily"),
|
||||
Done: true,
|
||||
},
|
||||
exp: &task.LocalUpdate{
|
||||
ForVersion: 2,
|
||||
Fields: []string{task.FIELD_ACTION, task.FIELD_PROJECT, task.FIELD_DUE, task.FIELD_RECUR, task.FIELD_DONE},
|
||||
Action: "action",
|
||||
Project: "project",
|
||||
Due: task.NewDate(2021, 8, 22),
|
||||
Recur: task.NewRecurrer("today, daily"),
|
||||
Done: true,
|
||||
},
|
||||
},
|
||||
{
|
||||
name: "too old",
|
||||
start: &task.LocalUpdate{
|
||||
ForVersion: 3,
|
||||
Fields: []string{},
|
||||
},
|
||||
add: &task.LocalUpdate{
|
||||
ForVersion: 2,
|
||||
Fields: []string{task.FIELD_ACTION},
|
||||
},
|
||||
exp: &task.LocalUpdate{
|
||||
ForVersion: 3,
|
||||
Fields: []string{},
|
||||
},
|
||||
},
|
||||
{
|
||||
name: "adding fields",
|
||||
start: &task.LocalUpdate{
|
||||
ForVersion: 3,
|
||||
Fields: []string{task.FIELD_ACTION, task.FIELD_PROJECT},
|
||||
Action: "action-1",
|
||||
Project: "project-1",
|
||||
},
|
||||
add: &task.LocalUpdate{
|
||||
ForVersion: 3,
|
||||
Fields: []string{task.FIELD_PROJECT, task.FIELD_DUE},
|
||||
Project: "project-2",
|
||||
Due: task.NewDate(2021, 8, 22),
|
||||
},
|
||||
exp: &task.LocalUpdate{
|
||||
ForVersion: 3,
|
||||
Fields: []string{task.FIELD_ACTION, task.FIELD_PROJECT, task.FIELD_DUE},
|
||||
Action: "action-1",
|
||||
Project: "project-2",
|
||||
Due: task.NewDate(2021, 8, 22),
|
||||
},
|
||||
},
|
||||
} {
|
||||
t.Run(tc.name, func(t *testing.T) {
|
||||
tc.start.Add(tc.add)
|
||||
test.Equals(t, tc.exp, tc.start)
|
||||
})
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue