search_log_test.go 1.2 KB
package log

import (
	"github.com/go-pg/pg/v10"
	"net/http"

	"github.com/gavv/httpexpect"
	. "github.com/onsi/ginkgo"
	. "github.com/onsi/gomega"
	pG "gitlab.fjmaimaimai.com/allied-creation/character-library-metadata-bastion/pkg/infrastructure/pg"
)

var _ = Describe("搜索日志", func() {
	var logId int64
	BeforeEach(func() {
		_, err := pG.DB.QueryOne(
			pg.Scan(&logId),
			"INSERT INTO logs (log_id, log_type, source_id, entry, created_at) VALUES (?, ?, ?, ?, ?) RETURNING log_id",
			"testLogId", "testLogType", "testSourceId", "testEntry", "testCreatedAt")
		Expect(err).NotTo(HaveOccurred())
	})
	Describe("搜索日志", func() {
		Context("", func() {
			It("", func() {
				httpExpect := httpexpect.New(GinkgoT(), server.URL)
				body := map[string]interface{}{
					"content": "string",
				}
				httpExpect.POST("/logs/search").
					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 logs WHERE true")
		Expect(err).NotTo(HaveOccurred())
	})
})