profile_test.go 1.0 KB
package auth

import (
	"net/http"

	"github.com/gavv/httpexpect"
	"github.com/go-pg/pg/v10"
	. "github.com/onsi/ginkgo"
	. "github.com/onsi/gomega"
	pG "github.com/tiptok/godevp/pkg/infrastructure/pg"
)

var _ = Describe("获得当前用户数据", func() {
	var Id int64
	BeforeEach(func() {
		_, err := pG.DB.QueryOne(
			pg.Scan(&Id),
			"INSERT INTO s () VALUES () RETURNING id",
		)
		Expect(err).NotTo(HaveOccurred())
	})
	Describe("获得当前用户数据", func() {
		Context("", func() {
			It("", func() {
				httpExpect := httpexpect.New(GinkgoT(), server.URL)
				body := map[string]interface{}{
					"userId": "int64",
				}
				httpExpect.POST("/auth/profile").
					WithJSON(body).
					Expect().
					Status(http.StatusOK).
					JSON().
					Object().
					ContainsKey("code").ValueEqual("code", 0).
					ContainsKey("msg").ValueEqual("msg", "ok").
					ContainsKey("data").Value("data").Object()
			})
		})
	})
	AfterEach(func() {
		_, err := pG.DB.Exec("DELETE FROM s WHERE true")
		Expect(err).NotTo(HaveOccurred())
	})
})