From e574c20d22f734e1f7f991b72aac86e35e7d3b97 Mon Sep 17 00:00:00 2001 From: Andrea Fazzi Date: Fri, 24 Jan 2020 12:48:50 +0100 Subject: [PATCH] Add helper for subscribing school as school --- handlers/handlers_test.go | 39 +++++++++++++++++++++++++++++++++++++++ 1 file changed, 39 insertions(+) diff --git a/handlers/handlers_test.go b/handlers/handlers_test.go index d113903f..33d4474c 100644 --- a/handlers/handlers_test.go +++ b/handlers/handlers_test.go @@ -3,6 +3,7 @@ package handlers import ( "context" "encoding/json" + "errors" "fmt" "log" "net/http" @@ -112,6 +113,39 @@ func deleteSchool(id uint) int { return rr.Code } +func subscribeSchoolAsSchool() error { + form := url.Values{} + form.Add("Name", "Foo School") + form.Add("Code", "123456789") + form.Add("Email", "foo@school.org") + + req, err := handlers.NewCreateRequest(&orm.School{}, "/schools/create/", "html", "POST", form) + if err != nil { + panic(err) + } + + req.Header.Set("Content-Type", "application/x-www-form-urlencoded") + + req, err = login(req, handlers, "subscriber", "subscribe") + if err != nil { + panic(err) + } + + rr := httptest.NewRecorder() + + router := mux.NewRouter() + router.Handle("/schools/create/", handlers.Create(&orm.School{})) + router.ServeHTTP(rr, req) + + if rr.Code != http.StatusSeeOther { + return errors.New("Unexpected response code") + } + + log.Println(rr.Header()["Location"]) + + return nil +} + func TestRunner(t *testing.T) { prettytest.Run( t, @@ -388,3 +422,8 @@ func (t *testSuite) TestSchoolSubscription() { t.Equal(http.StatusOK, deleteSchool(501)) } + +func (t *testSuite) TestUserModifier() { + err := subscribeSchoolAsSchool() + t.Nil(err) +}