-
-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
2 changed files
with
83 additions
and
3 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -10,7 +10,7 @@ import ( | |
_ "github.com/jinzhu/gorm/dialects/sqlite" | ||
) | ||
|
||
func TestSignup(t *testing.T) { | ||
func TestSignupWithUsername(t *testing.T) { | ||
|
||
w := httptest.NewRecorder() | ||
|
||
|
@@ -39,7 +39,7 @@ func TestSignup(t *testing.T) { | |
} | ||
} | ||
|
||
func TestLogout(t *testing.T) { | ||
func TestLogoutWithUsername(t *testing.T) { | ||
w := httptest.NewRecorder() | ||
|
||
db, err := gorm.Open("sqlite3", "test.db") | ||
|
@@ -63,7 +63,60 @@ func TestLogout(t *testing.T) { | |
} | ||
} | ||
|
||
func TestLogin(t *testing.T) { | ||
func TestSignupWithEmail(t *testing.T) { | ||
|
||
w := httptest.NewRecorder() | ||
|
||
db, err := gorm.Open("sqlite3", "test.db") | ||
if err != nil { | ||
t.Error(err) | ||
} | ||
defer db.Close() | ||
|
||
db.DropTable(&User{}) | ||
db.DropTable(&Sessionusername{}) | ||
|
||
db.AutoMigrate(&User{}) | ||
|
||
Config(db, "email") | ||
|
||
user := User{Username: "Erwan", Password: HashPassword("0000"), Mail: "[email protected]"} | ||
err = Signup(&user, user.Mail, w) | ||
if err != nil { | ||
t.Error(err) | ||
} | ||
|
||
resp := w.Result() | ||
if resp.Cookies()[0].Value == "" { | ||
t.Error(errors.New("no session cookie")) | ||
} | ||
} | ||
|
||
func TestLogoutWithEmail(t *testing.T) { | ||
w := httptest.NewRecorder() | ||
|
||
db, err := gorm.Open("sqlite3", "test.db") | ||
if err != nil { | ||
t.Error(err) | ||
} | ||
defer db.Close() | ||
|
||
Config(db, "email") | ||
|
||
user := User{Username: "Erwan", Password: "0000", Mail: "[email protected]"} | ||
|
||
err = Logout(user.Mail, w) | ||
if err != nil { | ||
t.Error(err) | ||
} | ||
|
||
resp := w.Result() | ||
if resp.Cookies()[0].Value != "" { | ||
t.Error(errors.New("cookie was not deleted")) | ||
} | ||
} | ||
|
||
func TestLoginWithUsername(t *testing.T) { | ||
|
||
w := httptest.NewRecorder() | ||
|
||
|
@@ -88,6 +141,31 @@ func TestLogin(t *testing.T) { | |
} | ||
} | ||
|
||
func TestLoginWithEmail(t *testing.T) { | ||
|
||
w := httptest.NewRecorder() | ||
|
||
db, err := gorm.Open("sqlite3", "test.db") | ||
if err != nil { | ||
t.Error(err) | ||
} | ||
defer db.Close() | ||
|
||
Config(db, "email") | ||
|
||
user := User{Username: "Erwan", Password: "0000", Mail: "[email protected]"} | ||
|
||
err = Login(user.Mail, user.Password, w) | ||
if err != nil { | ||
t.Error(err) | ||
} | ||
|
||
resp := w.Result() | ||
if resp.Cookies()[0].Value == "" { | ||
t.Error(errors.New("no session cookie")) | ||
} | ||
} | ||
|
||
func TestCurrentUser(t *testing.T) { | ||
w := httptest.NewRecorder() | ||
|
||
|