-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathconvert_test.go
More file actions
97 lines (76 loc) · 2.26 KB
/
convert_test.go
File metadata and controls
97 lines (76 loc) · 2.26 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
package convert_test
import (
"net/mail"
"strings"
"testing"
"github.com/google/go-cmp/cmp"
"github.com/mtlynch/screenjournal/v2/email"
"github.com/mtlynch/screenjournal/v2/email/smtp/convert"
)
func TestFromEmail(t *testing.T) {
convert.MultipartBoundary = "dummy-boundary-for-testing"
var tests = []struct {
input email.Message
expected string
}{
{
input: email.Message{
From: mail.Address{
Name: "ScreenJournal Bot",
Address: "bot@sj.example.com",
},
To: []mail.Address{
{
Name: "Alice User",
Address: "alice@user.example.com",
},
},
Subject: "Frank posted a review of The Room",
TextBody: `Hi Alice,
Frank has posted a new review of *The Room*:
https://sj.example.com/movies/1#review25
Sincerely,
ScreenJournal Bot`,
HtmlBody: `<p>Hi Alice,</p>
<p>Frank has posted a new review of <em>The Room</em>:</p>
<p><a href="https://sj.example.com/movies/1#review25">https://sj.example.com/movies/1#review25</a></p>
<p>-ScreenJournal Bot</p>`,
},
expected: normalizeLineEndings(`From: "ScreenJournal Bot" <bot@sj.example.com>
To: "Alice User" <alice@user.example.com>
Subject: Frank posted a review of The Room
MIME-Version: 1.0
Content-Type: multipart/alternative; boundary="dummy-boundary-for-testing"
--dummy-boundary-for-testing
Content-Transfer-Encoding: quoted-printable
Content-Type: text/plain; charset="UTF-8"
Hi Alice,
Frank has posted a new review of *The Room*:
https://sj.example.com/movies/1#review25
Sincerely,
ScreenJournal Bot
--dummy-boundary-for-testing
Content-Transfer-Encoding: quoted-printable
Content-Type: text/html; charset="UTF-8"
<p>Hi Alice,</p>
<p>Frank has posted a new review of <em>The Room</em>:</p>
<p><a href=3D"https://sj.example.com/movies/1#review25">https://sj.example.=
com/movies/1#review25</a></p>
<p>-ScreenJournal Bot</p>
--dummy-boundary-for-testing--
`),
},
}
for _, tt := range tests {
actual, err := convert.FromEmail(tt.input)
if err != nil {
t.Fatalf("failed to generate email: %v", err)
}
if diff := cmp.Diff(tt.expected, actual); diff != "" {
t.Fatalf("unexpected smtp message for email: %s (-want +got):\n%s", tt.input.Subject, diff)
}
}
}
func normalizeLineEndings(s string) string {
return strings.ReplaceAll(s, "\n", "\r\n")
}