66 lines
1.6 KiB
Go
66 lines
1.6 KiB
Go
package host
|
|
|
|
import (
|
|
"net/http"
|
|
"testing"
|
|
|
|
"github.com/stretchr/testify/assert"
|
|
|
|
"dev.sum7.eu/sum7/warehost/system"
|
|
"dev.sum7.eu/sum7/warehost/test"
|
|
)
|
|
|
|
func loginTest(session *test.Request, assertion *assert.Assertions) {
|
|
result, w := session.JSONRequest("POST", "/login", system.RequestLogin{Username: "root", Password: "root"})
|
|
assertion.Equal(w.StatusCode, http.StatusOK)
|
|
assertion.Equal(result.Data, true)
|
|
}
|
|
|
|
func TestAPI(t *testing.T) {
|
|
|
|
assertion, db, router := test.Init(t)
|
|
defer db.Close()
|
|
|
|
//load system Models to database
|
|
system.SyncModels(db)
|
|
db.Unscoped().Delete(Profil{})
|
|
SyncModels(db)
|
|
|
|
// Bind API
|
|
system.BindAPI(db, router, "")
|
|
BindAPI(db, router, "/host")
|
|
session := test.NewSession(router)
|
|
|
|
/*
|
|
* TEST signup
|
|
*/
|
|
result, w := session.JSONRequest("POST", "/host/signup", nil)
|
|
assertion.Equal(w.StatusCode, http.StatusUnauthorized)
|
|
assertion.Equal(result.Data, false)
|
|
|
|
loginTest(session, assertion)
|
|
|
|
result, w = session.JSONRequest("POST", "/host/signup", nil)
|
|
assertion.Equal(w.StatusCode, http.StatusOK)
|
|
assertion.Equal(result.Data, true)
|
|
|
|
result, w = session.JSONRequest("POST", "/host/signup", nil)
|
|
assertion.Equal(w.StatusCode, http.StatusOK)
|
|
assertion.Equal(result.Data, false)
|
|
|
|
/*
|
|
* TEST delete
|
|
*/
|
|
session.Clean()
|
|
result, w = session.JSONRequest("DELETE", "/host/delete", nil)
|
|
assertion.Equal(w.StatusCode, http.StatusUnauthorized)
|
|
assertion.Equal(result.Data, false)
|
|
|
|
loginTest(session, assertion)
|
|
|
|
result, w = session.JSONRequest("DELETE", "/host/delete", nil)
|
|
assertion.Equal(w.StatusCode, http.StatusOK)
|
|
assertion.Equal(result.Data, true)
|
|
|
|
}
|