operation_su_money_test.go 1.8 KB
package su_money

import (
	"net/http"

	"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() {
	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())
	})
	Describe("操作素币", func() {
		Context("操作人提交正确的数据操作素币", func() {
			It("操作成功", func() {
				httpExpect := httpexpect.New(GinkgoT(), server.URL)
				body := map[string]interface{}{
					"uid":                  2499036607974745088,
					"operationType":        1,
					"suMoney":              50,
					"operator":             2499036607974745099,
					"operationDescription": "操作说明",
				}
				httpExpect.POST("/su-money/operation").
					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 employees WHERE true")
		Expect(err).NotTo(HaveOccurred())
		_, err1 := pG.DB.Exec("DELETE FROM su_money_transaction_records WHERE true")
		Expect(err1).NotTo(HaveOccurred())
	})
})