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
|
// SPDX-FileCopyrightText: © 2020 Grégoire Duchêne <gduchene@awhk.org>
// SPDX-License-Identifier: ISC
package main
import (
"strings"
"testing"
"time"
"github.com/google/go-cmp/cmp"
"go.awhk.org/core"
"go.awhk.org/fwdsms/pkg/twilio"
)
func TestMailer_newEmail(s *testing.T) {
t := core.T{T: s, Options: []cmp.Option{cmp.AllowUnexported(email{})}}
m := newMailer(&Config{
Message: Message{
From: "fwdsms@example.com",
To: "sms{{.To}}@example.com",
Subject: "New SMS From {{.From}}",
Template: `From: {{.From}}
To: {{.To}}
Date: {{.DateReceived.UTC}}
{{.Body}}`,
}}, nil)
// Reserved phone numbers, see Ofcom's website.
sms := twilio.SMS{
DateReceived: time.Unix(0, 0),
From: "+442079460123",
To: "+447700900123",
Body: "Hello World!",
}
wants := email{
from: "fwdsms@example.com",
to: "sms+447700900123@example.com",
body: []byte(strings.Join([]string{
"From: fwdsms@example.com",
"To: sms+447700900123@example.com",
"Subject: New SMS From +442079460123",
"",
`From: +442079460123
To: +447700900123
Date: 1970-01-01 00:00:00 +0000 UTC
Hello World!`,
"",
}, "\r\n")),
}
t.AssertEqual(wants, m.newEmail(sms))
}
|