person_su_money_statistics_test.go 1.9 KB
package statistics

import (
	"gitlab.fjmaimaimai.com/linmadan/mmm-worth/pkg/domain"
	"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 suMoneyTransactionRecordId int64
	BeforeEach(func() {
		_, err := pG.DB.QueryOne(
			pg.Scan(&suMoneyTransactionRecordId),
			"INSERT INTO su_money_transaction_records (id, record_type, employee, su_money, operator, record_description, create_time) VALUES (?, ?, ?, ?, ?, ?, ?) RETURNING id",
			1, 2, &domain.EmployeeInfo{
				Uid: 2499036607974745088,
			}, 1000.00, &domain.EmployeeInfo{
				Uid: 2499036607974745099,
			}, "testRecordDescription", time.Now().AddDate(0, 0, -1))
		Expect(err).NotTo(HaveOccurred())
		_, err2 := pG.DB.QueryOne(
			pg.Scan(),
			"INSERT INTO employees (id, company_id, uid, employee_name, employee_account, su_money) VALUES (?, ?, ?, ?, ?, ?)",
			2, 101, 2499036607974745088, "testEmployeeName", "testEmployeeAccount", 1000)
		Expect(err2).NotTo(HaveOccurred())
	})
	Describe("获取个人素币统计", func() {
		Context("请求获取个人素币统计", func() {
			It("返回个人素币统计", func() {
				httpExpect := httpexpect.New(GinkgoT(), server.URL)
				body := map[string]interface{}{
					"uid": 2499036607974745088,
				}
				httpExpect.POST("/statistics/person-su-money").
					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 su_money_transaction_records WHERE true")
		Expect(err).NotTo(HaveOccurred())
		_, err1 := pG.DB.Exec("DELETE FROM employees WHERE true")
		Expect(err1).NotTo(HaveOccurred())
	})
})