@@ -8,14 +8,17 @@ import (
8
8
9
9
"github.com/go-chi/chi/v5"
10
10
"github.com/google/uuid"
11
+ "github.com/stretchr/testify/assert"
11
12
"github.com/stretchr/testify/require"
12
13
13
14
"github.com/coder/coder/v2/coderd/database"
14
15
"github.com/coder/coder/v2/coderd/database/dbgen"
15
16
"github.com/coder/coder/v2/coderd/database/dbmem"
16
17
"github.com/coder/coder/v2/coderd/database/dbtime"
17
18
"github.com/coder/coder/v2/coderd/httpmw"
19
+ "github.com/coder/coder/v2/coderd/rbac"
18
20
"github.com/coder/coder/v2/codersdk"
21
+ "github.com/coder/coder/v2/testutil"
19
22
)
20
23
21
24
func TestOrganizationParam (t * testing.T ) {
@@ -139,6 +142,7 @@ func TestOrganizationParam(t *testing.T) {
139
142
t .Run ("Success" , func (t * testing.T ) {
140
143
t .Parallel ()
141
144
var (
145
+ ctx = testutil .Context (t , testutil .WaitShort )
142
146
db = dbmem .New ()
143
147
rw = httptest .NewRecorder ()
144
148
r , user = setupAuthentication (db )
@@ -148,7 +152,14 @@ func TestOrganizationParam(t *testing.T) {
148
152
_ = dbgen .OrganizationMember (t , db , database.OrganizationMember {
149
153
OrganizationID : organization .ID ,
150
154
UserID : user .ID ,
155
+ Roles : []string {rbac .RoleOrgMember (organization .ID )},
151
156
})
157
+ _ , err := db .UpdateUserRoles (ctx , database.UpdateUserRolesParams {
158
+ ID : user .ID ,
159
+ GrantedRoles : []string {rbac .RoleTemplateAdmin ()},
160
+ })
161
+ require .NoError (t , err )
162
+
152
163
chi .RouteContext (r .Context ()).URLParams .Add ("organization" , organization .ID .String ())
153
164
chi .RouteContext (r .Context ()).URLParams .Add ("user" , user .ID .String ())
154
165
rtr .Use (
@@ -161,9 +172,27 @@ func TestOrganizationParam(t *testing.T) {
161
172
httpmw .ExtractOrganizationMemberParam (db ),
162
173
)
163
174
rtr .Get ("/" , func (rw http.ResponseWriter , r * http.Request ) {
164
- _ = httpmw .OrganizationParam (r )
165
- _ = httpmw .OrganizationMemberParam (r )
175
+ org := httpmw .OrganizationParam (r )
176
+ assert .NotZero (t , org )
177
+ assert .NotZero (t , org .CreatedAt )
178
+ // assert.NotZero(t, org.Description) // not supported
179
+ assert .NotZero (t , org .ID )
180
+ assert .NotEmpty (t , org .Name )
181
+ orgMem := httpmw .OrganizationMemberParam (r )
166
182
rw .WriteHeader (http .StatusOK )
183
+ assert .NotZero (t , orgMem )
184
+ assert .NotZero (t , orgMem .CreatedAt )
185
+ assert .NotZero (t , orgMem .UpdatedAt )
186
+ assert .Equal (t , org .ID , orgMem .OrganizationID )
187
+ assert .Equal (t , user .ID , orgMem .UserID )
188
+ assert .Equal (t , user .Username , orgMem .Username )
189
+ assert .Equal (t , user .AvatarURL , orgMem .AvatarURL )
190
+ assert .NotEmpty (t , orgMem .Roles )
191
+ assert .NotZero (t , orgMem .OrganizationMember )
192
+ assert .NotEmpty (t , orgMem .OrganizationMember .CreatedAt )
193
+ assert .NotEmpty (t , orgMem .OrganizationMember .UpdatedAt )
194
+ assert .NotEmpty (t , orgMem .OrganizationMember .UserID )
195
+ assert .NotEmpty (t , orgMem .OrganizationMember .Roles )
167
196
})
168
197
rtr .ServeHTTP (rw , r )
169
198
res := rw .Result ()
0 commit comments