forked from aarondl/authboss
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathresponse_test.go
More file actions
72 lines (62 loc) · 1.45 KB
/
Copy pathresponse_test.go
File metadata and controls
72 lines (62 loc) · 1.45 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
package authboss
import (
"bytes"
"context"
"fmt"
"io"
"net/http"
"net/http/httptest"
"strings"
"testing"
)
type testMailer struct {
io.Writer
}
func (t testMailer) Send(_ context.Context, email Email) error {
fmt.Fprintf(t.Writer, "%v", email)
return nil
}
func TestResponseEmail(t *testing.T) {
t.Parallel()
ab := New()
ab.renderer = mockEmailRenderer{}
ab.SessionStateStorer = newMockClientStateRW(
FlashSuccessKey, "flash_success",
FlashErrorKey, "flash_error",
)
ab.XSRFName = "xsrf"
ab.XSRFMaker = func(w http.ResponseWriter, r *http.Request) string {
return "xsrftoken"
}
ab.LayoutDataMaker = func(w http.ResponseWriter, r *http.Request) HTMLData {
return HTMLData{"hello": "world"}
}
output := &bytes.Buffer{}
ab.Mailer = testMailer{output}
r := httptest.NewRequest("GET", "/", nil)
wr := httptest.NewRecorder()
w := ab.NewResponse(wr, r)
email := Email{
To: []string{"test@example.com"},
From: "test@example.com",
Subject: "subject",
}
ro := EmailResponseOptions{Data: nil, HTMLTemplate: "html", TextTemplate: "text"}
err := ab.Email(w, r, email, ro)
if err != nil {
t.Error(err)
}
wantStrings := []string{
"To: test@example.com",
"From: test@example.com",
"Subject: subject",
"development text e-mail",
"development html e-mail",
}
out := output.String()
for i, test := range wantStrings {
if !strings.Contains(out, test) {
t.Errorf("output missing string(%d): %s\n%s", i, test, out)
}
}
}