-
Notifications
You must be signed in to change notification settings - Fork 389
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
test(boards2): add missing filetests for thread deletion (#3645)
Add missing filetests for `DeleteThread()` function. Related to #3623 This covers all tests for the function: - Successfully delete a thread - Fail because board is not found - Fail because thread is not found - Fail because user has no permission to delete a thread - Successfully delete a thread using a user with permission to delete
- Loading branch information
1 parent
d7dcd92
commit d7740a4
Showing
6 changed files
with
148 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 | ||
title = "Test Thread" | ||
body = "Test body" | ||
) | ||
|
||
var ( | ||
bid boards2.BoardID | ||
pid boards2.PostID | ||
) | ||
|
||
func init() { | ||
std.TestSetOrigCaller(owner) | ||
bid = boards2.CreateBoard("test-board") | ||
pid = boards2.CreateThread(bid, title, body) | ||
} | ||
|
||
func main() { | ||
boards2.DeleteThread(bid, pid) | ||
|
||
// Ensure thread doesn't exist | ||
println(boards2.Render("test-board/1")) | ||
} | ||
|
||
// Output: | ||
// Thread does not exist with ID: 1 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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.DeleteThread(404, 1) | ||
} | ||
|
||
// Error: | ||
// board does not exist with ID: 404 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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.DeleteThread(bid, 404) | ||
} | ||
|
||
// Error: | ||
// thread does not exist with ID: 404 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 | ||
pid boards2.PostID | ||
) | ||
|
||
func init() { | ||
std.TestSetOrigCaller(owner) | ||
bid = boards2.CreateBoard("test-board") | ||
pid = boards2.CreateThread(bid, "Foo", "bar") | ||
|
||
// Call using a user that has not permission to delete threads | ||
std.TestSetOrigCaller(user) | ||
} | ||
|
||
func main() { | ||
boards2.DeleteThread(bid, pid) | ||
} | ||
|
||
// Error: | ||
// unauthorized |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,37 @@ | ||
package main | ||
|
||
import ( | ||
"std" | ||
|
||
"gno.land/r/nt/boards2" | ||
) | ||
|
||
const ( | ||
owner = std.Address("g1jg8mtutu9khhfwc4nxmuhcpftf0pajdhfvsqf5") // @test1 | ||
member = std.Address("g1us8428u2a5satrlxzagqqa5m6vmuze025anjlj") // @test2 | ||
) | ||
|
||
var ( | ||
bid boards2.BoardID | ||
pid boards2.PostID | ||
) | ||
|
||
func init() { | ||
std.TestSetOrigCaller(owner) | ||
bid = boards2.CreateBoard("test-board") | ||
pid = boards2.CreateThread(bid, "Foo", "bar") | ||
|
||
// Invite a member using a role with permission to delete threads | ||
boards2.InviteMember(bid, member, boards2.RoleAdmin) | ||
std.TestSetOrigCaller(member) | ||
} | ||
|
||
func main() { | ||
boards2.DeleteThread(bid, pid) | ||
|
||
// Ensure thread doesn't exist | ||
println(boards2.Render("test-board/1")) | ||
} | ||
|
||
// Output: | ||
// Thread does not exist with ID: 1 |