authorizer/server/test/update_profile_test.go

57 lines
1.7 KiB
Go
Raw Normal View History

2021-12-24 00:57:39 +00:00
package test
import (
2022-01-09 12:05:37 +00:00
"fmt"
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"
2022-01-17 06:02:13 +00:00
"github.com/authorizerdev/authorizer/server/envstore"
2021-12-24 00:57:39 +00:00
"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 updateProfileTests(t *testing.T, s TestSetup) {
t.Helper()
2021-12-24 00:57:39 +00:00
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 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,
})
fName := "samani"
2022-01-17 06:02:13 +00:00
_, err := resolvers.UpdateProfileResolver(ctx, model.UpdateProfileInput{
2021-12-24 00:57:39 +00:00
FamilyName: &fName,
})
assert.NotNil(t, err, "unauthorized")
2022-01-21 08:04:04 +00:00
verificationRequest, err := db.Provider.GetVerificationRequestByEmail(email, constants.VerificationTypeBasicAuthSignup)
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,
})
token := *verifyRes.AccessToken
2022-02-28 02:25:01 +00:00
req.Header.Set("Cookie", fmt.Sprintf("%s=%s", envstore.EnvStoreObj.GetStringStoreEnvVariable(constants.EnvKeyCookieName)+".access_token", token))
2022-01-17 06:02:13 +00:00
_, err = resolvers.UpdateProfileResolver(ctx, model.UpdateProfileInput{
2021-12-24 00:57:39 +00:00
FamilyName: &fName,
})
assert.Nil(t, err)
newEmail := "new_" + email
2022-01-17 06:02:13 +00:00
_, err = resolvers.UpdateProfileResolver(ctx, model.UpdateProfileInput{
2021-12-24 00:57:39 +00:00
Email: &newEmail,
})
assert.Nil(t, err)
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")
cleanData(newEmail)
cleanData(email)
})
}