Skip to content

Commit

Permalink
add more tests
Browse files Browse the repository at this point in the history
  • Loading branch information
cblgh committed Mar 9, 2021
1 parent 5001e60 commit 1a2f050
Show file tree
Hide file tree
Showing 2 changed files with 49 additions and 1 deletion.
48 changes: 48 additions & 0 deletions web/handlers/admin/notices_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
package admin

import (
"fmt"
"net/http"
"testing"

"github.com/ssb-ngi-pointer/go-ssb-room/web/router"
"github.com/stretchr/testify/assert"
)

/* TODO: 500s for some reason? */
func TestNoticeEditFormIncludesAllFields(t *testing.T) {
ts := newSession(t)
a := assert.New(t)

// Construct notice url to edit
baseurl, err := ts.Router.Get(router.AdminNoticeEdit).URL()
a.Nil(err)
url := fmt.Sprintf("%s?id=%d", baseurl.String(), 1)

_, resp := ts.Client.GetHTML(url)
/* TODO: continue test by checking for 1) forms, and 2) their required input fields */
a.Equal(http.StatusOK, resp.Code, "Wrong HTTP status code")
}


/* TODO: use this test as an example for pair programming 2021-03-09 */
// Assumption: I can use all the exported routes for my tests
// Reality: I can only use the routes associated with the 'correct' testing setup function
// (setup for all, newSession for admin)

// TestEditButtonVisibleForAdmin specifically tests if the regular notice view at /notice/show?id=<x>
// displays an edit button for admin users
func TestNoticeEditButtonVisibleForAdmin(t *testing.T) {
ts := newSession(t)
a := assert.New(t)

// Construct notice url to edit
baseurl, err := ts.Router.Get(router.CompleteNoticeShow).URL() // MARK
fmt.Println(baseurl.String())
a.Nil(err)
// url := fmt.Sprintf("%s?id=%d", baseurl.String(), 1)
//
// html, resp := ts.Client.GetHTML(url)
// fmt.Println(html.Html())
// a.Equal(http.StatusOK, resp.Code, "Wrong HTTP status code")
}
2 changes: 1 addition & 1 deletion web/utils.go
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ func NewURLTo(appRouter *mux.Router) func(string, ...interface{}) *url.URL {
return func(routeName string, ps ...interface{}) *url.URL {
route := appRouter.Get(routeName)
if route == nil {
level.Warn(l).Log("msg", "no such route", "route", routeName, "params", fmt.Sprintf("%v", ps))
// level.Warn(l).Log("msg", "no such route", "route", routeName, "params", fmt.Sprintf("%v", ps))
return &url.URL{}
}

Expand Down

0 comments on commit 1a2f050

Please sign in to comment.