2021-12-21 18:02:25 -08:00
|
|
|
package middleware
|
|
|
|
|
|
|
|
import (
|
|
|
|
"fmt"
|
|
|
|
"testing"
|
|
|
|
|
2022-01-01 07:44:18 -08:00
|
|
|
"github.com/mikestefanello/pagoda/ent"
|
2022-11-02 16:23:26 -07:00
|
|
|
"github.com/mikestefanello/pagoda/pkg/context"
|
|
|
|
"github.com/mikestefanello/pagoda/pkg/tests"
|
2021-12-21 18:02:25 -08:00
|
|
|
|
|
|
|
"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)
|
|
|
|
}
|