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

Function TestChatACLSubChatInheritance

coderd/exp_chats_acl_test.go:181–227  ·  view source on GitHub ↗
(t *testing.T)

Source from the content-addressed store, hash-verified

179}
180
181func TestChatACLSubChatInheritance(t *testing.T) {
182 t.Parallel()
183
184 ctx := testutil.Context(t, testutil.WaitLong)
185 client, db := newChatClientWithDatabase(t)
186 firstUser := coderdtest.CreateFirstUser(t, client.Client)
187 modelConfig := createChatModelConfig(t, client)
188 sharedClient, sharedUser := coderdtest.CreateAnotherUser(t, client.Client, firstUser.OrganizationID)
189 sharedClientExp := codersdk.NewExperimentalClient(sharedClient)
190
191 root := createChatForSharing(ctx, t, client, firstUser.OrganizationID, "root chat")
192 child := dbgen.Chat(t, db, database.Chat{
193 OrganizationID: firstUser.OrganizationID,
194 OwnerID: firstUser.UserID,
195 ParentChatID: uuid.NullUUID{UUID: root.ID, Valid: true},
196 LastModelConfigID: modelConfig.ID,
197 Title: "child chat",
198 })
199
200 err := client.UpdateChatACL(ctx, root.ID, codersdk.UpdateChatACL{
201 UserRoles: map[string]codersdk.ChatRole{
202 sharedUser.ID.String(): codersdk.ChatRoleRead,
203 },
204 })
205 require.NoError(t, err)
206
207 sharedChild, err := sharedClientExp.GetChat(ctx, child.ID)
208 require.NoError(t, err)
209 require.Equal(t, child.ID, sharedChild.ID)
210 require.NotNil(t, sharedChild.RootChatID)
211 require.Equal(t, root.ID, *sharedChild.RootChatID)
212
213 _, err = sharedClientExp.GetChat(ctx, root.ID)
214 require.NoError(t, err)
215
216 err = client.UpdateChatACL(ctx, child.ID, codersdk.UpdateChatACL{
217 UserRoles: map[string]codersdk.ChatRole{
218 sharedUser.ID.String(): codersdk.ChatRoleDeleted,
219 },
220 })
221 sdkErr := requireSDKError(t, err, http.StatusBadRequest)
222 require.Equal(t, "Chat ACLs can only be set on root chats.", sdkErr.Message)
223
224 _, err = client.GetChatACL(ctx, child.ID)
225 sdkErr = requireSDKError(t, err, http.StatusBadRequest)
226 require.Equal(t, "Chat ACLs can only be set on root chats.", sdkErr.Message)
227}
228
229func TestChatACLValidation(t *testing.T) {
230 t.Parallel()

Callers

nothing calls this directly

Calls 14

GetChatMethod · 0.95
ContextFunction · 0.92
CreateFirstUserFunction · 0.92
CreateAnotherUserFunction · 0.92
NewExperimentalClientFunction · 0.92
ChatFunction · 0.92
createChatForSharingFunction · 0.85
requireSDKErrorFunction · 0.85
UpdateChatACLMethod · 0.80
GetChatACLMethod · 0.80
createChatModelConfigFunction · 0.70

Tested by

no test coverage detected