Skip to content

Commit

Permalink
test(journal): add test case for EndTime not set on String function
Browse files Browse the repository at this point in the history
  • Loading branch information
deadpyxel committed Nov 9, 2023
1 parent fdb862e commit c4c96b1
Showing 1 changed file with 25 additions and 10 deletions.
35 changes: 25 additions & 10 deletions internal/journal_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -118,18 +118,33 @@ func TestJournalEntryStringer(t *testing.T) {
endTime := time.Date(2021, time.January, 1, 13, 0, 0, 0, time.UTC)
notes := []string{"Note 1", "Note 2"}

journalEntry := &JournalEntry{
StartTime: startTime,
EndTime: endTime,
Notes: notes,
}
t.Run("When an entry has all fields filled returns formatted string", func(t *testing.T) {
journalEntry := &JournalEntry{
StartTime: startTime,
EndTime: endTime,
Notes: notes,
}

expected := "Date: 2021-01-01\nStart: 12:00:00 | End: 13:00:00 | Time: 1h0m0s\n\n- Note 1\n- Note 2"
result := journalEntry.String()
expected := "Date: 2021-01-01\nStart: 12:00:00 | End: 13:00:00 | Time: 1h0m0s\n\n- Note 1\n- Note 2"
result := journalEntry.String()

if result != expected {
t.Errorf("Expected: \n%s, but got: \n%s", expected, result)
}
if result != expected {
t.Errorf("Expected: \n%s, but got: \n%s", expected, result)
}
})
t.Run("When an entry has no EndTime returns formatted string with not closed message", func(t *testing.T) {
journalEntry := &JournalEntry{
StartTime: startTime,
Notes: notes,
}

expected := "Date: 2021-01-01\nStart: 12:00:00 | End: Not yet closed | Time: N/A\n\n- Note 1\n- Note 2"
result := journalEntry.String()

if result != expected {
t.Errorf("Expected: \n%s, but got: \n%s", expected, result)
}
})
}

func BenchmarkFetchEntryByID(b *testing.B) {
Expand Down

0 comments on commit c4c96b1

Please sign in to comment.