authorizer/server/test/profile_test.go

50 lines
1.5 KiB
Go
Raw Permalink Normal View History

2021-12-24 00:57:39 +00:00
package test
import (
2022-03-02 12:12:31 +00:00
"context"
2021-12-24 00:57:39 +00:00
"testing"
2022-01-09 12:05:37 +00:00
"github.com/authorizerdev/authorizer/server/constants"
2021-12-24 00:57:39 +00:00
"github.com/authorizerdev/authorizer/server/db"
"github.com/authorizerdev/authorizer/server/graph/model"
"github.com/authorizerdev/authorizer/server/resolvers"
"github.com/stretchr/testify/assert"
)
2022-01-17 06:02:13 +00:00
func profileTests(t *testing.T, s TestSetup) {
t.Helper()
2022-03-02 12:12:31 +00:00
t.Run(`should get profile only access_token token`, func(t *testing.T) {
2021-12-24 00:57:39 +00:00
req, ctx := createContext(s)
email := "profile." + s.TestInfo.Email
2022-01-17 06:02:13 +00:00
resolvers.SignupResolver(ctx, model.SignUpInput{
2021-12-24 00:57:39 +00:00
Email: email,
Password: s.TestInfo.Password,
ConfirmPassword: s.TestInfo.Password,
})
2022-01-17 06:02:13 +00:00
_, err := resolvers.ProfileResolver(ctx)
2021-12-24 00:57:39 +00:00
assert.NotNil(t, err, "unauthorized")
2022-07-10 16:19:33 +00:00
verificationRequest, err := db.Provider.GetVerificationRequestByEmail(ctx, email, constants.VerificationTypeBasicAuthSignup)
assert.NoError(t, err)
assert.NotNil(t, verificationRequest)
2022-01-17 06:02:13 +00:00
verifyRes, err := resolvers.VerifyEmailResolver(ctx, model.VerifyEmailInput{
2021-12-24 00:57:39 +00:00
Token: verificationRequest.Token,
})
2022-03-02 12:12:31 +00:00
assert.NoError(t, err)
assert.NotNil(t, verifyRes.AccessToken)
2021-12-24 00:57:39 +00:00
2022-03-02 12:12:31 +00:00
s.GinContext.Request.Header.Set("Authorization", "Bearer "+*verifyRes.AccessToken)
ctx = context.WithValue(req.Context(), "GinContextKey", s.GinContext)
2022-01-17 06:02:13 +00:00
profileRes, err := resolvers.ProfileResolver(ctx)
2021-12-24 00:57:39 +00:00
assert.Nil(t, err)
assert.NotNil(t, profileRes)
2022-03-02 12:12:31 +00:00
s.GinContext.Request.Header.Set("Authorization", "")
newEmail := profileRes.Email
2021-12-24 00:57:39 +00:00
assert.Equal(t, email, newEmail, "emails should be equal")
cleanData(email)
})
}