2023-06-20 08:46:56 +00:00
|
|
|
|
package logic
|
|
|
|
|
|
|
|
|
|
import (
|
|
|
|
|
"fmt"
|
|
|
|
|
"fusenapi/server/home-user-auth/internal/types"
|
2023-06-25 03:26:47 +00:00
|
|
|
|
fstests "fusenapi/utils/tests"
|
2023-06-20 08:46:56 +00:00
|
|
|
|
"testing"
|
|
|
|
|
|
|
|
|
|
"github.com/474420502/requests"
|
|
|
|
|
"github.com/tidwall/gjson"
|
|
|
|
|
)
|
|
|
|
|
|
|
|
|
|
func TestCaseLogic(t *testing.T) {
|
|
|
|
|
var err error
|
|
|
|
|
var resp *requests.Response
|
|
|
|
|
var result gjson.Result
|
|
|
|
|
|
|
|
|
|
// 获取 session,并携带 JWT token
|
2023-06-28 11:32:41 +00:00
|
|
|
|
ses := fstests.GetSessionWithUserToken(t, gserver, cnf.Host, cnf.Port)
|
2023-06-20 08:46:56 +00:00
|
|
|
|
|
|
|
|
|
// 向服务器发送 GET 请求,获取用户类型信息
|
|
|
|
|
tp := ses.Post(fmt.Sprintf("http://%s:%d/user/order-delete", cnf.Host, cnf.Port))
|
|
|
|
|
reqO := types.RequestOrderId{
|
|
|
|
|
OrderId: 12,
|
|
|
|
|
}
|
|
|
|
|
tp.SetBodyJson(reqO)
|
|
|
|
|
resp, err = tp.TestExecute(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)
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|