Added tests package with helpers. Started on middleware tests.

This commit is contained in:
mikestefanello 2021-12-21 15:18:17 -05:00
parent 0e2625bf51
commit 58ba9f6dcc
9 changed files with 197 additions and 66 deletions

View file

@ -9,20 +9,12 @@ import (
"goweb/ent/passwordtoken"
"goweb/ent/user"
"github.com/gorilla/sessions"
"github.com/labstack/echo-contrib/session"
"github.com/labstack/echo/v4"
"github.com/stretchr/testify/require"
"github.com/stretchr/testify/assert"
)
func TestAuth(t *testing.T) {
// Simulate an HTTP request through the session middleware to initiate the session
mw := session.Middleware(sessions.NewCookieStore([]byte("secret")))
handler := mw(echo.NotFoundHandler)
assert.Error(t, handler(ctx))
assertNoAuth := func() {
_, err := c.Auth.GetAuthenticatedUserID(ctx)
assert.True(t, errors.Is(err, NotAuthenticatedError{}))