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

Function TestUpdateUserProfile

coderd/users_test.go:1157–1336  ·  view source on GitHub ↗
(t *testing.T)

Source from the content-addressed store, hash-verified

1155}
1156
1157func TestUpdateUserProfile(t *testing.T) {
1158 t.Parallel()
1159 t.Run("UserNotFound", func(t *testing.T) {
1160 t.Parallel()
1161 client := coderdtest.New(t, nil)
1162 coderdtest.CreateFirstUser(t, client)
1163
1164 ctx, cancel := context.WithTimeout(context.Background(), testutil.WaitLong)
1165 defer cancel()
1166
1167 _, err := client.UpdateUserProfile(ctx, uuid.New().String(), codersdk.UpdateUserProfileRequest{
1168 Username: "newusername",
1169 })
1170 var apiErr *codersdk.Error
1171 require.ErrorAs(t, err, &apiErr)
1172 // Right now, we are raising a BAD request error because we don't support a
1173 // user accessing other users info
1174 require.Equal(t, http.StatusNotFound, apiErr.StatusCode())
1175 })
1176
1177 t.Run("ConflictingUsername", func(t *testing.T) {
1178 t.Parallel()
1179 client := coderdtest.New(t, nil)
1180 user := coderdtest.CreateFirstUser(t, client)
1181
1182 ctx, cancel := context.WithTimeout(context.Background(), testutil.WaitLong)
1183 defer cancel()
1184
1185 existentUser, err := client.CreateUserWithOrgs(ctx, codersdk.CreateUserRequestWithOrgs{
1186 Email: "bruno@coder.com",
1187 Username: "bruno",
1188 Password: "SomeSecurePassword!",
1189 OrganizationIDs: []uuid.UUID{user.OrganizationID},
1190 })
1191 require.NoError(t, err)
1192 _, err = client.UpdateUserProfile(ctx, codersdk.Me, codersdk.UpdateUserProfileRequest{
1193 Username: existentUser.Username,
1194 })
1195 var apiErr *codersdk.Error
1196 require.ErrorAs(t, err, &apiErr)
1197 require.Equal(t, http.StatusConflict, apiErr.StatusCode())
1198 })
1199
1200 t.Run("UpdateSelf", func(t *testing.T) {
1201 t.Parallel()
1202 auditor := audit.NewMock()
1203 client := coderdtest.New(t, &coderdtest.Options{Auditor: auditor})
1204 numLogs := len(auditor.AuditLogs())
1205
1206 coderdtest.CreateFirstUser(t, client)
1207 numLogs++ // add an audit log for login
1208
1209 ctx, cancel := context.WithTimeout(context.Background(), testutil.WaitLong)
1210 defer cancel()
1211
1212 me, err := client.User(ctx, codersdk.Me)
1213 require.NoError(t, err)
1214

Callers

nothing calls this directly

Calls 15

StatusCodeMethod · 0.95
NewFunction · 0.92
CreateFirstUserFunction · 0.92
NewMockFunction · 0.92
CreateAnotherUserFunction · 0.92
RandomNameFunction · 0.92
RandomUsernameFunction · 0.92
CreateUserWithOrgsMethod · 0.80
RunMethod · 0.65
UpdateUserProfileMethod · 0.65
NewMethod · 0.65
UserMethod · 0.65

Tested by

no test coverage detected