2021-12-23 05:01:52 +00:00
|
|
|
package test
|
|
|
|
|
|
|
|
import (
|
|
|
|
"testing"
|
|
|
|
|
|
|
|
"github.com/authorizerdev/authorizer/server/db"
|
|
|
|
"github.com/authorizerdev/authorizer/server/enum"
|
|
|
|
"github.com/authorizerdev/authorizer/server/graph/model"
|
|
|
|
"github.com/authorizerdev/authorizer/server/resolvers"
|
|
|
|
"github.com/stretchr/testify/assert"
|
|
|
|
)
|
|
|
|
|
2021-12-23 08:47:44 +00:00
|
|
|
func verifyEmailTest(s TestSetup, t *testing.T) {
|
2021-12-24 00:57:39 +00:00
|
|
|
t.Run(`should verify email`, func(t *testing.T) {
|
|
|
|
_, ctx := createContext(s)
|
|
|
|
email := "verify_email." + s.TestInfo.Email
|
|
|
|
res, err := resolvers.Signup(ctx, model.SignUpInput{
|
|
|
|
Email: email,
|
|
|
|
Password: s.TestInfo.Password,
|
|
|
|
ConfirmPassword: s.TestInfo.Password,
|
|
|
|
})
|
2021-12-23 05:01:52 +00:00
|
|
|
|
2021-12-24 00:57:39 +00:00
|
|
|
user := *res.User
|
|
|
|
assert.Equal(t, email, user.Email)
|
|
|
|
assert.Nil(t, res.AccessToken, "access token should be nil")
|
|
|
|
verificationRequest, err := db.Mgr.GetVerificationByEmail(email, enum.BasicAuthSignup.String())
|
|
|
|
assert.Nil(t, err)
|
|
|
|
assert.Equal(t, email, verificationRequest.Email)
|
2021-12-23 05:01:52 +00:00
|
|
|
|
2021-12-24 00:57:39 +00:00
|
|
|
verifyRes, err := resolvers.VerifyEmail(ctx, model.VerifyEmailInput{
|
|
|
|
Token: verificationRequest.Token,
|
|
|
|
})
|
|
|
|
assert.Nil(t, err)
|
|
|
|
assert.NotEqual(t, verifyRes.AccessToken, "", "access token should not be empty")
|
2021-12-23 05:01:52 +00:00
|
|
|
|
2021-12-24 00:57:39 +00:00
|
|
|
cleanData(email)
|
|
|
|
})
|
2021-12-23 05:01:52 +00:00
|
|
|
}
|