作者 yangfu

add users test case

@@ -14,7 +14,7 @@ type ConvertUserStatusCommand struct { @@ -14,7 +14,7 @@ type ConvertUserStatusCommand struct {
14 } 14 }
15 15
16 func (convertUserStatusCommand *ConvertUserStatusCommand) Valid(validation *validation.Validation) { 16 func (convertUserStatusCommand *ConvertUserStatusCommand) Valid(validation *validation.Validation) {
17 - validation.SetError("CustomValid", "未实现的自定义认证") 17 + //validation.SetError("CustomValid", "未实现的自定义认证")
18 } 18 }
19 19
20 func (convertUserStatusCommand *ConvertUserStatusCommand) ValidateCommand() error { 20 func (convertUserStatusCommand *ConvertUserStatusCommand) ValidateCommand() error {
@@ -29,7 +29,7 @@ type CreateUserCommand struct { @@ -29,7 +29,7 @@ type CreateUserCommand struct {
29 } 29 }
30 30
31 func (createUserCommand *CreateUserCommand) Valid(validation *validation.Validation) { 31 func (createUserCommand *CreateUserCommand) Valid(validation *validation.Validation) {
32 - validation.SetError("CustomValid", "未实现的自定义认证") 32 + //validation.SetError("CustomValid", "未实现的自定义认证")
33 } 33 }
34 34
35 func (createUserCommand *CreateUserCommand) ValidateCommand() error { 35 func (createUserCommand *CreateUserCommand) ValidateCommand() error {
@@ -12,7 +12,7 @@ type RemoveUserCommand struct { @@ -12,7 +12,7 @@ type RemoveUserCommand struct {
12 } 12 }
13 13
14 func (removeUserCommand *RemoveUserCommand) Valid(validation *validation.Validation) { 14 func (removeUserCommand *RemoveUserCommand) Valid(validation *validation.Validation) {
15 - validation.SetError("CustomValid", "未实现的自定义认证") 15 + //validation.SetError("CustomValid", "未实现的自定义认证")
16 } 16 }
17 17
18 func (removeUserCommand *RemoveUserCommand) ValidateCommand() error { 18 func (removeUserCommand *RemoveUserCommand) ValidateCommand() error {
@@ -14,7 +14,7 @@ type SetPermissionCommand struct { @@ -14,7 +14,7 @@ type SetPermissionCommand struct {
14 } 14 }
15 15
16 func (setPermissionCommand *SetPermissionCommand) Valid(validation *validation.Validation) { 16 func (setPermissionCommand *SetPermissionCommand) Valid(validation *validation.Validation) {
17 - validation.SetError("CustomValid", "未实现的自定义认证") 17 + //validation.SetError("CustomValid", "未实现的自定义认证")
18 } 18 }
19 19
20 func (setPermissionCommand *SetPermissionCommand) ValidateCommand() error { 20 func (setPermissionCommand *SetPermissionCommand) ValidateCommand() error {
@@ -2,10 +2,8 @@ package command @@ -2,10 +2,8 @@ package command
2 2
3 import ( 3 import (
4 "fmt" 4 "fmt"
5 - "gitlab.fjmaimaimai.com/mmm-go-pp/partner01/pkg/domain"  
6 - "time"  
7 -  
8 "github.com/beego/beego/v2/core/validation" 5 "github.com/beego/beego/v2/core/validation"
  6 + "gitlab.fjmaimaimai.com/mmm-go-pp/partner01/pkg/domain"
9 ) 7 )
10 8
11 type UpdateUserCommand struct { 9 type UpdateUserCommand struct {
@@ -16,39 +14,9 @@ type UpdateUserCommand struct { @@ -16,39 +14,9 @@ type UpdateUserCommand struct {
16 // 管理员类型 1.超级管理员 10:企业管理员 100:普通用户 14 // 管理员类型 1.超级管理员 10:企业管理员 100:普通用户
17 AdminType int `json:"adminType,omitempty"` 15 AdminType int `json:"adminType,omitempty"`
18 // 状态 1正常 2禁用 16 // 状态 1正常 2禁用
19 - Status int64 `json:"status" valid:"Required"` 17 + Status int64 `json:"status,omitempty"`
20 // 是否是公司负责人 18 // 是否是公司负责人
21 - IsPrincipal bool `json:"isPrincipal" valid:"Required"`  
22 - // 统一用户id  
23 - Uid int64 `json:"uid" valid:"Required"`  
24 - // 用户账号  
25 - UserAccount string `json:"userAccount" valid:"Required"`  
26 - // 用户头像URL  
27 - UserAvatarUrl string `json:"userAvatarUrl" valid:"Required"`  
28 - // 用户名称  
29 - UserName string `json:"userName" valid:"Required"`  
30 - // 邮件地址  
31 - Email string `json:"email" valid:"Required"`  
32 - // 性别  
33 - Gender int `json:"gender" valid:"Required"`  
34 - // 入职时间  
35 - EntryTime time.Time `json:"entryTime" valid:"Required"`  
36 - // 分机  
37 - Extension string `json:"extension" valid:"Required"`  
38 - // 工作地  
39 - Workplace string `json:"workplace" valid:"Required"`  
40 - // 私人电话  
41 - PrivateNumber string `json:"privateNumber" valid:"Required"`  
42 - // 工号  
43 - JobNumber string `json:"jobNumber" valid:"Required"`  
44 - // 合伙人账号  
45 - PartnerAccount string `json:"partnerAccount" valid:"Required"`  
46 - // 合伙人姓名  
47 - PartnerName string `json:"partnerName" valid:"Required"`  
48 - // 区域名称 eg:华南地区  
49 - RegionName string `json:"regionName,omitempty"`  
50 - // 合伙时间  
51 - CooperateTime time.Time `json:"cooperateTime" valid:"Required"` 19 + UserInfo *domain.UserInfo `json:"userInfo,omitempty"`
52 // 业务员 20 // 业务员
53 Salesmans []*domain.Salesman `json:"salesmans,omitempty"` 21 Salesmans []*domain.Salesman `json:"salesmans,omitempty"`
54 // 合伙人类型 22 // 合伙人类型
@@ -58,7 +26,7 @@ type UpdateUserCommand struct { @@ -58,7 +26,7 @@ type UpdateUserCommand struct {
58 } 26 }
59 27
60 func (updateUserCommand *UpdateUserCommand) Valid(validation *validation.Validation) { 28 func (updateUserCommand *UpdateUserCommand) Valid(validation *validation.Validation) {
61 - validation.SetError("CustomValid", "未实现的自定义认证") 29 + //validation.SetError("CustomValid", "未实现的自定义认证")
62 } 30 }
63 31
64 func (updateUserCommand *UpdateUserCommand) ValidateCommand() error { 32 func (updateUserCommand *UpdateUserCommand) ValidateCommand() error {
@@ -12,7 +12,7 @@ type GetUserQuery struct { @@ -12,7 +12,7 @@ type GetUserQuery struct {
12 } 12 }
13 13
14 func (getUserQuery *GetUserQuery) Valid(validation *validation.Validation) { 14 func (getUserQuery *GetUserQuery) Valid(validation *validation.Validation) {
15 - validation.SetError("CustomValid", "未实现的自定义认证") 15 + //validation.SetError("CustomValid", "未实现的自定义认证")
16 } 16 }
17 17
18 func (getUserQuery *GetUserQuery) ValidateQuery() error { 18 func (getUserQuery *GetUserQuery) ValidateQuery() error {
@@ -8,13 +8,13 @@ import ( @@ -8,13 +8,13 @@ import (
8 8
9 type ListUserQuery struct { 9 type ListUserQuery struct {
10 // 查询偏离量 10 // 查询偏离量
11 - Offset int `json:"offset" valid:"Required"` 11 + Offset int `json:"offset"`
12 // 查询限制 12 // 查询限制
13 Limit int `json:"limit" valid:"Required"` 13 Limit int `json:"limit" valid:"Required"`
14 } 14 }
15 15
16 func (listUserQuery *ListUserQuery) Valid(validation *validation.Validation) { 16 func (listUserQuery *ListUserQuery) Valid(validation *validation.Validation) {
17 - validation.SetError("CustomValid", "未实现的自定义认证") 17 + //validation.SetError("CustomValid", "未实现的自定义认证")
18 } 18 }
19 19
20 func (listUserQuery *ListUserQuery) ValidateQuery() error { 20 func (listUserQuery *ListUserQuery) ValidateQuery() error {
@@ -30,6 +30,29 @@ func (userService *UserService) ConvertUserStatus(convertUserStatusCommand *comm @@ -30,6 +30,29 @@ func (userService *UserService) ConvertUserStatus(convertUserStatusCommand *comm
30 defer func() { 30 defer func() {
31 transactionContext.RollbackTransaction() 31 transactionContext.RollbackTransaction()
32 }() 32 }()
  33 +
  34 + var userRepository domain.UserRepository
  35 + if value, err := factory.CreateUserRepository(map[string]interface{}{
  36 + "transactionContext": transactionContext,
  37 + }); err != nil {
  38 + return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())
  39 + } else {
  40 + userRepository = value
  41 + }
  42 + user, err := userRepository.FindOne(map[string]interface{}{"userId": convertUserStatusCommand.UserId})
  43 + if err != nil {
  44 + return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())
  45 + }
  46 + if user == nil {
  47 + return nil, application.ThrowError(application.RES_NO_FIND_ERROR, fmt.Sprintf("%s", string(convertUserStatusCommand.UserId)))
  48 + }
  49 + if err := user.CovertUserStatus(convertUserStatusCommand.Status); err != nil {
  50 + return nil, application.ThrowError(application.BUSINESS_ERROR, err.Error())
  51 + }
  52 + if _, err := userRepository.Save(user); err != nil {
  53 + return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())
  54 + }
  55 +
33 if err := transactionContext.CommitTransaction(); err != nil { 56 if err := transactionContext.CommitTransaction(); err != nil {
34 return nil, application.ThrowError(application.TRANSACTION_ERROR, err.Error()) 57 return nil, application.ThrowError(application.TRANSACTION_ERROR, err.Error())
35 } 58 }
@@ -60,8 +83,8 @@ func (userService *UserService) CreateUser(createUserCommand *command.CreateUser @@ -60,8 +83,8 @@ func (userService *UserService) CreateUser(createUserCommand *command.CreateUser
60 PartnerInfo: createUserCommand.PartnerInfo, 83 PartnerInfo: createUserCommand.PartnerInfo,
61 AccessPartners: createUserCommand.AccessPartners, 84 AccessPartners: createUserCommand.AccessPartners,
62 } 85 }
63 - var addUserService service.AddUserService  
64 - if value, err := factory.CreateAddUserService(map[string]interface{}{ 86 + var addUserService service.UserCreateService
  87 + if value, err := factory.CreateUserCreateService(map[string]interface{}{
65 "transactionContext": transactionContext, 88 "transactionContext": transactionContext,
66 }); err != nil { 89 }); err != nil {
67 return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error()) 90 return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())
@@ -69,7 +92,7 @@ func (userService *UserService) CreateUser(createUserCommand *command.CreateUser @@ -69,7 +92,7 @@ func (userService *UserService) CreateUser(createUserCommand *command.CreateUser
69 addUserService = value 92 addUserService = value
70 } 93 }
71 94
72 - if user, err := addUserService.AddUser(newUser); err != nil { 95 + if user, err := addUserService.CreateUser(0, newUser); err != nil {
73 return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error()) 96 return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())
74 } else { 97 } else {
75 if err := transactionContext.CommitTransaction(); err != nil { 98 if err := transactionContext.CommitTransaction(); err != nil {
@@ -207,6 +230,29 @@ func (userService *UserService) SetPermission(setPermissionCommand *command.SetP @@ -207,6 +230,29 @@ func (userService *UserService) SetPermission(setPermissionCommand *command.SetP
207 defer func() { 230 defer func() {
208 transactionContext.RollbackTransaction() 231 transactionContext.RollbackTransaction()
209 }() 232 }()
  233 +
  234 + var userRepository domain.UserRepository
  235 + if value, err := factory.CreateUserRepository(map[string]interface{}{
  236 + "transactionContext": transactionContext,
  237 + }); err != nil {
  238 + return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())
  239 + } else {
  240 + userRepository = value
  241 + }
  242 + user, err := userRepository.FindOne(map[string]interface{}{"userId": setPermissionCommand.UserId})
  243 + if err != nil {
  244 + return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())
  245 + }
  246 + if user == nil {
  247 + return nil, application.ThrowError(application.RES_NO_FIND_ERROR, fmt.Sprintf("%s", string(setPermissionCommand.UserId)))
  248 + }
  249 + if err := user.SetPermission(setPermissionCommand.Permissons); err != nil {
  250 + return nil, application.ThrowError(application.BUSINESS_ERROR, err.Error())
  251 + }
  252 + if _, err := userRepository.Save(user); err != nil {
  253 + return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())
  254 + }
  255 +
210 if err := transactionContext.CommitTransaction(); err != nil { 256 if err := transactionContext.CommitTransaction(); err != nil {
211 return nil, application.ThrowError(application.TRANSACTION_ERROR, err.Error()) 257 return nil, application.ThrowError(application.TRANSACTION_ERROR, err.Error())
212 } 258 }
@@ -68,6 +68,19 @@ func (user *User) Identify() interface{} { @@ -68,6 +68,19 @@ func (user *User) Identify() interface{} {
68 return user.UserId 68 return user.UserId
69 } 69 }
70 70
  71 +func (user *User) SetPermission(permissions []int) error {
  72 + user.Permissions = permissions
  73 + return nil
  74 +}
  75 +
  76 +func (user *User) CovertUserStatus(status int64) error {
  77 + if !(status == StatusEnable || status == StatusDisable) {
  78 + return fmt.Errorf("status options value (%v,%v) , invalid %v", StatusEnable, StatusDisable, status)
  79 + }
  80 + user.Status = status
  81 + return nil
  82 +}
  83 +
71 func (user *User) Update(data map[string]interface{}) error { 84 func (user *User) Update(data map[string]interface{}) error {
72 if userType, ok := data["userType"]; ok { 85 if userType, ok := data["userType"]; ok {
73 user.UserType = userType.(int) 86 user.UserType = userType.(int)
@@ -75,44 +88,8 @@ func (user *User) Update(data map[string]interface{}) error { @@ -75,44 +88,8 @@ func (user *User) Update(data map[string]interface{}) error {
75 if permissions, ok := data["permissions"]; ok { 88 if permissions, ok := data["permissions"]; ok {
76 user.Permissions = permissions.([]int) 89 user.Permissions = permissions.([]int)
77 } 90 }
78 - if companyId, ok := data["companyId"]; ok {  
79 - user.CompanyId = companyId.(int64)  
80 - }  
81 - if isPrincipal, ok := data["isPrincipal"]; ok {  
82 - user.UserInfo.IsPrincipal = isPrincipal.(bool)  
83 - }  
84 - if uid, ok := data["uid"]; ok {  
85 - user.UserInfo.Uid = uid.(int64)  
86 - }  
87 - if userAccount, ok := data["userAccount"]; ok {  
88 - user.UserInfo.UserAccount = userAccount.(string)  
89 - }  
90 - if userAvatarUrl, ok := data["userAvatarUrl"]; ok {  
91 - user.UserInfo.UserAvatarUrl = userAvatarUrl.(string)  
92 - }  
93 - if userName, ok := data["userName"]; ok {  
94 - user.UserInfo.UserName = userName.(string)  
95 - }  
96 - if email, ok := data["email"]; ok {  
97 - user.UserInfo.Email = email.(string)  
98 - }  
99 - if gender, ok := data["gender"]; ok {  
100 - user.UserInfo.Gender = gender.(int)  
101 - }  
102 - if entryTime, ok := data["entryTime"]; ok {  
103 - user.UserInfo.EntryTime = entryTime.(time.Time)  
104 - }  
105 - if extension, ok := data["extension"]; ok {  
106 - user.UserInfo.Extension = extension.(string)  
107 - }  
108 - if workplace, ok := data["workplace"]; ok {  
109 - user.UserInfo.Workplace = workplace.(string)  
110 - }  
111 - if privateNumber, ok := data["privateNumber"]; ok {  
112 - user.UserInfo.PrivateNumber = privateNumber.(string)  
113 - }  
114 - if jobNumber, ok := data["jobNumber"]; ok {  
115 - user.UserInfo.JobNumber = jobNumber.(string) 91 + if userInfo, ok := data["userInfo"]; ok {
  92 + user.UserInfo = userInfo.(*UserInfo)
116 } 93 }
117 if partnerAccount, ok := data["partnerAccount"]; ok { 94 if partnerAccount, ok := data["partnerAccount"]; ok {
118 user.PartnerInfo.PartnerAccount = partnerAccount.(string) 95 user.PartnerInfo.PartnerAccount = partnerAccount.(string)
@@ -126,6 +103,7 @@ func (user *User) Update(data map[string]interface{}) error { @@ -126,6 +103,7 @@ func (user *User) Update(data map[string]interface{}) error {
126 if status, ok := data["status"]; ok { 103 if status, ok := data["status"]; ok {
127 user.PartnerInfo.Status = status.(int64) 104 user.PartnerInfo.Status = status.(int64)
128 } 105 }
  106 + user.UpdateAt = time.Now()
129 return nil 107 return nil
130 } 108 }
131 109
@@ -43,7 +43,7 @@ func (repository *UserRepository) Save(user *domain.User) (*domain.User, error) @@ -43,7 +43,7 @@ func (repository *UserRepository) Save(user *domain.User) (*domain.User, error)
43 insertFieldsSnippet := sqlbuilder.SqlFieldsSnippet(sqlBuildFields) 43 insertFieldsSnippet := sqlbuilder.SqlFieldsSnippet(sqlBuildFields)
44 insertPlaceHoldersSnippet := sqlbuilder.SqlPlaceHoldersSnippet(sqlBuildFields) 44 insertPlaceHoldersSnippet := sqlbuilder.SqlPlaceHoldersSnippet(sqlBuildFields)
45 returningFieldsSnippet := sqlbuilder.SqlFieldsSnippet(sqlBuildFields) 45 returningFieldsSnippet := sqlbuilder.SqlFieldsSnippet(sqlBuildFields)
46 - updateFields := sqlbuilder.RemoveSqlFields(sqlBuildFields, "user_id") 46 + updateFields := sqlbuilder.RemoveSqlFields(sqlBuildFields, "user_id", "delete_at", "create_at")
47 updateFieldsSnippet := sqlbuilder.SqlUpdateFieldsSnippet(updateFields) 47 updateFieldsSnippet := sqlbuilder.SqlUpdateFieldsSnippet(updateFields)
48 tx := repository.transactionContext.PgTx 48 tx := repository.transactionContext.PgTx
49 if user.Identify() == nil { 49 if user.Identify() == nil {
@@ -104,7 +104,6 @@ func (repository *UserRepository) Save(user *domain.User) (*domain.User, error) @@ -104,7 +104,6 @@ func (repository *UserRepository) Save(user *domain.User) (*domain.User, error)
104 &user.DeleteAt, 104 &user.DeleteAt,
105 ), 105 ),
106 fmt.Sprintf("UPDATE users SET %s WHERE user_id=? RETURNING %s", updateFieldsSnippet, returningFieldsSnippet), 106 fmt.Sprintf("UPDATE users SET %s WHERE user_id=? RETURNING %s", updateFieldsSnippet, returningFieldsSnippet),
107 - user.UserId,  
108 user.UserType, 107 user.UserType,
109 pg.Array(user.Permissions), 108 pg.Array(user.Permissions),
110 user.CompanyId, 109 user.CompanyId,
@@ -114,9 +113,7 @@ func (repository *UserRepository) Save(user *domain.User) (*domain.User, error) @@ -114,9 +113,7 @@ func (repository *UserRepository) Save(user *domain.User) (*domain.User, error)
114 user.Status, 113 user.Status,
115 user.AdminType, 114 user.AdminType,
116 pg.Array(user.AccessPartners), 115 pg.Array(user.AccessPartners),
117 - user.CreateAt,  
118 user.UpdateAt, 116 user.UpdateAt,
119 - user.DeleteAt,  
120 user.Identify(), 117 user.Identify(),
121 ); err != nil { 118 ); err != nil {
122 return user, err 119 return user, err
@@ -11,13 +11,12 @@ import ( @@ -11,13 +11,12 @@ import (
11 ) 11 )
12 12
13 var _ = Describe("用户状态转换(禁用、启用)", func() { 13 var _ = Describe("用户状态转换(禁用、启用)", func() {
14 - return  
15 var userId int64 14 var userId int64
16 BeforeEach(func() { 15 BeforeEach(func() {
17 _, err := pG.DB.QueryOne( 16 _, err := pG.DB.QueryOne(
18 pg.Scan(&userId), 17 pg.Scan(&userId),
19 - "INSERT INTO users (user_id, user_type, permissions, company_id, user_info, partner_info, status, admin_type, access_partners, create_at, update_at, delete_at) VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?) RETURNING user_id",  
20 - "testUserId", "testUserType", "testPermissions", "testCompanyId", "testUserInfo", "testPartnerInfo", "testStatus", "testAdminType", "testAccessPartners", "testCreateAt", "testUpdateAt", "testDeleteAt") 18 + "INSERT INTO users (user_id, user_type, permissions, company_id, user_info, partner_info, status, admin_type) VALUES (?, ?, ?, ?, ?, ?, ?, ?) RETURNING user_id",
  19 + 1, 1, pg.Array([]int{}), 1, `{}`, `{}`, 1, 1)
21 Expect(err).NotTo(HaveOccurred()) 20 Expect(err).NotTo(HaveOccurred())
22 }) 21 })
23 Describe("用户状态转换(禁用、启用)", func() { 22 Describe("用户状态转换(禁用、启用)", func() {
@@ -25,23 +24,23 @@ var _ = Describe("用户状态转换(禁用、启用)", func() { @@ -25,23 +24,23 @@ var _ = Describe("用户状态转换(禁用、启用)", func() {
25 It("", func() { 24 It("", func() {
26 httpExpect := httpexpect.New(GinkgoT(), server.URL) 25 httpExpect := httpexpect.New(GinkgoT(), server.URL)
27 body := map[string]interface{}{ 26 body := map[string]interface{}{
28 - "userId": "int64",  
29 - "status": "int64", 27 + "userId": 1,
  28 + "status": 2,
30 } 29 }
31 - httpExpect.POST("/users/convertUserStatus"). 30 + httpExpect.POST("/users/convert-user-status").
32 WithJSON(body). 31 WithJSON(body).
33 Expect(). 32 Expect().
34 Status(http.StatusOK). 33 Status(http.StatusOK).
35 JSON(). 34 JSON().
36 Object(). 35 Object().
37 ContainsKey("code").ValueEqual("code", 0). 36 ContainsKey("code").ValueEqual("code", 0).
38 - ContainsKey("msg").ValueEqual("msg", "ok").  
39 - ContainsKey("data").Value("data").Object() 37 + ContainsKey("msg").ValueEqual("msg", "ok")
  38 + //ContainsKey("data").Value("data").Object()
40 }) 39 })
41 }) 40 })
42 }) 41 })
43 AfterEach(func() { 42 AfterEach(func() {
44 - //_, err := pG.DB.Exec("DELETE FROM users WHERE true")  
45 - //Expect(err).NotTo(HaveOccurred()) 43 + _, err := pG.DB.Exec("DELETE FROM users WHERE true")
  44 + Expect(err).NotTo(HaveOccurred())
46 }) 45 })
47 }) 46 })
1 package user 1 package user
2 2
3 import ( 3 import (
  4 + pG "gitlab.fjmaimaimai.com/mmm-go-pp/partner01/pkg/infrastructure/pg"
4 "net/http" 5 "net/http"
5 6
6 "github.com/gavv/httpexpect" 7 "github.com/gavv/httpexpect"
@@ -14,24 +15,23 @@ var _ = Describe("创建", func() { @@ -14,24 +15,23 @@ var _ = Describe("创建", func() {
14 It("返回用户实体数据", func() { 15 It("返回用户实体数据", func() {
15 httpExpect := httpexpect.New(GinkgoT(), server.URL) 16 httpExpect := httpexpect.New(GinkgoT(), server.URL)
16 body := map[string]interface{}{ 17 body := map[string]interface{}{
17 - "userType": 1,  
18 - "adminType": 1,  
19 - "status": 1,  
20 - "isPrincipal": false,  
21 - "uid": 5678664411598702,  
22 - "userAccount": "13800000000",  
23 - "userAvatarUrl": "www.baidu.com",  
24 - "userName": "彭于晏",  
25 - "email": "gfghf@qq.com",  
26 - "gender": 1,  
27 - "extension": "1",  
28 - "workplace": "2",  
29 - "privateNumber": "3",  
30 - "jobNumber": "4",  
31 - "partnerAccount": "5",  
32 - "partnerName": "6",  
33 - "regionName": "7",  
34 - "salesmans": "[1,2]", 18 + "userType": 1,
  19 + "adminType": 1,
  20 + "status": 1,
  21 + "userAccount": "13800000000",
  22 + "userInfo": map[string]interface{}{
  23 + "isPrincipal": false,
  24 + "uid": 5678664411598702,
  25 + "userAccount": "13800000000",
  26 + "userAvatarUrl": "www.baidu.com",
  27 + "userName": "彭于晏",
  28 + "email": "gfghf@qq.com",
  29 + "gender": 1,
  30 + "extension": "1",
  31 + "workplace": "2",
  32 + "privateNumber": "3",
  33 + "jobNumber": "4",
  34 + },
35 "partnerCategorys": "[]", 35 "partnerCategorys": "[]",
36 "accessPartners": "[]", 36 "accessPartners": "[]",
37 } 37 }
@@ -49,7 +49,8 @@ var _ = Describe("创建", func() { @@ -49,7 +49,8 @@ var _ = Describe("创建", func() {
49 }) 49 })
50 }) 50 })
51 AfterEach(func() { 51 AfterEach(func() {
52 - //_, err := pG.DB.Exec("DELETE FROM users WHERE true")  
53 - //Expect(err).NotTo(HaveOccurred()) 52 + _, err := pG.DB.Exec("DELETE FROM users WHERE true")
  53 + _, err = pG.DB.Exec("DELETE FROM user_auth WHERE true")
  54 + Expect(err).NotTo(HaveOccurred())
54 }) 55 })
55 }) 56 })
@@ -11,20 +11,19 @@ import ( @@ -11,20 +11,19 @@ import (
11 ) 11 )
12 12
13 var _ = Describe("返回", func() { 13 var _ = Describe("返回", func() {
14 - return  
15 var userId int64 14 var userId int64
16 BeforeEach(func() { 15 BeforeEach(func() {
17 _, err := pG.DB.QueryOne( 16 _, err := pG.DB.QueryOne(
18 pg.Scan(&userId), 17 pg.Scan(&userId),
19 - "INSERT INTO users (user_id, user_type, permissions, company_id, user_info, partner_info, status, admin_type, access_partners, create_at, update_at, delete_at) VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?) RETURNING user_id",  
20 - "testUserId", "testUserType", "testPermissions", "testCompanyId", "testUserInfo", "testPartnerInfo", "testStatus", "testAdminType", "testAccessPartners", "testCreateAt", "testUpdateAt", "testDeleteAt") 18 + "INSERT INTO users (user_id, user_type, permissions, company_id, user_info, partner_info, status, admin_type) VALUES (?, ?, ?, ?, ?, ?, ?, ?) RETURNING user_id",
  19 + 1, 1, pg.Array([]int{}), 1, `{}`, `{}`, 1, 1)
21 Expect(err).NotTo(HaveOccurred()) 20 Expect(err).NotTo(HaveOccurred())
22 }) 21 })
23 Describe("根据userId参数返回用户实体", func() { 22 Describe("根据userId参数返回用户实体", func() {
24 Context("传入有效的userId", func() { 23 Context("传入有效的userId", func() {
25 It("返回用户实体数据", func() { 24 It("返回用户实体数据", func() {
26 httpExpect := httpexpect.New(GinkgoT(), server.URL) 25 httpExpect := httpexpect.New(GinkgoT(), server.URL)
27 - httpExpect.GET("/users/{userId}"). 26 + httpExpect.GET("/users/1").
28 Expect(). 27 Expect().
29 Status(http.StatusOK). 28 Status(http.StatusOK).
30 JSON(). 29 JSON().
@@ -36,7 +35,7 @@ var _ = Describe("返回", func() { @@ -36,7 +35,7 @@ var _ = Describe("返回", func() {
36 }) 35 })
37 }) 36 })
38 AfterEach(func() { 37 AfterEach(func() {
39 - //_, err := pG.DB.Exec("DELETE FROM users WHERE true")  
40 - //Expect(err).NotTo(HaveOccurred()) 38 + _, err := pG.DB.Exec("DELETE FROM users WHERE true")
  39 + Expect(err).NotTo(HaveOccurred())
41 }) 40 })
42 }) 41 })
@@ -11,13 +11,12 @@ import ( @@ -11,13 +11,12 @@ import (
11 ) 11 )
12 12
13 var _ = Describe("返回列表", func() { 13 var _ = Describe("返回列表", func() {
14 - return  
15 var userId int64 14 var userId int64
16 BeforeEach(func() { 15 BeforeEach(func() {
17 _, err := pG.DB.QueryOne( 16 _, err := pG.DB.QueryOne(
18 pg.Scan(&userId), 17 pg.Scan(&userId),
19 - "INSERT INTO users (user_id, user_type, permissions, company_id, user_info, partner_info, status, admin_type, access_partners, create_at, update_at, delete_at) VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?) RETURNING user_id",  
20 - "testUserId", "testUserType", "testPermissions", "testCompanyId", "testUserInfo", "testPartnerInfo", "testStatus", "testAdminType", "testAccessPartners", "testCreateAt", "testUpdateAt", "testDeleteAt") 18 + "INSERT INTO users (user_id, user_type, permissions, company_id, user_info, partner_info, status, admin_type) VALUES (?, ?, ?, ?, ?, ?, ?, ?) RETURNING user_id",
  19 + 1, 1, pg.Array([]int{}), 1, `{}`, `{}`, 1, 1)
21 Expect(err).NotTo(HaveOccurred()) 20 Expect(err).NotTo(HaveOccurred())
22 }) 21 })
23 Describe("根据参数返回用户实体列表", func() { 22 Describe("根据参数返回用户实体列表", func() {
@@ -25,8 +24,8 @@ var _ = Describe("返回列表", func() { @@ -25,8 +24,8 @@ var _ = Describe("返回列表", func() {
25 It("返回用户实体数据列表", func() { 24 It("返回用户实体数据列表", func() {
26 httpExpect := httpexpect.New(GinkgoT(), server.URL) 25 httpExpect := httpexpect.New(GinkgoT(), server.URL)
27 httpExpect.GET("/users/"). 26 httpExpect.GET("/users/").
28 - WithQuery("offset", "int").  
29 - WithQuery("limit", "int"). 27 + WithQuery("offset", 0).
  28 + WithQuery("limit", 10).
30 Expect(). 29 Expect().
31 Status(http.StatusOK). 30 Status(http.StatusOK).
32 JSON(). 31 JSON().
@@ -40,7 +39,7 @@ var _ = Describe("返回列表", func() { @@ -40,7 +39,7 @@ var _ = Describe("返回列表", func() {
40 }) 39 })
41 }) 40 })
42 AfterEach(func() { 41 AfterEach(func() {
43 - //_, err := pG.DB.Exec("DELETE FROM users WHERE true")  
44 - //Expect(err).NotTo(HaveOccurred()) 42 + _, err := pG.DB.Exec("DELETE FROM users WHERE true")
  43 + Expect(err).NotTo(HaveOccurred())
45 }) 44 })
46 }) 45 })
@@ -11,20 +11,19 @@ import ( @@ -11,20 +11,19 @@ import (
11 ) 11 )
12 12
13 var _ = Describe("移除", func() { 13 var _ = Describe("移除", func() {
14 - return  
15 var userId int64 14 var userId int64
16 BeforeEach(func() { 15 BeforeEach(func() {
17 _, err := pG.DB.QueryOne( 16 _, err := pG.DB.QueryOne(
18 pg.Scan(&userId), 17 pg.Scan(&userId),
19 - "INSERT INTO users (user_id, user_type, permissions, company_id, user_info, partner_info, status, admin_type, access_partners, create_at, update_at, delete_at) VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?) RETURNING user_id",  
20 - "testUserId", "testUserType", "testPermissions", "testCompanyId", "testUserInfo", "testPartnerInfo", "testStatus", "testAdminType", "testAccessPartners", "testCreateAt", "testUpdateAt", "testDeleteAt") 18 + "INSERT INTO users (user_id, user_type, permissions, company_id, user_info, partner_info, status, admin_type) VALUES (?, ?, ?, ?, ?, ?, ?, ?) RETURNING user_id",
  19 + 1, 1, pg.Array([]int{}), 1, `{}`, `{}`, 1, 1)
21 Expect(err).NotTo(HaveOccurred()) 20 Expect(err).NotTo(HaveOccurred())
22 }) 21 })
23 Describe("根据参数移除", func() { 22 Describe("根据参数移除", func() {
24 Context("传入有效的userId", func() { 23 Context("传入有效的userId", func() {
25 It("返回被移除用户实体的数据", func() { 24 It("返回被移除用户实体的数据", func() {
26 httpExpect := httpexpect.New(GinkgoT(), server.URL) 25 httpExpect := httpexpect.New(GinkgoT(), server.URL)
27 - httpExpect.DELETE("/users/{userId}"). 26 + httpExpect.DELETE("/users/1").
28 Expect(). 27 Expect().
29 Status(http.StatusOK). 28 Status(http.StatusOK).
30 JSON(). 29 JSON().
@@ -36,7 +35,7 @@ var _ = Describe("移除", func() { @@ -36,7 +35,7 @@ var _ = Describe("移除", func() {
36 }) 35 })
37 }) 36 })
38 AfterEach(func() { 37 AfterEach(func() {
39 - //_, err := pG.DB.Exec("DELETE FROM users WHERE true")  
40 - //Expect(err).NotTo(HaveOccurred()) 38 + _, err := pG.DB.Exec("DELETE FROM users WHERE true")
  39 + Expect(err).NotTo(HaveOccurred())
41 }) 40 })
42 }) 41 })
@@ -16,8 +16,8 @@ var _ = Describe("设置权限", func() { @@ -16,8 +16,8 @@ var _ = Describe("设置权限", func() {
16 BeforeEach(func() { 16 BeforeEach(func() {
17 _, err := pG.DB.QueryOne( 17 _, err := pG.DB.QueryOne(
18 pg.Scan(&userId), 18 pg.Scan(&userId),
19 - "INSERT INTO users (user_id, user_type, permissions, company_id, user_info, partner_info, status, admin_type, access_partners, create_at, update_at, delete_at) VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?) RETURNING user_id",  
20 - "testUserId", "testUserType", "testPermissions", "testCompanyId", "testUserInfo", "testPartnerInfo", "testStatus", "testAdminType", "testAccessPartners", "testCreateAt", "testUpdateAt", "testDeleteAt") 19 + "INSERT INTO users (user_id, user_type, permissions, company_id, user_info, partner_info, status, admin_type) VALUES (?, ?, ?, ?, ?, ?, ?, ?) RETURNING user_id",
  20 + 1, 1, pg.Array([]int{}), 1, `{}`, `{}`, 1, 1)
21 Expect(err).NotTo(HaveOccurred()) 21 Expect(err).NotTo(HaveOccurred())
22 }) 22 })
23 Describe("设置权限", func() { 23 Describe("设置权限", func() {
@@ -25,8 +25,8 @@ var _ = Describe("设置权限", func() { @@ -25,8 +25,8 @@ var _ = Describe("设置权限", func() {
25 It("", func() { 25 It("", func() {
26 httpExpect := httpexpect.New(GinkgoT(), server.URL) 26 httpExpect := httpexpect.New(GinkgoT(), server.URL)
27 body := map[string]interface{}{ 27 body := map[string]interface{}{
28 - "userId": "int64",  
29 - "permissons": "array", 28 + "userId": 1,
  29 + "permissons": []int{1, 2, 3},
30 } 30 }
31 httpExpect.POST("/users/setPermission"). 31 httpExpect.POST("/users/setPermission").
32 WithJSON(body). 32 WithJSON(body).
@@ -11,13 +11,12 @@ import ( @@ -11,13 +11,12 @@ import (
11 ) 11 )
12 12
13 var _ = Describe("更新", func() { 13 var _ = Describe("更新", func() {
14 - return  
15 var userId int64 14 var userId int64
16 BeforeEach(func() { 15 BeforeEach(func() {
17 _, err := pG.DB.QueryOne( 16 _, err := pG.DB.QueryOne(
18 pg.Scan(&userId), 17 pg.Scan(&userId),
19 - "INSERT INTO users (user_id, user_type, permissions, company_id, user_info, partner_info, status, admin_type, access_partners, create_at, update_at, delete_at) VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?) RETURNING user_id",  
20 - "testUserId", "testUserType", "testPermissions", "testCompanyId", "testUserInfo", "testPartnerInfo", "testStatus", "testAdminType", "testAccessPartners", "testCreateAt", "testUpdateAt", "testDeleteAt") 18 + "INSERT INTO users (user_id, user_type, permissions, company_id, user_info, partner_info, status, admin_type) VALUES (?, ?, ?, ?, ?, ?, ?, ?) RETURNING user_id",
  19 + 1, 1, pg.Array([]int{}), 1, `{}`, `{}`, 1, 1)
21 Expect(err).NotTo(HaveOccurred()) 20 Expect(err).NotTo(HaveOccurred())
22 }) 21 })
23 Describe("提交数据更新", func() { 22 Describe("提交数据更新", func() {
@@ -25,30 +24,21 @@ var _ = Describe("更新", func() { @@ -25,30 +24,21 @@ var _ = Describe("更新", func() {
25 It("返回更新后的用户实体数据", func() { 24 It("返回更新后的用户实体数据", func() {
26 httpExpect := httpexpect.New(GinkgoT(), server.URL) 25 httpExpect := httpexpect.New(GinkgoT(), server.URL)
27 body := map[string]interface{}{ 26 body := map[string]interface{}{
28 - "userType": "int",  
29 - "adminType": "int",  
30 - "status": "int64",  
31 - "isPrincipal": "boolean",  
32 - "uid": "int64",  
33 - "userAccount": "string",  
34 - "userAvatarUrl": "string",  
35 - "userName": "string",  
36 - "email": "string",  
37 - "gender": "int",  
38 - "entryTime": "datetime",  
39 - "extension": "string",  
40 - "workplace": "string",  
41 - "privateNumber": "string",  
42 - "jobNumber": "string",  
43 - "partnerAccount": "string",  
44 - "partnerName": "string",  
45 - "regionName": "string",  
46 - "cooperateTime": "datetime",  
47 - "salesmans": "array",  
48 - "partnerCategorys": "array",  
49 - "accessPartners": "array", 27 + "userInfo": map[string]interface{}{
  28 + "isPrincipal": false,
  29 + "uid": 5678664411598702,
  30 + "userAccount": "13800000000",
  31 + "userAvatarUrl": "www.baidu.com",
  32 + "userName": "彭于晏01",
  33 + "email": "gfghf@qq.com",
  34 + "gender": 1,
  35 + "extension": "1",
  36 + "workplace": "2",
  37 + "privateNumber": "3",
  38 + "jobNumber": "4",
  39 + },
50 } 40 }
51 - httpExpect.PUT("/users/{userId}"). 41 + httpExpect.PUT("/users/1").
52 WithJSON(body). 42 WithJSON(body).
53 Expect(). 43 Expect().
54 Status(http.StatusOK). 44 Status(http.StatusOK).
@@ -62,7 +52,7 @@ var _ = Describe("更新", func() { @@ -62,7 +52,7 @@ var _ = Describe("更新", func() {
62 }) 52 })
63 }) 53 })
64 AfterEach(func() { 54 AfterEach(func() {
65 - //_, err := pG.DB.Exec("DELETE FROM users WHERE true")  
66 - //Expect(err).NotTo(HaveOccurred()) 55 + _, err := pG.DB.Exec("DELETE FROM users WHERE true")
  56 + Expect(err).NotTo(HaveOccurred())
67 }) 57 })
68 }) 58 })