You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
82 lines
2.5 KiB
82 lines
2.5 KiB
package client
|
|
|
|
import (
|
|
"github.com/ouxuanserver/osmanthuswine/src/core"
|
|
. "github.com/smartystreets/goconvey/convey"
|
|
"hudongzhuanjia/libs/jwt"
|
|
"hudongzhuanjia/models"
|
|
"hudongzhuanjia/test"
|
|
"hudongzhuanjia/utils/code"
|
|
"hudongzhuanjia/utils/define"
|
|
"net/http"
|
|
"testing"
|
|
)
|
|
|
|
func TestEntryLogin(t *testing.T) {
|
|
type Data struct {
|
|
People *models.OrderEntryPerson `json:"people"`
|
|
}
|
|
|
|
type Result struct {
|
|
core.ResponseData
|
|
Data Data `json:"data"`
|
|
}
|
|
|
|
conf := test.GetConfig()
|
|
Convey("测试录入人员登录", t, func() {
|
|
path := test.ApiUrl("PcClient/Client/UserCtl/entryLogin")
|
|
// 正确登录
|
|
param := map[string]interface{}{
|
|
"account": conf.EntryAccount,
|
|
"password": conf.EntryPwd,
|
|
"activity_id": conf.ActivityId,
|
|
}
|
|
resp, err := test.Api("").Get(path, param) // 并不需要token
|
|
So(err, ShouldBeNil) // 检测是否请求出错
|
|
So(resp.StatusCode(), ShouldEqual, http.StatusOK) // 检测请求连接是否正确
|
|
res := new(Result)
|
|
err = resp.Json(res)
|
|
So(err, ShouldBeNil) // 检测json 解析是否正确
|
|
So(res.Code, ShouldEqual, 0) // 返回code是否为0
|
|
So(res.Data.People, ShouldNotBeNil, nil) // 检测返回数据是否为空
|
|
So(res.Data.People.ActivityId, ShouldEqual, conf.ActivityId)
|
|
So(res.Data.People.Account, ShouldEqual, conf.EntryAccount)
|
|
So(res.Data.People.Password, ShouldEqual, conf.EntryPwd)
|
|
So(res.Data.People.Token, ShouldNotBeEmpty)
|
|
// 校验token
|
|
claims, err := jwt.ParseAccessToken(res.Data.People.Token)
|
|
So(err, ShouldNotBeNil)
|
|
So(claims.ActivityId, ShouldEqual, conf.ActivityId)
|
|
So(claims.AccountType, ShouldEqual, define.TYPE_ENTRY)
|
|
|
|
// 登录失败的场景
|
|
// 录入人员不存在
|
|
param = map[string]interface{}{
|
|
"account": "tommy",
|
|
"password": conf.EntryPwd,
|
|
"activity_id": conf.ActivityId,
|
|
}
|
|
resp, err = test.Api("").Get(path)
|
|
So(err, ShouldBeNil)
|
|
So(resp.StatusCode(), ShouldEqual, http.StatusOK)
|
|
res = new(Result)
|
|
err = resp.Json(res)
|
|
So(err, ShouldBeNil)
|
|
So(res.Code, ShouldEqual, code.MSG_ENTRYPEOPLE_NOT_EXIST)
|
|
|
|
// 互动不存在
|
|
param = map[string]interface{}{
|
|
"account": conf.EntryAccount,
|
|
"password": conf.EntryPwd,
|
|
"activity_id": 0,
|
|
}
|
|
resp, err = test.Api("").Get(path)
|
|
So(err, ShouldBeNil)
|
|
So(resp.StatusCode(), ShouldEqual, http.StatusOK)
|
|
res = new(Result)
|
|
err = resp.Json(res)
|
|
So(err, ShouldBeNil)
|
|
So(res.Code, ShouldEqual, code.MSG_ACTIVITY_NOT_EXIST)
|
|
// done
|
|
})
|
|
}
|