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

Function TestChatPinOrderQueries

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

Source from the content-addressed store, hash-verified

12030}
12031
12032func TestChatPinOrderQueries(t *testing.T) {
12033 t.Parallel()
12034 if testing.Short() {
12035 t.SkipNow()
12036 }
12037
12038 setup := func(t *testing.T) (context.Context, database.Store, uuid.UUID, uuid.UUID, uuid.UUID) {
12039 t.Helper()
12040
12041 db, _ := dbtestutil.NewDB(t)
12042 org := dbgen.Organization(t, db, database.Organization{})
12043 owner := dbgen.User(t, db, database.User{})
12044 dbgen.OrganizationMember(t, db, database.OrganizationMember{UserID: owner.ID, OrganizationID: org.ID})
12045
12046 // Use background context for fixture setup so the
12047 // timed test context doesn't tick during DB init.
12048 bg := context.Background()
12049 dbgen.ChatProvider(t, db, database.ChatProvider{
12050 Provider: "openai",
12051 DisplayName: "OpenAI",
12052 APIKey: "test-key",
12053 Enabled: true,
12054 CentralApiKeyEnabled: true,
12055 })
12056
12057 modelCfg, err := insertChatModelConfigForTest(bg, t, db, database.InsertChatModelConfigParams{
12058 Provider: "openai",
12059 Model: "test-model",
12060 DisplayName: "Test Model",
12061 CreatedBy: uuid.NullUUID{UUID: owner.ID, Valid: true},
12062 UpdatedBy: uuid.NullUUID{UUID: owner.ID, Valid: true},
12063 Enabled: true,
12064 IsDefault: true,
12065 ContextLimit: 128000,
12066 CompressionThreshold: 80,
12067 Options: json.RawMessage(`{}`),
12068 })
12069 require.NoError(t, err)
12070
12071 ctx := testutil.Context(t, testutil.WaitMedium)
12072 return ctx, db, owner.ID, modelCfg.ID, org.ID
12073 }
12074
12075 createChat := func(t *testing.T, ctx context.Context, db database.Store, ownerID, modelCfgID, orgID uuid.UUID, title string) database.Chat {
12076 t.Helper()
12077
12078 chat, err := db.InsertChat(ctx, database.InsertChatParams{
12079 OrganizationID: orgID,
12080 Status: database.ChatStatusWaiting,
12081 ClientType: database.ChatClientTypeUi,
12082 OwnerID: ownerID,
12083 LastModelConfigID: modelCfgID,
12084 Title: title,
12085 })
12086 require.NoError(t, err)
12087 return chat
12088 }
12089

Callers

nothing calls this directly

Calls 15

NewDBFunction · 0.92
OrganizationFunction · 0.92
UserFunction · 0.92
OrganizationMemberFunction · 0.92
ChatProviderFunction · 0.92
ContextFunction · 0.92
createChatFunction · 0.85
SkipNowMethod · 0.80
HelperMethod · 0.65
InsertChatMethod · 0.65
GetChatByIDMethod · 0.65

Tested by

no test coverage detected