cash_input_test.go
2.1 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
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() {
var (
cashPoolId int64
cash float64
)
BeforeEach(func() {
_, err := pG.DB.QueryOne(
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() {
httpExpect := httpexpect.New(GinkgoT(), server.URL)
body := map[string]interface{}{
"cash": 99,
"companyId": 312,
}
httpExpect.POST("/cash-pool/input").
WithJSON(body).
Expect().
Status(http.StatusOK).
JSON().
Object().
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()
})
})
})
AfterEach(func() {
_, err := pG.DB.Exec("DELETE FROM ")
Expect(err).NotTo(HaveOccurred())
})
})