2023-06-16 02:58:43 +00:00
|
|
|
|
package logic
|
2023-06-12 09:10:27 +00:00
|
|
|
|
|
|
|
|
|
import (
|
|
|
|
|
"fmt"
|
2023-06-25 03:26:47 +00:00
|
|
|
|
fstests "fusenapi/utils/tests"
|
2023-06-12 09:10:27 +00:00
|
|
|
|
"testing"
|
|
|
|
|
|
|
|
|
|
"github.com/474420502/requests"
|
2023-06-12 11:52:11 +00:00
|
|
|
|
"github.com/tidwall/gjson"
|
2023-06-12 09:10:27 +00:00
|
|
|
|
)
|
|
|
|
|
|
|
|
|
|
func TestCaseAddressList(t *testing.T) {
|
2023-06-12 11:52:11 +00:00
|
|
|
|
var err error
|
|
|
|
|
var resp *requests.Response
|
|
|
|
|
var result gjson.Result
|
2023-06-12 09:10:27 +00:00
|
|
|
|
|
2023-06-15 11:56:19 +00:00
|
|
|
|
// 获取 session,并携带 JWT token
|
2023-06-25 03:26:47 +00:00
|
|
|
|
ses := fstests.GetSesssionWithUserToken(t, gserver, cnf.Host, cnf.Port)
|
2023-06-12 09:10:27 +00:00
|
|
|
|
|
2023-06-15 11:56:19 +00:00
|
|
|
|
// 向服务器发送 GET 请求,获取用户地址列表
|
2023-06-20 04:15:14 +00:00
|
|
|
|
resp, err = ses.Get(fmt.Sprintf("http://%s:%d/user/address-list", cnf.Host, cnf.Port)).TestExecute(gserver)
|
2023-06-12 09:10:27 +00:00
|
|
|
|
if err != nil {
|
2023-06-12 10:08:34 +00:00
|
|
|
|
t.Error(err)
|
|
|
|
|
}
|
2023-06-15 11:56:19 +00:00
|
|
|
|
// log.Println(resp.ContentString())
|
|
|
|
|
|
|
|
|
|
// 检查返回值中的 code 字段是否存在,并且值是否为 200
|
2023-06-12 10:08:34 +00:00
|
|
|
|
result = resp.Json().Get("code")
|
|
|
|
|
if !result.Exists() {
|
|
|
|
|
t.Error("code is not exists")
|
|
|
|
|
}
|
|
|
|
|
if result.Int() != 200 {
|
|
|
|
|
t.Error("code != 200")
|
2023-06-12 09:10:27 +00:00
|
|
|
|
}
|
|
|
|
|
|
2023-06-15 11:56:19 +00:00
|
|
|
|
// 检查返回值中的 msg 字段是否存在,并且值是否为 "success"
|
2023-06-12 10:08:34 +00:00
|
|
|
|
result = resp.Json().Get("msg")
|
|
|
|
|
if !result.Exists() {
|
|
|
|
|
t.Error("msg is not exists")
|
|
|
|
|
}
|
|
|
|
|
if result.String() != "success" {
|
|
|
|
|
t.Error(result.String())
|
|
|
|
|
}
|
2023-06-15 11:56:19 +00:00
|
|
|
|
|
|
|
|
|
// 检查返回值中的 data 字段是否存在
|
|
|
|
|
result = resp.Json().Get("data")
|
|
|
|
|
if !result.Exists() {
|
|
|
|
|
t.Error("data is not exists")
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// 检查返回值中的每个地址信息是否符合预期
|
|
|
|
|
for _, address := range result.Array() {
|
|
|
|
|
// 检查地址信息中的各个字段是否存在并且不为空
|
|
|
|
|
if !address.Get("id").Exists() || address.Get("id").Int() == 0 {
|
|
|
|
|
t.Error("address id is not exists or empty")
|
|
|
|
|
}
|
|
|
|
|
if !address.Get("user_id").Exists() || address.Get("user_id").Int() == 0 {
|
|
|
|
|
t.Error("address user_id is not exists or empty")
|
|
|
|
|
}
|
|
|
|
|
if !address.Get("name").Exists() || address.Get("name").String() == "" {
|
|
|
|
|
t.Error("address name is not exists or empty")
|
|
|
|
|
}
|
|
|
|
|
if !address.Get("mobile").Exists() || address.Get("mobile").String() == "" {
|
|
|
|
|
t.Error("address mobile is not exists or empty")
|
|
|
|
|
}
|
|
|
|
|
if !address.Get("street").Exists() || address.Get("street").String() == "" {
|
|
|
|
|
t.Error("address street is not exists or empty")
|
|
|
|
|
}
|
|
|
|
|
if !address.Get("city").Exists() || address.Get("city").String() == "" {
|
|
|
|
|
t.Error("address city is not exists or empty")
|
|
|
|
|
}
|
|
|
|
|
if !address.Get("state").Exists() || address.Get("state").String() == "" {
|
|
|
|
|
t.Error("address state is not exists or empty")
|
|
|
|
|
}
|
|
|
|
|
if !address.Get("country").Exists() || address.Get("country").String() == "" {
|
|
|
|
|
t.Error("address country is not exists or empty")
|
|
|
|
|
}
|
|
|
|
|
if !address.Get("zip_code").Exists() || address.Get("zip_code").String() == "" {
|
|
|
|
|
t.Error("address zip_code is not exists or empty")
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// 检查地址信息中的 is_default 字段是否存在,并且值是否为布尔类型
|
|
|
|
|
if !address.Get("is_default").Exists() {
|
|
|
|
|
t.Error("address is_default is not exists or not a boolean")
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// 检查地址信息中的 status 字段是否存在,并且值是否为 1
|
|
|
|
|
if !address.Get("status").Exists() || address.Get("status").Int() != 1 {
|
|
|
|
|
t.Error("address status is not exists or != 1")
|
|
|
|
|
}
|
|
|
|
|
}
|
2023-06-12 09:10:27 +00:00
|
|
|
|
}
|