Files
authorizer/server/test/update_profile_test.go

54 lines
1.6 KiB
Go
Raw Normal View History

2021-12-24 06:27:39 +05:30
package test
import (
2022-03-02 17:42:31 +05:30
"context"
2021-12-24 06:27:39 +05:30
"testing"
2022-01-09 17:35:37 +05:30
"github.com/authorizerdev/authorizer/server/constants"
2021-12-24 06:27:39 +05:30
"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 11:32:13 +05:30
func updateProfileTests(t *testing.T, s TestSetup) {
t.Helper()
2021-12-24 06:27:39 +05:30
t.Run(`should update the profile with access token only`, func(t *testing.T) {
req, ctx := createContext(s)
email := "update_profile." + s.TestInfo.Email
2022-01-17 11:32:13 +05:30
resolvers.SignupResolver(ctx, model.SignUpInput{
2021-12-24 06:27:39 +05:30
Email: email,
Password: s.TestInfo.Password,
ConfirmPassword: s.TestInfo.Password,
})
fName := "samani"
2022-01-17 11:32:13 +05:30
_, err := resolvers.UpdateProfileResolver(ctx, model.UpdateProfileInput{
2021-12-24 06:27:39 +05:30
FamilyName: &fName,
})
assert.NotNil(t, err, "unauthorized")
2022-07-10 21:49:33 +05:30
verificationRequest, err := db.Provider.GetVerificationRequestByEmail(ctx, email, constants.VerificationTypeBasicAuthSignup)
2022-01-17 11:32:13 +05:30
verifyRes, err := resolvers.VerifyEmailResolver(ctx, model.VerifyEmailInput{
2021-12-24 06:27:39 +05:30
Token: verificationRequest.Token,
})
2022-03-02 17:42:31 +05:30
assert.NoError(t, err)
2021-12-24 06:27:39 +05:30
2022-03-02 17:42:31 +05:30
s.GinContext.Request.Header.Set("Authorization", "Bearer "+*verifyRes.AccessToken)
ctx = context.WithValue(req.Context(), "GinContextKey", s.GinContext)
2021-12-24 06:27:39 +05:30
newEmail := "new_" + email
2022-01-17 11:32:13 +05:30
_, err = resolvers.UpdateProfileResolver(ctx, model.UpdateProfileInput{
2021-12-24 06:27:39 +05:30
Email: &newEmail,
})
2022-03-02 17:42:31 +05:30
s.GinContext.Request.Header.Set("Authorization", "")
2021-12-24 06:27:39 +05:30
assert.Nil(t, err)
2022-01-17 11:32:13 +05:30
_, err = resolvers.ProfileResolver(ctx)
2021-12-24 06:27:39 +05:30
assert.NotNil(t, err, "unauthorized")
cleanData(newEmail)
cleanData(email)
})
}