github.com/keybase/client/go@v0.0.0-20241007131713-f10651d043c8/service/user_report_test.go (about) 1 package service 2 3 import ( 4 "testing" 5 6 "github.com/keybase/client/go/protocol/keybase1" 7 8 "github.com/keybase/client/go/chat/globals" 9 "github.com/keybase/client/go/chat/types" 10 "github.com/keybase/client/go/protocol/chat1" 11 gregor1 "github.com/keybase/client/go/protocol/gregor1" 12 "golang.org/x/net/context" 13 14 "github.com/keybase/client/go/kbtest" 15 "github.com/keybase/client/go/libkb" 16 "github.com/stretchr/testify/require" 17 ) 18 19 type mockConvSource struct { 20 types.ConversationSource 21 t *testing.T 22 callsToPull int 23 } 24 25 type reportTestAPIMock struct { 26 libkb.API 27 t *testing.T 28 args libkb.APIArg 29 } 30 31 func (n *reportTestAPIMock) Post(mctx libkb.MetaContext, arg libkb.APIArg) (*libkb.APIRes, error) { 32 n.args = arg 33 return nil, nil 34 } 35 36 func (s *mockConvSource) Pull(ctx context.Context, convID chat1.ConversationID, 37 uid gregor1.UID, reason chat1.GetThreadReason, customRi func() chat1.RemoteInterface, 38 query *chat1.GetThreadQuery, pagination *chat1.Pagination) (thread chat1.ThreadView, err error) { 39 40 s.callsToPull++ 41 42 require.Greater(s.t, pagination.Num, 0) 43 require.Len(s.t, pagination.Next, 0) 44 require.NotNil(s.t, query) 45 46 return chat1.ThreadView{ 47 Pagination: &chat1.Pagination{ 48 Last: true, 49 }, 50 }, nil 51 } 52 53 func TestPullTranscript(t *testing.T) { 54 tc := libkb.SetupTest(t, "transcript", 3) 55 defer tc.Cleanup() 56 57 offender, err := kbtest.CreateAndSignupFakeUser("reps", tc.G) 58 require.NoError(t, err) 59 60 _, err = kbtest.CreateAndSignupFakeUser("reps", tc.G) 61 require.NoError(t, err) 62 63 cs := &mockConvSource{t: t} 64 chatG := &globals.ChatContext{ 65 ConvSource: cs, 66 } 67 68 randBytes, err := libkb.RandBytes(32) 69 require.NoError(t, err) 70 testConvID := chat1.ConversationID(randBytes).String() 71 72 apiMock := &reportTestAPIMock{t: t} 73 tc.G.API = apiMock 74 75 userHandler := NewUserHandler(nil, tc.G, chatG, nil) 76 err = userHandler.ReportUser(context.Background(), keybase1.ReportUserArg{ 77 Username: offender.Username, 78 ConvID: &testConvID, 79 IncludeTranscript: true, 80 Comment: "Coming from user_report_test.go", 81 }) 82 require.NoError(t, err) 83 84 require.Equal(t, "report/conversation", apiMock.args.Endpoint) 85 require.Contains(t, apiMock.args.Args, "username") 86 require.Equal(t, testConvID, apiMock.args.Args["conv_id"].String()) 87 require.Contains(t, apiMock.args.Args, "transcript") 88 89 require.Greater(t, cs.callsToPull, 0) 90 }