Skip to content

Commit

Permalink
adds more tests
Browse files Browse the repository at this point in the history
  • Loading branch information
rishabhpoddar committed Nov 26, 2023
1 parent 1f08095 commit 86307e3
Show file tree
Hide file tree
Showing 2 changed files with 78 additions and 0 deletions.
39 changes: 39 additions & 0 deletions recipe/emailpassword/emailpassword_email_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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", "[email protected]", "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=")
}
39 changes: 39 additions & 0 deletions recipe/thirdpartyemailpassword/tpep_email_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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", "[email protected]", "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=")
}

0 comments on commit 86307e3

Please sign in to comment.