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

Function TestGetChatDiffStatus

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

Source from the content-addressed store, hash-verified

8682}
8683
8684func TestGetChatDiffStatus(t *testing.T) {
8685 t.Parallel()
8686
8687 t.Run("Success", func(t *testing.T) {
8688 t.Parallel()
8689
8690 ctx := testutil.Context(t, testutil.WaitLong)
8691 rawClient, _, api := coderdtest.NewWithAPI(t, &coderdtest.Options{
8692 DeploymentValues: chatDeploymentValues(t),
8693 ExternalAuthConfigs: []*externalauth.Config{
8694 {
8695 ID: "gitlab-test",
8696 Type: "gitlab",
8697 Regex: regexp.MustCompile(`github\.com`),
8698 },
8699 },
8700 })
8701 client := codersdk.NewExperimentalClient(rawClient)
8702 db := api.Database
8703
8704 user := coderdtest.CreateFirstUser(t, client.Client)
8705 modelConfig := createChatModelConfig(t, client)
8706
8707 noCachedStatusChat := dbgen.Chat(t, db, database.Chat{
8708 OrganizationID: user.OrganizationID,
8709 OwnerID: user.UserID,
8710 LastModelConfigID: modelConfig.ID,
8711 Title: "get diff status route no cache",
8712 })
8713
8714 noCachedChat, err := client.GetChat(ctx, noCachedStatusChat.ID)
8715 require.NoError(t, err)
8716 require.Equal(t, noCachedStatusChat.ID, noCachedChat.ID)
8717 require.Nil(t, noCachedChat.DiffStatus)
8718
8719 cachedStatusChat := dbgen.Chat(t, db, database.Chat{
8720 OrganizationID: user.OrganizationID,
8721 OwnerID: user.UserID,
8722 LastModelConfigID: modelConfig.ID,
8723 Title: "get diff status route cached",
8724 })
8725
8726 refreshedAt := time.Now().UTC().Truncate(time.Second)
8727 staleAt := refreshedAt.Add(time.Hour)
8728 _, err = db.UpsertChatDiffStatusReference(
8729 dbauthz.AsSystemRestricted(ctx),
8730 database.UpsertChatDiffStatusReferenceParams{
8731 ChatID: cachedStatusChat.ID,
8732 Url: sql.NullString{},
8733 GitBranch: "feature/diff-status",
8734 GitRemoteOrigin: "git@github.com:coder/coder.git",
8735 StaleAt: staleAt,
8736 },
8737 )
8738 require.NoError(t, err)
8739
8740 _, err = db.UpsertChatDiffStatus(
8741 dbauthz.AsSystemRestricted(ctx),

Callers

nothing calls this directly

Calls 15

GetChatMethod · 0.95
CreateChatMethod · 0.95
ContextFunction · 0.92
NewWithAPIFunction · 0.92
NewExperimentalClientFunction · 0.92
CreateFirstUserFunction · 0.92
ChatFunction · 0.92
AsSystemRestrictedFunction · 0.92
CreateAnotherUserFunction · 0.92
ScopedRoleAgentsAccessFunction · 0.92
chatDeploymentValuesFunction · 0.85
requireSDKErrorFunction · 0.85

Tested by

no test coverage detected