remove_task_test.go 1.4 KB
package task

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() {
		_, err := pG.DB.QueryOne(
			pg.Scan(),
			"INSERT INTO tasks (id, company_id, task_name, task_type, sponsor, task_status, reference_resource, customer_value, task_nature, su_money, acceptance_standard, task_description, task_picture_urls, is_reward_take) VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)",
			1, 101, "testTaskName", 1, "{}", 3, "null", pg.Array([]string{"口感"}), "testTaskNature", 100.00, "testAcceptanceStandard", "testTaskDescription", pg.Array([]string{"url"}), false)
		Expect(err).NotTo(HaveOccurred())
	})
	Describe("根据参数移除任务", func() {
		Context("传入有效的taskId", func() {
			It("返回被移除任务的数据", func() {
				httpExpect := httpexpect.New(GinkgoT(), server.URL)
				httpExpect.DELETE("/tasks/1").
					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 tasks WHERE true")
		Expect(err).NotTo(HaveOccurred())
	})
})