update_users_base_test.go 1.7 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{}{
					"userName": "string",
					"avatar":   "string",
					"phone":    "string",
					"email":    "string",
				}
				httpExpect.PUT("/user/{userId}/base-info").
					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 users WHERE true")
		Expect(err).NotTo(HaveOccurred())
	})
})