@@ -171,9 +171,17 @@ func Test_ListPullRequests(t *testing.T) {
171171{
172172name :"successful PRs listing" ,
173173mockedClient :mock .NewMockedHTTPClient (
174- mock .WithRequestMatch (
174+ mock .WithRequestMatchHandler (
175175mock .GetReposPullsByOwnerByRepo ,
176- mockPRs ,
176+ expectQueryParams (t ,map [string ]string {
177+ "state" :"all" ,
178+ "sort" :"created" ,
179+ "direction" :"desc" ,
180+ "per_page" :"30" ,
181+ "page" :"1" ,
182+ }).andThen (
183+ mockResponse (t ,http .StatusOK ,mockPRs ),
184+ ),
177185),
178186),
179187requestArgs :map [string ]interface {}{
@@ -281,9 +289,15 @@ func Test_MergePullRequest(t *testing.T) {
281289{
282290name :"successful merge" ,
283291mockedClient :mock .NewMockedHTTPClient (
284- mock .WithRequestMatch (
292+ mock .WithRequestMatchHandler (
285293mock .PutReposPullsMergeByOwnerByRepoByPullNumber ,
286- mockMergeResult ,
294+ expectRequestBody (t ,map [string ]interface {}{
295+ "commit_title" :"Merge PR #42" ,
296+ "commit_message" :"Merging awesome feature" ,
297+ "merge_method" :"squash" ,
298+ }).andThen (
299+ mockResponse (t ,http .StatusOK ,mockMergeResult ),
300+ ),
287301),
288302),
289303requestArgs :map [string ]interface {}{
@@ -662,7 +676,11 @@ func Test_UpdatePullRequestBranch(t *testing.T) {
662676mockedClient :mock .NewMockedHTTPClient (
663677mock .WithRequestMatchHandler (
664678mock .PutReposPullsUpdateBranchByOwnerByRepoByPullNumber ,
665- mockResponse (t ,http .StatusAccepted ,mockUpdateResult ),
679+ expectRequestBody (t ,map [string ]interface {}{
680+ "expected_head_sha" :"abcd1234" ,
681+ }).andThen (
682+ mockResponse (t ,http .StatusAccepted ,mockUpdateResult ),
683+ ),
666684),
667685),
668686requestArgs :map [string ]interface {}{
@@ -679,7 +697,9 @@ func Test_UpdatePullRequestBranch(t *testing.T) {
679697mockedClient :mock .NewMockedHTTPClient (
680698mock .WithRequestMatchHandler (
681699mock .PutReposPullsUpdateBranchByOwnerByRepoByPullNumber ,
682- mockResponse (t ,http .StatusAccepted ,mockUpdateResult ),
700+ expectRequestBody (t ,map [string ]interface {}{}).andThen (
701+ mockResponse (t ,http .StatusAccepted ,mockUpdateResult ),
702+ ),
683703),
684704),
685705requestArgs :map [string ]interface {}{
@@ -1030,9 +1050,14 @@ func Test_CreatePullRequestReview(t *testing.T) {
10301050{
10311051name :"successful review creation with body only" ,
10321052mockedClient :mock .NewMockedHTTPClient (
1033- mock .WithRequestMatch (
1053+ mock .WithRequestMatchHandler (
10341054mock .PostReposPullsReviewsByOwnerByRepoByPullNumber ,
1035- mockReview ,
1055+ expectRequestBody (t ,map [string ]interface {}{
1056+ "body" :"Looks good!" ,
1057+ "event" :"APPROVE" ,
1058+ }).andThen (
1059+ mockResponse (t ,http .StatusOK ,mockReview ),
1060+ ),
10361061),
10371062),
10381063requestArgs :map [string ]interface {}{
@@ -1048,9 +1073,15 @@ func Test_CreatePullRequestReview(t *testing.T) {
10481073{
10491074name :"successful review creation with commit_id" ,
10501075mockedClient :mock .NewMockedHTTPClient (
1051- mock .WithRequestMatch (
1076+ mock .WithRequestMatchHandler (
10521077mock .PostReposPullsReviewsByOwnerByRepoByPullNumber ,
1053- mockReview ,
1078+ expectRequestBody (t ,map [string ]interface {}{
1079+ "body" :"Looks good!" ,
1080+ "event" :"APPROVE" ,
1081+ "commit_id" :"abcdef123456" ,
1082+ }).andThen (
1083+ mockResponse (t ,http .StatusOK ,mockReview ),
1084+ ),
10541085),
10551086),
10561087requestArgs :map [string ]interface {}{
@@ -1067,9 +1098,26 @@ func Test_CreatePullRequestReview(t *testing.T) {
10671098{
10681099name :"successful review creation with comments" ,
10691100mockedClient :mock .NewMockedHTTPClient (
1070- mock .WithRequestMatch (
1101+ mock .WithRequestMatchHandler (
10711102mock .PostReposPullsReviewsByOwnerByRepoByPullNumber ,
1072- mockReview ,
1103+ expectRequestBody (t ,map [string ]interface {}{
1104+ "body" :"Some issues to fix" ,
1105+ "event" :"REQUEST_CHANGES" ,
1106+ "comments" : []interface {}{
1107+ map [string ]interface {}{
1108+ "path" :"file1.go" ,
1109+ "position" :float64 (10 ),
1110+ "body" :"This needs to be fixed" ,
1111+ },
1112+ map [string ]interface {}{
1113+ "path" :"file2.go" ,
1114+ "position" :float64 (20 ),
1115+ "body" :"Consider a different approach here" ,
1116+ },
1117+ },
1118+ }).andThen (
1119+ mockResponse (t ,http .StatusOK ,mockReview ),
1120+ ),
10731121),
10741122),
10751123requestArgs :map [string ]interface {}{
@@ -1240,10 +1288,18 @@ func Test_CreatePullRequest(t *testing.T) {
12401288mockedClient :mock .NewMockedHTTPClient (
12411289mock .WithRequestMatchHandler (
12421290mock .PostReposPullsByOwnerByRepo ,
1243- mockResponse (t ,http .StatusCreated ,mockPR ),
1291+ expectRequestBody (t ,map [string ]interface {}{
1292+ "title" :"Test PR" ,
1293+ "body" :"This is a test PR" ,
1294+ "head" :"feature-branch" ,
1295+ "base" :"main" ,
1296+ "draft" :false ,
1297+ "maintainer_can_modify" :true ,
1298+ }).andThen (
1299+ mockResponse (t ,http .StatusCreated ,mockPR ),
1300+ ),
12441301),
12451302),
1246-
12471303requestArgs :map [string ]interface {}{
12481304"owner" :"owner" ,
12491305"repo" :"repo" ,