作者 陈志颖

test:添加素币兑换活动集成测试

... ... @@ -12,16 +12,20 @@ import (
)
var _ = Describe("投入现金", func() {
var (
cashPoolId int64
cash float64
)
BeforeEach(func() {
_, err := pG.DB.QueryOne(
pg.Scan(),
"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",
pg.Scan( &cashPoolId, &cash),
"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",
100, 312, 100, 10001, 0, 0, 0, 0, time.Now)
Expect(err).NotTo(HaveOccurred())
})
Describe("投入现金", func() {
Context("投入现金需要大于已兑换的现金)", func() {
It("返回现金池数据", func() {
Describe("投入现金到现金池", func() {
Context("投入错误的金额", func() {
It("返回现金池错误数据", func() {
httpExpect := httpexpect.New(GinkgoT(), server.URL)
body := map[string]interface{}{
"cash": 99,
... ... @@ -33,8 +37,28 @@ var _ = Describe("投入现金", func() {
Status(http.StatusOK).
JSON().
Object().
ContainsKey("code").ValueNotEqual("code", 0).
ContainsKey("msg").ValueNotEqual("msg", "ok").
ContainsKey("code").ValueEqual("code", 501).
ContainsKey("msg").ValueEqual("msg", "投入的现金值必须大于当前已兑换现金值").
NotContainsKey("data").Value("data").Object()
})
})
})
Describe("投入现金到现金池", func() {
Context("投入正确的金额", func() {
It("返回正确现金池数据", func() {
httpExpect := httpexpect.New(GinkgoT(), server.URL)
body := map[string]interface{} {
"cash": 100,
"companyId": 312,
}
httpExpect.POST("/cash-pool/input").
WithJSON(body).
Expect().
Status(http.StatusOK).
JSON().
Object().
ContainsKey("code").ValueEqual("code", 0).
ContainsKey("msg").ValueEqual("msg", "ok").
ContainsKey("data").Value("data").Object()
})
})
... ...
... ... @@ -18,10 +18,14 @@ import (
)
var _ = Describe("返回现金池数据", func() {
var (
cashPoolId int64
cash float64
)
BeforeEach(func() {
_, err := pG.DB.QueryOne(
pg.Scan(),
"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",
pg.Scan(&cashPoolId, &cash),
"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",
100, 312, 100, 10001, 0, 0, 0, 0, time.Now)
Expect(err).NotTo(HaveOccurred())
})
... ...
/**
@author: stevechan
@date: 2021/2/23
@note:
**/
package exchange_activities
import (
"net/http"
"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() {
Describe("提交数据创建素币兑换活动", func() {
Context("提交正确的新活动数据", func() {
It("返回素币兑换活动数据", func() {
httpExpect := httpexpect.New(GinkgoT(), server.URL)
body := map[string]interface{}{
"companyId": 311,
"exchangeActivityName": "测试兑换活动",
"deadline": "2021-01-07T16:00:00.000Z",
"exchangeRate": 5.1,
}
httpExpect.POST("/cash-pool/activity").
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_activities WHERE true")
Expect(err).NotTo(HaveOccurred())
})
})
\ No newline at end of file
... ...
/**
@author: stevechan
@date: 2021/2/23
@note:
**/
package exchange_activities
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 (
exchangeCashActivityId int64
)
BeforeEach(func() {
_, err := pG.DB.QueryOne(
pg.Scan(&exchangeCashActivityId),
"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())
Expect(err).NotTo(HaveOccurred())
})
Describe("根据activityId返回活动", func(){
Context("传入有效的activityId", func() {
It("返回活动数据", func() {
httpExpect := httpexpect.New(GinkgoT(), server.URL)
httpExpect.GET("/cash-pool/activity/1").
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_activities WHERE true")
Expect(err).NotTo(HaveOccurred())
})
})
\ No newline at end of file
... ...
package exchange_activities
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 (
exchangeCashActivityId int64
)
BeforeEach(func() {
_, err := pG.DB.QueryOne(
pg.Scan(&exchangeCashActivityId),
"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())
Expect(err).NotTo(HaveOccurred())
})
Describe("根据参数返回素币兑换活动列表", func() {
Context("传入有效的参数", func() {
It("返回素币兑换清单列表", func() {
httpExpect := httpexpect.New(GinkgoT(), server.URL)
httpExpect.GET("/cash-pool/activity/?companyId=311&offset=0&limit=20").
WithQuery("companyId", 311).
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)
})
})
})
AfterEach(func() {
_, err := pG.DB.Exec("DELETE FROM exchange_cash_activities WHERE true")
Expect(err).NotTo(HaveOccurred())
})
})
\ No newline at end of file
... ...
package exchange_activities
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 (
activityId int64
)
BeforeEach(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())
Expect(err).NotTo(HaveOccurred())
})
Describe("根据参数移除素币兑换活动", func() {
Context("传入有效的活动id", func() {
It("返回被删除的素币兑换活动数据", func() {
activityIdStr := strconv.FormatInt(activityId, 10)
httpExpect := httpexpect.New(GinkgoT(), server.URL)
httpExpect.DELETE("/cash-pool/activity/" + activityIdStr).
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_activities WHERE true")
Expect(err).NotTo(HaveOccurred())
})
})
\ No newline at end of file
... ...
/**
@author: stevechan
@date: 2021/2/23
@note:
**/
package exchange_activities
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 activityId int64
BeforeEach(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())
Expect(err).NotTo(HaveOccurred())
})
Describe("搜索素币兑换活动", func() {
Context("指定搜索条件", func() {
It("返回搜索结果", func() {
httpExpect := httpexpect.New(GinkgoT(), server.URL)
body := map[string]interface{} {
}
httpExpect.POST("/cash-pool/activity/search-activity").
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_activities WHERE true")
Expect(err).NotTo(HaveOccurred())
})
})
\ No newline at end of file
... ...
package exchange_activities
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 activityId int64
BeforeEach(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())
Expect(err).NotTo(HaveOccurred())
})
Describe("提交数据更新素币兑换活动", func() {
Context("提交正确的素币兑换活动数据", func() {
It("返回更新后的素币兑换活动数据", func() {
httpExpect := httpexpect.New(GinkgoT(), server.URL)
body := map[string]interface{} {
}
httpExpect.PUT("/cash-pool/activity/").
WithJSON(body).
Expect().
Status(http.StatusOK).
JSON().
Object().
ContainsKey("code").ValueEqual("code", 0).
ContainsKey("msg").ValueEqual("msg", "ok").
ContainsKey("data").Value("data").Object().
ContainsKey("id").ValueEqual("id", activityId)
})
})
})
AfterEach(func() {
_, err := pG.DB.Exec("DELETE FROM exchange_cash_activities WHERE true")
Expect(err).NotTo(HaveOccurred())
})
})
... ...