Skip to content

Commit

Permalink
test: add missing filetest for reply creation
Browse files Browse the repository at this point in the history
  • Loading branch information
jeronimoalbi committed Jan 31, 2025
1 parent 5bbb46b commit 83d66eb
Show file tree
Hide file tree
Showing 8 changed files with 213 additions and 0 deletions.
3 changes: 3 additions & 0 deletions 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 Down
40 changes: 40 additions & 0 deletions examples/gno.land/r/nt/boards2/z_2_a_filetest.gno
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
package main

import (
"std"
"strings"

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

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() {
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"))
}

// Output:
// true
// true
20 changes: 20 additions & 0 deletions examples/gno.land/r/nt/boards2/z_2_b_filetest.gno
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
package main

import (
"std"

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

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

func init() {
std.TestSetOrigCaller(owner)
}

func main() {
boards2.CreateReply(404, 1, 0, "comment")
}

// Error:
// board does not exist with ID: 404
23 changes: 23 additions & 0 deletions examples/gno.land/r/nt/boards2/z_2_c_filetest.gno
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
package main

import (
"std"

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

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

var bid boards2.BoardID

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

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

// Error:
// thread does not exist with ID: 404
27 changes: 27 additions & 0 deletions examples/gno.land/r/nt/boards2/z_2_d_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, 404, "comment")
}

// Error:
// reply does not exist with ID: 404
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

0 comments on commit 83d66eb

Please sign in to comment.