-
-
Notifications
You must be signed in to change notification settings - Fork 386
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
move admin email notifications call to rest/api module
- Loading branch information
Showing
9 changed files
with
81 additions
and
141 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -100,17 +100,15 @@ func TestEmailSendErrors(t *testing.T) { | |
|
||
e.verifyTmpl, err = template.New("test").Parse("{{.Test}}") | ||
assert.NoError(t, err) | ||
err = e.Send(context.Background(), Request{Email: "[email protected]", Verification: VerificationMetadata{Token: "some"}}) | ||
assert.Error(t, err) | ||
assert.Contains(t, err.Error(), "error executing template to build verification message: template: test:1:2: executing \"test\" at <.Test>: can't evaluate field Test in type notify.verifyTmplData") | ||
assert.EqualError(t, e.Send(context.Background(), Request{Email: "[email protected]", Verification: VerificationMetadata{Token: "some"}}), | ||
"error executing template to build verification message: template: test:1:2: executing \"test\" at <.Test>: can't evaluate field Test in type notify.verifyTmplData") | ||
e.verifyTmpl, err = template.New("test").Parse(defaultEmailVerificationTemplate) | ||
assert.NoError(t, err) | ||
|
||
e.msgTmpl, err = template.New("test").Parse("{{.Test}}") | ||
assert.NoError(t, err) | ||
err = e.Send(context.Background(), Request{Comment: store.Comment{ID: "999"}, parent: store.Comment{User: store.User{ID: "test"}}, Email: "[email protected]"}) | ||
assert.Error(t, err) | ||
assert.Contains(t, err.Error(), "error executing template to build comment reply message: template: test:1:2: executing \"test\" at <.Test>: can't evaluate field Test in type notify.msgTmplData") | ||
assert.EqualError(t, e.Send(context.Background(), Request{Comment: store.Comment{ID: "999"}, parent: store.Comment{User: store.User{ID: "test"}}, Email: "[email protected]"}), | ||
"error executing template to build comment reply message: template: test:1:2: executing \"test\" at <.Test>: can't evaluate field Test in type notify.msgTmplData") | ||
e.msgTmpl, err = template.New("test").Parse(defaultEmailTemplate) | ||
assert.NoError(t, err) | ||
|
||
|
@@ -120,9 +118,8 @@ func TestEmailSendErrors(t *testing.T) { | |
"sending message to \"[email protected]\" aborted due to canceled context") | ||
|
||
e.smtp = &fakeTestSMTP{} | ||
err = e.Send(context.Background(), Request{Comment: store.Comment{ID: "999"}, parent: store.Comment{User: store.User{ID: "error"}}, Email: "[email protected]"}) | ||
assert.Error(t, err) | ||
assert.Contains(t, err.Error(), "error creating token for unsubscribe link: token generation error") | ||
assert.EqualError(t, e.Send(context.Background(), Request{Comment: store.Comment{ID: "999"}, parent: store.Comment{User: store.User{ID: "error"}}, Email: "[email protected]"}), | ||
"error creating token for unsubscribe link: token generation error") | ||
e.msgTmpl, err = template.New("test").Parse(defaultEmailTemplate) | ||
assert.NoError(t, err) | ||
} | ||
|
@@ -199,7 +196,7 @@ func TestEmail_Send(t *testing.T) { | |
assert.Equal(t, 1, fakeSmtp.readQuitCount()) | ||
assert.Equal(t, "[email protected]", fakeSmtp.readRcpt()) | ||
// test buildMessageFromRequest separately for message text | ||
res, err := email.buildMessageFromRequest(req, false) | ||
res, err := email.buildMessageFromRequest(req, req.ForAdmin) | ||
assert.NoError(t, err) | ||
assert.Contains(t, res, `From: [email protected] | ||
To: [email protected] | ||
|
@@ -210,39 +207,15 @@ Content-Type: text/html; charset="UTF-8" | |
List-Unsubscribe-Post: List-Unsubscribe=One-Click | ||
List-Unsubscribe: <https://remark42.com/api/v1/email/unsubscribe?site=&tkn=token> | ||
Date: `) | ||
} | ||
|
||
func TestEmail_SendAdmin(t *testing.T) { | ||
email, err := NewEmail(EmailParams{From: "[email protected]", AdminEmail: "[email protected]"}, SmtpParams{}) | ||
assert.NoError(t, err) | ||
assert.NotNil(t, email) | ||
fakeSmtp := fakeTestSMTP{} | ||
email.smtp = &fakeSmtp | ||
email.TokenGenFn = TokenGenFn | ||
req := Request{ | ||
Comment: store.Comment{ID: "999", User: store.User{ID: "1", Name: "test_user"}, ParentID: "1", PostTitle: "test_title"}, | ||
parent: store.Comment{ID: "1", User: store.User{ID: "999", Name: "parent_user"}}, | ||
} | ||
assert.NoError(t, email.Send(context.TODO(), req)) | ||
assert.Equal(t, "[email protected]", fakeSmtp.readMail()) | ||
assert.Equal(t, 1, fakeSmtp.readQuitCount()) | ||
assert.Equal(t, "[email protected]", fakeSmtp.readRcpt()) | ||
// test buildMessageFromRequest separately for message text | ||
res, err := email.buildMessageFromRequest(req, true) | ||
assert.NoError(t, err) | ||
assert.Contains(t, res, `From: [email protected] | ||
To: [email protected] | ||
Subject: New comment to your site for "test_title" | ||
Content-Transfer-Encoding: quoted-printable | ||
MIME-version: 1.0 | ||
Content-Type: text/html; charset="UTF-8" | ||
Date: `) | ||
// send email to admin without parent set | ||
req = Request{ | ||
Comment: store.Comment{ID: "999", User: store.User{ID: "1", Name: "test_user"}, PostTitle: "test_title"}, | ||
Comment: store.Comment{ID: "999", User: store.User{ID: "1", Name: "test_user"}, PostTitle: "test_title"}, | ||
Email: "[email protected]", | ||
ForAdmin: true, | ||
} | ||
assert.NoError(t, email.Send(context.TODO(), req)) | ||
res, err = email.buildMessageFromRequest(req, true) | ||
res, err = email.buildMessageFromRequest(req, req.ForAdmin) | ||
assert.NoError(t, err) | ||
assert.Contains(t, res, `From: [email protected] | ||
To: [email protected] | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.