105 lines
2.8 KiB
Go
105 lines
2.8 KiB
Go
package logic
|
||
|
||
import (
|
||
"encoding/json"
|
||
"fmt"
|
||
"fusenapi/server/home-user-auth/internal/types"
|
||
fstests "fusenapi/utils/tests"
|
||
"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.GetSesssionWithUserToken(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))
|
||
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/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/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")
|
||
}
|
||
}
|