package webui import ( "net/http" "net/url" "testing" "git.adyxax.org/adyxax/trains/pkg/database" "git.adyxax.org/adyxax/trains/pkg/model" "github.com/stretchr/testify/require" ) func TestLoginHandler(t *testing.T) { // test environment setup dbEnv, err := database.InitDB("sqlite3", "file::memory:?_foreign_keys=on") require.Nil(t, err) err = dbEnv.Migrate() require.Nil(t, err) user1, err := dbEnv.CreateUser(&model.UserRegistration{Username: "user1", Password: "password1", Email: "julien@adyxax.org"}) require.Nil(t, err) _, err = dbEnv.Login(&model.UserLogin{Username: "user1", Password: "password1"}) require.Nil(t, err) token1, err := dbEnv.CreateSession(user1) require.Nil(t, err) e := &env{dbEnv: dbEnv} // test GET requests runHttpTest(t, e, loginHandler, &httpTestCase{ name: "a simple get should display the login page", input: httpTestInput{ method: http.MethodGet, path: "/login", }, expect: httpTestExpect{ code: http.StatusOK, bodyString: "