Skip to content

Commit

Permalink
test(boards2): add missing filetests for member invite (#3632)
Browse files Browse the repository at this point in the history
Add missing filetests for `InviteMember()` function.

Related to #3623

This covers all tests for the function:
- Invite to realm success
- Fail when admin invites a new realm owner
- Success when admin invites a new realm admin
- Fail w/ invalid invite role
- Invite to board success
- Fail w/ existing user
- Fail for non member (unauthorized)
  • Loading branch information
jeronimoalbi authored Jan 30, 2025
1 parent 33fb889 commit 90a3c4e
Show file tree
Hide file tree
Showing 7 changed files with 121 additions and 14 deletions.
13 changes: 8 additions & 5 deletions examples/gno.land/r/nt/boards2/z_1_a_filetest.gno
Original file line number Diff line number Diff line change
Expand Up @@ -8,18 +8,21 @@ import (

const (
owner = std.Address("g1jg8mtutu9khhfwc4nxmuhcpftf0pajdhfvsqf5") // @test1
admin = std.Address("g1us8428u2a5satrlxzagqqa5m6vmuze025anjlj") // @test2
bid = boards2.BoardID(0) // Operate on realm DAO members instead of individual boards
user = std.Address("g1us8428u2a5satrlxzagqqa5m6vmuze025anjlj") // @test2
bid = boards2.BoardID(0) // Operate on realm DAO instead of individual boards
role = boards2.RoleOwner
)

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

func main() {
boards2.InviteMember(bid, admin, boards2.RoleAdmin)
println("ok")
boards2.InviteMember(bid, user, role)

// Check that user is invited
println(boards2.HasMemberRole(bid, user, role))
}

// Output:
// ok
// true
6 changes: 3 additions & 3 deletions examples/gno.land/r/nt/boards2/z_1_b_filetest.gno
Original file line number Diff line number Diff line change
Expand Up @@ -10,15 +10,15 @@ const (
owner = std.Address("g1jg8mtutu9khhfwc4nxmuhcpftf0pajdhfvsqf5") // @test1
admin = std.Address("g1us8428u2a5satrlxzagqqa5m6vmuze025anjlj") // @test2
user = std.Address("g1w4ek2u33ta047h6lta047h6lta047h6ldvdwpn")
bid = boards2.BoardID(0) // Operate on realm DAO members instead of individual boards
bid = boards2.BoardID(0) // Operate on realm DAO instead of individual boards
)

func init() {
// Add an admin user
// Add an admin member
std.TestSetOrigCaller(owner)
boards2.InviteMember(bid, admin, boards2.RoleAdmin)

// Next call will be done by the admin user
// Next call will be done by the admin member
std.TestSetOrigCaller(admin)
}

Expand Down
15 changes: 9 additions & 6 deletions examples/gno.land/r/nt/boards2/z_1_c_filetest.gno
Original file line number Diff line number Diff line change
Expand Up @@ -10,22 +10,25 @@ const (
owner = std.Address("g1jg8mtutu9khhfwc4nxmuhcpftf0pajdhfvsqf5") // @test1
admin = std.Address("g1us8428u2a5satrlxzagqqa5m6vmuze025anjlj") // @test2
user = std.Address("g1w4ek2u33ta047h6lta047h6lta047h6ldvdwpn")
bid = boards2.BoardID(0) // Operate on realm DAO members instead of individual boards
bid = boards2.BoardID(0) // Operate on realm DAO instead of individual boards
role = boards2.RoleAdmin
)

func init() {
// Add an admin user
// Add an admin member
std.TestSetOrigCaller(owner)
boards2.InviteMember(bid, admin, boards2.RoleAdmin)

// Next call will be done by the admin user
// Next call will be done by the admin member
std.TestSetOrigCaller(admin)
}

func main() {
boards2.InviteMember(bid, user, boards2.RoleAdmin)
println("ok")
boards2.InviteMember(bid, user, role)

// Check that user is invited
println(boards2.HasMemberRole(bid, user, role))
}

// Output:
// ok
// true
23 changes: 23 additions & 0 deletions examples/gno.land/r/nt/boards2/z_1_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
user = std.Address("g1us8428u2a5satrlxzagqqa5m6vmuze025anjlj") // @test2
)

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

func main() {
boards2.InviteMember(0, user, boards2.Role("foobar")) // Operate on realm DAO instead of individual boards
}

// Error:
// invalid role: foobar
32 changes: 32 additions & 0 deletions examples/gno.land/r/nt/boards2/z_1_e_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
role = boards2.RoleOwner
)

var bid boards2.BoardID

func init() {
std.TestSetOrigCaller(owner)
bid = boards2.CreateBoard("foo123") // Operate on board DAO members
}

func main() {
boards2.InviteMember(bid, user, role)

// Check that user is invited
println(boards2.HasMemberRole(0, user, role)) // Operate on realm DAO
println(boards2.HasMemberRole(bid, user, role))
}

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

import (
"std"

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

const (
owner = std.Address("g1jg8mtutu9khhfwc4nxmuhcpftf0pajdhfvsqf5") // @test1
user = std.Address("g1us8428u2a5satrlxzagqqa5m6vmuze025anjlj") // @test2
bid = boards2.BoardID(0) // Operate on realm DAO instead of individual boards
role = boards2.RoleOwner
)

func init() {
std.TestSetOrigCaller(owner)
boards2.InviteMember(bid, user, role)
}

func main() {
boards2.InviteMember(bid, user, role)
}

// Error:
// user already exists
20 changes: 20 additions & 0 deletions examples/gno.land/r/nt/boards2/z_1_g_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("g1us8428u2a5satrlxzagqqa5m6vmuze025anjlj") // @test2

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

func main() {
boards2.InviteMember(0, "g1w4ek2u33ta047h6lta047h6lta047h6ldvdwpn", boards2.RoleGuest)
}

// Error:
// unauthorized

0 comments on commit 90a3c4e

Please sign in to comment.