Files
authorizer/server/test/profile_test.go

46 lines
1.4 KiB
Go
Raw Normal View History

2021-12-24 06:27:39 +05:30
package test
import (
2022-01-09 17:35:37 +05:30
"fmt"
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"
2022-01-17 11:32:13 +05:30
"github.com/authorizerdev/authorizer/server/envstore"
2021-12-24 06:27:39 +05:30
"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 profileTests(t *testing.T, s TestSetup) {
t.Helper()
2021-12-24 06:27:39 +05:30
t.Run(`should get profile only with token`, func(t *testing.T) {
req, ctx := createContext(s)
email := "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,
})
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")
2022-01-21 13:34:04 +05:30
verificationRequest, err := db.Provider.GetVerificationRequestByEmail(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,
})
token := *verifyRes.AccessToken
req.Header.Set("Cookie", fmt.Sprintf("%s=%s", envstore.EnvInMemoryStoreObj.GetStringStoreEnvVariable(constants.EnvKeyCookieName)+".access_token", token))
2022-01-17 11:32:13 +05:30
profileRes, err := resolvers.ProfileResolver(ctx)
2021-12-24 06:27:39 +05:30
assert.Nil(t, err)
newEmail := *&profileRes.Email
assert.Equal(t, email, newEmail, "emails should be equal")
cleanData(email)
})
}