From 1a0f2be95fa91ae65d80dd0b8bcccdc242db1268 Mon Sep 17 00:00:00 2001 From: eson <9673575+githubcontent@user.noreply.gitee.com> Date: Thu, 15 Jun 2023 19:56:19 +0800 Subject: [PATCH] =?UTF-8?q?=E5=AE=8C=E6=88=90=E8=BF=99=E4=B8=AA=E5=8D=95?= =?UTF-8?q?=E5=85=83=E6=B5=8B=E8=AF=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../test/useraddresslistlogic_test.go | 54 +++++++++++++++++++ 1 file changed, 54 insertions(+) diff --git a/server/home-user-auth/test/useraddresslistlogic_test.go b/server/home-user-auth/test/useraddresslistlogic_test.go index 607cf86c..eac35495 100644 --- a/server/home-user-auth/test/useraddresslistlogic_test.go +++ b/server/home-user-auth/test/useraddresslistlogic_test.go @@ -13,12 +13,17 @@ func TestCaseAddressList(t *testing.T) { var resp *requests.Response var result gjson.Result + // 获取 session,并携带 JWT token ses := GetSesssionWithJwtToken(t, gserver) + // 向服务器发送 GET 请求,获取用户地址列表 resp, err = ses.Get(fmt.Sprintf("http://%s:%d/user/address-list", cnf.Host, cnf.Port)).TestInServer(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") @@ -27,6 +32,7 @@ func TestCaseAddressList(t *testing.T) { t.Error("code != 200") } + // 检查返回值中的 msg 字段是否存在,并且值是否为 "success" result = resp.Json().Get("msg") if !result.Exists() { t.Error("msg is not exists") @@ -34,4 +40,52 @@ func TestCaseAddressList(t *testing.T) { 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") + } + } }