Add helper for subscribing school as school

This commit is contained in:
Andrea Fazzi 2020-01-24 12:48:50 +01:00
parent 43952efd77
commit e574c20d22

View file

@ -3,6 +3,7 @@ package handlers
import ( import (
"context" "context"
"encoding/json" "encoding/json"
"errors"
"fmt" "fmt"
"log" "log"
"net/http" "net/http"
@ -112,6 +113,39 @@ func deleteSchool(id uint) int {
return rr.Code 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) { func TestRunner(t *testing.T) {
prettytest.Run( prettytest.Run(
t, t,
@ -388,3 +422,8 @@ func (t *testSuite) TestSchoolSubscription() {
t.Equal(http.StatusOK, deleteSchool(501)) t.Equal(http.StatusOK, deleteSchool(501))
} }
func (t *testSuite) TestUserModifier() {
err := subscribeSchoolAsSchool()
t.Nil(err)
}