8
8
"github.com/coder/coder/coderd/database"
9
9
"github.com/coder/coder/coderd/database/dbgen"
10
10
"github.com/coder/coder/coderd/rbac"
11
+ "github.com/coder/coder/coderd/util/slice"
11
12
)
12
13
13
14
func (suite * MethodTestSuite ) TestGroup () {
@@ -57,6 +58,15 @@ func (suite *MethodTestSuite) TestGroup() {
57
58
return methodCase (inputs (o .ID ), asserts (rbac .ResourceGroup .InOrg (o .ID ), rbac .ActionCreate ))
58
59
})
59
60
})
61
+ suite .Run ("InsertGroup" , func () {
62
+ suite .RunMethodTest (func (t * testing.T , db database.Store ) MethodCase {
63
+ o := dbgen .Organization (t , db , database.Organization {})
64
+ return methodCase (inputs (database.InsertGroupParams {
65
+ OrganizationID : o .ID ,
66
+ Name : "test" ,
67
+ }), asserts (rbac .ResourceGroup .InOrg (o .ID ), rbac .ActionCreate ))
68
+ })
69
+ })
60
70
suite .Run ("InsertGroupMember" , func () {
61
71
suite .RunMethodTest (func (t * testing.T , db database.Store ) MethodCase {
62
72
g := dbgen .Group (t , db , database.Group {})
@@ -66,6 +76,34 @@ func (suite *MethodTestSuite) TestGroup() {
66
76
}), asserts (g , rbac .ActionUpdate ))
67
77
})
68
78
})
79
+ suite .Run ("InsertUserGroupsByName" , func () {
80
+ suite .RunMethodTest (func (t * testing.T , db database.Store ) MethodCase {
81
+ o := dbgen .Organization (t , db , database.Organization {})
82
+ u1 := dbgen .User (t , db , database.User {})
83
+ g1 := dbgen .Group (t , db , database.Group {OrganizationID : o .ID })
84
+ g2 := dbgen .Group (t , db , database.Group {OrganizationID : o .ID })
85
+ _ = dbgen .GroupMember (t , db , database.GroupMember {GroupID : g1 .ID , UserID : u1 .ID })
86
+ return methodCase (inputs (database.InsertUserGroupsByNameParams {
87
+ OrganizationID : o .ID ,
88
+ UserID : u1 .ID ,
89
+ GroupNames : slice .New (g1 .Name , g2 .Name ),
90
+ }), asserts (rbac .ResourceGroup .InOrg (o .ID ), rbac .ActionUpdate ))
91
+ })
92
+ })
93
+ suite .Run ("DeleteGroupMembersByOrgAndUser" , func () {
94
+ suite .RunMethodTest (func (t * testing.T , db database.Store ) MethodCase {
95
+ o := dbgen .Organization (t , db , database.Organization {})
96
+ u1 := dbgen .User (t , db , database.User {})
97
+ g1 := dbgen .Group (t , db , database.Group {OrganizationID : o .ID })
98
+ g2 := dbgen .Group (t , db , database.Group {OrganizationID : o .ID })
99
+ _ = dbgen .GroupMember (t , db , database.GroupMember {GroupID : g1 .ID , UserID : u1 .ID })
100
+ _ = dbgen .GroupMember (t , db , database.GroupMember {GroupID : g2 .ID , UserID : u1 .ID })
101
+ return methodCase (inputs (database.DeleteGroupMembersByOrgAndUserParams {
102
+ OrganizationID : o .ID ,
103
+ UserID : u1 .ID ,
104
+ }), asserts (rbac .ResourceGroup .InOrg (o .ID ), rbac .ActionUpdate ))
105
+ })
106
+ })
69
107
suite .Run ("UpdateGroupByID" , func () {
70
108
suite .RunMethodTest (func (t * testing.T , db database.Store ) MethodCase {
71
109
g := dbgen .Group (t , db , database.Group {})
0 commit comments