update_customer_value_test.go 1.5 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("提交正确的客户价值数据", func() {
			It("返回更新后的客户价值数据", func() {
				httpExpect := httpexpect.New(GinkgoT(), server.URL)
				body := map[string]interface{}{
					"customerValueName": "口味",
				}
				httpExpect.PUT(fmt.Sprintf("/customer-values/%s", strconv.FormatInt(customerValueId, 10))).
					WithJSON(body).
					Expect().
					Status(http.StatusOK).
					JSON().
					Object().
					ContainsKey("code").ValueEqual("code", 0).
					ContainsKey("msg").ValueEqual("msg", "ok").
					ContainsKey("data").Value("data").Object().
					ContainsKey("customerValueId").ValueEqual("customerValueId", customerValueId).
					ContainsKey("customerValueName").ValueEqual("customerValueName", "口味")
			})
		})
	})
	AfterEach(func() {
		_, err := pG.DB.Exec("DELETE FROM customer_values WHERE true")
		Expect(err).NotTo(HaveOccurred())
	})
})