@@ -87,7 +87,7 @@ func TestNewWebHookLink(t *testing.T) {
8787func TestWebhookForms (t * testing.T ) {
8888 defer tests .PrepareTestEnv (t )()
8989
90- session := loginUser (t , "user2 " )
90+ session := loginUser (t , "user1 " )
9191
9292 t .Run ("forgejo/required" , testWebhookForms ("forgejo" , session , map [string ]string {
9393 "payload_url" : "https://forgejo.example.com" ,
@@ -299,7 +299,9 @@ func assertInput(t testing.TB, form *goquery.Selection, name string) string {
299299 t .Helper ()
300300 input := form .Find (`input[name="` + name + `"]` )
301301 if input .Length () != 1 {
302- t .Log (form .Html ())
302+ form .Find ("input" ).Each (func (i int , s * goquery.Selection ) {
303+ t .Logf ("found <input name=%q />" , s .AttrOr ("name" , "" ))
304+ })
303305 t .Errorf ("field <input name=%q /> found %d times, expected once" , name , input .Length ())
304306 }
305307 switch input .AttrOr ("type" , "" ) {
@@ -321,6 +323,12 @@ func testWebhookForms(name string, session *TestSession, validFields map[string]
321323 t .Run ("org3" , func (t * testing.T ) {
322324 testWebhookFormsShared (t , "/org/org3/settings/hooks" , name , session , validFields , invalidPatches ... )
323325 })
326+ t .Run ("system" , func (t * testing.T ) {
327+ testWebhookFormsShared (t , "/admin/system-hooks" , name , session , validFields , invalidPatches ... )
328+ })
329+ t .Run ("default" , func (t * testing.T ) {
330+ testWebhookFormsShared (t , "/admin/default-hooks" , name , session , validFields , invalidPatches ... )
331+ })
324332 }
325333}
326334
@@ -345,17 +353,29 @@ func testWebhookFormsShared(t *testing.T, endpoint, name string, session *TestSe
345353 // create the webhook (this redirects back to the hook list)
346354 resp = session .MakeRequest (t , NewRequestWithValues (t , "POST" , endpoint + "/" + name + "/new" , payload ), http .StatusSeeOther )
347355 assertHasFlashMessages (t , resp , "success" )
356+ listEndpoint := resp .Header ().Get ("Location" )
357+ updateEndpoint := endpoint + "/"
358+ if endpoint == "/admin/system-hooks" || endpoint == "/admin/default-hooks" {
359+ updateEndpoint = "/admin/hooks/"
360+ }
348361
349362 // find last created hook in the hook list
350363 // (a bit hacky, but the list should be sorted)
351- resp = session .MakeRequest (t , NewRequest (t , "GET" , endpoint ), http .StatusOK )
364+ resp = session .MakeRequest (t , NewRequest (t , "GET" , listEndpoint ), http .StatusOK )
352365 htmlDoc := NewHTMLParser (t , resp .Body )
353- editFormURL := htmlDoc .Find (`a[href^="` + endpoint + `/"]` ).Last ().AttrOr ("href" , "" )
366+ selector := `a[href^="` + updateEndpoint + `"]`
367+ if endpoint == "/admin/system-hooks" {
368+ // system-hooks and default-hooks are listed on the same page
369+ // add a specifier to select the latest system-hooks
370+ // (the default-hooks are at the end, so no further specifier needed)
371+ selector = `.admin-setting-content > div:first-of-type ` + selector
372+ }
373+ editFormURL := htmlDoc .Find (selector ).Last ().AttrOr ("href" , "" )
354374 assert .NotEmpty (t , editFormURL )
355375
356376 // edit webhook form
357377 resp = session .MakeRequest (t , NewRequest (t , "GET" , editFormURL ), http .StatusOK )
358- htmlForm = NewHTMLParser (t , resp .Body ).Find (`form[action^="` + endpoint + `/ "]` )
378+ htmlForm = NewHTMLParser (t , resp .Body ).Find (`form[action^="` + updateEndpoint + `"]` )
359379 editPostURL := htmlForm .AttrOr ("action" , "" )
360380 assert .NotEmpty (t , editPostURL )
361381
@@ -375,7 +395,7 @@ func testWebhookFormsShared(t *testing.T, endpoint, name string, session *TestSe
375395
376396 // check the updated webhook
377397 resp = session .MakeRequest (t , NewRequest (t , "GET" , editFormURL ), http .StatusOK )
378- htmlForm = NewHTMLParser (t , resp .Body ).Find (`form[action^="` + endpoint + `/ "]` )
398+ htmlForm = NewHTMLParser (t , resp .Body ).Find (`form[action^="` + updateEndpoint + `"]` )
379399 for k , v := range validFields {
380400 assert .Equal (t , v , assertInput (t , htmlForm , k ), "input %q did not contain value %q" , k , v )
381401 }
0 commit comments