authorizer/server/test/signup_test.go

66 lines
2.1 KiB
Go
Raw Permalink Normal View History

2021-12-22 10:01:45 +00:00
package test
import (
"testing"
2022-01-17 06:02:13 +00:00
"github.com/authorizerdev/authorizer/server/constants"
"github.com/authorizerdev/authorizer/server/db"
2021-12-22 10:01:45 +00:00
"github.com/authorizerdev/authorizer/server/graph/model"
2022-05-30 03:49:55 +00:00
"github.com/authorizerdev/authorizer/server/memorystore"
2021-12-22 10:01:45 +00:00
"github.com/authorizerdev/authorizer/server/resolvers"
"github.com/stretchr/testify/assert"
)
2022-01-17 06:02:13 +00:00
func signupTests(t *testing.T, s TestSetup) {
t.Helper()
2021-12-24 00:57:39 +00:00
t.Run(`should complete the signup and check duplicates`, func(t *testing.T) {
_, ctx := createContext(s)
email := "signup." + s.TestInfo.Email
2022-01-17 06:02:13 +00:00
res, err := resolvers.SignupResolver(ctx, model.SignUpInput{
2021-12-24 00:57:39 +00:00
Email: email,
Password: s.TestInfo.Password,
ConfirmPassword: s.TestInfo.Password + "s",
})
assert.NotNil(t, err, "invalid password")
2021-12-24 00:57:39 +00:00
res, err = resolvers.SignupResolver(ctx, model.SignUpInput{
Email: email,
Password: "test",
ConfirmPassword: "test",
})
assert.NotNil(t, err, "invalid password")
2022-05-30 07:17:50 +00:00
memorystore.Provider.UpdateEnvVariable(constants.EnvKeyDisableSignUp, true)
2022-01-17 06:02:13 +00:00
res, err = resolvers.SignupResolver(ctx, model.SignUpInput{
2021-12-24 00:57:39 +00:00
Email: email,
Password: s.TestInfo.Password,
ConfirmPassword: s.TestInfo.Password,
})
assert.NotNil(t, err, "singup disabled")
2021-12-24 00:57:39 +00:00
2022-05-30 07:17:50 +00:00
memorystore.Provider.UpdateEnvVariable(constants.EnvKeyDisableSignUp, false)
res, err = resolvers.SignupResolver(ctx, model.SignUpInput{
Email: email,
Password: s.TestInfo.Password,
ConfirmPassword: s.TestInfo.Password,
})
assert.Nil(t, err, "signup should be successful")
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")
2022-01-17 06:02:13 +00:00
res, err = resolvers.SignupResolver(ctx, model.SignUpInput{
2021-12-24 00:57:39 +00:00
Email: email,
Password: s.TestInfo.Password,
ConfirmPassword: s.TestInfo.Password,
})
assert.NotNil(t, err, "should throw duplicate email error")
2022-07-10 16:19:33 +00:00
verificationRequest, err := db.Provider.GetVerificationRequestByEmail(ctx, email, constants.VerificationTypeBasicAuthSignup)
2021-12-24 00:57:39 +00:00
assert.Nil(t, err)
assert.Equal(t, email, verificationRequest.Email)
cleanData(email)
})
}