正在显示
10 个修改的文件
包含
325 行增加
和
11 行删除
@@ -12,16 +12,20 @@ import ( | @@ -12,16 +12,20 @@ import ( | ||
12 | ) | 12 | ) |
13 | 13 | ||
14 | var _ = Describe("投入现金", func() { | 14 | var _ = Describe("投入现金", func() { |
15 | + var ( | ||
16 | + cashPoolId int64 | ||
17 | + cash float64 | ||
18 | + ) | ||
15 | BeforeEach(func() { | 19 | BeforeEach(func() { |
16 | _, err := pG.DB.QueryOne( | 20 | _, err := pG.DB.QueryOne( |
17 | - pg.Scan(), | ||
18 | - "INSERT INTO cash_pools (cash, company_id, exchanged_cash, un_exchange_cash, exchanged_su_money, un_exchange_su_money, rate, last_rate, create_time) VALUES (10001, 312, 0, 10001, 0, 0, 0, 0, '2021-02-23 08:08:17.754862+00:00:00') RETURNING id, cash, company_id, exchanged_cash, un_exchange_cash, exchanged_su_money, un_exchange_su_money, rate, last_rate, create_time", | 21 | + pg.Scan( &cashPoolId, &cash), |
22 | + "INSERT INTO cash_pools (cash, company_id, exchanged_cash, un_exchange_cash, exchanged_su_money, un_exchange_su_money, rate, last_rate, create_time) VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?) RETURNING id, cash, company_id, exchanged_cash, un_exchange_cash, exchanged_su_money, un_exchange_su_money, rate, last_rate, create_time", | ||
19 | 100, 312, 100, 10001, 0, 0, 0, 0, time.Now) | 23 | 100, 312, 100, 10001, 0, 0, 0, 0, time.Now) |
20 | Expect(err).NotTo(HaveOccurred()) | 24 | Expect(err).NotTo(HaveOccurred()) |
21 | }) | 25 | }) |
22 | - Describe("投入现金", func() { | ||
23 | - Context("投入现金需要大于已兑换的现金)", func() { | ||
24 | - It("返回现金池数据", func() { | 26 | + Describe("投入现金到现金池", func() { |
27 | + Context("投入错误的金额", func() { | ||
28 | + It("返回现金池错误数据", func() { | ||
25 | httpExpect := httpexpect.New(GinkgoT(), server.URL) | 29 | httpExpect := httpexpect.New(GinkgoT(), server.URL) |
26 | body := map[string]interface{}{ | 30 | body := map[string]interface{}{ |
27 | "cash": 99, | 31 | "cash": 99, |
@@ -33,8 +37,28 @@ var _ = Describe("投入现金", func() { | @@ -33,8 +37,28 @@ var _ = Describe("投入现金", func() { | ||
33 | Status(http.StatusOK). | 37 | Status(http.StatusOK). |
34 | JSON(). | 38 | JSON(). |
35 | Object(). | 39 | Object(). |
36 | - ContainsKey("code").ValueNotEqual("code", 0). | ||
37 | - ContainsKey("msg").ValueNotEqual("msg", "ok"). | 40 | + ContainsKey("code").ValueEqual("code", 501). |
41 | + ContainsKey("msg").ValueEqual("msg", "投入的现金值必须大于当前已兑换现金值"). | ||
42 | + NotContainsKey("data").Value("data").Object() | ||
43 | + }) | ||
44 | + }) | ||
45 | + }) | ||
46 | + Describe("投入现金到现金池", func() { | ||
47 | + Context("投入正确的金额", func() { | ||
48 | + It("返回正确现金池数据", func() { | ||
49 | + httpExpect := httpexpect.New(GinkgoT(), server.URL) | ||
50 | + body := map[string]interface{} { | ||
51 | + "cash": 100, | ||
52 | + "companyId": 312, | ||
53 | + } | ||
54 | + httpExpect.POST("/cash-pool/input"). | ||
55 | + WithJSON(body). | ||
56 | + Expect(). | ||
57 | + Status(http.StatusOK). | ||
58 | + JSON(). | ||
59 | + Object(). | ||
60 | + ContainsKey("code").ValueEqual("code", 0). | ||
61 | + ContainsKey("msg").ValueEqual("msg", "ok"). | ||
38 | ContainsKey("data").Value("data").Object() | 62 | ContainsKey("data").Value("data").Object() |
39 | }) | 63 | }) |
40 | }) | 64 | }) |
@@ -18,10 +18,14 @@ import ( | @@ -18,10 +18,14 @@ import ( | ||
18 | ) | 18 | ) |
19 | 19 | ||
20 | var _ = Describe("返回现金池数据", func() { | 20 | var _ = Describe("返回现金池数据", func() { |
21 | + var ( | ||
22 | + cashPoolId int64 | ||
23 | + cash float64 | ||
24 | + ) | ||
21 | BeforeEach(func() { | 25 | BeforeEach(func() { |
22 | _, err := pG.DB.QueryOne( | 26 | _, err := pG.DB.QueryOne( |
23 | - pg.Scan(), | ||
24 | - "INSERT INTO cash_pools (cash, company_id, exchanged_cash, un_exchange_cash, exchanged_su_money, un_exchange_su_money, rate, last_rate, create_time) VALUES (10001, 312, 0, 10001, 0, 0, 0, 0, '2021-02-23 08:08:17.754862+00:00:00') RETURNING id, cash, company_id, exchanged_cash, un_exchange_cash, exchanged_su_money, un_exchange_su_money, rate, last_rate, create_time", | 27 | + pg.Scan(&cashPoolId, &cash), |
28 | + "INSERT INTO cash_pools (cash, company_id, exchanged_cash, un_exchange_cash, exchanged_su_money, un_exchange_su_money, rate, last_rate, create_time) VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?) RETURNING id, cash, company_id, exchanged_cash, un_exchange_cash, exchanged_su_money, un_exchange_su_money, rate, last_rate, create_time", | ||
25 | 100, 312, 100, 10001, 0, 0, 0, 0, time.Now) | 29 | 100, 312, 100, 10001, 0, 0, 0, 0, time.Now) |
26 | Expect(err).NotTo(HaveOccurred()) | 30 | Expect(err).NotTo(HaveOccurred()) |
27 | }) | 31 | }) |
1 | +/** | ||
2 | + @author: stevechan | ||
3 | + @date: 2021/2/23 | ||
4 | + @note: | ||
5 | +**/ | ||
6 | + | ||
7 | +package exchange_activities | ||
8 | + | ||
9 | +import ( | ||
10 | + "net/http" | ||
11 | + | ||
12 | + "github.com/gavv/httpexpect" | ||
13 | + . "github.com/onsi/ginkgo" | ||
14 | + . "github.com/onsi/gomega" | ||
15 | + pG "gitlab.fjmaimaimai.com/linmadan/mmm-worth/pkg/infrastructure/pg" | ||
16 | +) | ||
17 | + | ||
18 | +var _ = Describe("创建素币兑换活动", func() { | ||
19 | + Describe("提交数据创建素币兑换活动", func() { | ||
20 | + Context("提交正确的新活动数据", func() { | ||
21 | + It("返回素币兑换活动数据", func() { | ||
22 | + httpExpect := httpexpect.New(GinkgoT(), server.URL) | ||
23 | + body := map[string]interface{}{ | ||
24 | + "companyId": 311, | ||
25 | + "exchangeActivityName": "测试兑换活动", | ||
26 | + "deadline": "2021-01-07T16:00:00.000Z", | ||
27 | + "exchangeRate": 5.1, | ||
28 | + } | ||
29 | + httpExpect.POST("/cash-pool/activity"). | ||
30 | + WithJSON(body). | ||
31 | + Expect(). | ||
32 | + Status(http.StatusOK). | ||
33 | + JSON(). | ||
34 | + Object(). | ||
35 | + ContainsKey("code").ValueEqual("code", 0). | ||
36 | + ContainsKey("msg").ValueEqual("msg", "ok"). | ||
37 | + ContainsKey("data").Value("data").Object() | ||
38 | + }) | ||
39 | + }) | ||
40 | + }) | ||
41 | + AfterEach(func(){ | ||
42 | + _, err := pG.DB.Exec("DELETE FROM exchange_cash_activities WHERE true") | ||
43 | + Expect(err).NotTo(HaveOccurred()) | ||
44 | + }) | ||
45 | +}) |
1 | +/** | ||
2 | + @author: stevechan | ||
3 | + @date: 2021/2/23 | ||
4 | + @note: | ||
5 | +**/ | ||
6 | + | ||
7 | +package exchange_activities | ||
8 | + | ||
9 | +import ( | ||
10 | + "net/http" | ||
11 | + "time" | ||
12 | + | ||
13 | + "github.com/gavv/httpexpect" | ||
14 | + "github.com/go-pg/pg" | ||
15 | + . "github.com/onsi/ginkgo" | ||
16 | + . "github.com/onsi/gomega" | ||
17 | + pG "gitlab.fjmaimaimai.com/linmadan/mmm-worth/pkg/infrastructure/pg" | ||
18 | +) | ||
19 | + | ||
20 | +var _ = Describe("返回素币兑换活动", func() { | ||
21 | + var ( | ||
22 | + exchangeCashActivityId int64 | ||
23 | + ) | ||
24 | + BeforeEach(func() { | ||
25 | + _, err := pG.DB.QueryOne( | ||
26 | + pg.Scan(&exchangeCashActivityId), | ||
27 | + "INSERT INTO exchange_cash_activities ( company_id, activity_name, deadline, count_down, exchanged_cash, exchanged_su_money, exchange_rate, create_time) VALUES (?, ?, ?, ?, ?, ?, ?, ?) RETURNING id, company_id, activity_name, deadline, count_down, exchanged_cash, exchanged_su_money, exchange_rate, create_time", | ||
28 | + 311, "测试活动", "2021-02-08 15:59:59+00:00:00", 0, 0, 0, 5.1, time.Now()) | ||
29 | + Expect(err).NotTo(HaveOccurred()) | ||
30 | + }) | ||
31 | + Describe("根据activityId返回活动", func(){ | ||
32 | + Context("传入有效的activityId", func() { | ||
33 | + It("返回活动数据", func() { | ||
34 | + httpExpect := httpexpect.New(GinkgoT(), server.URL) | ||
35 | + httpExpect.GET("/cash-pool/activity/1"). | ||
36 | + Expect(). | ||
37 | + Status(http.StatusOK). | ||
38 | + JSON(). | ||
39 | + Object(). | ||
40 | + ContainsKey("code").ValueEqual("code", 0). | ||
41 | + ContainsKey("msg").ValueEqual("msg", "ok"). | ||
42 | + ContainsKey("data").Value("data").Object() | ||
43 | + }) | ||
44 | + }) | ||
45 | + }) | ||
46 | + AfterEach(func() { | ||
47 | + _, err := pG.DB.Exec("DELETE FROM exchange_cash_activities WHERE true") | ||
48 | + Expect(err).NotTo(HaveOccurred()) | ||
49 | + }) | ||
50 | +}) |
1 | package exchange_activities | 1 | package exchange_activities |
2 | + | ||
3 | +import ( | ||
4 | + "net/http" | ||
5 | + "time" | ||
6 | + | ||
7 | + "github.com/gavv/httpexpect" | ||
8 | + "github.com/go-pg/pg" | ||
9 | + . "github.com/onsi/ginkgo" | ||
10 | + . "github.com/onsi/gomega" | ||
11 | + pG "gitlab.fjmaimaimai.com/linmadan/mmm-worth/pkg/infrastructure/pg" | ||
12 | +) | ||
13 | + | ||
14 | +var _ = Describe("返回兑换活动列表", func() { | ||
15 | + var ( | ||
16 | + exchangeCashActivityId int64 | ||
17 | + ) | ||
18 | + BeforeEach(func() { | ||
19 | + _, err := pG.DB.QueryOne( | ||
20 | + pg.Scan(&exchangeCashActivityId), | ||
21 | + "INSERT INTO exchange_cash_activities ( company_id, activity_name, deadline, count_down, exchanged_cash, exchanged_su_money, exchange_rate, create_time) VALUES (?, ?, ?, ?, ?, ?, ?, ?) RETURNING id, company_id, activity_name, deadline, count_down, exchanged_cash, exchanged_su_money, exchange_rate, create_time", | ||
22 | + 311, "测试活动", "2021-02-08 15:59:59+00:00:00", 0, 0, 0, 5.1, time.Now()) | ||
23 | + Expect(err).NotTo(HaveOccurred()) | ||
24 | + }) | ||
25 | + Describe("根据参数返回素币兑换活动列表", func() { | ||
26 | + Context("传入有效的参数", func() { | ||
27 | + It("返回素币兑换清单列表", func() { | ||
28 | + httpExpect := httpexpect.New(GinkgoT(), server.URL) | ||
29 | + httpExpect.GET("/cash-pool/activity/?companyId=311&offset=0&limit=20"). | ||
30 | + WithQuery("companyId", 311). | ||
31 | + WithQuery("offset", 0). | ||
32 | + WithQuery("limit", 1). | ||
33 | + Expect(). | ||
34 | + Status(http.StatusOK). | ||
35 | + JSON(). | ||
36 | + Object(). | ||
37 | + ContainsKey("code").ValueEqual("code", 0). | ||
38 | + ContainsKey("msg").ValueEqual("msg", "ok"). | ||
39 | + ContainsKey("data").Value("data").Object(). | ||
40 | + ContainsKey("count").ValueEqual("count", 1) | ||
41 | + }) | ||
42 | + }) | ||
43 | + }) | ||
44 | + AfterEach(func() { | ||
45 | + _, err := pG.DB.Exec("DELETE FROM exchange_cash_activities WHERE true") | ||
46 | + Expect(err).NotTo(HaveOccurred()) | ||
47 | + }) | ||
48 | +}) |
1 | -package exchange_activities |
1 | +package exchange_activities | ||
2 | + | ||
3 | +import ( | ||
4 | + "net/http" | ||
5 | + "strconv" | ||
6 | + "time" | ||
7 | + | ||
8 | + "github.com/gavv/httpexpect" | ||
9 | + "github.com/go-pg/pg" | ||
10 | + . "github.com/onsi/ginkgo" | ||
11 | + . "github.com/onsi/gomega" | ||
12 | + pG "gitlab.fjmaimaimai.com/linmadan/mmm-worth/pkg/infrastructure/pg" | ||
13 | +) | ||
14 | + | ||
15 | +var _ = Describe("移除素币兑换活动", func() { | ||
16 | + var ( | ||
17 | + activityId int64 | ||
18 | + ) | ||
19 | + BeforeEach(func() { | ||
20 | + _, err := pG.DB.QueryOne( | ||
21 | + pg.Scan(&activityId), | ||
22 | + "INSERT INTO exchange_cash_activities ( company_id, activity_name, deadline, count_down, exchanged_cash, exchanged_su_money, exchange_rate, create_time) VALUES (?, ?, ?, ?, ?, ?, ?, ?) RETURNING id, company_id, activity_name, deadline, count_down, exchanged_cash, exchanged_su_money, exchange_rate, create_time", | ||
23 | + 311, "测试活动", "2021-02-08 15:59:59+00:00:00", 0, 0, 0, 5.1, time.Now()) | ||
24 | + Expect(err).NotTo(HaveOccurred()) | ||
25 | + }) | ||
26 | + Describe("根据参数移除素币兑换活动", func() { | ||
27 | + Context("传入有效的活动id", func() { | ||
28 | + It("返回被删除的素币兑换活动数据", func() { | ||
29 | + activityIdStr := strconv.FormatInt(activityId, 10) | ||
30 | + httpExpect := httpexpect.New(GinkgoT(), server.URL) | ||
31 | + httpExpect.DELETE("/cash-pool/activity/" + activityIdStr). | ||
32 | + Expect(). | ||
33 | + Status(http.StatusOK). | ||
34 | + JSON(). | ||
35 | + Object(). | ||
36 | + ContainsKey("code").ValueEqual("code", 0). | ||
37 | + ContainsKey("msg").ValueEqual("msg", "ok"). | ||
38 | + ContainsKey("data").Value("data").Object() | ||
39 | + }) | ||
40 | + }) | ||
41 | + }) | ||
42 | + AfterEach(func() { | ||
43 | + _, err := pG.DB.Exec("DELETE FROM exchange_cash_activities WHERE true") | ||
44 | + Expect(err).NotTo(HaveOccurred()) | ||
45 | + }) | ||
46 | +}) |
1 | +/** | ||
2 | + @author: stevechan | ||
3 | + @date: 2021/2/23 | ||
4 | + @note: | ||
5 | +**/ | ||
6 | + | ||
7 | +package exchange_activities | ||
8 | + | ||
9 | +import ( | ||
10 | + "net/http" | ||
11 | + "time" | ||
12 | + | ||
13 | + "github.com/gavv/httpexpect" | ||
14 | + "github.com/go-pg/pg" | ||
15 | + . "github.com/onsi/ginkgo" | ||
16 | + . "github.com/onsi/gomega" | ||
17 | + pG "gitlab.fjmaimaimai.com/linmadan/mmm-worth/pkg/infrastructure/pg" | ||
18 | +) | ||
19 | + | ||
20 | +var _ = Describe("搜索素币兑换活动", func() { | ||
21 | + var activityId int64 | ||
22 | + BeforeEach(func() { | ||
23 | + _, err := pG.DB.QueryOne( | ||
24 | + pg.Scan(&activityId), | ||
25 | + "INSERT INTO exchange_cash_activities ( company_id, activity_name, deadline, count_down, exchanged_cash, exchanged_su_money, exchange_rate, create_time) VALUES (?, ?, ?, ?, ?, ?, ?, ?) RETURNING id, company_id, activity_name, deadline, count_down, exchanged_cash, exchanged_su_money, exchange_rate, create_time", | ||
26 | + 311, "测试活动", "2021-02-08 15:59:59+00:00:00", 0, 0, 0, 5.1, time.Now()) | ||
27 | + Expect(err).NotTo(HaveOccurred()) | ||
28 | + }) | ||
29 | + Describe("搜索素币兑换活动", func() { | ||
30 | + Context("指定搜索条件", func() { | ||
31 | + It("返回搜索结果", func() { | ||
32 | + httpExpect := httpexpect.New(GinkgoT(), server.URL) | ||
33 | + body := map[string]interface{} { | ||
34 | + | ||
35 | + } | ||
36 | + httpExpect.POST("/cash-pool/activity/search-activity"). | ||
37 | + WithJSON(body). | ||
38 | + Expect(). | ||
39 | + Status(http.StatusOK). | ||
40 | + JSON(). | ||
41 | + Object(). | ||
42 | + ContainsKey("code").ValueEqual("code", 0). | ||
43 | + ContainsKey("msg").ValueEqual("msg", "ok"). | ||
44 | + ContainsKey("data").Value("data").Object() | ||
45 | + }) | ||
46 | + }) | ||
47 | + }) | ||
48 | + AfterEach(func() { | ||
49 | + _, err := pG.DB.Exec("DELETE FROM exchange_cash_activities WHERE true") | ||
50 | + Expect(err).NotTo(HaveOccurred()) | ||
51 | + }) | ||
52 | +}) |
1 | -package exchange_activities |
1 | +package exchange_activities | ||
2 | + | ||
3 | + | ||
4 | +import ( | ||
5 | + "net/http" | ||
6 | + "time" | ||
7 | + | ||
8 | + "github.com/gavv/httpexpect" | ||
9 | + "github.com/go-pg/pg" | ||
10 | + . "github.com/onsi/ginkgo" | ||
11 | + . "github.com/onsi/gomega" | ||
12 | + pG "gitlab.fjmaimaimai.com/linmadan/mmm-worth/pkg/infrastructure/pg" | ||
13 | +) | ||
14 | + | ||
15 | +var _ = Describe("更新素币兑换活动", func() { | ||
16 | + var activityId int64 | ||
17 | + BeforeEach(func() { | ||
18 | + _, err := pG.DB.QueryOne( | ||
19 | + pg.Scan(&activityId), | ||
20 | + "INSERT INTO exchange_cash_activities ( company_id, activity_name, deadline, count_down, exchanged_cash, exchanged_su_money, exchange_rate, create_time) VALUES (?, ?, ?, ?, ?, ?, ?, ?) RETURNING id, company_id, activity_name, deadline, count_down, exchanged_cash, exchanged_su_money, exchange_rate, create_time", | ||
21 | + 311, "测试活动", "2021-02-08 15:59:59+00:00:00", 0, 0, 0, 5.1, time.Now()) | ||
22 | + Expect(err).NotTo(HaveOccurred()) | ||
23 | + }) | ||
24 | + Describe("提交数据更新素币兑换活动", func() { | ||
25 | + Context("提交正确的素币兑换活动数据", func() { | ||
26 | + It("返回更新后的素币兑换活动数据", func() { | ||
27 | + httpExpect := httpexpect.New(GinkgoT(), server.URL) | ||
28 | + body := map[string]interface{} { | ||
29 | + | ||
30 | + } | ||
31 | + httpExpect.PUT("/cash-pool/activity/"). | ||
32 | + WithJSON(body). | ||
33 | + Expect(). | ||
34 | + Status(http.StatusOK). | ||
35 | + JSON(). | ||
36 | + Object(). | ||
37 | + ContainsKey("code").ValueEqual("code", 0). | ||
38 | + ContainsKey("msg").ValueEqual("msg", "ok"). | ||
39 | + ContainsKey("data").Value("data").Object(). | ||
40 | + ContainsKey("id").ValueEqual("id", activityId) | ||
41 | + }) | ||
42 | + }) | ||
43 | + }) | ||
44 | + AfterEach(func() { | ||
45 | + _, err := pG.DB.Exec("DELETE FROM exchange_cash_activities WHERE true") | ||
46 | + Expect(err).NotTo(HaveOccurred()) | ||
47 | + }) | ||
48 | +}) |
-
请 注册 或 登录 后发表评论