package system import ( "net/http" "testing" "dev.sum7.eu/sum7/warehost/test" ) func TestAPI(t *testing.T) { assert, config, sessions, db, router := test.Init(t) defer db.Close() //load system Models to database SyncModels(db) // Bind API BindAPI(db, router, "") session := test.NewSession(router) // Test status result, w := session.JSONRequest("GET", "/status", nil) assert.Equal(w.StatusCode, http.StatusOK) assert.Nil(result.Error) assert.Equal(result.Data, true) // Test login result, w = session.JSONRequest("POST", "/login", RequestLogin{Username: "root", Password: "root2"}) assert.Equal(w.StatusCode, http.StatusOK) assert.Equal(result.Data, false) result, w = session.JSONRequest("POST", "/login", RequestLogin{Username: "root2", Password: "root"}) assert.Equal(w.StatusCode, http.StatusOK) assert.Equal(result.Data, false) result, w = session.JSONRequest("POST", "/login", []byte{2, 3}) assert.Equal(w.StatusCode, http.StatusBadRequest) result, w = session.JSONRequest("POST", "/login", RequestLogin{Username: "root", Password: "root"}) assert.Equal(w.StatusCode, http.StatusOK) assert.Equal(result.Data, true) // Test logout result, w = session.JSONRequest("GET", "/logout", nil) assert.Equal(w.StatusCode, http.StatusOK) assert.Equal(result.Data, true) // Test if crash on if not login in result, w = session.JSONRequest("GET", "/logout", nil) assert.Equal(w.StatusCode, http.StatusOK) assert.Equal(result.Data, false) }