-
Notifications
You must be signed in to change notification settings - Fork 4
Expand file tree
/
Copy pathSendEmailNotification_test.go
More file actions
40 lines (32 loc) · 966 Bytes
/
SendEmailNotification_test.go
File metadata and controls
40 lines (32 loc) · 966 Bytes
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
package main
import (
"net/smtp"
"testing"
"github.com/stretchr/testify/assert"
)
type SpySMTPServer struct {
To []string
Body []byte
AuthCalls int
SendCalls int
}
func (server *SpySMTPServer) PlainAuth(identity, username, password, host string) (auth smtp.Auth) {
server.AuthCalls++
return
}
func (server *SpySMTPServer) SendMail(addr string, a smtp.Auth, from string, to []string, msg []byte) (err error) {
server.SendCalls++
server.To = to
server.Body = msg
return
}
func TestSendEmailNotification(t *testing.T) {
t.Run("It parses and returns flights results", func(t *testing.T) {
server := &SpySMTPServer{}
SendEmailNotification(server, []string{"test1@test.com", "test2@test.com"}, []byte("TEST"), SearchInput{})
assert.Equal(t, 1, server.AuthCalls)
assert.Equal(t, 1, server.SendCalls)
assert.Equal(t, []string{"test1@test.com", "test2@test.com"}, server.To)
assert.Contains(t, string(server.Body), "TEST")
})
}