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 edit #3655

Open
wants to merge 4 commits into
base: devx/feature/boardsv2
Choose a base branch
from
Open
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
12 changes: 8 additions & 4 deletions examples/gno.land/r/nt/boards2/public.gno
Original file line number Diff line number Diff line change
Expand Up @@ -204,18 +204,22 @@ func EditThread(bid BoardID, threadID PostID, title, body string) {
thread.Update(title, body)
}

func EditReply(bid BoardID, threadID, replyID PostID, title, body string) {
func EditReply(bid BoardID, threadID, replyID PostID, body string) {
assertIsUserCall()

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

board := mustGetBoard(bid)
thread := mustGetThread(board, threadID)
reply := mustGetReply(thread, replyID)
caller := std.GetOrigCaller()
if caller != reply.GetCreator() {
assertReplyVisible(reply)

if std.GetOrigCaller() != reply.GetCreator() {
panic("only the reply creator is allowed to edit it")
}

reply.Update(title, body)
reply.Update("", body)
}

func InviteMember(bid BoardID, user std.Address, role Role) {
Expand Down
37 changes: 37 additions & 0 deletions examples/gno.land/r/nt/boards2/z_12_a_filetest.gno
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
package main

import (
"std"
"strings"

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

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

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, "body")
}

func main() {
boards2.EditReply(bid, tid, rid, body)

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

// Output:
// true
40 changes: 40 additions & 0 deletions examples/gno.land/r/nt/boards2/z_12_b_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
body = "Test reply"
path = "test-board/1/2"
)

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

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

// Create a reply and a sub reply
parentRID := boards2.CreateReply(bid, tid, 0, "Parent")
rid = boards2.CreateReply(bid, tid, parentRID, "Child")
}

func main() {
boards2.EditReply(bid, tid, rid, body)

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

// Output:
// true
20 changes: 20 additions & 0 deletions examples/gno.land/r/nt/boards2/z_12_c_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.EditReply(404, 1, 0, "body")
}

// Error:
// board does not exist with ID: 404
23 changes: 23 additions & 0 deletions examples/gno.land/r/nt/boards2/z_12_d_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("test-board")
}

func main() {
boards2.EditReply(bid, 404, 0, "body")
}

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

// Error:
// reply does not exist with ID: 404
32 changes: 32 additions & 0 deletions examples/gno.land/r/nt/boards2/z_12_f_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, 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, "body")
std.TestSetOrigCaller(user)
}

func main() {
boards2.EditReply(bid, tid, rid, "new body")
}

// Error:
// only the reply creator is allowed to edit it
34 changes: 34 additions & 0 deletions examples/gno.land/r/nt/boards2/z_12_g_filetest.gno
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
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, 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, "body")

// Flag the reply so it's hidden
boards2.FlagReply(bid, tid, rid, "reason")
}

func main() {
boards2.EditReply(bid, tid, rid, "body")
}

// Error:
// reply with ID: 2 was hidden
28 changes: 28 additions & 0 deletions examples/gno.land/r/nt/boards2/z_12_h_filetest.gno
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
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("test-board")
tid = boards2.CreateThread(bid, "Foo", "bar")
rid = boards2.CreateReply(bid, tid, 0, "body")
}

func main() {
boards2.EditReply(bid, tid, rid, "")
}

// Error:
// body is empty
Loading