(t *testing.T)
| 221 | } |
| 222 | |
| 223 | func TestPatchGroupSyncMapping(t *testing.T) { |
| 224 | t.Parallel() |
| 225 | |
| 226 | t.Run("OK", func(t *testing.T) { |
| 227 | t.Parallel() |
| 228 | |
| 229 | owner, user := coderdenttest.New(t, &coderdenttest.Options{ |
| 230 | LicenseOptions: &coderdenttest.LicenseOptions{ |
| 231 | Features: license.Features{ |
| 232 | codersdk.FeatureCustomRoles: 1, |
| 233 | codersdk.FeatureMultipleOrganizations: 1, |
| 234 | }, |
| 235 | }, |
| 236 | }) |
| 237 | |
| 238 | orgID := user.OrganizationID |
| 239 | orgAdmin, _ := coderdtest.CreateAnotherUser(t, owner, orgID, rbac.ScopedRoleOrgAdmin(user.OrganizationID)) |
| 240 | // These IDs are easier to visually diff if the test fails than truly random |
| 241 | // ones. |
| 242 | orgs := []uuid.UUID{ |
| 243 | uuid.MustParse("00000000-b8bd-46bb-bb6c-6c2b2c0dd2ea"), |
| 244 | uuid.MustParse("01000000-fbe8-464c-9429-fe01a03f3644"), |
| 245 | uuid.MustParse("02000000-0926-407b-9998-39af62e3d0c5"), |
| 246 | } |
| 247 | |
| 248 | ctx := testutil.Context(t, testutil.WaitShort) |
| 249 | _, err := orgAdmin.PatchGroupIDPSyncSettings(ctx, orgID.String(), codersdk.GroupSyncSettings{ |
| 250 | Field: "wibble", |
| 251 | RegexFilter: regexp.MustCompile("wib{2,}le"), |
| 252 | AutoCreateMissing: true, |
| 253 | Mapping: map[string][]uuid.UUID{"wobble": {orgs[0]}}, |
| 254 | }) |
| 255 | require.NoError(t, err) |
| 256 | |
| 257 | ctx = testutil.Context(t, testutil.WaitShort) |
| 258 | settings, err := orgAdmin.PatchGroupIDPSyncMapping(ctx, orgID.String(), codersdk.PatchGroupIDPSyncMappingRequest{ |
| 259 | Add: []codersdk.IDPSyncMapping[uuid.UUID]{ |
| 260 | {Given: "wibble", Gets: orgs[0]}, |
| 261 | {Given: "wobble", Gets: orgs[1]}, |
| 262 | {Given: "wobble", Gets: orgs[2]}, |
| 263 | }, |
| 264 | // Remove takes priority over Add, so "3" should not actually be added to wooble. |
| 265 | Remove: []codersdk.IDPSyncMapping[uuid.UUID]{ |
| 266 | {Given: "wobble", Gets: orgs[1]}, |
| 267 | }, |
| 268 | }) |
| 269 | |
| 270 | expected := map[string][]uuid.UUID{ |
| 271 | "wibble": {orgs[0]}, |
| 272 | "wobble": {orgs[0], orgs[2]}, |
| 273 | } |
| 274 | |
| 275 | require.NoError(t, err) |
| 276 | require.Equal(t, expected, settings.Mapping) |
| 277 | |
| 278 | fetchedSettings, err := orgAdmin.GroupIDPSyncSettings(ctx, orgID.String()) |
| 279 | require.NoError(t, err) |
| 280 | require.Equal(t, "wibble", fetchedSettings.Field) |
nothing calls this directly
no test coverage detected