list_user_test.go 1.9 KB
package user

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/allied-creation-user/pkg/infrastructure/pg"
)

var _ = Describe("返回列表", func() {
	var userId int64
	BeforeEach(func() {
		_, err := pG.DB.QueryOne(
			pg.Scan(&userId),
			"INSERT INTO users (user_id, company_id, user_base_id, user_type, user_code, organization_id, department_id, user_info, user_org, user_role, favorite_menus, cooperation_info, enable_status, ext, created_at, updated_at) VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?) RETURNING user_id",
			"testUserId", "testCompanyId", "testUserBaseId", "testUserType", "testUserCode", "testOrganizationId", "testDepartmentId", "testUserInfo", "testUserOrg", "testUserRole", "testFavoriteMenus", "testCooperationInfo", "testEnableStatus", "testExt", "testCreatedAt", "testUpdatedAt")
		Expect(err).NotTo(HaveOccurred())
	})
	Describe("根据参数返回用户列表", func() {
		Context("传入有效的参数", func() {
			It("返回用户数据列表", func() {
				httpExpect := httpexpect.New(GinkgoT(), server.URL)
				body := map[string]interface{}{
					"offset":         "int",
					"limit":          "int",
					"companyId":      "int64",
					"organizationId": "int64",
					"departmentId":   "int64",
					"userName":       "string",
					"depName":        "string",
					"phone":          "string",
				}
				httpExpect.POST("/user/search").
					WithJSON(body).
					Expect().
					Status(http.StatusOK).
					JSON().
					Object().
					ContainsKey("code").ValueEqual("code", 0).
					ContainsKey("msg").ValueEqual("msg", "ok").
					ContainsKey("data").Value("data").Object().
					ContainsKey("count").ValueEqual("count", 1).
					ContainsKey("users").Value("users").Array()
			})
		})
	})
	AfterEach(func() {
		_, err := pG.DB.Exec("DELETE FROM users WHERE true")
		Expect(err).NotTo(HaveOccurred())
	})
})