Skip to content

Commit

Permalink
chore: In r/demo/boards, add tests for CreateRepost and related errors
Browse files Browse the repository at this point in the history
Signed-off-by: Jeff Thompson <jeff@thefirst.org>
  • Loading branch information
jefft0 committed Jan 12, 2024
1 parent 384b106 commit c1d72b3
Show file tree
Hide file tree
Showing 5 changed files with 143 additions and 0 deletions.
32 changes: 32 additions & 0 deletions examples/gno.land/r/demo/boards/z_12_a_filetest.gno
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
// PKGPATH: gno.land/r/boards_test
package boards_test

// SEND: 200000000ugnot

import (
"std"

"gno.land/p/demo/testutils"
"gno.land/r/demo/boards"
"gno.land/r/demo/users"
)

func main() {
users.Register("", "gnouser", "my profile")
// create a post via registered user
bid1 := boards.CreateBoard("test_board1")
pid := boards.CreateThread(bid1, "First Post (title)", "Body of the first post. (body)")
bid2 := boards.CreateBoard("test_board2")

// create a repost via anon user
test2 := testutils.TestAddress("test2")
std.TestSetOrigCaller(test2)
std.TestSetOrigSend(std.Coins{{"ugnot", 9000000}}, nil)

rid := boards.CreateRepost(bid1, pid, "", "Check this out", bid2)
println(rid)
println(boards.Render("test_board1"))
}

// Error:
// please register, otherwise minimum fee 100000000 is required if anonymous
24 changes: 24 additions & 0 deletions examples/gno.land/r/demo/boards/z_12_b_filetest.gno
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
// PKGPATH: gno.land/r/boards_test
package boards_test

// SEND: 200000000ugnot

import (
"gno.land/r/demo/boards"
"gno.land/r/demo/users"
)

func main() {
users.Register("", "gnouser", "my profile")
bid1 := boards.CreateBoard("test_board1")
pid := boards.CreateThread(bid1, "First Post (title)", "Body of the first post. (body)")
bid2 := boards.CreateBoard("test_board2")

// create a repost to a non-existing board
rid := boards.CreateRepost(5, pid, "", "Check this out", bid2)
println(rid)
println(boards.Render("test_board1"))
}

// Error:
// src board not exist
24 changes: 24 additions & 0 deletions examples/gno.land/r/demo/boards/z_12_c_filetest.gno
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
// PKGPATH: gno.land/r/boards_test
package boards_test

// SEND: 200000000ugnot

import (
"gno.land/r/demo/boards"
"gno.land/r/demo/users"
)

func main() {
users.Register("", "gnouser", "my profile")
bid1 := boards.CreateBoard("test_board1")
boards.CreateThread(bid1, "First Post (title)", "Body of the first post. (body)")
bid2 := boards.CreateBoard("test_board2")

// create a repost to a non-existing thread
rid := boards.CreateRepost(bid1, 5, "", "Check this out", bid2)
println(rid)
println(boards.Render("test_board1"))
}

// Error:
// thread not exist
24 changes: 24 additions & 0 deletions examples/gno.land/r/demo/boards/z_12_d_filetest.gno
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
// PKGPATH: gno.land/r/boards_test
package boards_test

// SEND: 200000000ugnot

import (
"gno.land/r/demo/boards"
"gno.land/r/demo/users"
)

func main() {
users.Register("", "gnouser", "my profile")
bid1 := boards.CreateBoard("test_board1")
pid := boards.CreateThread(bid1, "First Post (title)", "Body of the first post. (body)")
boards.CreateBoard("test_board2")

// create a repost to a non-existing destination board
rid := boards.CreateRepost(bid1, pid, "", "Check this out", 5)
println(rid)
println(boards.Render("test_board1"))
}

// Error:
// dst board not exist
39 changes: 39 additions & 0 deletions examples/gno.land/r/demo/boards/z_12_filetest.gno
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
// PKGPATH: gno.land/r/boards_test
package boards_test

// SEND: 200000000ugnot

import (
"gno.land/r/demo/boards"
"gno.land/r/demo/users"
)

var (
bid1 boards.BoardID
bid2 boards.BoardID
pid boards.PostID
)

func init() {
users.Register("", "gnouser", "my profile")

bid1 = boards.CreateBoard("test_board1")
pid = boards.CreateThread(bid1, "First Post (title)", "Body of the first post. (body)")
bid2 = boards.CreateBoard("test_board2")
}

func main() {
rid := boards.CreateRepost(bid1, pid, "", "Check this out", bid2)
println(rid)
println(boards.Render("test_board1"))
}

// Output:
// 1
// \[[post](/r/demo/boards?help&__func=CreateThread&bid=1&body.type=textarea)]
//
// ----------------------------------------
// ## [First Post (title)](/r/demo/boards:test_board1/1)
//
// Body of the first post. (body)
// \- [@gnouser](/r/demo/users:gnouser), [2009-02-13 11:31pm UTC](/r/demo/boards:test_board1/1) \[[x](/r/demo/boards?help&__func=DeletePost&bid=1&threadid=1&postid=1)] (0 replies) (1 reposts)

0 comments on commit c1d72b3

Please sign in to comment.