remove_customer_value_test.go 1.2 KB
package customer_value

import (
	"fmt"
	"net/http"
	"strconv"

	"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 customerValueId int64
	BeforeEach(func() {
		_, err := pG.DB.QueryOne(
			pg.Scan(&customerValueId),
			"INSERT INTO customer_values (customer_value_name, company_id) VALUES (?, ?) RETURNING id",
			"口味", 101)
		Expect(err).NotTo(HaveOccurred())
	})
	Describe("根据参数移除客户价值", func() {
		Context("传入有效的customerValueId", func() {
			It("返回被移除客户价值的数据", func() {
				httpExpect := httpexpect.New(GinkgoT(), server.URL)
				httpExpect.DELETE(fmt.Sprintf("/customer-values/%s", strconv.FormatInt(customerValueId, 10))).
					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 customer_values WHERE true")
		Expect(err).NotTo(HaveOccurred())
	})
})