aboutsummaryrefslogtreecommitdiff
path: root/mailer_test.go
diff options
context:
space:
mode:
authorGrégoire Duchêne <gduchene@awhk.org>2021-07-04 17:20:50 +0100
committerGrégoire Duchêne <gduchene@awhk.org>2021-07-04 17:20:50 +0100
commitd95e8ce75cc193181fd8cf9272269fbfff911f66 (patch)
treef25e86b4768050d39b932bfb9e42970cfc5936e4 /mailer_test.go
parent03f9f907ed21a9c56b229668b28571969d988a8c (diff)
Simplify project structure
Diffstat (limited to 'mailer_test.go')
-rw-r--r--mailer_test.go52
1 files changed, 52 insertions, 0 deletions
diff --git a/mailer_test.go b/mailer_test.go
new file mode 100644
index 0000000..e1376c3
--- /dev/null
+++ b/mailer_test.go
@@ -0,0 +1,52 @@
+// SPDX-FileCopyrightText: © 2020 Grégoire Duchêne <gduchene@awhk.org>
+// SPDX-License-Identifier: ISC
+
+package main
+
+import (
+ "strings"
+ "testing"
+ "time"
+
+ "github.com/stretchr/testify/assert"
+
+ "go.awhk.org/fwdsms/pkg/twilio"
+)
+
+func TestMailer_newEmail(t *testing.T) {
+ 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")),
+ }
+ assert.Equal(t, wants, m.newEmail(sms))
+}