saasitone/pkg/middleware/entity_test.go

24 lines
603 B
Go
Raw Permalink Normal View History

package middleware
import (
"fmt"
"testing"
"github.com/stretchr/testify/assert"
"github.com/stretchr/testify/require"
2024-07-09 17:57:05 -07:00
"git.grosinger.net/tgrosinger/saasitone/pkg/context"
"git.grosinger.net/tgrosinger/saasitone/pkg/tests"
2024-07-11 21:09:15 -07:00
"git.grosinger.net/tgrosinger/saasitone/pkg/models/sqlc"
)
func TestLoadUser(t *testing.T) {
ctx, _ := tests.NewContext(c.Web, "/")
ctx.SetParamNames("user")
ctx.SetParamValues(fmt.Sprintf("%d", usr.ID))
2024-07-11 21:09:15 -07:00
_ = tests.ExecuteMiddleware(ctx, LoadUser(c.DB))
ctxUsr, ok := ctx.Get(context.UserKey).(*sqlc.User)
require.True(t, ok)
assert.Equal(t, usr.ID, ctxUsr.ID)
}