sum7/warehost
sum7
/
warehost
Archived
1
0
Fork 0
This repository has been archived on 2020-09-27. You can view files and clone it, but cannot push or open issues or pull requests.
warehost/modul/host/apiprofil_test.go

79 lines
2.0 KiB
Go
Raw Permalink Normal View History

package host
import (
"net/http"
"strconv"
"testing"
"dev.sum7.eu/sum7/warehost/system"
"dev.sum7.eu/sum7/warehost/test"
)
func TestAPIProfil(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)
loginTest(session, assertion)
result, w := session.JSONRequest("DELETE", "/host/delete", nil)
2016-12-19 12:24:18 +01:00
assertion.Equal(http.StatusOK, w.StatusCode)
// Need a Profile for Next tests
result, w = session.JSONRequest("POST", "/host/signup", nil)
2016-12-19 12:24:18 +01:00
assertion.Equal(http.StatusOK, w.StatusCode)
assertion.Equal(true, result.Data)
/*
* TEST profilList
*/
session.Clean()
result, w = session.JSONRequest("GET", "/host/profils", nil)
2016-12-19 12:52:43 +01:00
assertion.Equal(http.StatusUnauthorized, w.StatusCode)
2016-12-19 12:24:18 +01:00
assertion.Equal(false, result.Data)
loginTest(session, assertion)
result, w = session.JSONRequest("GET", "/host/profils", nil)
2016-12-19 12:24:18 +01:00
assertion.Equal(http.StatusOK, w.StatusCode)
assertion.NotEqual(result.Data, false)
/*
* TEST toggleReseller
*/
result, w = session.JSONRequest("GET", "/host/profils", nil)
2016-12-19 12:24:18 +01:00
assertion.Equal(http.StatusOK, w.StatusCode)
assertion.NotEqual(result.Data, false)
var id int
for _, obj := range result.Data.([]interface{}) {
item := obj.(map[string]interface{})
id = int(item["ID"].(float64))
}
session.Clean()
result, w = session.JSONRequest("PATCH", "/host/profil/"+strconv.Itoa(id), nil)
2016-12-19 12:52:43 +01:00
assertion.Equal(http.StatusUnauthorized, w.StatusCode)
2016-12-19 12:24:18 +01:00
assertion.Equal(false, result.Data)
loginTest(session, assertion)
result, w = session.JSONRequest("PATCH", "/host/profil/"+strconv.Itoa(id), nil)
2016-12-19 12:24:18 +01:00
assertion.Equal(http.StatusOK, w.StatusCode)
assertion.Equal(true, result.Data)
result, w = session.JSONRequest("PATCH", "/host/profil/"+strconv.Itoa(id), nil)
2016-12-19 12:24:18 +01:00
assertion.Equal(http.StatusOK, w.StatusCode)
assertion.Equal(true, result.Data)
}