fusenapi/server/home-user-auth/test/usersavebasicinfologic_test.go
2023-07-24 19:17:02 +08:00

105 lines
2.8 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 homeuserauthtest
import (
"encoding/json"
"fmt"
"fusenapi/server/home-user-auth/internal/types"
fstests "fusenapi/utils/fstests"
"testing"
"github.com/474420502/requests"
"github.com/tidwall/gjson"
)
func TestCaseUserSaveBasicinfoLogic(t *testing.T) {
var err error
var resp *requests.Response
var result gjson.Result
// 获取 session并携带 JWT token
ses := fstests.GetSessionWithUserToken(t, userserver, cnf.Host, cnf.Port)
var tp *requests.Temporary
tp = ses.Get(fmt.Sprintf("http://%s:%d/api/user/basic-info", cnf.Host, cnf.Port))
resp, err = tp.TestExecute(gserver)
if err != nil {
t.Error(err)
return
}
req := types.RequestBasicInfoForm{}
// log.Println(resp.Json().Get("data"))
err = json.Unmarshal([]byte(resp.Json().Get("data").String()), &req)
if err != nil {
t.Error(err)
return
}
IsOrderStatusEmail := req.IsOrderStatusEmail
IsEmailAdvertisement := req.IsEmailAdvertisement
IsOrderStatusPhone := req.IsOrderStatusPhone
IsOpenRender := req.IsOpenRender
IsLowRendering := req.IsLowRendering
IsRemoveBg := req.IsRemoveBg
req.IsOrderStatusEmail = ^req.IsOrderStatusEmail + 2
req.IsEmailAdvertisement = ^req.IsEmailAdvertisement + 2
req.IsOrderStatusPhone = ^req.IsOrderStatusPhone + 2
req.IsOpenRender = ^req.IsOpenRender + 2
req.IsLowRendering = ^req.IsLowRendering + 2
req.IsRemoveBg = ^req.IsRemoveBg + 2
// 向服务器发送 GET 请求,获取用户类型信息
tp = ses.Post(fmt.Sprintf("http://%s:%d/api/user/basic-info", cnf.Host, cnf.Port)).SetBodyJson(req)
resp, err = tp.TestExecute(gserver)
if err != nil {
t.Error(err)
return
}
// 使用 gjson 解析返回的 json 数据
result = gjson.Parse(resp.ContentString())
// log.Println(resp.ContentString())
// 检查返回值中的 code 字段是否存在,并且值是否为 200
code := result.Get("code").Int()
if code != 200 {
t.Errorf("Invalid code value: %d", code)
return
}
tp = ses.Get(fmt.Sprintf("http://%s:%d/api/user/basic-info", cnf.Host, cnf.Port))
resp, err = tp.TestExecute(gserver)
if err != nil {
t.Error(err)
return
}
// log.Println(resp.ContentString())
err = json.Unmarshal([]byte(resp.Json().Get("data").String()), &req)
if err != nil {
t.Error(err)
return
}
if req.IsOrderStatusEmail != ^IsOrderStatusEmail+2 {
t.Error("IsOrderStatusEmail is error, check this code")
}
if req.IsEmailAdvertisement != ^IsEmailAdvertisement+2 {
t.Error("IsEmailAdvertisement is error, check this code")
}
if req.IsOrderStatusPhone != ^IsOrderStatusPhone+2 {
t.Error("IsOrderStatusPhone is error, check this code")
}
if req.IsOpenRender != ^IsOpenRender+2 {
t.Error("IsOpenRender is error, check this code")
}
if req.IsLowRendering != ^IsLowRendering+2 {
t.Error("IsLowRendering is error, check this code")
}
if req.IsRemoveBg != ^IsRemoveBg+2 {
t.Error("IsRemoveBg is error, check this code")
}
}