forked from uadmin/uadmin
-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathforgot_password_handler_test.go
More file actions
35 lines (31 loc) · 967 Bytes
/
forgot_password_handler_test.go
File metadata and controls
35 lines (31 loc) · 967 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
package uadmin
import (
"net/http/httptest"
"strings"
"time"
)
// TestForgotPasswordHandler is a unit testing function for forgotPasswordHandler() function
func (t *UAdminTests) TestForgotPasswordHandler() {
r := httptest.NewRequest("GET", "/", nil)
user := User{}
Get(&user, "id = ?", 1)
err := forgotPasswordHandler(&user, r, "", "")
if err == nil {
t.Errorf("forgotPasswordHandler didn't return an error on a user with no email")
}
user.Email = "user@example.com"
err = forgotPasswordHandler(&user, r, "", "")
if err != nil {
t.Errorf("forgotPasswordHandler returned an error. %s", err)
}
time.Sleep(time.Millisecond * 500)
if receivedEmail == "" {
t.Errorf("forgotPasswordHandler didn't send an email")
}
if !strings.Contains(receivedEmail, "From: uadmin@example.com") {
t.Errorf("SendEmail don't have a valid From")
}
if !strings.Contains(receivedEmail, "To: user@example.com") {
t.Errorf("SendEmail don't have a valid To")
}
}