goodsorder_test.go 1.9KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970
  1. package tests
  2. import (
  3. "net/http"
  4. "net/url"
  5. "wechat-conf/controllers"
  6. "wechat-conf/utils"
  7. "testing"
  8. "time"
  9. . "github.com/smartystreets/goconvey/convey"
  10. )
  11. func TestPreGoodsOrder(t *testing.T) {
  12. Convey("商品下单", t, func() {
  13. Convey("正常下单", func() {
  14. params := url.Values{}
  15. params.Add("info", `{"CaseId":"1","AreaId":"12","AreaName":"吧台","TableId":"28","TableNo":"城咖啡水吧台","Amount":"23","OrdersNum":1,"Remark":"","OrgId":"1","UserName":"奥利奥","PayType":"coupon"}`)
  16. params.Add("detail", `[{"GoodsId":"61","GoodsName":"美式","SpecId":"40","SpecName":"去冰","Number":1,"Price":"23"}]`)
  17. result := &controllers.JSONMessage{}
  18. api := "/api/wechat/MQ/order/goods"
  19. token := &utils.JWTToken{
  20. Guest: false,
  21. ID: "oMOpz0kgTrasoAA3G70R7phomn1g", // openid
  22. Expire: time.Now().Local().Add(24 * 30 * time.Hour),
  23. BatchNo: "",
  24. }
  25. code, _, err := NewRequestMock().
  26. AddToken(token.ToMap()).
  27. AddWechatUA().
  28. Request(http.MethodPost, api, params, result)
  29. So(code, ShouldEqual, http.StatusOK)
  30. So(err, ShouldBeNil)
  31. // 业务返回判断
  32. So(result.Code, ShouldEqual, http.StatusOK)
  33. So(result.Result, ShouldNotBeEmpty)
  34. orderID := result.Result.(map[string]interface{})["OrdersId"].(string)
  35. Convey("下单确认", func() {
  36. result := &controllers.JSONMessage{}
  37. api := "/api/wechat/MQ/order/goods/" + orderID
  38. token := &utils.JWTToken{
  39. Guest: false,
  40. ID: "oMOpz0kgTrasoAA3G70R7phomn1g", // openid
  41. Expire: time.Now().Local().Add(24 * 30 * time.Hour),
  42. BatchNo: "",
  43. }
  44. code, _, err := NewRequestMock().
  45. AddToken(token.ToMap()).
  46. AddWechatUA().
  47. Request(http.MethodPut, api, nil, result)
  48. So(code, ShouldEqual, http.StatusOK)
  49. So(err, ShouldBeNil)
  50. // 业务返回判断
  51. So(result.Code, ShouldEqual, http.StatusOK)
  52. })
  53. })
  54. })
  55. }