2023-07-06 10:23:43 +00:00
|
|
|
|
package wetset_test
|
2023-06-25 03:26:47 +00:00
|
|
|
|
|
|
|
|
|
import (
|
|
|
|
|
"fmt"
|
2023-06-25 05:15:55 +00:00
|
|
|
|
"fusenapi/constants"
|
2023-07-05 11:00:33 +00:00
|
|
|
|
fstests "fusenapi/utils/fstests"
|
2023-06-25 03:26:47 +00:00
|
|
|
|
"testing"
|
|
|
|
|
|
|
|
|
|
"github.com/474420502/requests"
|
|
|
|
|
"github.com/tidwall/gjson"
|
|
|
|
|
)
|
|
|
|
|
|
|
|
|
|
func TestWetSetLogic(t *testing.T) {
|
|
|
|
|
var err error
|
|
|
|
|
var resp *requests.Response
|
|
|
|
|
var result gjson.Result
|
|
|
|
|
|
2023-06-25 05:15:55 +00:00
|
|
|
|
// constants.FONT_CONFIG ? 这个还没有测试的例子
|
|
|
|
|
testTypes := []constants.TypeWebSet{constants.POLICY_CONFIG, constants.CLAUSE_CONFIG, constants.FAQ_CONFIG}
|
|
|
|
|
|
2023-06-25 03:26:47 +00:00
|
|
|
|
// 获取 session,并携带 JWT token
|
|
|
|
|
ses := fstests.GetSesssion()
|
2023-06-25 05:15:55 +00:00
|
|
|
|
tp := ses.Get(fmt.Sprintf("http://%s:%d/web-set/setting", cnf.Host, cnf.Port))
|
2023-06-25 03:26:47 +00:00
|
|
|
|
|
2023-06-25 05:15:55 +00:00
|
|
|
|
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)
|
|
|
|
|
}
|
2023-06-25 03:26:47 +00:00
|
|
|
|
|
2023-06-25 05:15:55 +00:00
|
|
|
|
// 使用 gjson 解析返回的 json 数据
|
|
|
|
|
result = resp.Json() // gjson
|
2023-06-25 03:26:47 +00:00
|
|
|
|
|
2023-06-25 05:15:55 +00:00
|
|
|
|
// 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())
|
|
|
|
|
}
|
2023-06-25 03:26:47 +00:00
|
|
|
|
|
2023-06-25 05:15:55 +00:00
|
|
|
|
// 检查返回值中的 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")
|
|
|
|
|
}
|
|
|
|
|
// ...
|
|
|
|
|
}
|
2023-06-25 03:26:47 +00:00
|
|
|
|
}
|
2023-06-25 05:15:55 +00:00
|
|
|
|
|
2023-06-25 03:26:47 +00:00
|
|
|
|
}
|