Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: add 0 post check #3

Merged
merged 2 commits into from
Mar 15, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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