diff --git a/model/entry_test.go b/model/entry_test.go index de6cfaf..5acb3e2 100644 --- a/model/entry_test.go +++ b/model/entry_test.go @@ -3,28 +3,33 @@ package model import ( "git.nagee.dev/isthisnagee/diary/db" "testing" + "runtime/debug" ) func assert_string(t *testing.T, expected string, actual string) { if actual != expected { + t.Log(string(debug.Stack())) t.Fatalf("(%v, %v)", expected, actual) } } func assert_int(t *testing.T, expected int64, actual int64) { if actual != expected { + t.Log(string(debug.Stack())) t.Fatalf("(%v, %v)", expected, actual) } } func assert_bool(t *testing.T, expected bool, actual bool) { if actual != expected { + t.Log(string(debug.Stack())) t.Fatalf("(%v, %v)", expected, actual) } } func assert_exists(t *testing.T, actual interface{}) { if actual == nil { + t.Log(string(debug.Stack())) t.Fatalf("Unexpected nil: %s", actual) } } @@ -103,15 +108,30 @@ func DeleteDiaryEntryNotFound(t *testing.T) { func TestGetDiaryEntries(t *testing.T) { var app = setup() - var result_1 = app.NewDiaryEntry("Met with Nagee @ 1PM") var result_2 = app.NewDiaryEntry("Met with Nagee @ 2PM") - queried_result, _ := app.GetDiaryEntries(inserted_result.Id) - assert_int(t, inserted_result.Id, queried_result.Id) - assert_int(t, inserted_result.CreatedAt, queried_result.CreatedAt) - assert_int(t, inserted_result.Version, queried_result.Version) - assert_string(t, inserted_result.Title, queried_result.Title) + // no numEntries + entries := app.GetDiaryEntries( + GetDiaryEntriesQuery{}, + ) + + assert_int(t, int64(len(entries)), 2) + assert_int(t, result_2.Id, entries[0].Id) + assert_int(t, result_1.Id, entries[1].Id) + + + var numEntries = new(int64) + *numEntries = 1 + entries = app.GetDiaryEntries( + GetDiaryEntriesQuery{ + NumEntries: numEntries, + }, + ) + + assert_int(t, int64(len(entries)), 1) + assert_int(t, result_2.Id, entries[0].Id) + teardown(app) }