Skip to content

assert request params and body in pull_request_test #95

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Apr 4, 2025
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
84 changes: 70 additions & 14 deletions pkg/github/pullrequests_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -171,9 +171,17 @@ func Test_ListPullRequests(t *testing.T) {
{
name: "successful PRs listing",
mockedClient: mock.NewMockedHTTPClient(
mock.WithRequestMatch(
mock.WithRequestMatchHandler(
mock.GetReposPullsByOwnerByRepo,
mockPRs,
expectQueryParams(t, map[string]string{
"state": "all",
"sort": "created",
"direction": "desc",
"per_page": "30",
"page": "1",
}).andThen(
mockResponse(t, http.StatusOK, mockPRs),
),
),
),
requestArgs: map[string]interface{}{
Expand Down Expand Up @@ -281,9 +289,15 @@ func Test_MergePullRequest(t *testing.T) {
{
name: "successful merge",
mockedClient: mock.NewMockedHTTPClient(
mock.WithRequestMatch(
mock.WithRequestMatchHandler(
mock.PutReposPullsMergeByOwnerByRepoByPullNumber,
mockMergeResult,
expectRequestBody(t, map[string]interface{}{
"commit_title": "Merge PR #42",
"commit_message": "Merging awesome feature",
"merge_method": "squash",
}).andThen(
mockResponse(t, http.StatusOK, mockMergeResult),
),
),
),
requestArgs: map[string]interface{}{
Expand Down Expand Up @@ -662,7 +676,11 @@ func Test_UpdatePullRequestBranch(t *testing.T) {
mockedClient: mock.NewMockedHTTPClient(
mock.WithRequestMatchHandler(
mock.PutReposPullsUpdateBranchByOwnerByRepoByPullNumber,
mockResponse(t, http.StatusAccepted, mockUpdateResult),
expectRequestBody(t, map[string]interface{}{
"expected_head_sha": "abcd1234",
}).andThen(
mockResponse(t, http.StatusAccepted, mockUpdateResult),
),
),
),
requestArgs: map[string]interface{}{
Expand All @@ -679,7 +697,9 @@ func Test_UpdatePullRequestBranch(t *testing.T) {
mockedClient: mock.NewMockedHTTPClient(
mock.WithRequestMatchHandler(
mock.PutReposPullsUpdateBranchByOwnerByRepoByPullNumber,
mockResponse(t, http.StatusAccepted, mockUpdateResult),
expectRequestBody(t, map[string]interface{}{}).andThen(
mockResponse(t, http.StatusAccepted, mockUpdateResult),
),
),
),
requestArgs: map[string]interface{}{
Expand Down Expand Up @@ -1030,9 +1050,14 @@ func Test_CreatePullRequestReview(t *testing.T) {
{
name: "successful review creation with body only",
mockedClient: mock.NewMockedHTTPClient(
mock.WithRequestMatch(
mock.WithRequestMatchHandler(
mock.PostReposPullsReviewsByOwnerByRepoByPullNumber,
mockReview,
expectRequestBody(t, map[string]interface{}{
"body": "Looks good!",
"event": "APPROVE",
}).andThen(
mockResponse(t, http.StatusOK, mockReview),
),
),
),
requestArgs: map[string]interface{}{
Expand All @@ -1048,9 +1073,15 @@ func Test_CreatePullRequestReview(t *testing.T) {
{
name: "successful review creation with commit_id",
mockedClient: mock.NewMockedHTTPClient(
mock.WithRequestMatch(
mock.WithRequestMatchHandler(
mock.PostReposPullsReviewsByOwnerByRepoByPullNumber,
mockReview,
expectRequestBody(t, map[string]interface{}{
"body": "Looks good!",
"event": "APPROVE",
"commit_id": "abcdef123456",
}).andThen(
mockResponse(t, http.StatusOK, mockReview),
),
),
),
requestArgs: map[string]interface{}{
Expand All @@ -1067,9 +1098,26 @@ func Test_CreatePullRequestReview(t *testing.T) {
{
name: "successful review creation with comments",
mockedClient: mock.NewMockedHTTPClient(
mock.WithRequestMatch(
mock.WithRequestMatchHandler(
mock.PostReposPullsReviewsByOwnerByRepoByPullNumber,
mockReview,
expectRequestBody(t, map[string]interface{}{
"body": "Some issues to fix",
"event": "REQUEST_CHANGES",
"comments": []interface{}{
map[string]interface{}{
"path": "file1.go",
"position": float64(10),
"body": "This needs to be fixed",
},
map[string]interface{}{
"path": "file2.go",
"position": float64(20),
"body": "Consider a different approach here",
},
},
}).andThen(
mockResponse(t, http.StatusOK, mockReview),
),
),
),
requestArgs: map[string]interface{}{
Expand Down Expand Up @@ -1240,10 +1288,18 @@ func Test_CreatePullRequest(t *testing.T) {
mockedClient: mock.NewMockedHTTPClient(
mock.WithRequestMatchHandler(
mock.PostReposPullsByOwnerByRepo,
mockResponse(t, http.StatusCreated, mockPR),
expectRequestBody(t, map[string]interface{}{
"title": "Test PR",
"body": "This is a test PR",
"head": "feature-branch",
"base": "main",
"draft": false,
"maintainer_can_modify": true,
}).andThen(
mockResponse(t, http.StatusCreated, mockPR),
),
),
),

requestArgs: map[string]interface{}{
"owner": "owner",
"repo": "repo",
Expand Down