update_user_test.go 2.1 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() {
	return
	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{}{
					"organizationId":      "int64",
					"departmentId":        "int64",
					"userOrg":             "array",
					"userRole":            "array",
					"cooperationCompany":  "string",
					"cooperationDeadline": "datetime",
					"enableStatus":        "int",
					"userName":            "string",
					"phone":               "string",
					"avatar":              "string",
					"email":               "string",
				}
				httpExpect.PUT("/user/{userId}").
					WithJSON(body).
					Expect().
					Status(http.StatusOK).
					JSON().
					Object().
					ContainsKey("code").ValueEqual("code", 0).
					ContainsKey("msg").ValueEqual("msg", "ok").
					ContainsKey("data").Value("data").Object().
					ContainsKey("userId").ValueEqual("userId", userId)
			})
		})
	})
	AfterEach(func() {
		_, err := pG.DB.Exec("DELETE FROM users WHERE true")
		Expect(err).NotTo(HaveOccurred())
	})
})