@@ -457,9 +457,8 @@ func TestAPIEditPull(t *testing.T) {
457457 Base : "master" ,
458458 Title : title ,
459459 }).AddTokenAuth (token )
460- apiPull := new (api.PullRequest )
461460 resp := MakeRequest (t , req , http .StatusCreated )
462- DecodeJSON (t , resp , apiPull )
461+ apiPull := DecodeJSON (t , resp , & api. PullRequest {} )
463462 assert .Equal (t , "master" , apiPull .Base .Name )
464463
465464 newTitle := "edit a this pr"
@@ -470,8 +469,9 @@ func TestAPIEditPull(t *testing.T) {
470469 Body : & newBody ,
471470 }).AddTokenAuth (token )
472471 resp = MakeRequest (t , req , http .StatusCreated )
473- DecodeJSON (t , resp , apiPull )
472+ apiPull = DecodeJSON (t , resp , & api. PullRequest {} )
474473 assert .Equal (t , "feature/1" , apiPull .Base .Name )
474+
475475 // check comment history
476476 pull := unittest .AssertExistsAndLoadBean (t , & issues_model.PullRequest {ID : apiPull .ID })
477477 err := pull .LoadIssue (t .Context ())
@@ -483,6 +483,62 @@ func TestAPIEditPull(t *testing.T) {
483483 Base : "not-exist" ,
484484 }).AddTokenAuth (token )
485485 MakeRequest (t , req , http .StatusNotFound )
486+
487+ t .Run ("PullContentVersion" , func (t * testing.T ) {
488+ testAPIPullContentVersion (t , pull .ID )
489+ })
490+ }
491+
492+ func testAPIPullContentVersion (t * testing.T , pullID int64 ) {
493+ pull := unittest .AssertExistsAndLoadBean (t , & issues_model.PullRequest {ID : pullID })
494+ repo := unittest .AssertExistsAndLoadBean (t , & repo_model.Repository {ID : pull .BaseRepoID })
495+ owner := unittest .AssertExistsAndLoadBean (t , & user_model.User {ID : repo .OwnerID })
496+
497+ session := loginUser (t , owner .Name )
498+ token := getTokenForLoggedInUser (t , session , auth_model .AccessTokenScopeWriteRepository )
499+ urlStr := fmt .Sprintf ("/api/v1/repos/%s/%s/pulls/%d" , owner .Name , repo .Name , pull .Index )
500+
501+ t .Run ("ResponseIncludesContentVersion" , func (t * testing.T ) {
502+ defer tests .PrintCurrentTest (t )()
503+
504+ req := NewRequest (t , "GET" , urlStr ).AddTokenAuth (token )
505+ resp := MakeRequest (t , req , http .StatusOK )
506+ apiPull := DecodeJSON (t , resp , & api.PullRequest {})
507+ assert .GreaterOrEqual (t , apiPull .ContentVersion , 0 )
508+ })
509+
510+ t .Run ("EditWithCorrectVersion" , func (t * testing.T ) {
511+ defer tests .PrintCurrentTest (t )()
512+
513+ req := NewRequest (t , "GET" , urlStr ).AddTokenAuth (token )
514+ resp := MakeRequest (t , req , http .StatusOK )
515+ before := DecodeJSON (t , resp , & api.PullRequest {})
516+ req = NewRequestWithJSON (t , "PATCH" , urlStr , api.EditPullRequestOption {
517+ Body : new ("updated body with correct version "),
518+ ContentVersion : new (before.ContentVersion ),
519+ }).AddTokenAuth (token )
520+ resp = MakeRequest (t , req , http .StatusCreated )
521+ after := DecodeJSON (t , resp , & api.PullRequest {})
522+ assert .Equal (t , "updated body with correct version" , after .Body )
523+ assert .Greater (t , after .ContentVersion , before .ContentVersion )
524+ })
525+
526+ t .Run ("EditWithWrongVersion" , func (t * testing.T ) {
527+ defer tests .PrintCurrentTest (t )()
528+ req := NewRequestWithJSON (t , "PATCH" , urlStr , api.EditPullRequestOption {
529+ Body : new ("should fail "),
530+ ContentVersion : new (99999 ),
531+ }).AddTokenAuth (token )
532+ MakeRequest (t , req , http .StatusConflict )
533+ })
534+
535+ t .Run ("EditWithoutVersion" , func (t * testing.T ) {
536+ defer tests .PrintCurrentTest (t )()
537+ req := NewRequestWithJSON (t , "PATCH" , urlStr , api.EditPullRequestOption {
538+ Body : new ("edit without version succeeds "),
539+ }).AddTokenAuth (token )
540+ MakeRequest (t , req , http .StatusCreated )
541+ })
486542}
487543
488544func doAPIGetPullFiles (ctx APITestContext , pr * api.PullRequest , callback func (* testing.T , []* api.ChangedFile )) func (* testing.T ) {
0 commit comments