Skip to content

Commit

Permalink
test: add missing filetest for reply flagging
Browse files Browse the repository at this point in the history
  • Loading branch information
jeronimoalbi committed Jan 31, 2025
1 parent b983f8f commit a847c73
Show file tree
Hide file tree
Showing 6 changed files with 165 additions and 0 deletions.
33 changes: 33 additions & 0 deletions examples/gno.land/r/nt/boards2/z_13_a_filetest.gno
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
package main

import (
"std"
"strings"

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

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

var (
bid boards2.BoardID
rid, tid 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.FlagReply(bid, tid, rid, "")

// Render content must contain a message about the hidden reply
content := boards2.Render("test-board/1/2")
println(strings.Contains(content, "\n> _Reply is hidden as it has been flagged as inappropriate_\n"))
}

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

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

func main() {
boards2.FlagReply(bid, 404, 1, "")
}

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

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

import (
"std"

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

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

var (
bid boards2.BoardID
rid, tid 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")
boards2.FlagReply(bid, tid, rid, "")
}

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

// Error:
// item flag count threshold exceeded: 1
33 changes: 33 additions & 0 deletions examples/gno.land/r/nt/boards2/z_13_f_filetest.gno
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
package main

import (
"std"

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

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

var (
bid boards2.BoardID
rid, tid 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.FlagReply(bid, tid, rid, "")
}

// Error:
// unauthorized

0 comments on commit a847c73

Please sign in to comment.