(t *testing.T)
| 190 | } |
| 191 | |
| 192 | func 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 | }) |
nothing calls this directly
no test coverage detected