12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970 |
- package tests
-
- import (
- "net/http"
- "net/url"
- "wechat-conf/controllers"
- "wechat-conf/utils"
- "testing"
- "time"
-
- . "github.com/smartystreets/goconvey/convey"
- )
-
- func TestPreGoodsOrder(t *testing.T) {
- Convey("商品下单", t, func() {
-
- Convey("正常下单", func() {
- params := url.Values{}
- params.Add("info", `{"CaseId":"1","AreaId":"12","AreaName":"吧台","TableId":"28","TableNo":"城咖啡水吧台","Amount":"23","OrdersNum":1,"Remark":"","OrgId":"1","UserName":"奥利奥","PayType":"coupon"}`)
- params.Add("detail", `[{"GoodsId":"61","GoodsName":"美式","SpecId":"40","SpecName":"去冰","Number":1,"Price":"23"}]`)
-
- result := &controllers.JSONMessage{}
- api := "/api/wechat/MQ/order/goods"
-
- token := &utils.JWTToken{
- Guest: false,
- ID: "oMOpz0kgTrasoAA3G70R7phomn1g", // openid
- Expire: time.Now().Local().Add(24 * 30 * time.Hour),
- BatchNo: "",
- }
-
- code, _, err := NewRequestMock().
- AddToken(token.ToMap()).
- AddWechatUA().
- Request(http.MethodPost, api, params, result)
-
- So(code, ShouldEqual, http.StatusOK)
- So(err, ShouldBeNil)
-
- // 业务返回判断
- So(result.Code, ShouldEqual, http.StatusOK)
- So(result.Result, ShouldNotBeEmpty)
-
- orderID := result.Result.(map[string]interface{})["OrdersId"].(string)
-
- Convey("下单确认", func() {
- result := &controllers.JSONMessage{}
- api := "/api/wechat/MQ/order/goods/" + orderID
-
- token := &utils.JWTToken{
- Guest: false,
- ID: "oMOpz0kgTrasoAA3G70R7phomn1g", // openid
- Expire: time.Now().Local().Add(24 * 30 * time.Hour),
- BatchNo: "",
- }
-
- code, _, err := NewRequestMock().
- AddToken(token.ToMap()).
- AddWechatUA().
- Request(http.MethodPut, api, nil, result)
-
- So(code, ShouldEqual, http.StatusOK)
- So(err, ShouldBeNil)
-
- // 业务返回判断
- So(result.Code, ShouldEqual, http.StatusOK)
- })
- })
- })
- }
|