修改gorm序列化错误
This commit is contained in:
@@ -30,12 +30,7 @@ func (l *UserAddressListLogic) UserAddressList(req *types.Request, userinfo *aut
|
||||
// 返回值必须调用Set重新返回, resp可以空指针调用 resp.SetStatus(basic.CodeOK, data)
|
||||
m := gmodel.NewFsAddressModel(l.svcCtx.MysqlConn)
|
||||
userinfo.GetIdType()
|
||||
// user := auth.GetUserInfoFormCtx(l.ctx)
|
||||
// if user.UserId == 0 {
|
||||
// return resp.SetStatus(basic.CodeUnAuth)
|
||||
// }
|
||||
// user.UserId = 22
|
||||
// model里设置了 返回值. 和 types 里的一至可以直接返回
|
||||
|
||||
data, err := m.GetUserAllAddress(l.ctx, 22)
|
||||
if err != nil {
|
||||
logx.Error(err)
|
||||
|
||||
@@ -40,15 +40,6 @@ func (l *UserBasicInfoLogic) UserBasicInfo(req *types.Request, userinfo *auth.Us
|
||||
return resp.SetStatus(basic.CodeServiceErr)
|
||||
}
|
||||
|
||||
// $userInfo->type = $userInfo->type != 0 ? $userInfo->type : '';
|
||||
// $userInfo->is_order_status_email = (boolean)$userInfo->is_order_status_email;
|
||||
// $userInfo->is_email_advertisement = (boolean)$userInfo->is_email_advertisement;
|
||||
// $userInfo->is_order_status_phone = (boolean)$userInfo->is_order_status_phone;
|
||||
// $userInfo->is_phone_advertisement = (boolean)$userInfo->is_phone_advertisement;
|
||||
// $userInfo->is_open_render = (boolean)$userInfo->is_open_render;
|
||||
// $userInfo->is_low_rendering = (boolean)$userInfo->is_low_rendering;
|
||||
// $userInfo->is_remove_bg = (boolean)$userInfo->is_remove_bg;
|
||||
|
||||
return resp.SetStatus(basic.CodeOK, types.DataUserBasicInfo{
|
||||
Type: *user.Type,
|
||||
IsOrderStatusEmail: *user.IsOrderStatusEmail > 0,
|
||||
|
||||
45
server/home-user-auth/test/acceptcookielogic_test.go
Normal file
45
server/home-user-auth/test/acceptcookielogic_test.go
Normal file
@@ -0,0 +1,45 @@
|
||||
package logic
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"testing"
|
||||
|
||||
"github.com/474420502/requests"
|
||||
"github.com/tidwall/gjson"
|
||||
)
|
||||
|
||||
func TestAcceptCookieLogic(t *testing.T) {
|
||||
var err error
|
||||
var resp *requests.Response
|
||||
var result gjson.Result
|
||||
|
||||
// 获取 session,并携带 JWT token
|
||||
ses := GetSesssion(t, gserver)
|
||||
|
||||
// 向服务器发送 GET 请求,获取 cookie 信息
|
||||
resp, err = ses.Post(fmt.Sprintf("http://%s:%d/user/accept-cookie", cnf.Host, cnf.Port)).TestInServer(gserver)
|
||||
if err != nil {
|
||||
t.Error(err)
|
||||
}
|
||||
|
||||
// 使用 gjson 解析返回的 json 数据
|
||||
result = resp.Json() // gjson
|
||||
|
||||
// 检查返回值中的 code 字段是否存在,并且值是否为 200
|
||||
code := result.Get("code").Int()
|
||||
if code != 200 {
|
||||
t.Errorf("Invalid code value: %d", code)
|
||||
}
|
||||
|
||||
// 检查返回值中的 msg 字段是否存在,并且值是否为 "success"
|
||||
msg := result.Get("msg").String()
|
||||
if msg != "success" {
|
||||
t.Errorf(`Invalid msg value: "%s"`, msg)
|
||||
}
|
||||
|
||||
// 检查返回值中的 data 字段是否存在,并且值是否符合预期
|
||||
token := result.Get("data.token").String()
|
||||
if len(token) == 0 {
|
||||
t.Error("Missing token field")
|
||||
}
|
||||
}
|
||||
@@ -1,4 +1,4 @@
|
||||
package logic_test
|
||||
package logic
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
@@ -34,6 +34,11 @@ func GetTestServer() *rest.Server {
|
||||
return server
|
||||
}
|
||||
|
||||
func GetSesssion(t *testing.T, server requests.ITestServer) *requests.Session {
|
||||
ses := requests.NewSession()
|
||||
return ses
|
||||
}
|
||||
|
||||
func GetSesssionWithJwtToken(t *testing.T, server requests.ITestServer) *requests.Session {
|
||||
ses := requests.NewSession()
|
||||
tp := ses.Post(fmt.Sprintf("http://%s:%d/user/login", cnf.Host, cnf.Port))
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
package logic_test
|
||||
package logic
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
package logic_test
|
||||
package logic
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
|
||||
59
server/home-user-auth/test/userfontslogic_test.go
Normal file
59
server/home-user-auth/test/userfontslogic_test.go
Normal file
@@ -0,0 +1,59 @@
|
||||
package logic
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"testing"
|
||||
|
||||
"github.com/474420502/requests"
|
||||
"github.com/tidwall/gjson"
|
||||
)
|
||||
|
||||
func TestCaseUserFontsLogic(t *testing.T) {
|
||||
var err error
|
||||
var resp *requests.Response
|
||||
var result gjson.Result
|
||||
|
||||
// 获取 session,并携带 JWT token
|
||||
ses := GetSesssionWithJwtToken(t, gserver)
|
||||
|
||||
// 向服务器发送 GET 请求,获取字体列表
|
||||
resp, err = ses.Get(fmt.Sprintf("http://%s:%d/user/fonts", cnf.Host, cnf.Port)).TestInServer(gserver)
|
||||
if err != nil {
|
||||
t.Error(err)
|
||||
}
|
||||
|
||||
// 使用 gjson 解析返回的 json 数据
|
||||
result = gjson.Parse(resp.ContentString())
|
||||
|
||||
// 检查返回值中的 code 字段是否存在,并且值是否为 200
|
||||
code := result.Get("code").Int()
|
||||
if code != 200 {
|
||||
t.Errorf("Invalid code value: %d", code)
|
||||
}
|
||||
|
||||
// 检查返回值中的 msg 字段是否存在,并且值是否为 "success"
|
||||
msg := result.Get("msg").String()
|
||||
if msg != "success" {
|
||||
t.Errorf(`Invalid msg value: "%s"`, msg)
|
||||
}
|
||||
|
||||
// 检查返回值中的 data 字段是否存在,并且值是否为数组类型
|
||||
dataArray := result.Get("data").Array()
|
||||
if len(dataArray) == 0 {
|
||||
t.Error("Empty data field")
|
||||
}
|
||||
|
||||
// 遍历每个元素,检查其 key 和 name 字段是否存在,并且值是否符合预期
|
||||
for i, item := range dataArray {
|
||||
key := item.Get("key").Int()
|
||||
name := item.Get("name").String()
|
||||
|
||||
if key != int64(i+1) {
|
||||
t.Errorf("Unexpected key value at index %d: %d", i, key)
|
||||
}
|
||||
|
||||
if len(name) == 0 {
|
||||
t.Errorf("Missing name value at index %d", i)
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1,4 +1,4 @@
|
||||
package logic_test
|
||||
package logic
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
|
||||
Reference in New Issue
Block a user