update_exchange_activity_test.go 1.7 KB
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{} {
					"exchangeActivityName": "这是更新后的公司311的兑换活动,哈哈哈",
					"deadline": "2020-12-14T23:59:59+08:00",
					"exchangeRate": 1.2,
				}
				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())
	})
})