(t *testing.T)
| 1013 | } |
| 1014 | |
| 1015 | func 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 | |
| 1064 | func TestRefreshChat_NoPR(t *testing.T) { |
| 1065 | t.Parallel() |
nothing calls this directly
no test coverage detected