@@ -74,8 +74,79 @@ func TestAPICreatePullSuccess(t *testing.T) {
74
74
Base : "master" ,
75
75
Title : "create a failure pr" ,
76
76
})
77
-
78
77
session .MakeRequest (t , req , 201 )
78
+ session .MakeRequest (t , req , http .StatusUnprocessableEntity ) // second request should fail
79
+ }
80
+
81
+ func TestAPICreatePullWithFieldsSuccess (t * testing.T ) {
82
+ defer prepareTestEnv (t )()
83
+ // repo10 have code, pulls units.
84
+ repo10 := models .AssertExistsAndLoadBean (t , & models.Repository {ID : 10 }).(* models.Repository )
85
+ owner10 := models .AssertExistsAndLoadBean (t , & models.User {ID : repo10 .OwnerID }).(* models.User )
86
+ // repo11 only have code unit but should still create pulls
87
+ repo11 := models .AssertExistsAndLoadBean (t , & models.Repository {ID : 11 }).(* models.Repository )
88
+ owner11 := models .AssertExistsAndLoadBean (t , & models.User {ID : repo11 .OwnerID }).(* models.User )
89
+
90
+ session := loginUser (t , owner11 .Name )
91
+ token := getTokenForLoggedInUser (t , session )
92
+
93
+ opts := & api.CreatePullRequestOption {
94
+ Head : fmt .Sprintf ("%s:master" , owner11 .Name ),
95
+ Base : "master" ,
96
+ Title : "create a failure pr" ,
97
+ Body : "foobaaar" ,
98
+ Milestone : 5 ,
99
+ Assignees : []string {owner10 .Name },
100
+ Labels : []int64 {5 },
101
+ }
102
+
103
+ req := NewRequestWithJSON (t , http .MethodPost , fmt .Sprintf ("/api/v1/repos/%s/%s/pulls?token=%s" , owner10 .Name , repo10 .Name , token ), opts )
104
+
105
+ res := session .MakeRequest (t , req , 201 )
106
+ pull := new (api.PullRequest )
107
+ DecodeJSON (t , res , pull )
108
+
109
+ assert .NotNil (t , pull .Milestone )
110
+ assert .EqualValues (t , opts .Milestone , pull .Milestone .ID )
111
+ if assert .Len (t , pull .Assignees , 1 ) {
112
+ assert .EqualValues (t , opts .Assignees [0 ], owner10 .Name )
113
+ }
114
+ assert .NotNil (t , pull .Labels )
115
+ assert .EqualValues (t , opts .Labels [0 ], pull .Labels [0 ].ID )
116
+ }
117
+
118
+ func TestAPICreatePullWithFieldsFailure (t * testing.T ) {
119
+ defer prepareTestEnv (t )()
120
+ // repo10 have code, pulls units.
121
+ repo10 := models .AssertExistsAndLoadBean (t , & models.Repository {ID : 10 }).(* models.Repository )
122
+ owner10 := models .AssertExistsAndLoadBean (t , & models.User {ID : repo10 .OwnerID }).(* models.User )
123
+ // repo11 only have code unit but should still create pulls
124
+ repo11 := models .AssertExistsAndLoadBean (t , & models.Repository {ID : 11 }).(* models.Repository )
125
+ owner11 := models .AssertExistsAndLoadBean (t , & models.User {ID : repo11 .OwnerID }).(* models.User )
126
+
127
+ session := loginUser (t , owner11 .Name )
128
+ token := getTokenForLoggedInUser (t , session )
129
+
130
+ opts := & api.CreatePullRequestOption {
131
+ Head : fmt .Sprintf ("%s:master" , owner11 .Name ),
132
+ Base : "master" ,
133
+ }
134
+
135
+ req := NewRequestWithJSON (t , http .MethodPost , fmt .Sprintf ("/api/v1/repos/%s/%s/pulls?token=%s" , owner10 .Name , repo10 .Name , token ), opts )
136
+ session .MakeRequest (t , req , http .StatusUnprocessableEntity )
137
+ opts .Title = "is required"
138
+
139
+ opts .Milestone = 666
140
+ session .MakeRequest (t , req , http .StatusUnprocessableEntity )
141
+ opts .Milestone = 5
142
+
143
+ opts .Assignees = []string {"qweruqweroiuyqweoiruywqer" }
144
+ session .MakeRequest (t , req , http .StatusUnprocessableEntity )
145
+ opts .Assignees = []string {owner10 .LoginName }
146
+
147
+ opts .Labels = []int64 {55555 }
148
+ session .MakeRequest (t , req , http .StatusUnprocessableEntity )
149
+ opts .Labels = []int64 {5 }
79
150
}
80
151
81
152
func TestAPIEditPull (t * testing.T ) {
0 commit comments