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

Function TestChatPinOrder

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

Source from the content-addressed store, hash-verified

6088}
6089
6090func TestChatPinOrder(t *testing.T) {
6091 t.Parallel()
6092
6093 createChat := func(ctx context.Context, t *testing.T, client *codersdk.ExperimentalClient, orgID uuid.UUID, title string) codersdk.Chat {
6094 t.Helper()
6095
6096 chat, err := client.CreateChat(ctx, codersdk.CreateChatRequest{
6097 OrganizationID: orgID,
6098 Content: []codersdk.ChatInputPart{
6099 {
6100 Type: codersdk.ChatInputPartTypeText,
6101 Text: title,
6102 },
6103 },
6104 })
6105 require.NoError(t, err)
6106 return chat
6107 }
6108
6109 getChat := func(ctx context.Context, t *testing.T, client *codersdk.ExperimentalClient, chatID uuid.UUID) codersdk.Chat {
6110 t.Helper()
6111
6112 chat, err := client.GetChat(ctx, chatID)
6113 require.NoError(t, err)
6114 return chat
6115 }
6116
6117 t.Run("PinReorderAndUnpin", func(t *testing.T) {
6118 t.Parallel()
6119
6120 ctx := testutil.Context(t, testutil.WaitLong)
6121 client := newChatClient(t)
6122 firstUser := coderdtest.CreateFirstUser(t, client.Client)
6123 _ = createChatModelConfig(t, client)
6124
6125 first := createChat(ctx, t, client, firstUser.OrganizationID, "first pinned chat")
6126 second := createChat(ctx, t, client, firstUser.OrganizationID, "second pinned chat")
6127 third := createChat(ctx, t, client, firstUser.OrganizationID, "third pinned chat")
6128
6129 err := client.UpdateChat(ctx, first.ID, codersdk.UpdateChatRequest{PinOrder: ptr.Ref(int32(1))})
6130 require.NoError(t, err)
6131 err = client.UpdateChat(ctx, second.ID, codersdk.UpdateChatRequest{PinOrder: ptr.Ref(int32(1))})
6132 require.NoError(t, err)
6133 err = client.UpdateChat(ctx, third.ID, codersdk.UpdateChatRequest{PinOrder: ptr.Ref(int32(1))})
6134 require.NoError(t, err)
6135
6136 first = getChat(ctx, t, client, first.ID)
6137 second = getChat(ctx, t, client, second.ID)
6138 third = getChat(ctx, t, client, third.ID)
6139 require.EqualValues(t, 1, first.PinOrder)
6140 require.EqualValues(t, 2, second.PinOrder)
6141 require.EqualValues(t, 3, third.PinOrder)
6142
6143 err = client.UpdateChat(ctx, third.ID, codersdk.UpdateChatRequest{PinOrder: ptr.Ref(int32(1))})
6144 require.NoError(t, err)
6145
6146 first = getChat(ctx, t, client, first.ID)
6147 second = getChat(ctx, t, client, second.ID)

Callers

nothing calls this directly

Calls 15

ContextFunction · 0.92
CreateFirstUserFunction · 0.92
RefFunction · 0.92
ChatFunction · 0.92
createChatFunction · 0.85
requireSDKErrorFunction · 0.85
GetChatMethod · 0.80
newChatClientFunction · 0.70
createChatModelConfigFunction · 0.70
HelperMethod · 0.65
CreateChatMethod · 0.65

Tested by

no test coverage detected