作者 陈志颖

test:增加素币兑换清单集成测试

@@ -8,6 +8,7 @@ package exchange_activities @@ -8,6 +8,7 @@ package exchange_activities
8 8
9 import ( 9 import (
10 "net/http" 10 "net/http"
  11 + "strconv"
11 "time" 12 "time"
12 13
13 "github.com/gavv/httpexpect" 14 "github.com/gavv/httpexpect"
@@ -31,8 +32,9 @@ var _ = Describe("返回素币兑换活动", func() { @@ -31,8 +32,9 @@ var _ = Describe("返回素币兑换活动", func() {
31 Describe("根据activityId返回活动", func(){ 32 Describe("根据activityId返回活动", func(){
32 Context("传入有效的activityId", func() { 33 Context("传入有效的activityId", func() {
33 It("返回活动数据", func() { 34 It("返回活动数据", func() {
  35 + activityIdStr := strconv.FormatInt(exchangeCashActivityId, 10)
34 httpExpect := httpexpect.New(GinkgoT(), server.URL) 36 httpExpect := httpexpect.New(GinkgoT(), server.URL)
35 - httpExpect.GET("/cash-pool/activity/1"). 37 + httpExpect.GET("/cash-pool/activity/" + activityIdStr).
36 Expect(). 38 Expect().
37 Status(http.StatusOK). 39 Status(http.StatusOK).
38 JSON(). 40 JSON().
@@ -23,7 +23,7 @@ var _ = Describe("搜索素币兑换活动", func() { @@ -23,7 +23,7 @@ var _ = Describe("搜索素币兑换活动", func() {
23 _, err := pG.DB.QueryOne( 23 _, err := pG.DB.QueryOne(
24 pg.Scan(&activityId), 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", 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()) 26 + 312, "测试活动", "2021-02-08 15:59:59+00:00:00", 0, 0, 0, 5.1, time.Now())
27 Expect(err).NotTo(HaveOccurred()) 27 Expect(err).NotTo(HaveOccurred())
28 }) 28 })
29 Describe("搜索素币兑换活动", func() { 29 Describe("搜索素币兑换活动", func() {
@@ -31,7 +31,11 @@ var _ = Describe("搜索素币兑换活动", func() { @@ -31,7 +31,11 @@ var _ = Describe("搜索素币兑换活动", func() {
31 It("返回搜索结果", func() { 31 It("返回搜索结果", func() {
32 httpExpect := httpexpect.New(GinkgoT(), server.URL) 32 httpExpect := httpexpect.New(GinkgoT(), server.URL)
33 body := map[string]interface{} { 33 body := map[string]interface{} {
34 - 34 + "companyId": 312,
  35 + "deadline": "",
  36 + "activityNameMatch": "测试活动",
  37 + "offset": 0,
  38 + "limit": 20,
35 } 39 }
36 httpExpect.POST("/cash-pool/activity/search-activity"). 40 httpExpect.POST("/cash-pool/activity/search-activity").
37 WithJSON(body). 41 WithJSON(body).
@@ -26,7 +26,9 @@ var _ = Describe("更新素币兑换活动", func() { @@ -26,7 +26,9 @@ var _ = Describe("更新素币兑换活动", func() {
26 It("返回更新后的素币兑换活动数据", func() { 26 It("返回更新后的素币兑换活动数据", func() {
27 httpExpect := httpexpect.New(GinkgoT(), server.URL) 27 httpExpect := httpexpect.New(GinkgoT(), server.URL)
28 body := map[string]interface{} { 28 body := map[string]interface{} {
29 - 29 + "exchangeActivityName": "这是更新后的公司311的兑换活动,哈哈哈",
  30 + "deadline": "2020-12-14T23:59:59+08:00",
  31 + "exchangeRate": 1.2,
30 } 32 }
31 httpExpect.PUT("/cash-pool/activity/"). 33 httpExpect.PUT("/cash-pool/activity/").
32 WithJSON(body). 34 WithJSON(body).
1 package exchange_list 1 package exchange_list
  2 +
  3 +import (
  4 + "github.com/go-pg/pg"
  5 + "net/http"
  6 + "time"
  7 +
  8 + "github.com/gavv/httpexpect"
  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 activityId int64
  16 + BeforeEach(func() {
  17 + _, err1 := pG.DB.QueryOne(
  18 + pg.Scan(),
  19 + "INSERT INTO employees (id, company_id, uid, employee_name, employee_account, su_money) VALUES (?, ?, ?, ?, ?, ?)",
  20 + 1, 101, 2499036607974745088, "testEmployeeName", "testEmployeeAccount", 100.00)
  21 + Expect(err1).NotTo(HaveOccurred())
  22 + _, err2 := pG.DB.QueryOne(
  23 + pg.Scan(),
  24 + "INSERT INTO employees (id, company_id, uid, employee_name, employee_account, su_money) VALUES (?, ?, ?, ?, ?, ?)",
  25 + 2, 101, 2499036607974745099, "testEmployeeName", "testEmployeeAccount", 0)
  26 + Expect(err2).NotTo(HaveOccurred())
  27 + _, err3 := pG.DB.QueryOne(
  28 + pg.Scan(&activityId),
  29 + "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",
  30 + 101, "测试活动", "2021-02-08 15:59:59+00:00:00", 0, 0, 0, 5.1, time.Now())
  31 + Expect(err3).NotTo(HaveOccurred())
  32 + })
  33 + Describe("提交数据创建素币兑换清单", func() {
  34 + Context("提交正确的新建素币兑换清单数据", func() {
  35 + It("返回素币兑换清单数据", func() {
  36 + httpExpect := httpexpect.New(GinkgoT(), server.URL)
  37 + body := map[string]interface{} {
  38 + "uid": 2499036607974745088,
  39 + "exchangeCashActivityId": activityId,
  40 + "exchangedSuMoney": 1.13,
  41 + "operator": 2499036607974745099,
  42 + }
  43 + httpExpect.POST("/cash-pool/activity/exchange-list").
  44 + WithJSON(body).
  45 + Expect().
  46 + Status(http.StatusOK).
  47 + JSON().
  48 + Object().
  49 + ContainsKey("code").ValueEqual("code", 0).
  50 + ContainsKey("msg").ValueEqual("msg", "ok").
  51 + ContainsKey("data").Value("data").Object()
  52 + })
  53 + })
  54 + })
  55 + AfterEach(func() {
  56 + _, err := pG.DB.Exec("DELETE FROM exchange_cash_person_lists WHERE true")
  57 + Expect(err).NotTo(HaveOccurred())
  58 + })
  59 +})
  1 +/**
  2 + @author: stevechan
  3 + @date: 2021/2/25
  4 + @note:
  5 +**/
  6 +
  7 +package exchange_list
  8 +
  9 +import (
  10 + "net/http"
  11 + "strconv"
  12 + "time"
  13 +
  14 + "github.com/gavv/httpexpect"
  15 + "github.com/go-pg/pg"
  16 + . "github.com/onsi/ginkgo"
  17 + . "github.com/onsi/gomega"
  18 + pG "gitlab.fjmaimaimai.com/linmadan/mmm-worth/pkg/infrastructure/pg"
  19 +)
  20 +
  21 +var _ = Describe("获取素币兑换人员清单", func() {
  22 + var (
  23 + listId int64
  24 + )
  25 + BeforeEach(func() {
  26 + var (
  27 + activityId int64
  28 + )
  29 + _, err1 := pG.DB.QueryOne(
  30 + pg.Scan(&activityId),
  31 + "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",
  32 + 101, "测试活动", "2021-02-08 15:59:59+00:00:00", 0, 0, 0, 5.1, time.Now())
  33 + Expect(err1).NotTo(HaveOccurred())
  34 + _, err2 := pG.DB.QueryOne(
  35 + pg.Scan(&listId),
  36 + "INSERT INTO exchange_cash_person_lists (activity_id, uid, employee_name, employee_account, exchanged_su_money, exchanged_cash) VALUES (100, 3242227175192320, '卞信华3', '18900000000', 1.13, 5.76,3) RETURNING id, activity_id, uid, employee_name, employee_acco, exchanged_su_money, exchanged_cash",
  37 + activityId, 3242227175192320, "卞信华3", "18900000000", 1.13, 5.76, 3)
  38 + Expect(err2).NotTo(HaveOccurred())
  39 + })
  40 + Describe("根据listId返回素币兑换清单", func() {
  41 + Context("传入有效的listId", func() {
  42 + It("返回素币兑换清单", func() {
  43 + listIdStr := strconv.FormatInt(listId, 10)
  44 + httpExpect := httpexpect.New(GinkgoT(), server.URL)
  45 + httpExpect.GET("/cash-pool/activity/exchange-list/"+listIdStr).
  46 + Expect().
  47 + Status(http.StatusOK).
  48 + JSON().
  49 + Object().
  50 + ContainsKey("code").ValueEqual("code", 0).
  51 + ContainsKey("msg").ValueEqual("msg", "ok").
  52 + ContainsKey("data").Value("data").Object()
  53 + })
  54 + })
  55 + })
  56 + AfterEach(func() {
  57 + _, err := pG.DB.Exec("DELETE FROM exchange_cash_person_lists WHERE true")
  58 + Expect(err).NotTo(HaveOccurred())
  59 + })
  60 +})
  1 +package exchange_list
  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 + listId int64
  17 + )
  18 + BeforeEach(func() {
  19 + var (
  20 + activityId int64
  21 + )
  22 + _, err1 := pG.DB.QueryOne(
  23 + pg.Scan(&activityId),
  24 + "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",
  25 + 101, "测试活动", "2021-02-08 15:59:59+00:00:00", 0, 0, 0, 5.1, time.Now())
  26 + Expect(err1).NotTo(HaveOccurred())
  27 + _, err2 := pG.DB.QueryOne(
  28 + pg.Scan(&listId),
  29 + "INSERT INTO exchange_cash_person_lists (activity_id, uid, employee_name, employee_account, exchanged_su_money, exchanged_cash) VALUES (100, 3242227175192320, '卞信华3', '18900000000', 1.13, 5.76,3) RETURNING id, activity_id, uid, employee_name, employee_acco, exchanged_su_money, exchanged_cash",
  30 + activityId, 3242227175192320, "卞信华3", "18900000000", 1.13, 5.76, 3)
  31 + Expect(err2).NotTo(HaveOccurred())
  32 + })
  33 + Describe("返回素币兑换清单列表", func() {
  34 + Context("传入有效的参数", func() {
  35 + It("返回素币兑换清单列表", func() {
  36 + httpExpect := httpexpect.New(GinkgoT(), server.URL)
  37 + httpExpect.GET("/cash-pool/activity/exchange-list").
  38 + WithQuery("companyId", 101).
  39 + WithQuery("offset", 0).
  40 + WithQuery("limit", 1).
  41 + Expect().
  42 + Status(http.StatusOK).
  43 + JSON().
  44 + Object().
  45 + ContainsKey("code").ValueEqual("code", 0).
  46 + ContainsKey("msg").ValueEqual("msg", "ok").
  47 + ContainsKey("data").Value("data").Object().
  48 + ContainsKey("count").ValueEqual("count", 1).
  49 + ContainsKey("people").Value("people").Array()
  50 + })
  51 + })
  52 + })
  53 + AfterEach(func() {
  54 + _, err := pG.DB.Exec("DELETE FROM exchange_cash_person_lists WHERE true")
  55 + Expect(err).NotTo(HaveOccurred())
  56 + })
  57 +})
1 package exchange_list 1 package exchange_list
  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 + listId int64
  18 + )
  19 + BeforeEach(func() {
  20 + var (
  21 + activityId int64
  22 + )
  23 + _, err1 := 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 + 101, "测试活动", "2021-02-08 15:59:59+00:00:00", 0, 0, 0, 5.1, time.Now())
  27 + Expect(err1).NotTo(HaveOccurred())
  28 + _, err2 := pG.DB.QueryOne(
  29 + pg.Scan(&listId),
  30 + "INSERT INTO exchange_cash_person_lists (activity_id, uid, employee_name, employee_account, exchanged_su_money, exchanged_cash) VALUES (100, 3242227175192320, '卞信华3', '18900000000', 1.13, 5.76,3) RETURNING id, activity_id, uid, employee_name, employee_acco, exchanged_su_money, exchanged_cash",
  31 + activityId, 3242227175192320, "卞信华3", "18900000000", 1.13, 5.76, 3)
  32 + Expect(err2).NotTo(HaveOccurred())
  33 + })
  34 + Describe("根据listId删除素币兑换清单", func() {
  35 + Context("传入有效的listId", func() {
  36 + It("返回已删除的素币兑换清单", func() {
  37 + listIdStr := strconv.FormatInt(listId, 10)
  38 + httpExpect := httpexpect.New(GinkgoT(), server.URL)
  39 + httpExpect.DELETE("/cash-pool/activity/exchange-list/"+listIdStr).
  40 + WithQuery("operator", 3242227175192320).
  41 + Expect().
  42 + Status(http.StatusOK).
  43 + JSON().
  44 + Object().
  45 + ContainsKey("code").ValueEqual("code", 0).
  46 + ContainsKey("msg").ValueEqual("msg", "ok").
  47 + ContainsKey("data").Value("data").Object()
  48 + })
  49 + })
  50 + })
  51 + AfterEach(func() {
  52 + _, err := pG.DB.Exec("DELETE FROM exchange_cash_person_lists WHERE true")
  53 + Expect(err).NotTo(HaveOccurred())
  54 + })
  55 +})
1 package exchange_list 1 package exchange_list
  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 + listId int64
  18 + )
  19 + BeforeEach(func() {
  20 + var (
  21 + activityId int64
  22 + )
  23 + _, err1 := 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 + 101, "测试活动", "2021-02-08 15:59:59+00:00:00", 0, 0, 0, 5.1, time.Now())
  27 + Expect(err1).NotTo(HaveOccurred())
  28 + _, err2 := pG.DB.QueryOne(
  29 + pg.Scan(&listId),
  30 + "INSERT INTO exchange_cash_person_lists (activity_id, uid, employee_name, employee_account, exchanged_su_money, exchanged_cash) VALUES (100, 3242227175192320, '卞信华3', '18900000000', 1.13, 5.76,3) RETURNING id, activity_id, uid, employee_name, employee_acco, exchanged_su_money, exchanged_cash",
  31 + activityId, 3242227175192320, "卞信华3", "18900000000", 1.13, 5.76, 3)
  32 + Expect(err2).NotTo(HaveOccurred())
  33 + })
  34 + Describe("根据listId更新素币兑换清单", func() {
  35 + Context("传入有效的listId", func() {
  36 + It("返回已更新的素币兑换清单", func() {
  37 + listIdStr := strconv.FormatInt(listId, 10)
  38 + httpExpect := httpexpect.New(GinkgoT(), server.URL)
  39 + body := map[string]interface{}{
  40 + "exchangedSuMoney": 13,
  41 + "operator": 3242227175192320,
  42 + }
  43 + httpExpect.PUT("/cash-pool/activity/exchange-list/"+listIdStr).
  44 + WithJSON(body).
  45 + Expect().
  46 + Status(http.StatusOK).
  47 + JSON().
  48 + Object().
  49 + ContainsKey("code").ValueEqual("code", 0).
  50 + ContainsKey("msg").ValueEqual("msg", "ok").
  51 + ContainsKey("data").Value("data").Object().
  52 + ContainsKey("listId").ValueEqual("listId", listId)
  53 + })
  54 + })
  55 + })
  56 + AfterEach(func() {
  57 + _, err := pG.DB.Exec("DELETE FROM exchange_cash_person_lists WHERE true")
  58 + Expect(err).NotTo(HaveOccurred())
  59 + })
  60 +})