2021-12-23 05:01:52 +00:00
|
|
|
package test
|
|
|
|
|
|
|
|
import (
|
|
|
|
"testing"
|
|
|
|
|
2022-01-17 06:02:13 +00:00
|
|
|
"github.com/authorizerdev/authorizer/server/constants"
|
2021-12-23 05:01:52 +00:00
|
|
|
"github.com/authorizerdev/authorizer/server/db"
|
|
|
|
"github.com/authorizerdev/authorizer/server/graph/model"
|
2023-10-21 21:03:36 +00:00
|
|
|
"github.com/authorizerdev/authorizer/server/refs"
|
2021-12-23 05:01:52 +00:00
|
|
|
"github.com/authorizerdev/authorizer/server/resolvers"
|
|
|
|
"github.com/stretchr/testify/assert"
|
|
|
|
)
|
|
|
|
|
2022-01-17 06:02:13 +00:00
|
|
|
func forgotPasswordTest(t *testing.T, s TestSetup) {
|
|
|
|
t.Helper()
|
2021-12-24 00:57:39 +00:00
|
|
|
t.Run(`should run forgot password`, func(t *testing.T) {
|
|
|
|
_, ctx := createContext(s)
|
|
|
|
email := "forgot_password." + s.TestInfo.Email
|
2023-03-29 01:36:33 +00:00
|
|
|
res, err := resolvers.SignupResolver(ctx, model.SignUpInput{
|
2023-10-21 21:03:36 +00:00
|
|
|
Email: refs.NewStringRef(email),
|
2021-12-24 00:57:39 +00:00
|
|
|
Password: s.TestInfo.Password,
|
|
|
|
ConfirmPassword: s.TestInfo.Password,
|
|
|
|
})
|
2023-03-29 01:36:33 +00:00
|
|
|
assert.NoError(t, err)
|
|
|
|
assert.NotNil(t, res)
|
|
|
|
forgotPasswordRes, err := resolvers.ForgotPasswordResolver(ctx, model.ForgotPasswordInput{
|
2023-12-21 19:56:14 +00:00
|
|
|
Email: refs.NewStringRef(email),
|
2021-12-24 00:57:39 +00:00
|
|
|
})
|
|
|
|
assert.Nil(t, err, "no errors for forgot password")
|
2023-03-29 01:36:33 +00:00
|
|
|
assert.NotNil(t, forgotPasswordRes)
|
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)
|
2021-12-23 05:01:52 +00:00
|
|
|
|
2022-01-17 06:02:13 +00:00
|
|
|
assert.Equal(t, verificationRequest.Identifier, constants.VerificationTypeForgotPassword)
|
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
|
|
|
}
|