saasitone/middleware/entity_test.go
2022-01-01 10:44:18 -05:00

24 lines
565 B
Go

package middleware
import (
"fmt"
"testing"
"github.com/mikestefanello/pagoda/context"
"github.com/mikestefanello/pagoda/ent"
"github.com/mikestefanello/pagoda/tests"
"github.com/stretchr/testify/assert"
"github.com/stretchr/testify/require"
)
func TestLoadUser(t *testing.T) {
ctx, _ := tests.NewContext(c.Web, "/")
ctx.SetParamNames("user")
ctx.SetParamValues(fmt.Sprintf("%d", usr.ID))
_ = tests.ExecuteMiddleware(ctx, LoadUser(c.ORM))
ctxUsr, ok := ctx.Get(context.UserKey).(*ent.User)
require.True(t, ok)
assert.Equal(t, usr.ID, ctxUsr.ID)
}