authorizer/server/test/reset_password_test.go

60 lines
1.8 KiB
Go
Raw Normal View History

package test
import (
"testing"
2022-01-17 06:02:13 +00:00
"github.com/authorizerdev/authorizer/server/constants"
"github.com/authorizerdev/authorizer/server/db"
"github.com/authorizerdev/authorizer/server/graph/model"
"github.com/authorizerdev/authorizer/server/refs"
"github.com/authorizerdev/authorizer/server/resolvers"
"github.com/stretchr/testify/assert"
)
2022-01-17 06:02:13 +00:00
func resetPasswordTest(t *testing.T, s TestSetup) {
t.Helper()
2021-12-24 00:57:39 +00:00
t.Run(`should reset password`, func(t *testing.T) {
email := "reset_password." + s.TestInfo.Email
_, ctx := createContext(s)
2022-01-17 06:02:13 +00:00
_, err := resolvers.SignupResolver(ctx, model.SignUpInput{
Email: refs.NewStringRef(email),
2021-12-24 00:57:39 +00:00
Password: s.TestInfo.Password,
ConfirmPassword: s.TestInfo.Password,
})
assert.NoError(t, err)
2022-01-17 06:02:13 +00:00
_, err = resolvers.ForgotPasswordResolver(ctx, model.ForgotPasswordInput{
2021-12-24 00:57:39 +00:00
Email: email,
})
assert.Nil(t, err, "no errors for forgot password")
2022-07-10 16:19:33 +00:00
verificationRequest, err := db.Provider.GetVerificationRequestByEmail(ctx, email, constants.VerificationTypeForgotPassword)
2021-12-24 00:57:39 +00:00
assert.Nil(t, err, "should get forgot password request")
assert.NotNil(t, verificationRequest)
2022-01-17 06:02:13 +00:00
_, err = resolvers.ResetPasswordResolver(ctx, model.ResetPasswordInput{
2021-12-24 00:57:39 +00:00
Token: verificationRequest.Token,
Password: "test1",
ConfirmPassword: "test",
})
assert.NotNil(t, err, "passowrds don't match")
2022-01-17 06:02:13 +00:00
_, err = resolvers.ResetPasswordResolver(ctx, model.ResetPasswordInput{
2021-12-24 00:57:39 +00:00
Token: verificationRequest.Token,
Password: "test1",
ConfirmPassword: "test1",
})
assert.NotNil(t, err, "invalid password")
_, err = resolvers.ResetPasswordResolver(ctx, model.ResetPasswordInput{
Token: verificationRequest.Token,
Password: "Test@1234",
ConfirmPassword: "Test@1234",
})
2021-12-24 00:57:39 +00:00
assert.Nil(t, err, "password changed successfully")
cleanData(email)
})
}