authorizer/server/test/reset_password_test.go

51 lines
1.5 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/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{
2021-12-24 00:57:39 +00:00
Email: email,
Password: s.TestInfo.Password,
ConfirmPassword: s.TestInfo.Password,
})
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-01-21 08:04:04 +00:00
verificationRequest, err := db.Provider.GetVerificationRequestByEmail(email, constants.VerificationTypeForgotPassword)
2021-12-24 00:57:39 +00:00
assert.Nil(t, err, "should get forgot password request")
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.Nil(t, err, "password changed successfully")
cleanData(email)
})
}