作者 陈志颖

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

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