diff --git a/constants/webset.go b/constants/webset.go index 91b86149..84a7f102 100644 --- a/constants/webset.go +++ b/constants/webset.go @@ -3,10 +3,11 @@ package constants type TypeWebSet string const ( - FONT_CONFIG TypeWebSet = "font_config" //字体 - POLICY_CONFIG TypeWebSet = "policy" //政策 - CLAUSE_CONFIG TypeWebSet = "clause" //条款 - FAQ_CONFIG TypeWebSet = "faq" //问答 + FONT_CONFIG TypeWebSet = "font_config" //字体 + POLICY_CONFIG TypeWebSet = "policy" //政策 + CLAUSE_CONFIG TypeWebSet = "clause" //条款 + FAQ_CONFIG TypeWebSet = "faq" //问答 + RECOMMEND_DETAIL_PRODUCT TypeWebSet = "recommend_detail_" //详情页推荐-后街pid RENDER_DESIGN TypeWebSet = "render_design_" //云渲染 后接client_no LAST_DESIGN TypeWebSet = "last_design_" //最后设计 后接uid diff --git a/go.mod b/go.mod index 5f4837dc..cc7770cd 100644 --- a/go.mod +++ b/go.mod @@ -7,6 +7,7 @@ require ( github.com/golang-jwt/jwt v3.2.2+incompatible github.com/nfnt/resize v0.0.0-20180221191011-83c6a9932646 github.com/skip2/go-qrcode v0.0.0-20200617195104-da1b6568686e + github.com/stripe/stripe-go/v74 v74.22.0 github.com/zeromicro/go-zero v1.5.2 golang.org/x/image v0.0.0-20190802002840-cff245a6509b gorm.io/driver/mysql v1.5.1 @@ -16,11 +17,10 @@ require ( require ( github.com/google/uuid v1.3.0 // indirect github.com/schollz/progressbar v1.0.0 // indirect - github.com/stripe/stripe-go/v74 v74.22.0 // indirect ) require ( - github.com/474420502/requests v1.33.0 + github.com/474420502/requests v1.33.3 github.com/jinzhu/inflection v1.0.0 // indirect github.com/jinzhu/now v1.1.5 // indirect github.com/tidwall/gjson v1.12.0 diff --git a/go.sum b/go.sum index c2890a2b..53209a58 100644 --- a/go.sum +++ b/go.sum @@ -32,8 +32,8 @@ cloud.google.com/go/storage v1.8.0/go.mod h1:Wv1Oy7z6Yz3DshWRJFhqM/UCfaWIRTdp0RX cloud.google.com/go/storage v1.10.0/go.mod h1:FLPqc6j+Ki4BU591ie1oL6qBQGu2Bl/tZ9ullr3+Kg0= dmitri.shuralyov.com/gpu/mtl v0.0.0-20190408044501-666a987793e9/go.mod h1:H6x//7gZCb22OMCxBHrMx7a5I7Hp++hsVxbQ4BYO7hU= github.com/474420502/random v0.4.1 h1:HUUyLXRWMijVb7CJoEC16f0aFQOW25Lkr80Mut6PoKU= -github.com/474420502/requests v1.33.0 h1:psSTM9WsIDjbjJIXXXhhT52BlpcaNs+gDetQi2wgu1o= -github.com/474420502/requests v1.33.0/go.mod h1:5qAlksMg7JIrEXrpkxw1++4Z5W2tUkZbHA6M7oq1r/0= +github.com/474420502/requests v1.33.3 h1:CZs7M9OoaDMTJBCPQh4kob+rgFp2R9vHVZD0kaVDdrs= +github.com/474420502/requests v1.33.3/go.mod h1:5qAlksMg7JIrEXrpkxw1++4Z5W2tUkZbHA6M7oq1r/0= github.com/BurntSushi/toml v0.3.1/go.mod h1:xHWCNGjB5oqiDr8zfno3MHue2Ht5sIBksp03qcyfWMU= github.com/BurntSushi/xgb v0.0.0-20160522181843-27f122750802/go.mod h1:IVnqGOEym/WlBOVXweHU+Q+/VP0lqqI8lqeDx9IjBqo= github.com/DATA-DOG/go-sqlmock v1.5.0 h1:Shsta01QNfFxHCfpW6YH2STWB0MudeXXEWMr20OEh60= diff --git a/server/home-user-auth/test/basic.go b/server/home-user-auth/test/basic.go index d47c8eae..8daa0e1c 100644 --- a/server/home-user-auth/test/basic.go +++ b/server/home-user-auth/test/basic.go @@ -17,10 +17,10 @@ var gserver *rest.Server func init() { log.SetFlags(log.Llongfile) - gserver = GetTestServer(testConfigFile) + gserver = GetTestServer() } -func GetTestServer(testConfigFile string) *rest.Server { +func GetTestServer() *rest.Server { conf.MustLoad(testConfigFile, &cnf) diff --git a/server/webset/etc/wetset.yaml b/server/webset/etc/wetset.yaml index 5a728a3f..063e8f06 100644 --- a/server/webset/etc/wetset.yaml +++ b/server/webset/etc/wetset.yaml @@ -1,7 +1,7 @@ Name: wetset Host: 0.0.0.0 Port: 8888 -SourceMysql: "" +SourceMysql: "fusentest:XErSYmLELKMnf3Dh@tcp(110.41.19.98:3306)/fusentest" Auth: AccessSecret: fusen2023 AccessExpire: 604800 diff --git a/server/webset/internal/logic/wetsetsettinglogic.go b/server/webset/internal/logic/wetsetsettinglogic.go index 68556769..702ce328 100644 --- a/server/webset/internal/logic/wetsetsettinglogic.go +++ b/server/webset/internal/logic/wetsetsettinglogic.go @@ -5,7 +5,6 @@ import ( "fusenapi/constants" "fusenapi/utils/auth" "fusenapi/utils/basic" - "strings" "context" @@ -51,36 +50,6 @@ func (l *WetSetSettingLogic) WetSetSetting(req *types.RequestWebSet, userinfo *a if err != nil { return resp.SetStatus(basic.CodeJsonErr) } - //组装配置项的内容数据 - for k, v := range result["list"].(map[string]interface{}) { - //按空格分隔内容 - result["list"].(map[string]interface{})[k].(map[string]interface{})["content"] = strings.Split(v.(string), "\n") - } - // TODO: 缓存 - if typeConf == constants.CLAUSE_CONFIG || typeConf == constants.FAQ_CONFIG || typeConf == constants.POLICY_CONFIG { - // cache := redis.NewClient(&redis.Options{ - // Addr: "localhost:6379", - // Password: "", // no password set - // DB: 0, // use default DB - // }) - // if cache.Exists(ctx.Query("type")).Val() > 0 { - // result = cache.HGetAll(ctx.Query("type")).Val() - // } else { - // //读取配置项 - // model := WebSet{Key: typeStr} - // db.First(&model) - // result = json.Unmarshal([]byte(model.Value), &result) - // //组装配置项的内容数据 - // for k, v := range result["list"].(map[string]interface{}) { - // //按空格分隔内容 - // result["list"].(map[string]interface{})[k].(map[string]interface{})["content"] = strings.Split(v.(string), "\n") - // } - // cache.HMSet(ctx.Query("type"), result) - // } - } else { - - } - - return resp.SetStatus(basic.CodeOK) + return resp.SetStatus(basic.CodeOK, result) } diff --git a/server/webset/test/basic.go b/server/webset/test/basic.go index 34dbd613..e8c7e486 100644 --- a/server/webset/test/basic.go +++ b/server/webset/test/basic.go @@ -17,10 +17,10 @@ var gserver *rest.Server func init() { log.SetFlags(log.Llongfile) - gserver = GetTestServer(testConfigFile) + gserver = GetTestServer() } -func GetTestServer(testConfigFile string) *rest.Server { +func GetTestServer() *rest.Server { conf.MustLoad(testConfigFile, &cnf) diff --git a/server/webset/test/wetset_test.go b/server/webset/test/wetset_test.go index 1ce43b54..95cf0bb4 100644 --- a/server/webset/test/wetset_test.go +++ b/server/webset/test/wetset_test.go @@ -2,8 +2,8 @@ package logic import ( "fmt" + "fusenapi/constants" fstests "fusenapi/utils/tests" - "log" "testing" "github.com/474420502/requests" @@ -15,33 +15,100 @@ func TestWetSetLogic(t *testing.T) { var resp *requests.Response var result gjson.Result + // constants.FONT_CONFIG ? 这个还没有测试的例子 + testTypes := []constants.TypeWebSet{constants.POLICY_CONFIG, constants.CLAUSE_CONFIG, constants.FAQ_CONFIG} + // 获取 session,并携带 JWT token ses := fstests.GetSesssion() - // 向服务器发送 GET 请求,获取 cookie 信息 - resp, err = ses.Get(fmt.Sprintf("http://%s:%d/wet-set/setting", cnf.Host, cnf.Port)).TestExecute(gserver) - if err != nil { - t.Error(err) + tp := ses.Get(fmt.Sprintf("http://%s:%d/web-set/setting", cnf.Host, cnf.Port)) + + for _, tType := range testTypes { + tp.QueryParam("type").Set(tType) + // log.Println(tp.GetRawURL()) + // 向服务器发送 GET 请求,获取 cookie 信息 + resp, err = tp.TestExecute(gserver) + if err != nil { + t.Error(err) + } + + // 使用 gjson 解析返回的 json 数据 + result = resp.Json() // gjson + + // log.Println(result) + // 检查返回值中的 code 字段是否存在,并且值是否为 200 + result = result.Get("code") + if !result.Exists() { + t.Error("code is not exists") + } + if result.Int() != 200 { + t.Error("code != 200") + } + + // 检查返回值中的 msg 字段是否存在,并且值是否为 "success" + result = resp.Json().Get("msg") + if !result.Exists() { + t.Error("msg is not exists") + } + if result.String() != "success" { + t.Error(result.String()) + } + + // 检查返回值中的 data 字段是否存在 + result = resp.Json().Get("data") + if !result.Exists() { + t.Error("data is not exists") + } + + // 根据data的不同,分别校验 + intro := result.Get("introduction") + if intro.Exists() { + // 如果有introduction,则校验introduction和list + if !intro.Exists() { + t.Error("introduction is not exists") + } + list := result.Get("list") + if !list.Exists() { + t.Error("list is not exists") + } + // ... + } else { + // 如果没有introduction,则校验icon、items和title + icon := result.Get("icon") + if !icon.Exists() { + t.Error("icon is not exists") + } + items := result.Get("items") + if !items.Exists() { + t.Error("items is not exists") + } + title := result.Get("title") + if !title.Exists() { + t.Error("title is not exists") + } + // ... + } } - // 使用 gjson 解析返回的 json 数据 - result = resp.Json() // gjson + // 检查返回值中的 introduction 字段是否存在 + // intro := result.Get("introduction") + // if !intro.Exists() { + // t.Error("introduction is not exists") + // } - log.Println(result) - // 检查返回值中的 code 字段是否存在,并且值是否为 200 - code := result.Get("code").Int() - if code != 200 { - t.Errorf("Invalid code value: %d", code) - } + // // 检查返回值中的 list 数组是否存在 + // list := result.Get("list") + // if !list.Exists() { + // t.Error("list is not exists") + // } - // 检查返回值中的 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") - } + // // 校验 list 数组中的每个条款 title 和 content 字段是否存在 + // for _, item := range list.Array() { + // title := item.Get("title") + // content := item.Get("content") + // if !title.Exists() || !content.Exists() { + // t.Error("title or content not exists") + // log.Println(result) + // continue + // } + // } }