Generalize post reply notifications (#6)
## Summary - Notify the direct parent post author for replies throughout nested conversations - Skip root creation, self-replies, edits, disabled mail, and recipients without email - Link directly to each reply and use per-reply Resend idempotency Co-authored-by: codegirl-007 <s.raide@gmail.com>
This commit was merged in pull request #6.
This commit is contained in:
+21
-17
@@ -14,24 +14,27 @@ func TestEmbeddedMarkIsPNG(t *testing.T) {
|
||||
}
|
||||
}
|
||||
|
||||
func TestQuestionAnsweredContent(t *testing.T) {
|
||||
func TestPostReplyContent(t *testing.T) {
|
||||
t.Parallel()
|
||||
|
||||
text, htmlBody := questionAnsweredContent("https://plumber.example/", QuestionAnswered{
|
||||
ToName: `<Sam & Pat>`,
|
||||
QuestionID: "question-123",
|
||||
QuestionTitle: `<b>Leaky sink</b>`,
|
||||
AnswerBody: "Replace the cartridge.\nThen test the handle. <script>alert('x')</script>",
|
||||
text, htmlBody := postReplyContent("https://www.askaplumberfirst.com/", PostReply{
|
||||
ToName: `<Sam & Pat>`,
|
||||
RootID: "question-123",
|
||||
RootTitle: `<b>Leaky sink</b>`,
|
||||
ReplyID: "reply-456",
|
||||
ReplyBody: "Replace the cartridge.\nThen test the handle. <script>alert('x')</script>",
|
||||
ReplyAuthorName: `<Jo & Co>`,
|
||||
})
|
||||
|
||||
for _, want := range []string{
|
||||
"Ask a Plumber First",
|
||||
"Shop response",
|
||||
"cid:answer-notification-mark",
|
||||
"https://plumber.example/questions/question-123",
|
||||
"New reply",
|
||||
"cid:reply-notification-mark",
|
||||
"https://www.askaplumberfirst.com/questions/question-123#post-reply-456",
|
||||
"white-space:pre-wrap",
|
||||
"<Sam & Pat>",
|
||||
"<b>Leaky sink</b>",
|
||||
"<Jo & Co>",
|
||||
"<script>alert('x')</script>",
|
||||
} {
|
||||
if !strings.Contains(htmlBody, want) {
|
||||
@@ -41,6 +44,7 @@ func TestQuestionAnsweredContent(t *testing.T) {
|
||||
for _, unsafe := range []string{
|
||||
"<Sam & Pat>",
|
||||
"<b>Leaky sink</b>",
|
||||
"<Jo & Co>",
|
||||
"<script>alert('x')</script>",
|
||||
} {
|
||||
if strings.Contains(htmlBody, unsafe) {
|
||||
@@ -52,9 +56,9 @@ func TestQuestionAnsweredContent(t *testing.T) {
|
||||
}
|
||||
for _, want := range []string{
|
||||
`Hi <Sam & Pat>,`,
|
||||
`Your question "<b>Leaky sink</b>"`,
|
||||
`<Jo & Co> replied in "<b>Leaky sink</b>"`,
|
||||
"Replace the cartridge.\nThen test the handle.",
|
||||
"https://plumber.example/questions/question-123",
|
||||
"https://www.askaplumberfirst.com/questions/question-123#post-reply-456",
|
||||
} {
|
||||
if !strings.Contains(text, want) {
|
||||
t.Errorf("text missing %q", want)
|
||||
@@ -62,15 +66,15 @@ func TestQuestionAnsweredContent(t *testing.T) {
|
||||
}
|
||||
}
|
||||
|
||||
func TestQuestionAnsweredContentUsesFallbackTitle(t *testing.T) {
|
||||
func TestPostReplyContentUsesFallbacks(t *testing.T) {
|
||||
t.Parallel()
|
||||
|
||||
text, htmlBody := questionAnsweredContent("https://plumber.example", QuestionAnswered{})
|
||||
if !strings.Contains(text, `"your question"`) {
|
||||
text, htmlBody := postReplyContent("https://www.askaplumberfirst.com", PostReply{})
|
||||
if !strings.Contains(text, `Someone replied in "your conversation"`) {
|
||||
t.Errorf("text missing fallback title")
|
||||
}
|
||||
if !strings.Contains(htmlBody, "a plumber replied to:</p>") ||
|
||||
!strings.Contains(htmlBody, "“your question”") {
|
||||
t.Errorf("HTML missing fallback title")
|
||||
if !strings.Contains(htmlBody, "Someone replied in:</p>") ||
|
||||
!strings.Contains(htmlBody, "“your conversation”") {
|
||||
t.Errorf("HTML missing fallbacks")
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user