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

Function TestArchiveChat

coderd/exp_chats_test.go:5574–5814  ·  view source on GitHub ↗
(t *testing.T)

Source from the content-addressed store, hash-verified

5572}
5573
5574func TestArchiveChat(t *testing.T) {
5575 t.Parallel()
5576
5577 t.Run("Success", func(t *testing.T) {
5578 t.Parallel()
5579
5580 ctx := testutil.Context(t, testutil.WaitLong)
5581 mAudit := audit.NewMock()
5582 client := newChatClient(t, func(o *coderdtest.Options) {
5583 o.Auditor = mAudit
5584 })
5585 firstUser := coderdtest.CreateFirstUser(t, client.Client)
5586 _ = createChatModelConfig(t, client)
5587
5588 chatToArchive, err := client.CreateChat(ctx, codersdk.CreateChatRequest{
5589 OrganizationID: firstUser.OrganizationID,
5590 Content: []codersdk.ChatInputPart{
5591 {
5592 Type: codersdk.ChatInputPartTypeText,
5593 Text: "archive me",
5594 },
5595 },
5596 })
5597 require.NoError(t, err)
5598
5599 chatToKeep, err := client.CreateChat(ctx, codersdk.CreateChatRequest{
5600 OrganizationID: firstUser.OrganizationID,
5601 Content: []codersdk.ChatInputPart{
5602 {
5603 Type: codersdk.ChatInputPartTypeText,
5604 Text: "keep me",
5605 },
5606 },
5607 })
5608 require.NoError(t, err)
5609
5610 chatsBeforeArchive, err := client.ListChats(ctx, nil)
5611 require.NoError(t, err)
5612 require.Len(t, chatsBeforeArchive, 2)
5613
5614 err = client.UpdateChat(ctx, chatToArchive.ID, codersdk.UpdateChatRequest{Archived: ptr.Ref(true)})
5615 require.NoError(t, err)
5616
5617 // Default (no filter) returns only non-archived chats.
5618 allChats, err := client.ListChats(ctx, nil)
5619 require.NoError(t, err)
5620 require.Len(t, allChats, 1)
5621 require.Equal(t, chatToKeep.ID, allChats[0].ID)
5622
5623 // archived:false returns only non-archived chats.
5624 activeChats, err := client.ListChats(ctx, &codersdk.ListChatsOptions{
5625 Query: "archived:false",
5626 })
5627 require.NoError(t, err)
5628 require.Len(t, activeChats, 1)
5629 require.Equal(t, chatToKeep.ID, activeChats[0].ID)
5630 require.False(t, activeChats[0].Archived)
5631

Callers

nothing calls this directly

Calls 15

ContextFunction · 0.92
NewMockFunction · 0.92
CreateFirstUserFunction · 0.92
RefFunction · 0.92
ChatFunction · 0.92
AsSystemRestrictedFunction · 0.92
requireSDKErrorFunction · 0.85
ListChatsMethod · 0.80
newChatClientFunction · 0.70
createChatModelConfigFunction · 0.70
RunMethod · 0.65

Tested by

no test coverage detected