authorizer/server/test/mobile_signup_test.go

86 lines
3.0 KiB
Go
Raw Permalink Normal View History

2022-12-21 17:44:24 +00:00
package test
import (
"testing"
"github.com/authorizerdev/authorizer/server/constants"
"github.com/authorizerdev/authorizer/server/graph/model"
"github.com/authorizerdev/authorizer/server/memorystore"
"github.com/authorizerdev/authorizer/server/refs"
"github.com/authorizerdev/authorizer/server/resolvers"
"github.com/stretchr/testify/assert"
)
2022-12-24 21:52:42 +00:00
func mobileSingupTest(t *testing.T, s TestSetup) {
2022-12-21 17:44:24 +00:00
t.Helper()
t.Run(`should complete the signup with mobile and check duplicates`, func(t *testing.T) {
_, ctx := createContext(s)
email := "mobile_basic_auth_signup." + s.TestInfo.Email
2022-12-24 21:52:42 +00:00
res, err := resolvers.MobileSignupResolver(ctx, &model.MobileSignUpInput{
2022-12-21 17:44:24 +00:00
Email: refs.NewStringRef(email),
Password: s.TestInfo.Password,
ConfirmPassword: s.TestInfo.Password + "s",
})
assert.NotNil(t, err, "invalid password")
assert.Nil(t, res)
2022-12-24 21:52:42 +00:00
res, err = resolvers.MobileSignupResolver(ctx, &model.MobileSignUpInput{
2022-12-21 17:44:24 +00:00
Email: refs.NewStringRef(email),
Password: "test",
ConfirmPassword: "test",
})
assert.NotNil(t, err, "invalid password")
memorystore.Provider.UpdateEnvVariable(constants.EnvKeyDisableSignUp, true)
2022-12-24 21:52:42 +00:00
res, err = resolvers.MobileSignupResolver(ctx, &model.MobileSignUpInput{
2022-12-21 17:44:24 +00:00
Email: refs.NewStringRef(email),
Password: s.TestInfo.Password,
ConfirmPassword: s.TestInfo.Password,
})
assert.NotNil(t, err, "singup disabled")
memorystore.Provider.UpdateEnvVariable(constants.EnvKeyDisableSignUp, false)
memorystore.Provider.UpdateEnvVariable(constants.EnvKeyDisableMobileBasicAuthentication, true)
2022-12-24 21:52:42 +00:00
res, err = resolvers.MobileSignupResolver(ctx, &model.MobileSignUpInput{
2022-12-21 17:44:24 +00:00
Email: refs.NewStringRef(email),
Password: s.TestInfo.Password,
ConfirmPassword: s.TestInfo.Password,
})
assert.NotNil(t, err, "singup disabled")
memorystore.Provider.UpdateEnvVariable(constants.EnvKeyDisableMobileBasicAuthentication, false)
2022-12-24 21:52:42 +00:00
res, err = resolvers.MobileSignupResolver(ctx, &model.MobileSignUpInput{
2022-12-21 17:44:24 +00:00
PhoneNumber: " ",
Password: s.TestInfo.Password,
ConfirmPassword: s.TestInfo.Password,
})
assert.NotNil(t, err, "invalid mobile")
2022-12-24 21:52:42 +00:00
res, err = resolvers.MobileSignupResolver(ctx, &model.MobileSignUpInput{
2022-12-21 17:44:24 +00:00
PhoneNumber: "test",
Password: s.TestInfo.Password,
ConfirmPassword: s.TestInfo.Password,
})
assert.NotNil(t, err, "invalid mobile")
2022-12-24 21:52:42 +00:00
res, err = resolvers.MobileSignupResolver(ctx, &model.MobileSignUpInput{
2022-12-21 17:44:24 +00:00
PhoneNumber: "1234567890",
Password: s.TestInfo.Password,
ConfirmPassword: s.TestInfo.Password,
})
assert.NoError(t, err)
assert.NotEmpty(t, res.AccessToken)
assert.Equal(t, "1234567890@authorizer.dev", res.User.Email)
2022-12-24 21:52:42 +00:00
res, err = resolvers.MobileSignupResolver(ctx, &model.MobileSignUpInput{
2022-12-21 17:44:24 +00:00
PhoneNumber: "1234567890",
Password: s.TestInfo.Password,
ConfirmPassword: s.TestInfo.Password,
})
assert.Error(t, err, "user exists")
2022-12-24 21:52:42 +00:00
cleanData(email)
cleanData("1234567890@authorizer.dev")
2022-12-21 17:44:24 +00:00
})
}