clortho/lib/apis/systems_endpoints_test.go
Maxime Duchene-Savard ea2bb235a2 work
2025-04-14 23:50:22 -04:00

33 lines
782 B
Go

package apis
import (
"encoding/json"
"github.com/gin-gonic/gin"
"github.com/stretchr/testify/assert"
"net/http"
"net/http/httptest"
"strings"
"testing"
)
func TestInitSystemsEndpoints_getSystems(t *testing.T) {
_, err := InitUser("admin", "password")
if err != nil {
t.Fatal(err)
}
r := gin.Default()
SetupRouter(r, nil)
reqBody := loginRequest{Username: "admin", Password: "password"}
strReqBody, _ := json.Marshal(reqBody)
w := httptest.NewRecorder()
req, _ := http.NewRequest("POST", "/gui/auth/signin", strings.NewReader(string(strReqBody)))
r.ServeHTTP(w, req)
assert.Equal(t, 200, w.Code)
assert.JSONEq(t, `{"valid": true}`, w.Body.String())
setCookie := w.Header().Get("Set-Cookie")
assert.True(t, strings.Contains(setCookie, "CLORTHO_AUTH="))
}