From ff86bab8ba37dbef3ef295666006f0ec0996ba7f Mon Sep 17 00:00:00 2001 From: Erik Winter Date: Sun, 22 Aug 2021 16:45:03 +0200 Subject: [PATCH] some tests --- internal/process/update.go | 1 + internal/task/localtask_test.go | 102 ++++++++++++++++++++++++++++++++ 2 files changed, 103 insertions(+) diff --git a/internal/process/update.go b/internal/process/update.go index 7d7abb8..13e24e6 100644 --- a/internal/process/update.go +++ b/internal/process/update.go @@ -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) diff --git a/internal/task/localtask_test.go b/internal/task/localtask_test.go index c609e0f..22cefd3 100644 --- a/internal/task/localtask_test.go +++ b/internal/task/localtask_test.go @@ -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) + }) + } +}