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

Function TestPatchGroupSyncSettings

enterprise/coderd/idpsync_test.go:85–141  ·  view source on GitHub ↗
(t *testing.T)

Source from the content-addressed store, hash-verified

83}
84
85func TestPatchGroupSyncSettings(t *testing.T) {
86 t.Parallel()
87
88 t.Run("OK", func(t *testing.T) {
89 t.Parallel()
90
91 owner, user := coderdenttest.New(t, &coderdenttest.Options{
92 LicenseOptions: &coderdenttest.LicenseOptions{
93 Features: license.Features{
94 codersdk.FeatureCustomRoles: 1,
95 codersdk.FeatureMultipleOrganizations: 1,
96 },
97 },
98 })
99
100 orgAdmin, _ := coderdtest.CreateAnotherUser(t, owner, user.OrganizationID, rbac.ScopedRoleOrgAdmin(user.OrganizationID))
101
102 // Test as org admin
103 ctx := testutil.Context(t, testutil.WaitShort)
104 settings, err := orgAdmin.PatchGroupIDPSyncSettings(ctx, user.OrganizationID.String(), codersdk.GroupSyncSettings{
105 Field: "august",
106 })
107 require.NoError(t, err)
108 require.Equal(t, "august", settings.Field)
109
110 fetchedSettings, err := orgAdmin.GroupIDPSyncSettings(ctx, user.OrganizationID.String())
111 require.NoError(t, err)
112 require.Equal(t, "august", fetchedSettings.Field)
113 })
114
115 t.Run("NotAuthorized", func(t *testing.T) {
116 t.Parallel()
117
118 owner, user := coderdenttest.New(t, &coderdenttest.Options{
119 LicenseOptions: &coderdenttest.LicenseOptions{
120 Features: license.Features{
121 codersdk.FeatureCustomRoles: 1,
122 codersdk.FeatureMultipleOrganizations: 1,
123 },
124 },
125 })
126
127 member, _ := coderdtest.CreateAnotherUser(t, owner, user.OrganizationID)
128
129 ctx := testutil.Context(t, testutil.WaitShort)
130 _, err := member.PatchGroupIDPSyncSettings(ctx, user.OrganizationID.String(), codersdk.GroupSyncSettings{
131 Field: "august",
132 })
133 var apiError *codersdk.Error
134 require.ErrorAs(t, err, &apiError)
135 require.Equal(t, http.StatusForbidden, apiError.StatusCode())
136
137 _, err = member.GroupIDPSyncSettings(ctx, user.OrganizationID.String())
138 require.ErrorAs(t, err, &apiError)
139 require.Equal(t, http.StatusForbidden, apiError.StatusCode())
140 })
141}
142

Callers

nothing calls this directly

Calls 10

StatusCodeMethod · 0.95
NewFunction · 0.92
CreateAnotherUserFunction · 0.92
ScopedRoleOrgAdminFunction · 0.92
ContextFunction · 0.92
GroupIDPSyncSettingsMethod · 0.80
RunMethod · 0.65
StringMethod · 0.45
EqualMethod · 0.45

Tested by

no test coverage detected