MCPcopy Index your code
hub / github.com/coder/coder / TestUpdateOrganizationRoles

Function TestUpdateOrganizationRoles

enterprise/cli/organization_test.go:192–291  ·  view source on GitHub ↗
(t *testing.T)

Source from the content-addressed store, hash-verified

190}
191
192func TestUpdateOrganizationRoles(t *testing.T) {
193 t.Parallel()
194
195 t.Run("JSON", func(t *testing.T) {
196 t.Parallel()
197
198 ownerClient, db, owner := coderdenttest.NewWithDatabase(t, &coderdenttest.Options{
199 LicenseOptions: &coderdenttest.LicenseOptions{
200 Features: license.Features{
201 codersdk.FeatureCustomRoles: 1,
202 },
203 },
204 })
205 client, _ := coderdtest.CreateAnotherUser(t, ownerClient, owner.OrganizationID, rbac.RoleOwner())
206
207 // Create a role in the DB with no permissions
208 const expectedRole = "test-role"
209 dbgen.CustomRole(t, db, database.CustomRole{
210 Name: expectedRole,
211 DisplayName: "Expected",
212 SitePermissions: nil,
213 OrgPermissions: nil,
214 UserPermissions: nil,
215 OrganizationID: uuid.NullUUID{
216 UUID: owner.OrganizationID,
217 Valid: true,
218 },
219 })
220
221 // Update the new role via JSON
222 ctx := testutil.Context(t, testutil.WaitMedium)
223 inv, root := clitest.New(t, "organization", "roles", "update", "--stdin")
224 inv.Stdin = bytes.NewBufferString(fmt.Sprintf(`{
225 "name": "test-role",
226 "organization_id": "%s",
227 "display_name": "",
228 "site_permissions": [],
229 "organization_permissions": [
230 {
231 "resource_type": "workspace",
232 "action": "read"
233 }
234 ],
235 "user_permissions": [],
236 "assignable": false,
237 "built_in": false
238 }`, owner.OrganizationID.String()))
239
240 //nolint:gocritic // only owners can edit roles
241 clitest.SetupConfig(t, client, root)
242
243 buf := new(bytes.Buffer)
244 inv.Stdout = buf
245 err := inv.WithContext(ctx).Run()
246 require.NoError(t, err)
247 require.Contains(t, buf.String(), "test-role")
248 require.Contains(t, buf.String(), "1 permissions")
249 })

Callers

nothing calls this directly

Calls 12

NewWithDatabaseFunction · 0.92
CreateAnotherUserFunction · 0.92
RoleOwnerFunction · 0.92
CustomRoleFunction · 0.92
ContextFunction · 0.92
NewFunction · 0.92
SetupConfigFunction · 0.92
WithContextMethod · 0.80
RunMethod · 0.65
StringMethod · 0.45
ContainsMethod · 0.45
ErrorMethod · 0.45

Tested by

no test coverage detected