@@ -11,6 +11,7 @@ import (
1111
1212 "code.gitea.io/gitea/models"
1313 api "code.gitea.io/gitea/modules/structs"
14+ jsoniter "github.com/json-iterator/go"
1415 "github.com/stretchr/testify/assert"
1516)
1617
@@ -139,6 +140,59 @@ func TestAPIPullReview(t *testing.T) {
139140 req = NewRequestf (t , http .MethodDelete , "/api/v1/repos/%s/%s/pulls/%d/reviews/%d?token=%s" , repo .OwnerName , repo .Name , pullIssue .Index , review .ID , token )
140141 resp = session .MakeRequest (t , req , http .StatusNoContent )
141142
143+ // test CreatePullReview Comment without body but with comments
144+ req = NewRequestWithJSON (t , http .MethodPost , fmt .Sprintf ("/api/v1/repos/%s/%s/pulls/%d/reviews?token=%s" , repo .OwnerName , repo .Name , pullIssue .Index , token ), & api.CreatePullReviewOptions {
145+ // Body: "",
146+ Event : "COMMENT" ,
147+ Comments : []api.CreatePullReviewComment {{
148+ Path : "README.md" ,
149+ Body : "first new line" ,
150+ OldLineNum : 0 ,
151+ NewLineNum : 1 ,
152+ }, {
153+ Path : "README.md" ,
154+ Body : "first old line" ,
155+ OldLineNum : 1 ,
156+ NewLineNum : 0 ,
157+ },
158+ },
159+ })
160+ var commentReview api.PullReview
161+
162+ resp = session .MakeRequest (t , req , http .StatusOK )
163+ DecodeJSON (t , resp , & commentReview )
164+ assert .EqualValues (t , "COMMENT" , commentReview .State )
165+ assert .EqualValues (t , 2 , commentReview .CodeCommentsCount )
166+ assert .EqualValues (t , "" , commentReview .Body )
167+ assert .EqualValues (t , false , commentReview .Dismissed )
168+
169+ // test CreatePullReview Comment with body but without comments
170+ commentBody := "This is a body of the comment."
171+ req = NewRequestWithJSON (t , http .MethodPost , fmt .Sprintf ("/api/v1/repos/%s/%s/pulls/%d/reviews?token=%s" , repo .OwnerName , repo .Name , pullIssue .Index , token ), & api.CreatePullReviewOptions {
172+ Body : commentBody ,
173+ Event : "COMMENT" ,
174+ Comments : []api.CreatePullReviewComment {},
175+ })
176+
177+ resp = session .MakeRequest (t , req , http .StatusOK )
178+ DecodeJSON (t , resp , & commentReview )
179+ assert .EqualValues (t , "COMMENT" , commentReview .State )
180+ assert .EqualValues (t , 0 , commentReview .CodeCommentsCount )
181+ assert .EqualValues (t , commentBody , commentReview .Body )
182+ assert .EqualValues (t , false , commentReview .Dismissed )
183+
184+ // test CreatePullReview Comment without body and no comments
185+ req = NewRequestWithJSON (t , http .MethodPost , fmt .Sprintf ("/api/v1/repos/%s/%s/pulls/%d/reviews?token=%s" , repo .OwnerName , repo .Name , pullIssue .Index , token ), & api.CreatePullReviewOptions {
186+ Body : "" ,
187+ Event : "COMMENT" ,
188+ Comments : []api.CreatePullReviewComment {},
189+ })
190+ resp = session .MakeRequest (t , req , http .StatusUnprocessableEntity )
191+ errMap := make (map [string ]interface {})
192+ json := jsoniter .ConfigCompatibleWithStandardLibrary
193+ json .Unmarshal (resp .Body .Bytes (), & errMap )
194+ assert .EqualValues (t , "review event COMMENT requires a body or a comment" , errMap ["message" ].(string ))
195+
142196 // test get review requests
143197 // to make it simple, use same api with get review
144198 pullIssue12 := models .AssertExistsAndLoadBean (t , & models.Issue {ID : 12 }).(* models.Issue )
0 commit comments