TODO: render/ 相关模块
This commit is contained in:
@@ -37,13 +37,14 @@ func (l *UserContactServiceLogic) UserContactService(req *types.RequestContactSe
|
||||
return resp.SetStatus(basic.CodeUnAuth)
|
||||
}
|
||||
|
||||
cs := gmodel.FsContactService{}
|
||||
|
||||
collect.LoadJsonTag(cs, req)
|
||||
cs := gmodel.FsContactService{
|
||||
UserId: &userinfo.UserId,
|
||||
}
|
||||
collect.LoadJsonTag(&cs, &req)
|
||||
|
||||
switch req.Type {
|
||||
case "order":
|
||||
_, err := l.svcCtx.AllModels.FsOrder.FindOneAndCreateServiceContact(l.ctx, userinfo.UserId, req.RelationID)
|
||||
_, err := l.svcCtx.AllModels.FsOrder.FindOneAndCreateServiceContact(l.ctx, userinfo.UserId, req.RelationID, &cs)
|
||||
if err != nil {
|
||||
if err == gorm.ErrRecordNotFound {
|
||||
return resp.SetStatus(basic.CodeOrderNotFoundErr)
|
||||
@@ -51,16 +52,17 @@ func (l *UserContactServiceLogic) UserContactService(req *types.RequestContactSe
|
||||
return resp.SetStatus(basic.CodeDbSqlErr)
|
||||
}
|
||||
case "cloud":
|
||||
_, err := l.svcCtx.AllModels.FsCloudPickUp.GetCloudPickUpByIDAndUserID(l.ctx, userinfo.UserId, req.RelationID)
|
||||
_, err := l.svcCtx.AllModels.FsCloudPickUp.GetCloudPickUpByIDAndUserID(l.ctx, userinfo.UserId, req.RelationID, &cs)
|
||||
if err != nil {
|
||||
if err == gorm.ErrRecordNotFound {
|
||||
return resp.SetStatus(basic.CodeCloudOrderNotFoundErr)
|
||||
}
|
||||
return resp.SetStatus(basic.CodeDbSqlErr)
|
||||
}
|
||||
return
|
||||
default:
|
||||
return resp.SetStatusWithMessage(basic.CodeRequestParamsErr, "type is unknown")
|
||||
}
|
||||
|
||||
return resp.SetStatus(basic.CodeOK)
|
||||
return resp.SetStatus(basic.CodeOK, cs)
|
||||
}
|
||||
|
||||
@@ -18,16 +18,16 @@ func TestUserContactService(t *testing.T) {
|
||||
// 获取 session,并携带 JWT token
|
||||
ses := fstests.GetSessionWithUserToken(t, gserver, cnf.Host, cnf.Port)
|
||||
tp := ses.Post(fmt.Sprintf("http://%s:%d/user/contact-service", cnf.Host, cnf.Port))
|
||||
req := types.RequestContactService{Type: "order", RelationID: 123, Email: "admin@admin.com", Name: "eson"}
|
||||
req := types.RequestContactService{Type: "order", RelationID: 481, Email: "9107058@qq.com", Name: "zhang"}
|
||||
tp.SetBodyJson(req)
|
||||
// 向服务器发送 GET 请求,获取用户基本信息
|
||||
resp, err = tp.TestExecute(gserver)
|
||||
if err != nil {
|
||||
t.Error(err)
|
||||
}
|
||||
|
||||
respjson := resp.Json()
|
||||
// 检查返回值中的 code 字段是否存在,并且值是否为 200
|
||||
result = resp.Json().Get("code")
|
||||
result = respjson.Get("code")
|
||||
if !result.Exists() {
|
||||
t.Error("code is not exists")
|
||||
}
|
||||
@@ -36,7 +36,7 @@ func TestUserContactService(t *testing.T) {
|
||||
}
|
||||
|
||||
// 检查返回值中的 msg 字段是否存在,并且值是否为 "success"
|
||||
result = resp.Json().Get("msg")
|
||||
result = respjson.Get("msg")
|
||||
if !result.Exists() {
|
||||
t.Error("msg is not exists")
|
||||
}
|
||||
@@ -45,63 +45,26 @@ func TestUserContactService(t *testing.T) {
|
||||
}
|
||||
|
||||
// 检查返回值中的 data 字段是否存在
|
||||
result = resp.Json().Get("data")
|
||||
result = respjson.Get("data")
|
||||
if !result.Exists() {
|
||||
t.Error("data is not exists")
|
||||
}
|
||||
|
||||
// 检查返回值中的 type 字段是否存在,并且值是否为 0
|
||||
result = resp.Json().Get("data.type")
|
||||
// 检查返回值中的 msg 字段是否存在,并且值是否为 "success"
|
||||
result = respjson.Get("msg")
|
||||
if !result.Exists() {
|
||||
t.Error("type is not exists")
|
||||
t.Error("msg does not exist")
|
||||
}
|
||||
|
||||
// 检查返回值中的 is_order_status_email 字段是否存在,并且值是否为 false
|
||||
result = resp.Json().Get("data.is_order_status_email")
|
||||
if !result.Exists() {
|
||||
t.Error("is_order_status_email is not exists")
|
||||
}
|
||||
data := respjson.Get("data")
|
||||
|
||||
// 检查返回值中的 is_email_advertisement 字段是否存在,并且值是否为 false
|
||||
result = resp.Json().Get("data.is_email_advertisement")
|
||||
if !result.Exists() {
|
||||
t.Error("is_email_advertisement is not exists")
|
||||
}
|
||||
|
||||
// 检查返回值中的 is_order_status_phone 字段是否存在,并且值是否为 false
|
||||
result = resp.Json().Get("data.is_order_status_phone")
|
||||
if !result.Exists() {
|
||||
t.Error("is_order_status_phone is not exists")
|
||||
}
|
||||
|
||||
// 检查返回值中的 is_phone_advertisement 字段是否存在,并且值是否为 false
|
||||
result = resp.Json().Get("data.is_phone_advertisement")
|
||||
if !result.Exists() {
|
||||
t.Error("is_phone_advertisement is not exists")
|
||||
}
|
||||
|
||||
// 检查返回值中的 is_open_render 字段是否存在,并且值是否为 false
|
||||
result = resp.Json().Get("data.is_open_render")
|
||||
if !result.Exists() {
|
||||
t.Error("is_open_render is not exists")
|
||||
}
|
||||
|
||||
// 检查返回值中的 is_thousand_face 字段是否存在,并且值是否为 false
|
||||
result = resp.Json().Get("data.is_thousand_face")
|
||||
if !result.Exists() {
|
||||
t.Error("is_thousand_face is not exists")
|
||||
}
|
||||
|
||||
// 检查返回值中的 is_low_rendering 字段是否存在,并且值是否为 false
|
||||
result = resp.Json().Get("data.is_low_rendering")
|
||||
if !result.Exists() {
|
||||
t.Error("is_low_rendering is not exists")
|
||||
}
|
||||
|
||||
// 检查返回值中的 is_remove_bg 字段是否存在,并且值是否为 true
|
||||
result = resp.Json().Get("data.is_remove_bg")
|
||||
if !result.Exists() {
|
||||
t.Error("is_remove_bg is not exists")
|
||||
// 补充检查返回值中的每个字段是否存在
|
||||
fieldKeys := []string{"id", "type", "relation_id", "user_id", "name", "email", "phone", "remark", "is_handle", "ctime", "handle_remark", "handle_uid", "handle_time"}
|
||||
for _, key := range fieldKeys {
|
||||
field := data.Get(key)
|
||||
if !field.Exists() {
|
||||
t.Errorf("Field '%s' does not exist", key)
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user