Skip to content

Commit

Permalink
fix: add 0 post check (#3)
Browse files Browse the repository at this point in the history
* add no post check

* add test
  • Loading branch information
leohhhn authored Mar 15, 2024
1 parent ff42293 commit 3673959
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 0 deletions.
4 changes: 4 additions & 0 deletions api/p/memeland/memeland.gno
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,10 @@ func (m *Memeland) Upvote(id string) string {

// GetPostsInRange returns a JSON string of posts within the given timestamp range, supporting pagination.
func (m *Memeland) GetPostsInRange(startTimestamp, endTimestamp int64, page, pageSize int, sortBy string) string {
if len(m.Posts) == 0 {
return "[]"
}

if page < 1 {
panic("page count cannot be less than 1")
}
Expand Down
14 changes: 14 additions & 0 deletions api/p/memeland/memeland_test.gno
Original file line number Diff line number Diff line change
Expand Up @@ -199,6 +199,20 @@ func TestGetPostsInRangeByUpvote(t *testing.T) {
}
}

func TestNoPosts(t *testing.T) {
m := NewMemeland()

// Add a post to Memeland
now := time.Now().Unix()

jsonStr := m.GetPostsInRange(0, now, 1, 1, "DATE_CREATED")

if jsonStr != "[]" {
t.Errorf("Expected 0 posts to return [], got %s", jsonStr)
}

}

func TestUpvote(t *testing.T) {
m := NewMemeland()

Expand Down

0 comments on commit 3673959

Please sign in to comment.