2021-12-21 18:02:25 -08:00
|
|
|
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"
|
2021-12-21 18:02:25 -08:00
|
|
|
)
|
|
|
|
|
|
|
|
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)
|
2021-12-21 18:02:25 -08:00
|
|
|
require.True(t, ok)
|
|
|
|
assert.Equal(t, usr.ID, ctxUsr.ID)
|
|
|
|
}
|