93 lines
2.9 KiB
Go
93 lines
2.9 KiB
Go
package homeuserauthtest
|
||
|
||
import (
|
||
"fmt"
|
||
fstests "fusenapi/utils/fstests"
|
||
"testing"
|
||
|
||
"github.com/474420502/requests"
|
||
"github.com/tidwall/gjson"
|
||
)
|
||
|
||
func TestCaseAddressList(t *testing.T) {
|
||
var err error
|
||
var resp *requests.Response
|
||
var result gjson.Result
|
||
|
||
// 获取 session,并携带 JWT token
|
||
ses := fstests.GetSessionWithUserToken(t, gserver, cnf.Host, cnf.Port)
|
||
|
||
// 向服务器发送 GET 请求,获取用户地址列表
|
||
resp, err = ses.Get(fmt.Sprintf("http://%s:%d/user/address-list", cnf.Host, cnf.Port)).TestExecute(gserver)
|
||
if err != nil {
|
||
t.Error(err)
|
||
}
|
||
// log.Println(resp.ContentString())
|
||
|
||
// 检查返回值中的 code 字段是否存在,并且值是否为 200
|
||
result = resp.Json().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")
|
||
}
|
||
|
||
// 检查返回值中的每个地址信息是否符合预期
|
||
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")
|
||
}
|
||
}
|
||
}
|