作者 linmadan

添加同步企业用户平台接口

package command
import (
"fmt"
"github.com/astaxie/beego/validation"
)
type SyncEmployeeCallbackCommand struct {
// position:职位,department:部门,employee:员工,company:公司,profile员工档案
Module string `json:"module" valid:"Required"`
// add:添加,edit:编辑,delete删除,batchDelete:批量删除,setCompanyCharge:更改公司主管,batchForbid:批量禁用用户,batchRemove:批量更改用户部门,changeAdmin换管理员
Action string `json:"action" valid:"Required"`
// 具体的对象JSON数据
Data string `json:"data" valid:"Required"`
}
func (syncEmployeeCallbackCommand *SyncEmployeeCallbackCommand) ValidateCommand() error {
valid := validation.Validation{}
b, err := valid.Valid(syncEmployeeCallbackCommand)
if err != nil {
return err
}
if !b {
for _, validErr := range valid.Errors {
return fmt.Errorf("%s %s", validErr.Key, validErr.Message)
}
}
return nil
}
... ...
package service
import (
"encoding/json"
"github.com/linmadan/egglib-go/core/application"
"gitlab.fjmaimaimai.com/linmadan/mmm-worth/pkg/application/factory"
"gitlab.fjmaimaimai.com/linmadan/mmm-worth/pkg/application/unifiedUserCenter/command"
"gitlab.fjmaimaimai.com/linmadan/mmm-worth/pkg/domain"
"gitlab.fjmaimaimai.com/linmadan/mmm-worth/pkg/infrastructure/dao"
)
// 统一用户中心适配服务
type UnifiedUserCenterService struct {
}
// 同步企业员工回调
func (unifiedUserCenterService *UnifiedUserCenterService) SyncEmployeeCallback(syncEmployeeCallbackCommand *command.SyncEmployeeCallbackCommand) (interface{}, error) {
if err := syncEmployeeCallbackCommand.ValidateCommand(); err != nil {
return nil, application.ThrowError(application.ARG_ERROR, err.Error())
}
transactionContext, err := factory.CreateTransactionContext(nil)
if err != nil {
return nil, application.ThrowError(application.TRANSACTION_ERROR, err.Error())
}
if err := transactionContext.StartTransaction(); err != nil {
return nil, application.ThrowError(application.TRANSACTION_ERROR, err.Error())
}
defer func() {
transactionContext.RollbackTransaction()
}()
var employeeRepository domain.EmployeeRepository
if value, err := factory.CreateEmployeeRepository(map[string]interface{}{
"transactionContext": transactionContext,
}); err != nil {
return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())
} else {
employeeRepository = value
}
var employeeDao *dao.EmployeeDao
if value, err := factory.CreateEmployeeDao(map[string]interface{}{
"transactionContext": transactionContext,
}); err != nil {
return nil, application.ThrowError(application.TRANSACTION_ERROR, err.Error())
} else {
employeeDao = value
}
var companyId int64
var uid int64
var employeeName string
var employeeAccount string
var employeeAvatarUrl string
var isPrincipal bool
var status int
var uids []int64
var data map[string]interface{}
if err := json.Unmarshal([]byte(syncEmployeeCallbackCommand.Data), &data); err != nil {
return false, err
}
if value, ok := data["company_id"]; ok {
companyId = int64(value.(float64))
}
if value, ok := data["id"]; ok {
uid = int64(value.(float64))
}
if value, ok := data["name"]; ok {
employeeName = value.(string)
}
if value, ok := data["phone"]; ok {
employeeAccount = value.(string)
}
if value, ok := data["avatar"]; ok {
employeeAvatarUrl = value.(string)
}
if value, ok := data["admin_type"]; ok {
if int(value.(float64)) == 2 {
isPrincipal = true
} else {
isPrincipal = false
}
}
if value, ok := data["status"]; ok {
status = int(value.(float64))
}
if value, ok := data["ids"]; ok {
for _, uid := range value.([]interface{}) {
uids = append(uids, int64(uid.(float64)))
}
}
if syncEmployeeCallbackCommand.Module == "employee" {
switch syncEmployeeCallbackCommand.Action {
case "add":
employee := &domain.Employee{
CompanyId: companyId,
EmployeeInfo: &domain.EmployeeInfo{
Uid: uid,
EmployeeName: employeeName,
EmployeeAccount: employeeAccount,
EmployeeAvatarUrl: employeeAvatarUrl,
IsPrincipal: isPrincipal,
},
Status: status,
SuMoney: 0,
}
if _, err := employeeRepository.Save(employee); err != nil {
return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())
}
break
case "edit":
employee, err := employeeRepository.FindOne(map[string]interface{}{"uid": uid})
if err != nil {
return false, nil
}
if employee == nil {
return false, nil
}
updateData := make(map[string]interface{})
updateData["employeeName"] = employeeName
updateData["employeeAccount"] = employeeAccount
updateData["employeeAvatarUrl"] = employeeAvatarUrl
updateData["isPrincipal"] = isPrincipal
updateData["status"] = status
if err := employee.Update(updateData); err != nil {
return nil, application.ThrowError(application.BUSINESS_ERROR, err.Error())
}
if _, err := employeeRepository.Save(employee); err != nil {
return false, nil
}
break
case "batchDelete":
err := employeeDao.BatchRemove(uids)
if err != nil {
return false, nil
}
break
case "batchForbid":
err := employeeDao.BatchSetStatus(uids, status)
if err != nil {
return false, nil
}
break
default:
return false, nil
}
if err := transactionContext.CommitTransaction(); err != nil {
return nil, application.ThrowError(application.TRANSACTION_ERROR, err.Error())
}
return true, nil
} else if syncEmployeeCallbackCommand.Module == "company" {
switch syncEmployeeCallbackCommand.Action {
case "changeAdmin":
err := employeeDao.ChangePrincipal(companyId, employeeAccount)
if err != nil {
return false, nil
}
break
default:
return false, nil
}
return true, nil
} else {
return false, nil
}
}
func NewUnifiedUserCenterService(options map[string]interface{}) *UnifiedUserCenterService {
newUnifiedUserCenterService := &UnifiedUserCenterService{}
return newUnifiedUserCenterService
}
... ...
... ... @@ -37,6 +37,12 @@ func (employee *Employee) Update(data map[string]interface{}) error {
if employeeAccount, ok := data["employeeAccount"]; ok && employeeAccount != "" {
employee.EmployeeInfo.EmployeeAccount = employeeAccount.(string)
}
if employeeAvatarUrl, ok := data["employeeAvatarUrl"]; ok && employeeAvatarUrl != "" {
employee.EmployeeInfo.EmployeeAvatarUrl = employeeAvatarUrl.(string)
}
if isPrincipal, ok := data["isPrincipal"]; ok {
employee.EmployeeInfo.IsPrincipal = isPrincipal.(bool)
}
if status, ok := data["status"]; ok && status != 0 {
employee.Status = status.(int)
}
... ...
... ... @@ -10,4 +10,6 @@ type EmployeeInfo struct {
EmployeeAccount string `json:"employeeAccount"`
// 员工头像URL
EmployeeAvatarUrl string `json:"employeeAvatarUrl"`
// 是否公司负责人
IsPrincipal bool `json:"isPrincipal"`
}
... ...
... ... @@ -12,6 +12,41 @@ type EmployeeDao struct {
transactionContext *pgTransaction.TransactionContext
}
func (dao *EmployeeDao) BatchRemove(uids []int64) error {
tx := dao.transactionContext.PgTx
_, err := tx.QueryOne(
pg.Scan(),
"DELETE FROM employees WHERE uid IN (?)",
pg.In(uids))
return err
}
func (dao *EmployeeDao) BatchSetStatus(uids []int64, status int) error {
tx := dao.transactionContext.PgTx
_, err := tx.QueryOne(
pg.Scan(),
"UPDATE employees SET status=? WHERE uid IN (?)",
status, pg.In(uids))
return err
}
func (dao *EmployeeDao) ChangePrincipal(companyId int64, employeeAccount string) error {
tx := dao.transactionContext.PgTx
if _, err := tx.QueryOne(
pg.Scan(),
"UPDATE employees SET is_principal=? WHERE company_id=?",
false, companyId); err != nil {
return err
}
if _, err := tx.QueryOne(
pg.Scan(),
"UPDATE employees SET is_principal=? WHERE company_id=? AND employee_account=?",
true, companyId, employeeAccount); err != nil {
return err
}
return nil
}
func (dao *EmployeeDao) TransferSuMoney(uid int64, suMoney float64) error {
tx := dao.transactionContext.PgTx
_, err := tx.QueryOne(
... ...
... ... @@ -14,10 +14,12 @@ type Employee struct {
EmployeeAccount string
// 员工头像URL
EmployeeAvatarUrl string
// 是否公司负责人
IsPrincipal bool `pg:",notnull,default:false"`
// 当前素币
SuMoney float64
SuMoney float64 `pg:",notnull,default:0"`
// 员工状态(启用或者禁用)
Status int
Status int `pg:",notnull,default:1"`
// 员工权限集合
Permissions []int `pg:",array"`
}
... ...
... ... @@ -30,16 +30,16 @@ func (repository *EmployeeRepository) Save(employee *domain.Employee) (*domain.E
return employee, err
}
if _, err := tx.QueryOne(
pg.Scan(&employee.EmployeeId, &employee.CompanyId, &employee.EmployeeInfo.Uid, &employee.EmployeeInfo.EmployeeName, &employee.EmployeeInfo.EmployeeAccount, &employee.EmployeeInfo.EmployeeAvatarUrl, &employee.SuMoney, &employee.Status, pg.Array(&employee.Permissions)),
"INSERT INTO employees (id, company_id, uid, employee_name, employee_account, employee_avatar_url, su_money, status, permissions) VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?) RETURNING id, company_id, uid, employee_name, employee_account, employee_avatar_url, su_money, status, permissions",
employee.EmployeeId, employee.CompanyId, employee.EmployeeInfo.Uid, employee.EmployeeInfo.EmployeeName, employee.EmployeeInfo.EmployeeAccount, employee.EmployeeInfo.EmployeeAvatarUrl, employee.SuMoney, employee.Status, pg.Array(employee.Permissions)); err != nil {
pg.Scan(&employee.EmployeeId, &employee.CompanyId, &employee.EmployeeInfo.Uid, &employee.EmployeeInfo.EmployeeName, &employee.EmployeeInfo.EmployeeAccount, &employee.EmployeeInfo.EmployeeAvatarUrl, &employee.EmployeeInfo.IsPrincipal, &employee.SuMoney, &employee.Status, pg.Array(&employee.Permissions)),
"INSERT INTO employees (id, company_id, uid, employee_name, employee_account, employee_avatar_url, is_principal, su_money, status, permissions) VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?) RETURNING id, company_id, uid, employee_name, employee_account, employee_avatar_url, is_principal, su_money, status, permissions",
employee.EmployeeId, employee.CompanyId, employee.EmployeeInfo.Uid, employee.EmployeeInfo.EmployeeName, employee.EmployeeInfo.EmployeeAccount, employee.EmployeeInfo.EmployeeAvatarUrl, employee.EmployeeInfo.IsPrincipal, employee.SuMoney, employee.Status, pg.Array(employee.Permissions)); err != nil {
return employee, err
}
} else {
if _, err := tx.QueryOne(
pg.Scan(&employee.EmployeeId, &employee.CompanyId, &employee.EmployeeInfo.Uid, &employee.EmployeeInfo.EmployeeName, &employee.EmployeeInfo.EmployeeAccount, &employee.EmployeeInfo.EmployeeAvatarUrl, &employee.SuMoney, &employee.Status, pg.Array(&employee.Permissions)),
"UPDATE employees SET employee_name=?, employee_account=?, employee_avatar_url=?, su_money=?, status=?, permissions=? WHERE uid=? RETURNING id, company_id, uid, employee_name, employee_account, employee_avatar_url, su_money, status, permissions",
employee.EmployeeInfo.EmployeeName, employee.EmployeeInfo.EmployeeAccount, &employee.EmployeeInfo.EmployeeAvatarUrl, employee.SuMoney, employee.Status, pg.Array(employee.Permissions), employee.EmployeeInfo.Uid); err != nil {
pg.Scan(&employee.EmployeeId, &employee.CompanyId, &employee.EmployeeInfo.Uid, &employee.EmployeeInfo.EmployeeName, &employee.EmployeeInfo.EmployeeAccount, &employee.EmployeeInfo.EmployeeAvatarUrl, &employee.EmployeeInfo.IsPrincipal, &employee.SuMoney, &employee.Status, pg.Array(&employee.Permissions)),
"UPDATE employees SET employee_name=?, employee_account=?, employee_avatar_url=?, is_principal=?, su_money=?, status=?, permissions=? WHERE uid=? RETURNING id, company_id, uid, employee_name, employee_account, employee_avatar_url, is_principal, su_money, status, permissions",
employee.EmployeeInfo.EmployeeName, employee.EmployeeInfo.EmployeeAccount, &employee.EmployeeInfo.EmployeeAvatarUrl, employee.EmployeeInfo.IsPrincipal, employee.SuMoney, employee.Status, pg.Array(employee.Permissions), employee.EmployeeInfo.Uid); err != nil {
return employee, err
}
}
... ... @@ -88,6 +88,12 @@ func (repository *EmployeeRepository) Find(queryOptions map[string]interface{})
if employeeNameMatch, ok := queryOptions["employeeNameMatch"]; ok && (employeeNameMatch != "") {
query = query.Where("employee.employee_name LIKE ?", fmt.Sprintf("%%%s%%", employeeNameMatch.(string)))
}
if status, ok := queryOptions["status"]; ok && (status != 0) {
query = query.Where(`employee.status = ?`, status)
}
if isPrincipal, ok := queryOptions["isPrincipal"]; ok && isPrincipal.(bool) != false {
query = query.Where("employee.is_principal = ? ", isPrincipal)
}
if offset, ok := queryOptions["offset"]; ok {
offset := offset.(int)
if offset > -1 {
... ... @@ -127,6 +133,7 @@ func (repository *EmployeeRepository) transformPgModelToDomainModel(employeeMode
EmployeeName: employeeModel.EmployeeName,
EmployeeAccount: employeeModel.EmployeeAccount,
EmployeeAvatarUrl: employeeModel.EmployeeAvatarUrl,
IsPrincipal: employeeModel.IsPrincipal,
},
SuMoney: employeeModel.SuMoney,
Status: employeeModel.Status,
... ...
package controllers
import (
"encoding/json"
"github.com/astaxie/beego"
"github.com/linmadan/egglib-go/web/beego/utils"
"gitlab.fjmaimaimai.com/linmadan/mmm-worth/pkg/application/unifiedUserCenter/command"
"gitlab.fjmaimaimai.com/linmadan/mmm-worth/pkg/application/unifiedUserCenter/service"
)
type UnifiedUserCenterController struct {
beego.Controller
}
func (controller *UnifiedUserCenterController) SyncEmployeeCallback() {
unifiedUserCenterService := service.NewUnifiedUserCenterService(nil)
syncEmployeeCallbackCommand := &command.SyncEmployeeCallbackCommand{}
json.Unmarshal(controller.Ctx.Input.GetData("requestBody").([]byte), syncEmployeeCallbackCommand)
data, err := unifiedUserCenterService.SyncEmployeeCallback(syncEmployeeCallbackCommand)
var response utils.JsonResponse
if err != nil {
response = utils.ResponseError(controller.Ctx, err)
} else {
response = utils.ResponseData(controller.Ctx, data)
}
controller.Data["json"] = response
controller.ServeJSON()
}
... ...
package routers
import (
"github.com/astaxie/beego"
"gitlab.fjmaimaimai.com/linmadan/mmm-worth/pkg/port/beego/controllers"
)
func init() {
beego.Router("/api/business/index", &controllers.UnifiedUserCenterController{}, "Post:SyncEmployeeCallback")
}
... ...
package unified_user_center
import (
"net/http"
"github.com/gavv/httpexpect"
"github.com/go-pg/pg"
. "github.com/onsi/ginkgo"
. "github.com/onsi/gomega"
pG "gitlab.fjmaimaimai.com/linmadan/mmm-worth/pkg/infrastructure/pg"
)
var _ = Describe("同步企业员工回调", func() {
var employeeId int64
BeforeEach(func() {
_, err := pG.DB.QueryOne(
pg.Scan(&employeeId),
"INSERT INTO employees (id, company_id, uid, employee_name, employee_account, employee_avatar_url, is_principal, su_money, status, permissions) VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?) RETURNING id",
1, 101, 2499036607974745088, "employee_name", "13799999999", "employee_avatar_url", false, 1000.00, 1, pg.Array([]int{1, 3}))
Expect(err).NotTo(HaveOccurred())
})
Describe("同步企业员工回调", func() {
Context("同步添加企业员工", func() {
It("添加成功", func() {
httpExpect := httpexpect.New(GinkgoT(), server.URL)
body := map[string]interface{}{
"module": "employee",
"action": "add",
"data": `{
"id": 5040167991950442755,
"company_id": 1000,
"open_id": 0,
"name": "杨洲2",
"sex": 1,
"job_num": 59101419,
"phone": "15659781344",
"private_phone": "18050324007",
"email": "cczhang319@qq.com",
"extension_num": "0591-83845806",
"entry_time": "2020-02-10",
"workspace": "买买买",
"is_business": 1,
"status": 1,
"avatar": "http://suplus-business-admin-dev.fjmaimaimai.com//images/default_avatar.png",
"extra_text": "[]",
"remarks": "无",
"admin_type": 1,
"charge_status": 2,
"created_at": "2020-02-14 22:45:32",
"updated_at": "2020-02-14 22:45:32",
"deleted_at": null,
"user_departments": [
{
"id": 102,
"company_id": 1000,
"department_id": 0,
"user_id": 5040167991950442755,
"created_at": "2020-02-14 22:45:32",
"updated_at": "2020-02-14 22:45:32",
"deleted_at": null
},
{
"id": 103,
"company_id": 1000,
"department_id": 10,
"user_id": 5040167991950442755,
"created_at": "2020-02-14 22:45:32",
"updated_at": "2020-02-14 22:45:32",
"deleted_at": null
},
{
"id": 104,
"company_id": 1000,
"department_id": 11,
"user_id": 5040167991950442755,
"created_at": "2020-02-14 22:45:32",
"updated_at": "2020-02-14 22:45:32",
"deleted_at": null
},
{
"id": 105,
"company_id": 1000,
"department_id": 12,
"user_id": 5040167991950442755,
"created_at": "2020-02-14 22:45:32",
"updated_at": "2020-02-14 22:45:32",
"deleted_at": null
}
],
"user_positions": [
{
"id": 28,
"company_id": 1000,
"position_id": 10,
"user_id": 5040167991950442755,
"created_at": "2020-02-14 22:45:32",
"updated_at": "2020-02-14 22:45:32",
"deleted_at": null
},
{
"id": 29,
"company_id": 1000,
"position_id": 11,
"user_id": 5040167991950442755,
"created_at": "2020-02-14 22:45:32",
"updated_at": "2020-02-14 22:45:32",
"deleted_at": null
},
{
"id": 30,
"company_id": 1000,
"position_id": 12,
"user_id": 5040167991950442755,
"created_at": "2020-02-14 22:45:32",
"updated_at": "2020-02-14 22:45:32",
"deleted_at": null
}
],
"user_roles": [
{
"id": 32,
"role_id": 6,
"enable_status": 1,
"company_id": 1000,
"user_id": 5040167991950442755
},
{
"id": 33,
"role_id": 7,
"enable_status": 1,
"company_id": 1000,
"user_id": 5040167991950442755
}
]
}`,
}
httpExpect.POST("/api/business/index").
WithJSON(body).
Expect().
Status(http.StatusOK).
JSON().
Object().
ContainsKey("code").ValueEqual("code", 0).
ContainsKey("msg").ValueEqual("msg", "ok").
ContainsKey("data").ValueEqual("data", true)
})
})
Context("同步更新企业员工", func() {
It("更新成功", func() {
httpExpect := httpexpect.New(GinkgoT(), server.URL)
body := map[string]interface{}{
"module": "employee",
"action": "edit",
"data": `{
"id": 2499036607974745088,
"company_id": 1000,
"open_id": 0,
"name": "杨洲2",
"sex": 1,
"job_num": 59101419,
"phone": "15659781344",
"private_phone": "18050324007",
"email": "cczhang319@qq.com",
"extension_num": "0591-83845806",
"entry_time": "2020-02-10",
"workspace": "买买买",
"is_business": 1,
"status": 1,
"avatar": "http://suplus-business-admin-dev.fjmaimaimai.com//images/default_avatar.png",
"extra_text": "[]",
"remarks": "无",
"admin_type": 1,
"charge_status": 2,
"created_at": "2020-02-14 22:45:32",
"updated_at": "2020-02-14 22:45:32",
"deleted_at": null,
"user_departments": [
{
"id": 102,
"company_id": 1000,
"department_id": 0,
"user_id": 5040167991950442755,
"created_at": "2020-02-14 22:45:32",
"updated_at": "2020-02-14 22:45:32",
"deleted_at": null
},
{
"id": 103,
"company_id": 1000,
"department_id": 10,
"user_id": 5040167991950442755,
"created_at": "2020-02-14 22:45:32",
"updated_at": "2020-02-14 22:45:32",
"deleted_at": null
},
{
"id": 104,
"company_id": 1000,
"department_id": 11,
"user_id": 5040167991950442755,
"created_at": "2020-02-14 22:45:32",
"updated_at": "2020-02-14 22:45:32",
"deleted_at": null
},
{
"id": 105,
"company_id": 1000,
"department_id": 12,
"user_id": 5040167991950442755,
"created_at": "2020-02-14 22:45:32",
"updated_at": "2020-02-14 22:45:32",
"deleted_at": null
}
],
"user_positions": [
{
"id": 28,
"company_id": 1000,
"position_id": 10,
"user_id": 5040167991950442755,
"created_at": "2020-02-14 22:45:32",
"updated_at": "2020-02-14 22:45:32",
"deleted_at": null
},
{
"id": 29,
"company_id": 1000,
"position_id": 11,
"user_id": 5040167991950442755,
"created_at": "2020-02-14 22:45:32",
"updated_at": "2020-02-14 22:45:32",
"deleted_at": null
},
{
"id": 30,
"company_id": 1000,
"position_id": 12,
"user_id": 5040167991950442755,
"created_at": "2020-02-14 22:45:32",
"updated_at": "2020-02-14 22:45:32",
"deleted_at": null
}
],
"user_roles": [
{
"id": 32,
"role_id": 6,
"enable_status": 1,
"company_id": 1000,
"user_id": 5040167991950442755
},
{
"id": 33,
"role_id": 7,
"enable_status": 1,
"company_id": 1000,
"user_id": 5040167991950442755
}
]
}`,
}
httpExpect.POST("/api/business/index").
WithJSON(body).
Expect().
Status(http.StatusOK).
JSON().
Object().
ContainsKey("code").ValueEqual("code", 0).
ContainsKey("msg").ValueEqual("msg", "ok").
ContainsKey("data").ValueEqual("data", true)
})
})
Context("同步批量删除企业员工", func() {
It("删除成功", func() {
httpExpect := httpexpect.New(GinkgoT(), server.URL)
body := map[string]interface{}{
"module": "employee",
"action": "batchDelete",
"data": ` {
"ids": [
2499036607974745088
]
}`,
}
httpExpect.POST("/api/business/index").
WithJSON(body).
Expect().
Status(http.StatusOK).
JSON().
Object().
ContainsKey("code").ValueEqual("code", 0).
ContainsKey("msg").ValueEqual("msg", "ok").
ContainsKey("data").ValueEqual("data", true)
})
})
Context("同步批量设置企业员工状态", func() {
It("设置成功", func() {
httpExpect := httpexpect.New(GinkgoT(), server.URL)
body := map[string]interface{}{
"module": "employee",
"action": "batchForbid",
"data": ` {
"ids": [
2499036607974745088
],
"status": 2
}`,
}
httpExpect.POST("/api/business/index").
WithJSON(body).
Expect().
Status(http.StatusOK).
JSON().
Object().
ContainsKey("code").ValueEqual("code", 0).
ContainsKey("msg").ValueEqual("msg", "ok").
ContainsKey("data").ValueEqual("data", true)
})
})
Context("同步更换管理员", func() {
It("更换成功", func() {
httpExpect := httpexpect.New(GinkgoT(), server.URL)
body := map[string]interface{}{
"module": "company",
"action": "changeAdmin",
"data": ` {
"company_id": 101,
"phone": "13799999999"
}`,
}
httpExpect.POST("/api/business/index").
WithJSON(body).
Expect().
Status(http.StatusOK).
JSON().
Object().
ContainsKey("code").ValueEqual("code", 0).
ContainsKey("msg").ValueEqual("msg", "ok").
ContainsKey("data").ValueEqual("data", true)
})
})
})
AfterEach(func() {
_, err := pG.DB.Exec("DELETE FROM employees WHERE true")
Expect(err).NotTo(HaveOccurred())
})
})
... ...
package unified_user_center
import (
"net/http"
"net/http/httptest"
"testing"
"github.com/astaxie/beego"
. "github.com/onsi/ginkgo"
. "github.com/onsi/gomega"
_ "gitlab.fjmaimaimai.com/linmadan/mmm-worth/pkg/infrastructure/pg"
_ "gitlab.fjmaimaimai.com/linmadan/mmm-worth/pkg/port/beego"
)
func TestUnifiedUserCenter(t *testing.T) {
RegisterFailHandler(Fail)
RunSpecs(t, "Beego Port UnifiedUserCenter Correlations Test Case Suite")
}
var handler http.Handler
var server *httptest.Server
var _ = BeforeSuite(func() {
handler = beego.BeeApp.Handlers
server = httptest.NewServer(handler)
})
var _ = AfterSuite(func() {
server.Close()
})
... ...