Compare commits

..

No commits in common. "4d3c81d85a0ffa407ab7585576ff7f045798e7cb" and "3b74c5eeb52816b830a10116ae5e84e5ab117960" have entirely different histories.

9 changed files with 10 additions and 110 deletions

View File

@ -167,7 +167,7 @@ func (d Date) DaysBetween(d2 Date) int {
func (d Date) String() string {
if d.t.IsZero() {
return ""
return "no date"
}
return strings.ToLower(d.t.Format(DateFormat))

View File

@ -230,7 +230,7 @@ func TestDateString(t *testing.T) {
{
name: "zero",
date: item.NewDate(0, 0, 0),
exp: "",
exp: "no date",
},
{
name: "normal",

View File

@ -4,7 +4,6 @@ import (
"encoding/json"
"time"
"github.com/google/go-cmp/cmp"
"github.com/google/uuid"
)
@ -69,10 +68,3 @@ func NewItem(k Kind, body string) Item {
Body: body,
}
}
func ItemDiff(exp, got Item) string {
expJSON, _ := json.Marshal(exp)
actJSON, _ := json.Marshal(got)
return cmp.Diff(string(expJSON), string(actJSON))
}

View File

@ -1,83 +0,0 @@
package item_test
import (
"bytes"
"encoding/json"
"testing"
"time"
"go-mod.ewintr.nl/planner/item"
)
func TestItemJSON(t *testing.T) {
t.Parallel()
for _, tc := range []struct {
name string
item item.Item
expJSON string
}{
{
name: "minimal",
item: item.Item{
ID: "a",
Kind: item.KindTask,
Body: `{"title":"title"}`,
},
expJSON: `{
"recurrer": "",
"id": "a",
"kind": "task",
"updated": "0001-01-01T00:00:00Z",
"deleted": false,
"date": "",
"recurNext": "",
"body": "{\"title\":\"title\"}"
}`,
},
{
name: "full",
item: item.Item{
ID: "a",
Kind: item.KindTask,
Updated: time.Date(2024, 12, 25, 11, 9, 0, 0, time.UTC),
Deleted: true,
Date: item.NewDate(2024, 12, 26),
Recurrer: item.NewRecurrer("2024-12-25, daily"),
RecurNext: item.NewDateFromString("2024-12-30"),
Body: `{"title":"title"}`,
},
expJSON: `{
"recurrer": "2024-12-25, daily",
"id": "a",
"kind": "task",
"updated": "2024-12-25T11:09:00Z",
"deleted": true,
"date": "2024-12-26",
"recurNext": "2024-12-30",
"body": "{\"title\":\"title\"}"
}`,
},
} {
t.Run(tc.name, func(t *testing.T) {
actJSON, err := json.Marshal(tc.item)
if err != nil {
t.Errorf("exp nil, got %v", err)
}
expJSON := bytes.NewBuffer([]byte(``))
if err := json.Compact(expJSON, []byte(tc.expJSON)); err != nil {
t.Errorf("exp nil, got %v", err)
}
if expJSON.String() != string(actJSON) {
t.Errorf("exp %v, got %v", expJSON.String(), string(actJSON))
}
var actItem item.Item
if err := json.Unmarshal(actJSON, &actItem); err != nil {
t.Errorf("exp nil, got %v", err)
}
if diff := item.ItemDiff(tc.item, actItem); diff != "" {
t.Errorf("(+exp, -got)%s\n", diff)
}
})
}
}

View File

@ -102,7 +102,7 @@ func TestTaskItem(t *testing.T) {
expItem: item.Item{
Kind: item.KindTask,
Updated: time.Time{},
Body: `{"duration":"0s","title":"","time":""}`,
Body: `{"duration":"0s","title":"","time":"00:00"}`,
},
},
{

View File

@ -44,10 +44,6 @@ func NewTimeFromString(timeStr string) Time {
}
func (t *Time) String() string {
if t.t.IsZero() {
return ""
}
return t.t.Format(TimeFormat)
}

View File

@ -44,16 +44,11 @@ func TestTimeFromString(t *testing.T) {
}{
{
name: "empty",
exp: "",
exp: "00:00",
},
{
name: "invalid",
str: "invalid",
exp: "",
},
{
name: "00:00",
str: "00:00",
exp: "00:00",
},
{

View File

@ -43,9 +43,9 @@ func TestDelete(t *testing.T) {
},
} {
t.Run(tc.name, func(t *testing.T) {
taskRepo := memory.NewTask()
eventRepo := memory.NewTask()
syncRepo := memory.NewSync()
if err := taskRepo.Store(e); err != nil {
if err := eventRepo.Store(e); err != nil {
t.Errorf("exp nil, got %v", err)
}
localRepo := memory.NewLocalID()
@ -53,7 +53,7 @@ func TestDelete(t *testing.T) {
t.Errorf("exp nil, got %v", err)
}
cmd := command.NewDelete(localRepo, taskRepo, syncRepo)
cmd := command.NewDelete(localRepo, eventRepo, syncRepo)
actErr := cmd.Execute(tc.main, tc.flags) != nil
if tc.expErr != actErr {
@ -63,7 +63,7 @@ func TestDelete(t *testing.T) {
return
}
_, repoErr := taskRepo.Find(e.ID)
_, repoErr := eventRepo.Find(e.ID)
if !errors.Is(repoErr, storage.ErrNotFound) {
t.Errorf("exp %v, got %v", storage.ErrNotFound, actErr)
}

View File

@ -35,8 +35,8 @@ func (t *Task) FindAll() ([]item.Task, error) {
defer t.mutex.RUnlock()
tasks := make([]item.Task, 0, len(t.tasks))
for _, tsk := range t.tasks {
tasks = append(tasks, tsk)
for _, event := range t.tasks {
tasks = append(tasks, event)
}
sort.Slice(tasks, func(i, j int) bool {
return tasks[i].ID < tasks[j].ID