From d95e8ce75cc193181fd8cf9272269fbfff911f66 Mon Sep 17 00:00:00 2001 From: Grégoire Duchêne Date: Sun, 4 Jul 2021 17:20:50 +0100 Subject: Simplify project structure --- mailer_test.go | 52 ++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 52 insertions(+) create mode 100644 mailer_test.go (limited to 'mailer_test.go') 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 +// 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)) +} -- cgit v1.2.3-70-g09d2