create_menu_test.go 1.2 KB
package menu

import (
	"net/http"

	"github.com/gavv/httpexpect"
	. "github.com/onsi/ginkgo"
	. "github.com/onsi/gomega"
	pG "gitlab.fjmaimaimai.com/mmm-go-pp/terms/pkg/infrastructure/pg"
)

var _ = Describe("创建菜单服务", func() {
	Describe("提交数据创建菜单服务", func() {
		Context("提交正确的新系统菜单数据", func() {
			It("返回系统菜单数据", func() {
				httpExpect := httpexpect.New(GinkgoT(), server.URL)
				body := map[string]interface{}{
					"parentId":   0,
					"menuName":   "string",
					"code":       "string",
					"accessCode": "string",
					"menuType":   "string",
					"icon":       "string",
					"sort":       1,
					"desc":       "string",
					"isPublish":  1,
				}
				httpExpect.POST("/menus/").
					WithJSON(body).
					Expect().
					Status(http.StatusOK).
					JSON().
					Object().
					ContainsKey("code").ValueEqual("code", 0).
					ContainsKey("msg").ValueEqual("msg", "ok").
					ContainsKey("data").Value("data").Object().
					ContainsKey("menuId").ValueNotEqual("menuId", BeZero())
			})
		})
	})
	AfterEach(func() {
		_, err := pG.DB.Exec("DELETE FROM base.menu WHERE true")
		Expect(err).NotTo(HaveOccurred())
	})
})