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

Function TestChatPinOrderConstraints

coderd/database/querier_test.go:12217–12303  ·  view source on GitHub ↗
(t *testing.T)

Source from the content-addressed store, hash-verified

12215}
12216
12217func TestChatPinOrderConstraints(t *testing.T) {
12218 t.Parallel()
12219 if testing.Short() {
12220 t.SkipNow()
12221 }
12222
12223 db, _ := dbtestutil.NewDB(t)
12224 org := dbgen.Organization(t, db, database.Organization{})
12225 owner := dbgen.User(t, db, database.User{})
12226 dbgen.OrganizationMember(t, db, database.OrganizationMember{UserID: owner.ID, OrganizationID: org.ID})
12227
12228 bg := context.Background()
12229 dbgen.ChatProvider(t, db, database.ChatProvider{
12230 Provider: "openai",
12231 DisplayName: "OpenAI",
12232 APIKey: "test-key",
12233 Enabled: true,
12234 CentralApiKeyEnabled: true,
12235 })
12236
12237 modelCfg, err := insertChatModelConfigForTest(bg, t, db, database.InsertChatModelConfigParams{
12238 Provider: "openai",
12239 Model: "test-model",
12240 DisplayName: "Test Model",
12241 CreatedBy: uuid.NullUUID{UUID: owner.ID, Valid: true},
12242 UpdatedBy: uuid.NullUUID{UUID: owner.ID, Valid: true},
12243 Enabled: true,
12244 IsDefault: true,
12245 ContextLimit: 128000,
12246 CompressionThreshold: 80,
12247 Options: json.RawMessage(`{}`),
12248 })
12249 require.NoError(t, err)
12250
12251 t.Run("ChildChatCannotBePinned", func(t *testing.T) {
12252 t.Parallel()
12253 ctx := testutil.Context(t, testutil.WaitMedium)
12254
12255 parent, err := db.InsertChat(ctx, database.InsertChatParams{
12256 OrganizationID: org.ID,
12257 Status: database.ChatStatusCompleted,
12258 ClientType: database.ChatClientTypeUi,
12259 OwnerID: owner.ID,
12260 LastModelConfigID: modelCfg.ID,
12261 Title: "parent",
12262 })
12263 require.NoError(t, err)
12264
12265 child, err := db.InsertChat(ctx, database.InsertChatParams{
12266 OrganizationID: org.ID,
12267 Status: database.ChatStatusCompleted,
12268 ClientType: database.ChatClientTypeUi,
12269 OwnerID: owner.ID,
12270 LastModelConfigID: modelCfg.ID,
12271 Title: "child",
12272 ParentChatID: uuid.NullUUID{UUID: parent.ID, Valid: true},
12273 RootChatID: uuid.NullUUID{UUID: parent.ID, Valid: true},
12274 })

Callers

nothing calls this directly

Calls 14

NewDBFunction · 0.92
OrganizationFunction · 0.92
UserFunction · 0.92
OrganizationMemberFunction · 0.92
ChatProviderFunction · 0.92
ContextFunction · 0.92
IsCheckViolationFunction · 0.92
SkipNowMethod · 0.80
RunMethod · 0.65
InsertChatMethod · 0.65
PinChatByIDMethod · 0.65

Tested by

no test coverage detected