courseorder_test.go 1.7KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374
  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/astaxie/beego"
  10. . "github.com/smartystreets/goconvey/convey"
  11. )
  12. func TestPreCourseOrder(t *testing.T) {
  13. Convey("课程下单", t, func() {
  14. Convey("正常下单", func() {
  15. params := url.Values{}
  16. params.Add("info", `{"CourseId":"ecc55f91-52b4-4e9b-89a8-b9b3362730f9","CaseId":"10","Price":"2.00"}`)
  17. result := &controllers.JSONMessage{}
  18. api := "/api/wechat/MQ/order/course"
  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. beego.Trace(result)
  30. So(code, ShouldEqual, http.StatusOK)
  31. So(err, ShouldBeNil)
  32. // 业务返回判断
  33. So(result.Code, ShouldEqual, http.StatusOK)
  34. So(result.Result, ShouldNotBeEmpty)
  35. orderID := result.Result.(map[string]interface{})["OrdersId"].(string)
  36. Convey("下单确认", func() {
  37. result := &controllers.JSONMessage{}
  38. api := "/api/wechat/MQ/order/course/" + orderID
  39. token := &utils.JWTToken{
  40. Guest: false,
  41. ID: "oMOpz0kgTrasoAA3G70R7phomn1g", // openid
  42. Expire: time.Now().Local().Add(24 * 30 * time.Hour),
  43. BatchNo: "",
  44. }
  45. code, _, err := NewRequestMock().
  46. AddToken(token.ToMap()).
  47. AddWechatUA().
  48. Request(http.MethodPut, api, nil, result)
  49. beego.Trace(result)
  50. So(code, ShouldEqual, http.StatusOK)
  51. So(err, ShouldBeNil)
  52. // 业务返回判断
  53. So(result.Code, ShouldEqual, http.StatusOK)
  54. })
  55. })
  56. })
  57. }