fusenapi/server/home-user-auth/test/usercontactservicelogic_test.go
2023-06-29 18:04:59 +08:00

71 lines
1.9 KiB
Go
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

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: 481, Email: "9107058@qq.com", Name: "zhang"}
tp.SetBodyJson(req)
// 向服务器发送 GET 请求,获取用户基本信息
resp, err = tp.TestExecute(gserver)
if err != nil {
t.Error(err)
}
respjson := resp.Json()
// 检查返回值中的 code 字段是否存在,并且值是否为 200
result = respjson.Get("code")
if !result.Exists() {
t.Error("code is not exists")
}
if result.Int() != 200 {
t.Error("code != 200")
}
// 检查返回值中的 msg 字段是否存在,并且值是否为 "success"
result = respjson.Get("msg")
if !result.Exists() {
t.Error("msg is not exists")
}
if result.String() != "success" {
t.Error(result.String())
}
// 检查返回值中的 data 字段是否存在
result = respjson.Get("data")
if !result.Exists() {
t.Error("data is not exists")
}
// 检查返回值中的 msg 字段是否存在,并且值是否为 "success"
result = respjson.Get("msg")
if !result.Exists() {
t.Error("msg does not exist")
}
data := respjson.Get("data")
// 补充检查返回值中的每个字段是否存在
fieldKeys := []string{"id", "type", "relation_id", "user_id", "name", "email", "phone", "remark", "is_handle", "ctime", "handle_remark", "handle_uid", "handle_time"}
for _, key := range fieldKeys {
field := data.Get(key)
if !field.Exists() {
t.Errorf("Field '%s' does not exist", key)
}
}
}