2022-08-30 02:30:36 +00:00
|
|
|
package services
|
|
|
|
|
|
|
|
import (
|
|
|
|
"context"
|
|
|
|
"testing"
|
|
|
|
|
|
|
|
"github.com/google/uuid"
|
2022-08-30 18:05:11 +00:00
|
|
|
"github.com/hay-kot/content/backend/ent"
|
2022-08-30 02:30:36 +00:00
|
|
|
"github.com/stretchr/testify/assert"
|
|
|
|
)
|
|
|
|
|
|
|
|
func Test_SetAuthContext(t *testing.T) {
|
2022-08-30 18:05:11 +00:00
|
|
|
user := &ent.User{
|
2022-08-30 02:30:36 +00:00
|
|
|
ID: uuid.New(),
|
|
|
|
}
|
|
|
|
|
|
|
|
token := uuid.New().String()
|
|
|
|
|
|
|
|
ctx := SetUserCtx(context.Background(), user, token)
|
|
|
|
|
|
|
|
ctxUser := UseUserCtx(ctx)
|
|
|
|
|
|
|
|
assert.NotNil(t, ctxUser)
|
|
|
|
assert.Equal(t, user.ID, ctxUser.ID)
|
|
|
|
|
|
|
|
ctxUserToken := UseTokenCtx(ctx)
|
|
|
|
assert.NotEmpty(t, ctxUserToken)
|
|
|
|
}
|
|
|
|
|
|
|
|
func Test_SetAuthContext_Nulls(t *testing.T) {
|
|
|
|
ctx := SetUserCtx(context.Background(), nil, "")
|
|
|
|
|
|
|
|
ctxUser := UseUserCtx(ctx)
|
|
|
|
|
|
|
|
assert.Nil(t, ctxUser)
|
|
|
|
|
|
|
|
ctxUserToken := UseTokenCtx(ctx)
|
|
|
|
assert.Empty(t, ctxUserToken)
|
|
|
|
}
|