z_hub_7_b_filetest.gno
1.07 Kb · 40 lines
1// PKGPATH: gno.land/r/gnoland/boards2/v1/filetests/z_hub_7_b_filetest
2
3// Test getting comments from a thread
4package z_hub_7_b_filetest
5
6import (
7 "testing"
8
9 boards2 "gno.land/r/gnoland/boards2/v1"
10)
11
12var thread boards2.Thread
13
14func init(cur realm) {
15 testing.SetRealm(testing.NewUserRealm("g1rp7cmetn27eqlpjpc4vuusf8kaj746tysc0qgh"))
16 boardID := boards2.CreateBoard(cross(cur), "test123", false, false)
17 threadID := boards2.CreateThread(cross(cur), boardID, "Title", "Body")
18 commentID := boards2.CreateReply(cross(cur), boardID, threadID, 0, "Comment 1")
19
20 // Create another comment
21 boards2.CreateReply(cross(cur), boardID, threadID, 0, "Comment 2")
22
23 // Add a reply (it should not be included in the output)
24 boards2.CreateReply(cross(cur), boardID, threadID, commentID, "Reply")
25
26 // Get readonly thread
27 thread, _ = boards2.GetThread(uint64(boardID), uint64(threadID))
28}
29
30func main(cur realm) {
31 comments := boards2.GetComments(thread.BoardID(), thread.ID(), 0, thread.CommentCount())
32
33 for _, c := range comments {
34 println(c.ID(), c.Body())
35 }
36}
37
38// Output:
39// 2 Comment 1
40// 3 Comment 2