Skip to content

Commit

Permalink
Fix rendering nil chart data for goals
Browse files Browse the repository at this point in the history
  • Loading branch information
gandarez committed Sep 7, 2023
1 parent 2de3e86 commit 131e675
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 0 deletions.
4 changes: 4 additions & 0 deletions pkg/goal/goal.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
12 changes: 12 additions & 0 deletions pkg/goal/goal_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down

0 comments on commit 131e675

Please sign in to comment.