@@ -92,6 +92,23 @@ func TestNewLabel(t *testing.T) {
9292 assert .Equal (t , "/user2/repo1/labels" , test .RedirectURL (ctx .Resp ))
9393}
9494
95+ func TestNewLabelGivenInvalidLabelCode (t * testing.T ) {
96+ unittest .PrepareTestEnv (t )
97+ ctx , _ := contexttest .MockContext (t , "user2/repo1/labels/edit" )
98+ contexttest .LoadUser (t , ctx , 2 )
99+ contexttest .LoadRepo (t , ctx , 1 )
100+ web .SetForm (ctx , & forms.CreateLabelForm {
101+ Title : "newlabel" ,
102+ Color : "bad-label-code" ,
103+ })
104+ NewLabel (ctx )
105+ assert .Equal (t , http .StatusSeeOther , ctx .Resp .WrittenStatus ())
106+ assert .True (t , ctx .Flash .Has ("error" ))
107+ unittest .AssertNotExistsBean (t , & issues_model.Label {
108+ Name : "newlabel" ,
109+ })
110+ }
111+
95112func TestUpdateLabel (t * testing.T ) {
96113 unittest .PrepareTestEnv (t )
97114 ctx , _ := contexttest .MockContext (t , "user2/repo1/labels/edit" )
@@ -113,6 +130,29 @@ func TestUpdateLabel(t *testing.T) {
113130 assert .Equal (t , "/user2/repo1/labels" , test .RedirectURL (ctx .Resp ))
114131}
115132
133+ func TestUpdateLabelGivenInvalidLabelCode (t * testing.T ) {
134+ unittest .PrepareTestEnv (t )
135+ ctx , _ := contexttest .MockContext (t , "user2/repo1/labels/edit" )
136+ contexttest .LoadUser (t , ctx , 2 )
137+ contexttest .LoadRepo (t , ctx , 1 )
138+ web .SetForm (ctx , & forms.CreateLabelForm {
139+ ID : 1 ,
140+ Title : "label1" ,
141+ Color : "bad-label-code" ,
142+ })
143+
144+ UpdateLabel (ctx )
145+
146+ assert .Equal (t , http .StatusSeeOther , ctx .Resp .WrittenStatus ())
147+ assert .Equal (t , "/user2/repo1/labels" , test .RedirectURL (ctx .Resp ))
148+ assert .True (t , ctx .Flash .Has ("error" ))
149+ unittest .AssertExistsAndLoadBean (t , & issues_model.Label {
150+ ID : 1 ,
151+ Name : "label1" ,
152+ Color : "#abcdef" ,
153+ })
154+ }
155+
116156func TestDeleteLabel (t * testing.T ) {
117157 unittest .PrepareTestEnv (t )
118158 ctx , _ := contexttest .MockContext (t , "user2/repo1/labels/delete" )
0 commit comments