package user

import (
	"fmt"
	"io"
	"net/http"
	"net/http/httptest"
	"testing"

	"github.com/gin-gonic/gin"
	"github.com/onsi/gomega"

	"github.com/pingcap-inc/clinic/pkg/auth/session"
	"github.com/pingcap-inc/clinic/pkg/db/model"
)

func TestProfile(t *testing.T) {
	g := gomega.NewWithT(t)
	if _, err := model.InsertUserIfAbsent("test", "user01", "test@pingcap.com", true); err != nil {
		panic(err)
	}
	w := httptest.NewRecorder()
	context, _ := gin.CreateTestContext(w)
	context.Set(session.CtxUserKey, &session.CtxUser{
		Username:        "user01",
		UserID:          1,
		Email:           "test01",
		Internal:        true,
		OrgIDInApiToken: 1,
	})
	context.Request = httptest.NewRequest(http.MethodGet, "http://127.0.0.1:8080", nil)
	Profile(context)
	if w.Body != nil {
		body, err := io.ReadAll(w.Body)
		if err != nil {
			panic(err)
		}
		fmt.Println("respBody: ", string(body))
	}
	g.Expect(w.Code).To(gomega.Equal(http.StatusOK))
}
