作者 陈志颖

test:增加现金池操作测试

/**
@author: stevechan
@date: 2021/2/23
@note:
**/
package service
import (
coreDomain "github.com/linmadan/egglib-go/core/domain"
)
type MutationCashPoolService interface {
coreDomain.DomainEventPublisher
Mutation() error
}
... ...
package cash_pool
import (
"github.com/go-pg/pg"
"net/http"
"time"
"github.com/gavv/httpexpect"
. "github.com/onsi/ginkgo"
... ... @@ -10,21 +12,29 @@ import (
)
var _ = Describe("投入现金", func() {
Describe("投入现金并更新现金池数据", func() {
Context("提交正确的现金值(>=已兑换的现金)", func() {
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",
100, 312, 100, 10001, 0, 0, 0, 0, time.Now)
Expect(err).NotTo(HaveOccurred())
})
Describe("投入现金", func() {
Context("投入现金需要大于已兑换的现金)", func() {
It("返回现金池数据", func() {
httpExpect := httpexpect.New(GinkgoT(), server.URL)
body := map[string]interface{}{
"cashAmount": 100,
"cash": 99,
"companyId": 312,
}
httpExpect.POST("/cash_pool/input").
httpExpect.POST("/cash-pool/input").
WithJSON(body).
Expect().
Status(http.StatusOK).
JSON().
Object().
ContainsKey("code").ValueEqual("code", 0).
ContainsKey("msg").ValueEqual("msg", "ok").
ContainsKey("code").ValueNotEqual("code", 0).
ContainsKey("msg").ValueNotEqual("msg", "ok").
ContainsKey("data").Value("data").Object()
})
})
... ...
/**
@author: stevechan
@date: 2021/2/23
@note:
**/
package cash_pool
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() {
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",
100, 312, 100, 10001, 0, 0, 0, 0, time.Now)
Expect(err).NotTo(HaveOccurred())
})
Describe("根据公司id返回现金池数据", func() {
Context("传入有效的公司id", func() {
It("返回现金池数据", func() {
httpExpect := httpexpect.New(GinkgoT(), server.URL)
httpExpect.GET("/cash-pool/cash-pool?companyId=312").
Expect().
Status(http.StatusOK).
JSON().
Object().
ContainsKey("code").ValueNotEqual("code", 0).
ContainsKey("msg").ValueNotEqual("msg", "ok").
ContainsKey("data").Value("data").Object()
})
})
})
AfterEach(func() {
_, err := pG.DB.Exec("DELETE FROM cash_pools WHERE true")
Expect(err).NotTo(HaveOccurred())
})
})
\ No newline at end of file
... ...
... ... @@ -5,3 +5,32 @@
**/
package exchange_activities
import (
"github.com/onsi/ginkgo"
"github.com/onsi/gomega"
"net/http"
"net/http/httptest"
"testing"
"github.com/astaxie/beego"
_ "gitlab.fjmaimaimai.com/linmadan/mmm-worth/pkg/infrastructure/pg"
_ "gitlab.fjmaimaimai.com/linmadan/mmm-worth/pkg/port/beego"
)
func TestConfig(t *testing.T) {
gomega.RegisterFailHandler(ginkgo.Fail)
ginkgo.RunSpecs(t, "Beego Port Exchange Activities Correlations Test Case Suite")
}
var handler http.Handler
var server *httptest.Server
var _ = ginkgo.BeforeSuite(func() {
handler = beego.BeeApp.Handlers
server = httptest.NewServer(handler)
})
var _ = ginkgo.AfterSuite(func() {
server.Close()
})
\ No newline at end of file
... ...
... ... @@ -5,3 +5,32 @@
**/
package exchange_list
import (
"github.com/onsi/ginkgo"
"github.com/onsi/gomega"
"net/http"
"net/http/httptest"
"testing"
"github.com/astaxie/beego"
_ "gitlab.fjmaimaimai.com/linmadan/mmm-worth/pkg/infrastructure/pg"
_ "gitlab.fjmaimaimai.com/linmadan/mmm-worth/pkg/port/beego"
)
func TestConfig(t *testing.T) {
gomega.RegisterFailHandler(ginkgo.Fail)
ginkgo.RunSpecs(t, "Beego Port Exchange List Correlations Test Case Suite")
}
var handler http.Handler
var server *httptest.Server
var _ = ginkgo.BeforeSuite(func() {
handler = beego.BeeApp.Handlers
server = httptest.NewServer(handler)
})
var _ = ginkgo.AfterSuite(func() {
server.Close()
})
... ...