(t *testing.T)
| 8803 | } |
| 8804 | |
| 8805 | func TestGetChatDiffContents(t *testing.T) { |
| 8806 | t.Parallel() |
| 8807 | |
| 8808 | t.Run("SuccessWithCachedRepositoryReference", func(t *testing.T) { |
| 8809 | t.Parallel() |
| 8810 | |
| 8811 | ctx := testutil.Context(t, testutil.WaitLong) |
| 8812 | rawClient, _, api := coderdtest.NewWithAPI(t, &coderdtest.Options{ |
| 8813 | DeploymentValues: chatDeploymentValues(t), |
| 8814 | ExternalAuthConfigs: []*externalauth.Config{ |
| 8815 | { |
| 8816 | ID: "gitlab-test", |
| 8817 | Type: "gitlab", |
| 8818 | Regex: regexp.MustCompile(`gitlab\.example\.com`), |
| 8819 | }, |
| 8820 | }, |
| 8821 | }) |
| 8822 | client := codersdk.NewExperimentalClient(rawClient) |
| 8823 | db := api.Database |
| 8824 | user := coderdtest.CreateFirstUser(t, client.Client) |
| 8825 | modelConfig := createChatModelConfig(t, client) |
| 8826 | chat := dbgen.Chat(t, db, database.Chat{ |
| 8827 | OrganizationID: user.OrganizationID, |
| 8828 | OwnerID: user.UserID, |
| 8829 | LastModelConfigID: modelConfig.ID, |
| 8830 | Title: "diff contents with cached repository reference", |
| 8831 | }) |
| 8832 | |
| 8833 | _, err := db.UpsertChatDiffStatusReference( |
| 8834 | dbauthz.AsSystemRestricted(ctx), |
| 8835 | database.UpsertChatDiffStatusReferenceParams{ |
| 8836 | ChatID: chat.ID, |
| 8837 | Url: sql.NullString{}, |
| 8838 | GitBranch: "feature/cached-diff", |
| 8839 | GitRemoteOrigin: "https://gitlab.example.com/acme/project.git", |
| 8840 | StaleAt: time.Now().UTC().Add(time.Hour), |
| 8841 | }, |
| 8842 | ) |
| 8843 | require.NoError(t, err) |
| 8844 | |
| 8845 | diffContents, err := client.GetChatDiffContents(ctx, chat.ID) |
| 8846 | require.NoError(t, err) |
| 8847 | require.Equal(t, chat.ID, diffContents.ChatID) |
| 8848 | require.NotNil(t, diffContents.Provider) |
| 8849 | require.Equal(t, "gitlab", *diffContents.Provider) |
| 8850 | require.NotNil(t, diffContents.RemoteOrigin) |
| 8851 | require.Equal(t, "https://gitlab.example.com/acme/project.git", *diffContents.RemoteOrigin) |
| 8852 | require.NotNil(t, diffContents.Branch) |
| 8853 | require.Equal(t, "feature/cached-diff", *diffContents.Branch) |
| 8854 | require.Nil(t, diffContents.PullRequestURL) |
| 8855 | require.Empty(t, diffContents.Diff) |
| 8856 | }) |
| 8857 | |
| 8858 | t.Run("SuccessWithoutCachedReference", func(t *testing.T) { |
| 8859 | t.Parallel() |
| 8860 | |
| 8861 | ctx := testutil.Context(t, testutil.WaitLong) |
| 8862 | client := newChatClient(t) |
nothing calls this directly
no test coverage detected