TODO: 反射

This commit is contained in:
eson
2023-06-28 19:32:41 +08:00
parent 0851c922ef
commit d4e75b1efc
27 changed files with 527 additions and 186 deletions

View File

@@ -16,7 +16,7 @@ func TestCaseUserAddAddress(t *testing.T) {
var result gjson.Result
// 获取 session,并携带 JWT token
ses := fstests.GetSesssionWithUserToken(t, gserver, cnf.Host, cnf.Port)
ses := fstests.GetSessionWithUserToken(t, gserver, cnf.Host, cnf.Port)
// 构建新增地址请求体
addrReq := types.RequestAddAddress{

View File

@@ -15,7 +15,7 @@ func TestCaseAddressList(t *testing.T) {
var result gjson.Result
// 获取 session并携带 JWT token
ses := fstests.GetSesssionWithUserToken(t, gserver, cnf.Host, cnf.Port)
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)

View File

@@ -15,7 +15,7 @@ func TestCaseBasicInfoLogic(t *testing.T) {
var result gjson.Result
// 获取 session并携带 JWT token
ses := fstests.GetSesssionWithUserToken(t, gserver, cnf.Host, cnf.Port)
ses := fstests.GetSessionWithUserToken(t, gserver, cnf.Host, cnf.Port)
// 向服务器发送 GET 请求,获取用户基本信息
resp, err = ses.Get(fmt.Sprintf("http://%s:%d/user/basic-info", cnf.Host, cnf.Port)).TestExecute(gserver)

View File

@@ -0,0 +1,107 @@
package logic
import (
"fmt"
"fusenapi/server/home-user-auth/internal/types"
fstests "fusenapi/utils/tests"
"testing"
"github.com/474420502/requests"
"github.com/tidwall/gjson"
)
func TestUserContactService(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)
tp := ses.Post(fmt.Sprintf("http://%s:%d/user/contact-service", cnf.Host, cnf.Port))
req := types.RequestContactService{Type: "order", RelationID: 123, Email: "admin@admin.com", Name: "eson"}
tp.SetBodyJson(req)
// 向服务器发送 GET 请求,获取用户基本信息
resp, err = tp.TestExecute(gserver)
if err != nil {
t.Error(err)
}
// 检查返回值中的 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")
}
// 检查返回值中的 type 字段是否存在,并且值是否为 0
result = resp.Json().Get("data.type")
if !result.Exists() {
t.Error("type is not exists")
}
// 检查返回值中的 is_order_status_email 字段是否存在,并且值是否为 false
result = resp.Json().Get("data.is_order_status_email")
if !result.Exists() {
t.Error("is_order_status_email is not exists")
}
// 检查返回值中的 is_email_advertisement 字段是否存在,并且值是否为 false
result = resp.Json().Get("data.is_email_advertisement")
if !result.Exists() {
t.Error("is_email_advertisement is not exists")
}
// 检查返回值中的 is_order_status_phone 字段是否存在,并且值是否为 false
result = resp.Json().Get("data.is_order_status_phone")
if !result.Exists() {
t.Error("is_order_status_phone is not exists")
}
// 检查返回值中的 is_phone_advertisement 字段是否存在,并且值是否为 false
result = resp.Json().Get("data.is_phone_advertisement")
if !result.Exists() {
t.Error("is_phone_advertisement is not exists")
}
// 检查返回值中的 is_open_render 字段是否存在,并且值是否为 false
result = resp.Json().Get("data.is_open_render")
if !result.Exists() {
t.Error("is_open_render is not exists")
}
// 检查返回值中的 is_thousand_face 字段是否存在,并且值是否为 false
result = resp.Json().Get("data.is_thousand_face")
if !result.Exists() {
t.Error("is_thousand_face is not exists")
}
// 检查返回值中的 is_low_rendering 字段是否存在,并且值是否为 false
result = resp.Json().Get("data.is_low_rendering")
if !result.Exists() {
t.Error("is_low_rendering is not exists")
}
// 检查返回值中的 is_remove_bg 字段是否存在,并且值是否为 true
result = resp.Json().Get("data.is_remove_bg")
if !result.Exists() {
t.Error("is_remove_bg is not exists")
}
}

View File

@@ -16,7 +16,7 @@ func TestCaseUserFontsLogic(t *testing.T) {
var result gjson.Result
// 获取 session并携带 JWT token
ses := fstests.GetSesssionWithUserToken(t, gserver, cnf.Host, cnf.Port)
ses := fstests.GetSessionWithUserToken(t, gserver, cnf.Host, cnf.Port)
// 向服务器发送 GET 请求,获取字体列表
resp, err = ses.Get(fmt.Sprintf("http://%s:%d/user/fonts", cnf.Host, cnf.Port)).TestExecute(gserver)

View File

@@ -15,7 +15,7 @@ func TestCaseGetTypeLogic(t *testing.T) {
var result gjson.Result
// 获取 session并携带 JWT token
ses := fstests.GetSesssionWithUserToken(t, gserver, cnf.Host, cnf.Port)
ses := fstests.GetSessionWithUserToken(t, gserver, cnf.Host, cnf.Port)
// 向服务器发送 GET 请求,获取用户类型信息
resp, err = ses.Get(fmt.Sprintf("http://%s:%d/user/get-type", cnf.Host, cnf.Port)).TestExecute(gserver)

View File

@@ -16,7 +16,7 @@ func TestCaseLogic(t *testing.T) {
var result gjson.Result
// 获取 session并携带 JWT token
ses := fstests.GetSesssionWithUserToken(t, gserver, cnf.Host, cnf.Port)
ses := fstests.GetSessionWithUserToken(t, gserver, cnf.Host, cnf.Port)
// 向服务器发送 GET 请求,获取用户类型信息
tp := ses.Post(fmt.Sprintf("http://%s:%d/user/order-delete", cnf.Host, cnf.Port))

View File

@@ -17,7 +17,7 @@ func TestCaseUserSaveBasicinfoLogic(t *testing.T) {
var result gjson.Result
// 获取 session并携带 JWT token
ses := fstests.GetSesssionWithUserToken(t, gserver, cnf.Host, cnf.Port)
ses := fstests.GetSessionWithUserToken(t, gserver, cnf.Host, cnf.Port)
var tp *requests.Temporary
tp = ses.Get(fmt.Sprintf("http://%s:%d/user/basic-info", cnf.Host, cnf.Port))

View File

@@ -15,7 +15,7 @@ func TestCaseUserStatusConfigLogic(t *testing.T) {
var result gjson.Result
// 获取 session并携带 JWT token
ses := fstests.GetSesssionWithUserToken(t, gserver, cnf.Host, cnf.Port)
ses := fstests.GetSessionWithUserToken(t, gserver, cnf.Host, cnf.Port)
// 向服务器发送 GET 请求,获取用户类型信息
resp, err = ses.Post(fmt.Sprintf("http://%s:%d/user/status-config", cnf.Host, cnf.Port)).TestExecute(gserver)