@@ -171,9 +171,17 @@ func Test_ListPullRequests(t *testing.T) {
171
171
{
172
172
name : "successful PRs listing" ,
173
173
mockedClient : mock .NewMockedHTTPClient (
174
- mock .WithRequestMatch (
174
+ mock .WithRequestMatchHandler (
175
175
mock .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
+ ),
177
185
),
178
186
),
179
187
requestArgs : map [string ]interface {}{
@@ -281,9 +289,15 @@ func Test_MergePullRequest(t *testing.T) {
281
289
{
282
290
name : "successful merge" ,
283
291
mockedClient : mock .NewMockedHTTPClient (
284
- mock .WithRequestMatch (
292
+ mock .WithRequestMatchHandler (
285
293
mock .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
+ ),
287
301
),
288
302
),
289
303
requestArgs : map [string ]interface {}{
@@ -662,7 +676,11 @@ func Test_UpdatePullRequestBranch(t *testing.T) {
662
676
mockedClient : mock .NewMockedHTTPClient (
663
677
mock .WithRequestMatchHandler (
664
678
mock .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
+ ),
666
684
),
667
685
),
668
686
requestArgs : map [string ]interface {}{
@@ -679,7 +697,9 @@ func Test_UpdatePullRequestBranch(t *testing.T) {
679
697
mockedClient : mock .NewMockedHTTPClient (
680
698
mock .WithRequestMatchHandler (
681
699
mock .PutReposPullsUpdateBranchByOwnerByRepoByPullNumber ,
682
- mockResponse (t , http .StatusAccepted , mockUpdateResult ),
700
+ expectRequestBody (t , map [string ]interface {}{}).andThen (
701
+ mockResponse (t , http .StatusAccepted , mockUpdateResult ),
702
+ ),
683
703
),
684
704
),
685
705
requestArgs : map [string ]interface {}{
@@ -1030,9 +1050,14 @@ func Test_CreatePullRequestReview(t *testing.T) {
1030
1050
{
1031
1051
name : "successful review creation with body only" ,
1032
1052
mockedClient : mock .NewMockedHTTPClient (
1033
- mock .WithRequestMatch (
1053
+ mock .WithRequestMatchHandler (
1034
1054
mock .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
+ ),
1036
1061
),
1037
1062
),
1038
1063
requestArgs : map [string ]interface {}{
@@ -1048,9 +1073,15 @@ func Test_CreatePullRequestReview(t *testing.T) {
1048
1073
{
1049
1074
name : "successful review creation with commit_id" ,
1050
1075
mockedClient : mock .NewMockedHTTPClient (
1051
- mock .WithRequestMatch (
1076
+ mock .WithRequestMatchHandler (
1052
1077
mock .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
+ ),
1054
1085
),
1055
1086
),
1056
1087
requestArgs : map [string ]interface {}{
@@ -1067,9 +1098,26 @@ func Test_CreatePullRequestReview(t *testing.T) {
1067
1098
{
1068
1099
name : "successful review creation with comments" ,
1069
1100
mockedClient : mock .NewMockedHTTPClient (
1070
- mock .WithRequestMatch (
1101
+ mock .WithRequestMatchHandler (
1071
1102
mock .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
+ ),
1073
1121
),
1074
1122
),
1075
1123
requestArgs : map [string ]interface {}{
@@ -1240,10 +1288,18 @@ func Test_CreatePullRequest(t *testing.T) {
1240
1288
mockedClient : mock .NewMockedHTTPClient (
1241
1289
mock .WithRequestMatchHandler (
1242
1290
mock .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
+ ),
1244
1301
),
1245
1302
),
1246
-
1247
1303
requestArgs : map [string ]interface {}{
1248
1304
"owner" : "owner" ,
1249
1305
"repo" : "repo" ,
0 commit comments