(t *testing.T)
| 8525 | } |
| 8526 | |
| 8527 | func TestProposeChatTitle(t *testing.T) { |
| 8528 | t.Parallel() |
| 8529 | |
| 8530 | t.Run("ChatNotFound", func(t *testing.T) { |
| 8531 | t.Parallel() |
| 8532 | |
| 8533 | ctx := testutil.Context(t, testutil.WaitLong) |
| 8534 | client := newChatClient(t) |
| 8535 | _ = coderdtest.CreateFirstUser(t, client.Client) |
| 8536 | |
| 8537 | _, err := client.ProposeChatTitle(ctx, uuid.New()) |
| 8538 | requireSDKError(t, err, http.StatusNotFound) |
| 8539 | }) |
| 8540 | |
| 8541 | t.Run("UpdateDenied", func(t *testing.T) { |
| 8542 | t.Parallel() |
| 8543 | |
| 8544 | ctx := testutil.Context(t, testutil.WaitLong) |
| 8545 | clientRaw, db := coderdtest.NewWithDatabase(t, &coderdtest.Options{ |
| 8546 | Authorizer: &coderdtest.FakeAuthorizer{ |
| 8547 | ConditionalReturn: func(_ context.Context, _ rbac.Subject, action policy.Action, object rbac.Object) error { |
| 8548 | if action == policy.ActionUpdate && object.Type == rbac.ResourceChat.Type { |
| 8549 | return xerrors.New("denied") |
| 8550 | } |
| 8551 | return nil |
| 8552 | }, |
| 8553 | }, |
| 8554 | DeploymentValues: chatDeploymentValues(t), |
| 8555 | }) |
| 8556 | client := codersdk.NewExperimentalClient(clientRaw) |
| 8557 | user := coderdtest.CreateFirstUser(t, client.Client) |
| 8558 | modelConfig := createChatModelConfig(t, client) |
| 8559 | |
| 8560 | chat := dbgen.Chat(t, db, database.Chat{ |
| 8561 | OrganizationID: user.OrganizationID, |
| 8562 | OwnerID: user.UserID, |
| 8563 | LastModelConfigID: modelConfig.ID, |
| 8564 | Title: "chat with update denied", |
| 8565 | }) |
| 8566 | |
| 8567 | _, err := client.ProposeChatTitle(ctx, chat.ID) |
| 8568 | |
| 8569 | requireSDKError(t, err, http.StatusNotFound) |
| 8570 | }) |
| 8571 | |
| 8572 | t.Run("DoesNotPersistTitleOrBumpUpdatedAt", func(t *testing.T) { |
| 8573 | t.Parallel() |
| 8574 | |
| 8575 | ctx := testutil.Context(t, testutil.WaitLong) |
| 8576 | client, db, api := newChatClientWithAPIAndDatabase(t) |
| 8577 | firstUser := coderdtest.CreateFirstUser(t, client.Client) |
| 8578 | _ = createChatModelConfigWithTitleFailure(t, client) |
| 8579 | |
| 8580 | chat, err := client.CreateChat(ctx, codersdk.CreateChatRequest{ |
| 8581 | OrganizationID: firstUser.OrganizationID, |
| 8582 | Content: []codersdk.ChatInputPart{ |
| 8583 | {Type: codersdk.ChatInputPartTypeText, Text: "test chat"}, |
| 8584 | }, |
nothing calls this directly
no test coverage detected