(t *testing.T)
| 8256 | } |
| 8257 | |
| 8258 | func TestRegenerateChatTitle(t *testing.T) { |
| 8259 | t.Parallel() |
| 8260 | |
| 8261 | t.Run("ChatNotFound", func(t *testing.T) { |
| 8262 | t.Parallel() |
| 8263 | |
| 8264 | ctx := testutil.Context(t, testutil.WaitLong) |
| 8265 | client := newChatClient(t) |
| 8266 | _ = coderdtest.CreateFirstUser(t, client.Client) |
| 8267 | |
| 8268 | _, err := client.RegenerateChatTitle(ctx, uuid.New()) |
| 8269 | requireSDKError(t, err, http.StatusNotFound) |
| 8270 | }) |
| 8271 | |
| 8272 | t.Run("UpdateDenied", func(t *testing.T) { |
| 8273 | t.Parallel() |
| 8274 | |
| 8275 | ctx := testutil.Context(t, testutil.WaitLong) |
| 8276 | clientRaw, db := coderdtest.NewWithDatabase(t, &coderdtest.Options{ |
| 8277 | Authorizer: &coderdtest.FakeAuthorizer{ |
| 8278 | ConditionalReturn: func(_ context.Context, _ rbac.Subject, action policy.Action, object rbac.Object) error { |
| 8279 | if action == policy.ActionUpdate && object.Type == rbac.ResourceChat.Type { |
| 8280 | return xerrors.New("denied") |
| 8281 | } |
| 8282 | return nil |
| 8283 | }, |
| 8284 | }, |
| 8285 | DeploymentValues: chatDeploymentValues(t), |
| 8286 | }) |
| 8287 | client := codersdk.NewExperimentalClient(clientRaw) |
| 8288 | user := coderdtest.CreateFirstUser(t, client.Client) |
| 8289 | modelConfig := createChatModelConfig(t, client) |
| 8290 | |
| 8291 | chat := dbgen.Chat(t, db, database.Chat{ |
| 8292 | OrganizationID: user.OrganizationID, |
| 8293 | OwnerID: user.UserID, |
| 8294 | LastModelConfigID: modelConfig.ID, |
| 8295 | Title: "chat with update denied", |
| 8296 | }) |
| 8297 | |
| 8298 | _, err := client.RegenerateChatTitle(ctx, chat.ID) |
| 8299 | requireSDKError(t, err, http.StatusNotFound) |
| 8300 | }) |
| 8301 | |
| 8302 | t.Run("NotFoundForDifferentUser", func(t *testing.T) { |
| 8303 | t.Parallel() |
| 8304 | |
| 8305 | ctx := testutil.Context(t, testutil.WaitLong) |
| 8306 | client := newChatClient(t) |
| 8307 | firstUser := coderdtest.CreateFirstUser(t, client.Client) |
| 8308 | _ = createChatModelConfig(t, client) |
| 8309 | |
| 8310 | createdChat, err := client.CreateChat(ctx, codersdk.CreateChatRequest{ |
| 8311 | OrganizationID: firstUser.OrganizationID, |
| 8312 | Content: []codersdk.ChatInputPart{ |
| 8313 | { |
| 8314 | Type: codersdk.ChatInputPartTypeText, |
| 8315 | Text: "private chat", |
nothing calls this directly
no test coverage detected