add cookie to request for logged in users in tests

This commit is contained in:
Lars Hoogestraat 2019-01-08 10:30:44 +01:00
parent ef9c3d235e
commit d1e22852a2
2 changed files with 9 additions and 1 deletions

View File

@ -93,7 +93,8 @@ func doAdminProfileRequest(user reqUser, u *models.User, currentPassword string)
}
rw := httptest.NewRecorder()
tpl := controllers.AdminProfilePostHandler(ctx, rw, r.buildRequest())
re := r.buildRequest()
tpl := controllers.AdminProfilePostHandler(ctx, rw, re)
if tpl.Err != nil {
return tpl.Err

View File

@ -342,6 +342,13 @@ func (r request) buildRequest() *http.Request {
return req
} else {
user, _ = ctx.UserService.GetByID(int(r.user))
recorder := httptest.NewRecorder()
session := ctx.SessionService.Create(recorder, req)
session.SetValue("userid", user.ID)
cookie := recorder.Result().Cookies()[0]
req.AddCookie(cookie)
}
reqCtx := context.WithValue(req.Context(), middleware.UserContextKey, user)