Skip to content

Commit

Permalink
use errHandler in admin tests
Browse files Browse the repository at this point in the history
  • Loading branch information
cryptix authored and cblgh committed Apr 26, 2021
1 parent cae80e3 commit 3651432
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 6 deletions.
3 changes: 1 addition & 2 deletions web/handlers/admin/invites_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -159,8 +159,7 @@ func TestInvitesCreate(t *testing.T) {
_, userID := ts.InvitesDB.CreateArgsForCall(totalCreateCallCount - 1)
a.EqualValues(ts.User.ID, userID)
} else {
// TODO: status should be http.StatusForbidden? see invites.go:79
a.Equal(http.StatusInternalServerError, rec.Code)
a.Equal(http.StatusForbidden, rec.Code)
r.Equal(totalCreateCallCount, ts.InvitesDB.CreateCallCount())
}
return rec
Expand Down
2 changes: 1 addition & 1 deletion web/handlers/admin/notices_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,7 @@ func TestNoticeAddLanguageOnlyAllowsPost(t *testing.T) {
// verify that a GET request is no bueno
u := ts.URLTo(router.AdminNoticeAddTranslation, "name", roomdb.NoticeNews.String())
_, resp := ts.Client.GetHTML(u)
a.Equal(http.StatusMethodNotAllowed, resp.Code, "GET should not be allowed for this route")
a.Equal(http.StatusBadRequest, resp.Code, "GET should not be allowed for this route")

// next up, we verify that a correct POST request actually works:
id := []string{"1"}
Expand Down
10 changes: 7 additions & 3 deletions web/handlers/admin/setup_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -130,10 +130,10 @@ func newSession(t *testing.T) *testSession {
os.MkdirAll(sessionsPath, 0700)
fsStore := sessions.NewFilesystemStore(sessionsPath, authKey, encKey)

flashHelper := weberrs.NewFlashHelper(fsStore, locHelper)

// setup rendering
flashHelper := weberrs.NewFlashHelper(fsStore, locHelper)

// template funcs
// TODO: make testing utils and move these there
testFuncs := web.TemplateFuncs(router, ts.netInfo)
testFuncs["current_page_is"] = func(routeName string) bool { return true }
Expand All @@ -152,11 +152,13 @@ func newSession(t *testing.T) *testSession {
testFuncs["list_languages"] = func(*url.URL, string) string { return "" }
testFuncs["relative_time"] = func(when time.Time) string { return humanize.Time(when) }

eh := weberrs.NewErrorHandler(locHelper, flashHelper)

renderOpts := []render.Option{
render.SetLogger(log),
render.BaseTemplates("base.tmpl", "menu.tmpl", "flashes.tmpl"),
render.AddTemplates(append(HTMLTemplates, "error.tmpl")...),
render.ErrorTemplate("error.tmpl"),
render.SetErrorHandler(eh.Handle),
render.FuncMap(testFuncs),
}
renderOpts = append(renderOpts, locHelper.GetRenderFuncs()...)
Expand All @@ -166,6 +168,8 @@ func newSession(t *testing.T) *testSession {
t.Fatal(errors.Wrap(err, "setup: render init failed"))
}

eh.SetRenderer(r)

handler := Handler(
ts.netInfo,
r,
Expand Down

0 comments on commit 3651432

Please sign in to comment.