From 86307e367f99d6b3f5d1479fa43861cf32c9618a Mon Sep 17 00:00:00 2001 From: rishabhpoddar Date: Sun, 26 Nov 2023 22:03:59 +0530 Subject: [PATCH] adds more tests --- .../emailpassword/emailpassword_email_test.go | 39 +++++++++++++++++++ .../tpep_email_test.go | 39 +++++++++++++++++++ 2 files changed, 78 insertions(+) diff --git a/recipe/emailpassword/emailpassword_email_test.go b/recipe/emailpassword/emailpassword_email_test.go index ca1c2361..a9dc100f 100644 --- a/recipe/emailpassword/emailpassword_email_test.go +++ b/recipe/emailpassword/emailpassword_email_test.go @@ -668,3 +668,42 @@ func TestSMTPOverrideEmailVerifyForEmailPasswordUser(t *testing.T) { assert.Equal(t, getContentCalled, true) assert.Equal(t, sendRawEmailCalled, true) } + +func TestSendResetPassworEmailFunction(t *testing.T) { + BeforeEach() + unittesting.StartUpST("localhost", "8080") + defer AfterEach() + + resetLink := "" + + testServer := supertokensInitForTest(t, + session.Init(&sessmodels.TypeInput{ + GetTokenTransferMethod: func(req *http.Request, forCreateNewSession bool, userContext supertokens.UserContext) sessmodels.TokenTransferMethod { + return sessmodels.CookieTransferMethod + }, + }), + Init(&epmodels.TypeInput{ + EmailDelivery: &emaildelivery.TypeInput{ + Override: func(originalImplementation emaildelivery.EmailDeliveryInterface) emaildelivery.EmailDeliveryInterface { + *originalImplementation.SendEmail = func(input emaildelivery.EmailType, userContext supertokens.UserContext) error { + resetLink = input.PasswordReset.PasswordResetLink + return nil + } + return originalImplementation + }, + }, + }), + ) + defer testServer.Close() + + user, err := SignUp("public", "test@example.com", "pass1234") + assert.NoError(t, err) + + resp, err := SendResetPasswordEmail("public", user.OK.User.ID) + assert.NoError(t, err) + assert.True(t, resp.OK != nil) + + assert.Contains(t, resetLink, "rid=emailpassword") + assert.Contains(t, resetLink, "tenantId=public") + assert.Contains(t, resetLink, "token=") +} diff --git a/recipe/thirdpartyemailpassword/tpep_email_test.go b/recipe/thirdpartyemailpassword/tpep_email_test.go index f1437e28..828eeb8c 100644 --- a/recipe/thirdpartyemailpassword/tpep_email_test.go +++ b/recipe/thirdpartyemailpassword/tpep_email_test.go @@ -927,3 +927,42 @@ func TestSMTPOverrideEmailVerifyForThirdpartyUser(t *testing.T) { assert.Equal(t, getContentCalled, true) assert.Equal(t, sendRawEmailCalled, true) } + +func TestSendResetPassworEmailFunction(t *testing.T) { + BeforeEach() + unittesting.StartUpST("localhost", "8080") + defer AfterEach() + + resetLink := "" + + testServer := supertokensInitForTest(t, + session.Init(&sessmodels.TypeInput{ + GetTokenTransferMethod: func(req *http.Request, forCreateNewSession bool, userContext supertokens.UserContext) sessmodels.TokenTransferMethod { + return sessmodels.CookieTransferMethod + }, + }), + Init(&tpepmodels.TypeInput{ + EmailDelivery: &emaildelivery.TypeInput{ + Override: func(originalImplementation emaildelivery.EmailDeliveryInterface) emaildelivery.EmailDeliveryInterface { + *originalImplementation.SendEmail = func(input emaildelivery.EmailType, userContext supertokens.UserContext) error { + resetLink = input.PasswordReset.PasswordResetLink + return nil + } + return originalImplementation + }, + }, + }), + ) + defer testServer.Close() + + user, err := EmailPasswordSignUp("public", "test@example.com", "pass1234") + assert.NoError(t, err) + + resp, err := SendResetPasswordEmail("public", user.OK.User.ID) + assert.NoError(t, err) + assert.True(t, resp.OK != nil) + + assert.Contains(t, resetLink, "rid=thirdpartyemailpassword") + assert.Contains(t, resetLink, "tenantId=public") + assert.Contains(t, resetLink, "token=") +}