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

test(boards2): add missing filetests for reply creation #3653

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
5 changes: 4 additions & 1 deletion examples/gno.land/r/nt/boards2/public.gno
Original file line number Diff line number Diff line change
Expand Up @@ -92,6 +92,9 @@ func CreateThread(bid BoardID, title, body string) PostID {
func CreateReply(bid BoardID, threadID, replyID PostID, body string) PostID {
assertIsUserCall()

body = strings.TrimSpace(body)
assertBodyIsNotEmpty(body)

caller := std.GetOrigCaller()
board := mustGetBoard(bid)
assertHasBoardPermission(board, caller, PermissionReplyCreate)
Expand All @@ -100,7 +103,7 @@ func CreateReply(bid BoardID, threadID, replyID PostID, body string) PostID {
assertThreadVisible(thread)

var reply *Post
if replyID == threadID {
if replyID == 0 {
// When the parent reply is the thread just add reply to thread
reply = thread.AddReply(caller, body)
} else {
Expand Down
31 changes: 24 additions & 7 deletions examples/gno.land/r/nt/boards2/z_2_a_filetest.gno
Original file line number Diff line number Diff line change
Expand Up @@ -2,22 +2,39 @@ package main

import (
"std"
"strings"

"gno.land/r/nt/boards2"
)

const owner = std.Address("g1jg8mtutu9khhfwc4nxmuhcpftf0pajdhfvsqf5") // @test1
const (
owner = std.Address("g1jg8mtutu9khhfwc4nxmuhcpftf0pajdhfvsqf5") // @test1
path = "test-board/1/2"
comment = "Test comment"
)

var (
bid boards2.BoardID
tid boards2.PostID
)

func init() {
std.TestSetOrigCaller(owner)
bid = boards2.CreateBoard("test-board")
tid = boards2.CreateThread(bid, "Foo", "bar")
}

func main() {
bid := boards2.CreateBoard("test123")
pid := boards2.CreateThread(bid, "thread", "thread")
boards2.FlagThread(bid, pid, "reason")
_ = boards2.CreateReply(bid, pid, pid, "reply")
rid := boards2.CreateReply(bid, tid, 0, comment)

// Ensure that returned ID is right
println(rid == 2)

// Render content must contain the reply
content := boards2.Render(path)
println(strings.Contains(content, "\n> "+comment+"\n"))
}

// Error:
// thread with ID: 1 was hidden
// Output:
// true
// true
10 changes: 2 additions & 8 deletions examples/gno.land/r/nt/boards2/z_2_b_filetest.gno
Original file line number Diff line number Diff line change
Expand Up @@ -13,14 +13,8 @@ func init() {
}

func main() {
// ensure that nested replies denied if root thread is hidden.
bid := boards2.CreateBoard("test123")
pid := boards2.CreateThread(bid, "thread", "thread")
rid := boards2.CreateReply(bid, pid, pid, "reply1")

boards2.FlagThread(bid, pid, "reason")
_ = boards2.CreateReply(bid, pid, rid, "reply1.1")
boards2.CreateReply(404, 1, 0, "comment")
}

// Error:
// thread with ID: 1 was hidden
// board does not exist with ID: 404
13 changes: 5 additions & 8 deletions examples/gno.land/r/nt/boards2/z_2_c_filetest.gno
Original file line number Diff line number Diff line change
Expand Up @@ -8,19 +8,16 @@ import (

const owner = std.Address("g1jg8mtutu9khhfwc4nxmuhcpftf0pajdhfvsqf5") // @test1

var bid boards2.BoardID

func init() {
std.TestSetOrigCaller(owner)
bid = boards2.CreateBoard("test123")
}

func main() {
// ensure that nested replies denied if root thread is hidden.
bid := boards2.CreateBoard("test123")
pid := boards2.CreateThread(bid, "thread", "thread")
rid := boards2.CreateReply(bid, pid, pid, "reply1")

boards2.FlagReply(bid, pid, rid, "reason")
_ = boards2.CreateReply(bid, pid, rid, "reply1.1")
boards2.CreateReply(bid, 404, 0, "comment")
}

// Error:
// reply with ID: 2 was hidden
// thread does not exist with ID: 404
16 changes: 9 additions & 7 deletions examples/gno.land/r/nt/boards2/z_2_d_filetest.gno
Original file line number Diff line number Diff line change
Expand Up @@ -8,18 +8,20 @@ import (

const owner = std.Address("g1jg8mtutu9khhfwc4nxmuhcpftf0pajdhfvsqf5") // @test1

var (
bid boards2.BoardID
tid boards2.PostID
)

func init() {
std.TestSetOrigCaller(owner)
bid = boards2.CreateBoard("test-board")
tid = boards2.CreateThread(bid, "Foo", "bar")
}

func main() {
// Only single user per flag can't be tested atm, as flagThreshold = 1.
bid := boards2.CreateBoard("test123")
pid := boards2.CreateThread(bid, "thread", "thread")

boards2.FlagThread(bid, pid, "reason1")
boards2.FlagThread(bid, pid, "reason2")
boards2.CreateReply(bid, tid, 404, "comment")
}

// Error:
// item flag count threshold exceeded: 1
// reply does not exist with ID: 404
30 changes: 30 additions & 0 deletions examples/gno.land/r/nt/boards2/z_2_e_filetest.gno
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
package main

import (
"std"

"gno.land/r/nt/boards2"
)

const owner = std.Address("g1jg8mtutu9khhfwc4nxmuhcpftf0pajdhfvsqf5") // @test1

var (
bid boards2.BoardID
tid boards2.PostID
)

func init() {
std.TestSetOrigCaller(owner)
bid = boards2.CreateBoard("test123")
tid = boards2.CreateThread(bid, "Foo", "bar")

// Hide thread by flagging it so reply can't be submitted
boards2.FlagThread(bid, tid, "reason")
}

func main() {
boards2.CreateReply(bid, tid, 0, "Test reply")
}

// Error:
// thread with ID: 1 was hidden
31 changes: 31 additions & 0 deletions examples/gno.land/r/nt/boards2/z_2_f_filetest.gno
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
package main

import (
"std"

"gno.land/r/nt/boards2"
)

const owner = std.Address("g1jg8mtutu9khhfwc4nxmuhcpftf0pajdhfvsqf5") // @test1

var (
bid boards2.BoardID
tid, rid boards2.PostID
)

func init() {
std.TestSetOrigCaller(owner)
bid = boards2.CreateBoard("test123")
tid = boards2.CreateThread(bid, "Foo", "bar")
rid = boards2.CreateReply(bid, tid, 0, "reply1")

// Hide thread by flagging it so reply of a reply can't be submitted
boards2.FlagThread(bid, tid, "reason")
}

func main() {
boards2.CreateReply(bid, tid, rid, "reply1.1")
}

// Error:
// thread with ID: 1 was hidden
31 changes: 31 additions & 0 deletions examples/gno.land/r/nt/boards2/z_2_g_filetest.gno
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
package main

import (
"std"

"gno.land/r/nt/boards2"
)

const owner = std.Address("g1jg8mtutu9khhfwc4nxmuhcpftf0pajdhfvsqf5") // @test1

var (
bid boards2.BoardID
tid, rid boards2.PostID
)

func init() {
std.TestSetOrigCaller(owner)
bid = boards2.CreateBoard("test123")
tid = boards2.CreateThread(bid, "thread", "thread")
rid = boards2.CreateReply(bid, tid, 0, "reply1")

// Hide reply by flagging it so sub reply can't be submitted
boards2.FlagReply(bid, tid, rid, "reason")
}

func main() {
boards2.CreateReply(bid, tid, rid, "reply1.1")
}

// Error:
// reply with ID: 2 was hidden
32 changes: 32 additions & 0 deletions examples/gno.land/r/nt/boards2/z_2_h_filetest.gno
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
package main

import (
"std"

"gno.land/r/nt/boards2"
)

const (
owner = std.Address("g1jg8mtutu9khhfwc4nxmuhcpftf0pajdhfvsqf5") // @test1
user = std.Address("g1us8428u2a5satrlxzagqqa5m6vmuze025anjlj") // @test2
)

var (
bid boards2.BoardID
tid boards2.PostID
)

func init() {
std.TestSetOrigCaller(owner)
bid = boards2.CreateBoard("test123")
tid = boards2.CreateThread(bid, "Foo", "bar")

std.TestSetOrigCaller(user)
}

func main() {
boards2.CreateReply(bid, tid, 0, "Test reply")
}

// Error:
// unauthorized
27 changes: 27 additions & 0 deletions examples/gno.land/r/nt/boards2/z_2_i_filetest.gno
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
package main

import (
"std"

"gno.land/r/nt/boards2"
)

const owner = std.Address("g1jg8mtutu9khhfwc4nxmuhcpftf0pajdhfvsqf5") // @test1

var (
bid boards2.BoardID
tid boards2.PostID
)

func init() {
std.TestSetOrigCaller(owner)
bid = boards2.CreateBoard("test-board")
tid = boards2.CreateThread(bid, "Foo", "bar")
}

func main() {
boards2.CreateReply(bid, tid, 0, "")
}

// Error:
// body is empty
41 changes: 41 additions & 0 deletions examples/gno.land/r/nt/boards2/z_2_j_filetest.gno
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
package main

import (
"std"
"strings"

"gno.land/r/nt/boards2"
)

const (
owner = std.Address("g1jg8mtutu9khhfwc4nxmuhcpftf0pajdhfvsqf5") // @test1
path = "test-board/1/2"
comment = "Second comment"
)

var (
bid boards2.BoardID
tid, rid boards2.PostID
)

func init() {
std.TestSetOrigCaller(owner)
bid = boards2.CreateBoard("test-board")
tid = boards2.CreateThread(bid, "Foo", "bar")
rid = boards2.CreateReply(bid, tid, 0, "First comment")
}

func main() {
rid2 := boards2.CreateReply(bid, tid, rid, comment)

// Ensure that returned ID is right
println(rid2 == 3)

// Render content must contain the sub-reply
content := boards2.Render(path)
println(strings.Contains(content, "\n> > "+comment+"\n"))
}

// Output:
// true
// true
Loading