2021-11-04 16:58:23 +00:00
|
|
|
package user
|
|
|
|
|
|
|
|
import (
|
|
|
|
"testing"
|
|
|
|
)
|
|
|
|
|
|
|
|
func TestAdminUserExists(t *testing.T) {
|
|
|
|
u := GetUserClient()
|
|
|
|
res, err := u.login("admin", "password")
|
|
|
|
if err != nil {
|
|
|
|
t.Error("Login should not return a error")
|
|
|
|
}
|
|
|
|
|
|
|
|
if res == false {
|
|
|
|
t.Error("Login should return true for admin/password")
|
|
|
|
} else {
|
|
|
|
t.Log("Login for admin/password works")
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
func TestLoginWithWrongUserDataFailed(t *testing.T) {
|
|
|
|
u := GetUserClient()
|
|
|
|
res, err := u.login("invalide", "data")
|
|
|
|
if err != nil {
|
|
|
|
t.Error("Login shouldnt return an erroro")
|
|
|
|
}
|
|
|
|
|
|
|
|
if res == true {
|
|
|
|
t.Error("Login shouldnt be true with invalide data")
|
|
|
|
} else {
|
|
|
|
t.Log("Login failed successfully")
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
func TestRegisterAndLogin(t *testing.T) {
|
|
|
|
u := GetUserClient()
|
2021-11-09 18:23:19 +00:00
|
|
|
res, err := u.register("test", "test", "test@example.com")
|
2021-11-04 16:58:23 +00:00
|
|
|
if err != nil {
|
|
|
|
t.Error("Register should not return an error")
|
|
|
|
}
|
|
|
|
|
|
|
|
if res == false {
|
|
|
|
t.Error("Register schould return true")
|
|
|
|
} else {
|
|
|
|
t.Log("User Register ok")
|
|
|
|
}
|
|
|
|
|
|
|
|
res, err = u.login("test", "test")
|
|
|
|
|
|
|
|
if err != nil {
|
|
|
|
t.Error("Login should not return an error")
|
|
|
|
}
|
|
|
|
|
|
|
|
if res == false {
|
|
|
|
t.Error("Login schould return true")
|
|
|
|
} else {
|
|
|
|
t.Log("User Login ok")
|
|
|
|
}
|
|
|
|
}
|