|
@@ -0,0 +1,74 @@
|
|
1
|
+package tests
|
|
2
|
+
|
|
3
|
+import (
|
|
4
|
+ "net/http"
|
|
5
|
+ "net/url"
|
|
6
|
+ "spaceofcheng/services/controllers"
|
|
7
|
+ "spaceofcheng/services/utils"
|
|
8
|
+ "testing"
|
|
9
|
+ "time"
|
|
10
|
+
|
|
11
|
+ "github.com/astaxie/beego"
|
|
12
|
+
|
|
13
|
+ . "github.com/smartystreets/goconvey/convey"
|
|
14
|
+)
|
|
15
|
+
|
|
16
|
+func TestPreCourseOrder(t *testing.T) {
|
|
17
|
+ Convey("课程下单", t, func() {
|
|
18
|
+
|
|
19
|
+ Convey("正常下单", func() {
|
|
20
|
+ params := url.Values{}
|
|
21
|
+ params.Add("info", `{"CourseId":"ecc55f91-52b4-4e9b-89a8-b9b3362730f9","CaseId":"10","Price":"2.00"}`)
|
|
22
|
+ result := &controllers.JSONMessage{}
|
|
23
|
+ api := "/api/wechat/MQ/order/course"
|
|
24
|
+
|
|
25
|
+ token := &utils.JWTToken{
|
|
26
|
+ Guest: false,
|
|
27
|
+ ID: "oMOpz0kgTrasoAA3G70R7phomn1g", // openid
|
|
28
|
+ Expire: time.Now().Local().Add(24 * 30 * time.Hour),
|
|
29
|
+ BatchNo: "",
|
|
30
|
+ }
|
|
31
|
+
|
|
32
|
+ code, _, err := NewRequestMock().
|
|
33
|
+ AddToken(token.ToMap()).
|
|
34
|
+ AddWechatUA().
|
|
35
|
+ Request(http.MethodPost, api, params, result)
|
|
36
|
+
|
|
37
|
+ beego.Trace(result)
|
|
38
|
+
|
|
39
|
+ So(code, ShouldEqual, http.StatusOK)
|
|
40
|
+ So(err, ShouldBeNil)
|
|
41
|
+
|
|
42
|
+ // 业务返回判断
|
|
43
|
+ So(result.Code, ShouldEqual, http.StatusOK)
|
|
44
|
+ So(result.Result, ShouldNotBeEmpty)
|
|
45
|
+
|
|
46
|
+ orderID := result.Result.(map[string]interface{})["OrdersId"].(string)
|
|
47
|
+
|
|
48
|
+ Convey("下单确认", func() {
|
|
49
|
+ result := &controllers.JSONMessage{}
|
|
50
|
+ api := "/api/wechat/MQ/order/course/" + orderID
|
|
51
|
+
|
|
52
|
+ token := &utils.JWTToken{
|
|
53
|
+ Guest: false,
|
|
54
|
+ ID: "oMOpz0kgTrasoAA3G70R7phomn1g", // openid
|
|
55
|
+ Expire: time.Now().Local().Add(24 * 30 * time.Hour),
|
|
56
|
+ BatchNo: "",
|
|
57
|
+ }
|
|
58
|
+
|
|
59
|
+ code, _, err := NewRequestMock().
|
|
60
|
+ AddToken(token.ToMap()).
|
|
61
|
+ AddWechatUA().
|
|
62
|
+ Request(http.MethodPut, api, nil, result)
|
|
63
|
+
|
|
64
|
+ beego.Trace(result)
|
|
65
|
+
|
|
66
|
+ So(code, ShouldEqual, http.StatusOK)
|
|
67
|
+ So(err, ShouldBeNil)
|
|
68
|
+
|
|
69
|
+ // 业务返回判断
|
|
70
|
+ So(result.Code, ShouldEqual, http.StatusOK)
|
|
71
|
+ })
|
|
72
|
+ })
|
|
73
|
+ })
|
|
74
|
+}
|