Skip to content

Commit e95a567

Browse files
committed
test: add unit tests for ResolveReviewThread
1 parent 6ba06d8 commit e95a567

1 file changed

Lines changed: 171 additions & 0 deletions

File tree

pkg/github/pullrequests_test.go

Lines changed: 171 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3391,3 +3391,174 @@ func TestAddReplyToPullRequestComment(t *testing.T) {
33913391
})
33923392
}
33933393
}
3394+
3395+
func TestResolveReviewThread(t *testing.T) {
3396+
t.Parallel()
3397+
3398+
tests := []struct {
3399+
name string
3400+
requestArgs map[string]any
3401+
mockedClient *http.Client
3402+
expectToolError bool
3403+
expectedToolErrMsg string
3404+
expectedResult string
3405+
}{
3406+
{
3407+
name: "successful resolve thread",
3408+
requestArgs: map[string]any{
3409+
"method": "resolve_thread",
3410+
"owner": "owner",
3411+
"repo": "repo",
3412+
"pullNumber": float64(42),
3413+
"threadId": "PRRT_kwDOTest123",
3414+
},
3415+
mockedClient: githubv4mock.NewMockedHTTPClient(
3416+
githubv4mock.NewMutationMatcher(
3417+
struct {
3418+
ResolveReviewThread struct {
3419+
Thread struct {
3420+
ID githubv4.ID
3421+
IsResolved githubv4.Boolean
3422+
}
3423+
} `graphql:"resolveReviewThread(input: $input)"`
3424+
}{},
3425+
githubv4.ResolveReviewThreadInput{
3426+
ThreadID: githubv4.ID("PRRT_kwDOTest123"),
3427+
},
3428+
nil,
3429+
githubv4mock.DataResponse(map[string]any{
3430+
"resolveReviewThread": map[string]any{
3431+
"thread": map[string]any{
3432+
"id": "PRRT_kwDOTest123",
3433+
"isResolved": true,
3434+
},
3435+
},
3436+
}),
3437+
),
3438+
),
3439+
expectedResult: "review thread resolved successfully",
3440+
},
3441+
{
3442+
name: "successful unresolve thread",
3443+
requestArgs: map[string]any{
3444+
"method": "unresolve_thread",
3445+
"owner": "owner",
3446+
"repo": "repo",
3447+
"pullNumber": float64(42),
3448+
"threadId": "PRRT_kwDOTest123",
3449+
},
3450+
mockedClient: githubv4mock.NewMockedHTTPClient(
3451+
githubv4mock.NewMutationMatcher(
3452+
struct {
3453+
UnresolveReviewThread struct {
3454+
Thread struct {
3455+
ID githubv4.ID
3456+
IsResolved githubv4.Boolean
3457+
}
3458+
} `graphql:"unresolveReviewThread(input: $input)"`
3459+
}{},
3460+
githubv4.UnresolveReviewThreadInput{
3461+
ThreadID: githubv4.ID("PRRT_kwDOTest123"),
3462+
},
3463+
nil,
3464+
githubv4mock.DataResponse(map[string]any{
3465+
"unresolveReviewThread": map[string]any{
3466+
"thread": map[string]any{
3467+
"id": "PRRT_kwDOTest123",
3468+
"isResolved": false,
3469+
},
3470+
},
3471+
}),
3472+
),
3473+
),
3474+
expectedResult: "review thread unresolved successfully",
3475+
},
3476+
{
3477+
name: "empty threadId for resolve",
3478+
requestArgs: map[string]any{
3479+
"method": "resolve_thread",
3480+
"owner": "owner",
3481+
"repo": "repo",
3482+
"pullNumber": float64(42),
3483+
"threadId": "",
3484+
},
3485+
mockedClient: githubv4mock.NewMockedHTTPClient(),
3486+
expectToolError: true,
3487+
expectedToolErrMsg: "threadId is required",
3488+
},
3489+
{
3490+
name: "empty threadId for unresolve",
3491+
requestArgs: map[string]any{
3492+
"method": "unresolve_thread",
3493+
"owner": "owner",
3494+
"repo": "repo",
3495+
"pullNumber": float64(42),
3496+
"threadId": "",
3497+
},
3498+
mockedClient: githubv4mock.NewMockedHTTPClient(),
3499+
expectToolError: true,
3500+
expectedToolErrMsg: "threadId is required",
3501+
},
3502+
{
3503+
name: "thread not found",
3504+
requestArgs: map[string]any{
3505+
"method": "resolve_thread",
3506+
"owner": "owner",
3507+
"repo": "repo",
3508+
"pullNumber": float64(42),
3509+
"threadId": "PRRT_invalid",
3510+
},
3511+
mockedClient: githubv4mock.NewMockedHTTPClient(
3512+
githubv4mock.NewMutationMatcher(
3513+
struct {
3514+
ResolveReviewThread struct {
3515+
Thread struct {
3516+
ID githubv4.ID
3517+
IsResolved githubv4.Boolean
3518+
}
3519+
} `graphql:"resolveReviewThread(input: $input)"`
3520+
}{},
3521+
githubv4.ResolveReviewThreadInput{
3522+
ThreadID: githubv4.ID("PRRT_invalid"),
3523+
},
3524+
nil,
3525+
githubv4mock.ErrorResponse("Could not resolve to a PullRequestReviewThread with the id of 'PRRT_invalid'"),
3526+
),
3527+
),
3528+
expectToolError: true,
3529+
expectedToolErrMsg: "Could not resolve to a PullRequestReviewThread",
3530+
},
3531+
}
3532+
3533+
for _, tc := range tests {
3534+
t.Run(tc.name, func(t *testing.T) {
3535+
t.Parallel()
3536+
3537+
// Setup client with mock
3538+
client := githubv4.NewClient(tc.mockedClient)
3539+
serverTool := PullRequestReviewWrite(translations.NullTranslationHelper)
3540+
deps := BaseDeps{
3541+
GQLClient: client,
3542+
}
3543+
handler := serverTool.Handler(deps)
3544+
3545+
// Create call request
3546+
request := createMCPRequest(tc.requestArgs)
3547+
3548+
// Call handler
3549+
result, err := handler(ContextWithDeps(context.Background(), deps), &request)
3550+
require.NoError(t, err)
3551+
3552+
textContent := getTextResult(t, result)
3553+
3554+
if tc.expectToolError {
3555+
require.True(t, result.IsError)
3556+
assert.Contains(t, textContent.Text, tc.expectedToolErrMsg)
3557+
return
3558+
}
3559+
3560+
require.False(t, result.IsError)
3561+
assert.Equal(t, tc.expectedResult, textContent.Text)
3562+
})
3563+
}
3564+
}

0 commit comments

Comments
 (0)