diff --git a/pkg/goal/goal.go b/pkg/goal/goal.go index ba4259cc..ec0e8c38 100644 --- a/pkg/goal/goal.go +++ b/pkg/goal/goal.go @@ -98,6 +98,10 @@ func RenderToday(goal *Goal, out output.Output) (string, error) { return "", errors.New("no goal found for the current day") } + if len(goal.Data.ChartData) == 0 { + return "", errors.New("no chart data found for the current day") + } + if out == output.RawJSONOutput { data, err := json.Marshal(goal) if err != nil { diff --git a/pkg/goal/goal_test.go b/pkg/goal/goal_test.go index 421b5fc3..5cefb293 100644 --- a/pkg/goal/goal_test.go +++ b/pkg/goal/goal_test.go @@ -36,6 +36,18 @@ func TestRenderToday(t *testing.T) { } } +func TestRenderToday_NilGoal(t *testing.T) { + _, err := goal.RenderToday(nil, output.TextOutput) + + assert.EqualError(t, err, "no goal found for the current day") +} + +func TestRenderToday_EmptyChartData(t *testing.T) { + _, err := goal.RenderToday(&goal.Goal{}, output.TextOutput) + + assert.EqualError(t, err, "no chart data found for the current day") +} + func readFile(t *testing.T, fp string) string { data, err := os.ReadFile(fp) require.NoError(t, err)