Skip to content

Commit d4fc64c

Browse files
committed
more test
1 parent e5b6b24 commit d4fc64c

File tree

1 file changed

+55
-0
lines changed

1 file changed

+55
-0
lines changed

recipe/emailverification/emailverification_email_test.go

Lines changed: 55 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@ import (
2626
"github.com/supertokens/supertokens-golang/recipe/session"
2727
"github.com/supertokens/supertokens-golang/recipe/session/sessmodels"
2828
"github.com/supertokens/supertokens-golang/supertokens"
29+
"github.com/supertokens/supertokens-golang/test/unittesting"
2930
)
3031

3132
func TestBackwardCompatibilityServiceWithoutCustomFunction(t *testing.T) {
@@ -286,6 +287,60 @@ func TestSMTPServiceOverrideDefaultEmailTemplate(t *testing.T) {
286287
assert.Equal(t, sendRawEmailCalled, true)
287288
}
288289

290+
func TestThatLinkUsesResultFromOriginFunction(t *testing.T) {
291+
link := ""
292+
configValue := supertokens.TypeInput{
293+
Supertokens: &supertokens.ConnectionInfo{
294+
ConnectionURI: "http://localhost:8080",
295+
},
296+
AppInfo: supertokens.AppInfo{
297+
APIDomain: "api.supertokens.io",
298+
AppName: "SuperTokens",
299+
GetOrigin: func(request *http.Request, userContext supertokens.UserContext) (string, error) {
300+
return (*userContext)["link"].(string), nil
301+
},
302+
},
303+
RecipeList: []supertokens.Recipe{
304+
Init(evmodels.TypeInput{
305+
Mode: "OPTIONAL",
306+
EmailDelivery: &emaildelivery.TypeInput{
307+
Override: func(originalImplementation emaildelivery.EmailDeliveryInterface) emaildelivery.EmailDeliveryInterface {
308+
(*originalImplementation.SendEmail) = func(input emaildelivery.EmailType, userContext supertokens.UserContext) error {
309+
link = input.EmailVerification.EmailVerifyLink
310+
return nil
311+
}
312+
return originalImplementation
313+
},
314+
},
315+
}),
316+
session.Init(nil),
317+
},
318+
}
319+
320+
BeforeEach()
321+
unittesting.StartUpST("localhost", "8080")
322+
defer AfterEach()
323+
err := supertokens.Init(configValue)
324+
if err != nil {
325+
t.Error(err.Error())
326+
}
327+
328+
email := "[email protected]"
329+
resp, err := SendEmailVerificationEmail("public", "userId", &email, &map[string]interface{}{
330+
"link": "localhost:8080",
331+
})
332+
if err != nil {
333+
t.Error(err.Error())
334+
}
335+
assert.True(t, resp.OK != nil)
336+
337+
assert.Equal(t, EmailVerificationEmailSentForTest, false)
338+
// assert that link starts with http://localhost:8080. We use starts with because the link
339+
// can continue a path and random query params too
340+
assert.Equal(t, link[:21], "http://localhost:8080")
341+
342+
}
343+
289344
// func TestSMTPServiceManually(t *testing.T) {
290345
// targetEmail := "..."
291346
// fromEmail := "[email protected]"

0 commit comments

Comments
 (0)