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

Function TestRefreshChat_Success

coderd/x/gitsync/worker_test.go:1015–1062  ·  view source on GitHub ↗
(t *testing.T)

Source from the content-addressed store, hash-verified

1013}
1014
1015func TestRefreshChat_Success(t *testing.T) {
1016 t.Parallel()
1017 ctx := testutil.Context(t, testutil.WaitShort)
1018
1019 chatID := uuid.New()
1020 ownerID := uuid.New()
1021
1022 row := database.ChatDiffStatus{
1023 ChatID: chatID,
1024 GitBranch: "feature",
1025 GitRemoteOrigin: "https://github.com/owner/repo",
1026 }
1027
1028 ctrl := gomock.NewController(t)
1029 store := dbmock.NewMockStore(ctrl)
1030
1031 upsertedStatus := database.ChatDiffStatus{
1032 ChatID: chatID,
1033 Url: sql.NullString{String: "https://github.com/o/r/pull/1", Valid: true},
1034 Additions: 10,
1035 Deletions: 3,
1036 ChangedFiles: 2,
1037 }
1038 store.EXPECT().UpsertChatDiffStatus(gomock.Any(), gomock.Any()).
1039 DoAndReturn(func(_ context.Context, arg database.UpsertChatDiffStatusParams) (database.ChatDiffStatus, error) {
1040 assert.Equal(t, chatID, arg.ChatID)
1041 return upsertedStatus, nil
1042 })
1043
1044 var publishCalled atomic.Bool
1045 pub := func(_ context.Context, id uuid.UUID) error {
1046 assert.Equal(t, chatID, id)
1047 publishCalled.Store(true)
1048 return nil
1049 }
1050
1051 mClock := quartz.NewMock(t)
1052 logger := slogtest.Make(t, &slogtest.Options{IgnoreErrors: true})
1053 refresher := newTestRefresher(t, mClock)
1054 worker := gitsync.NewWorker(store, refresher, pub, mClock, logger)
1055
1056 result, err := worker.RefreshChat(ctx, row, ownerID)
1057 require.NoError(t, err)
1058 require.NotNil(t, result)
1059 assert.Equal(t, chatID, result.ChatID)
1060 assert.Equal(t, upsertedStatus.Url, result.Url)
1061 assert.True(t, publishCalled.Load(), "publish should have been called")
1062}
1063
1064func TestRefreshChat_NoPR(t *testing.T) {
1065 t.Parallel()

Callers

nothing calls this directly

Calls 11

EXPECTMethod · 0.95
RefreshChatMethod · 0.95
ContextFunction · 0.92
NewMockStoreFunction · 0.92
NewWorkerFunction · 0.92
newTestRefresherFunction · 0.85
NewMethod · 0.65
UpsertChatDiffStatusMethod · 0.65
EqualMethod · 0.45
StoreMethod · 0.45
LoadMethod · 0.45

Tested by

no test coverage detected