list_task_test.go 12.6 KB
package task

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 projectBelongId int
	var taskNatureId int
	var customerValueId1 int
	var customerValueId2 int
	var customerValueId3 int
	BeforeEach(func() {
		_, err8 := pG.DB.QueryOne(
			pg.Scan(&projectBelongId),
			"INSERT INTO project_belongs (project_belong_name, company_id) VALUES (?, ?) RETURNING id",
			"能力展示", 101)
		Expect(err8).NotTo(HaveOccurred())
		_, err9 := pG.DB.QueryOne(
			pg.Scan(&customerValueId1),
			"INSERT INTO customer_values (customer_value_name, company_id) VALUES (?, ?) RETURNING id",
			"口味", 101)
		Expect(err9).NotTo(HaveOccurred())
		_, err10 := pG.DB.QueryOne(
			pg.Scan(&customerValueId2),
			"INSERT INTO customer_values (customer_value_name, company_id) VALUES (?, ?) RETURNING id",
			"口感", 101)
		Expect(err10).NotTo(HaveOccurred())
		_, err11 := pG.DB.QueryOne(
			pg.Scan(&customerValueId3),
			"INSERT INTO customer_values (customer_value_name, company_id) VALUES (?, ?) RETURNING id",
			"性价比", 101)
		Expect(err11).NotTo(HaveOccurred())
		_, err12 := pG.DB.QueryOne(
			pg.Scan(&taskNatureId),
			"INSERT INTO task_natures (task_nature_name, company_id) VALUES (?, ?) RETURNING id",
			"点", 101)
		Expect(err12).NotTo(HaveOccurred())
		dayAfter, _ := time.ParseDuration("72h")
		_, err := pG.DB.QueryOne(
			pg.Scan(),
			"INSERT INTO tasks (id, company_id, task_name, task_type, sponsor, task_status, reference_resource, project_belong, customer_values, task_nature, su_money, acceptance_standard, task_description, task_picture_urls, is_reward_take, participators, task_percentage, solve_report, solve_picture_urls, receiver_uid, create_time, release_time) VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)",
			1, 101, "抢单任务1", 1, &domain.EmployeeInfo{
				Uid: 2499036607974745088,
			}, 1, "null", projectBelongId, pg.Array([]int{customerValueId1, customerValueId2, customerValueId3}), taskNatureId, 1000.00, "验收标准1", "任务描述1", pg.Array([]string{}), true, []*domain.EmployeeInfo{
				{
					Uid: 2499036607974745077,
				},
				{
					Uid: 2499036607974745066,
				},
			}, "null", "", pg.Array([]string{}), 2499036607974745099, time.Now(), time.Now().Add(dayAfter))
		Expect(err).NotTo(HaveOccurred())
		_, err1 := pG.DB.QueryOne(
			pg.Scan(),
			"INSERT INTO tasks (id, company_id, task_name, task_type, sponsor, task_status, reference_resource, project_belong, customer_values, task_nature, su_money, acceptance_standard, task_description, task_picture_urls, is_reward_take, participators, task_percentage, solve_report, solve_picture_urls, create_time, release_time) VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)",
			2, 101, "抢单任务2", 1, &domain.EmployeeInfo{
				Uid: 2499036607974745088,
			}, 1, "null", projectBelongId, pg.Array([]int{customerValueId1, customerValueId2}), taskNatureId, 1000.00, "验收标准1", "任务描述1", pg.Array([]string{}), false, "null", "null", "", pg.Array([]string{}), time.Now(), time.Now().Add(dayAfter))
		_, err2 := pG.DB.QueryOne(
			pg.Scan(),
			"INSERT INTO tasks (id, company_id, task_name, task_type, sponsor, task_status, reference_resource, project_belong, customer_values, task_nature, su_money, acceptance_standard, task_description, task_picture_urls, is_reward_take, participators, task_percentage, solve_report, solve_picture_urls, create_time, release_time) VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)",
			3, 102, "竞标任务1", 2, &domain.EmployeeInfo{
				Uid: 2499036607974745088,
			}, 1, "null", projectBelongId, pg.Array([]int{customerValueId1, customerValueId2}), taskNatureId, 1000.00, "验收标准1", "任务描述1", pg.Array([]string{}), true, "null", "null", "", pg.Array([]string{}), time.Now(), time.Now().Add(dayAfter))
		Expect(err2).NotTo(HaveOccurred())
		_, err3 := pG.DB.QueryOne(
			pg.Scan(),
			"INSERT INTO tasks (id, company_id, task_name, task_type, sponsor, task_status, reference_resource, project_belong, customer_values, task_nature, su_money, acceptance_standard, task_description, task_picture_urls, is_reward_take, participators, task_percentage, solve_report, solve_picture_urls, create_time, release_time) VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)",
			4, 101, "竞标任务1", 2, &domain.EmployeeInfo{
				Uid: 2499036607974745099,
			}, 1, "null", projectBelongId, pg.Array([]int{customerValueId1, customerValueId2}), taskNatureId, 1000.00, "验收标准1", "任务描述1", pg.Array([]string{}), false, "null", "null", "", pg.Array([]string{}), time.Now(), time.Now().Add(dayAfter))
		Expect(err3).NotTo(HaveOccurred())
		_, err4 := pG.DB.QueryOne(
			pg.Scan(),
			"INSERT INTO tasks (id, company_id, task_name, task_type, sponsor, task_status, reference_resource, project_belong, customer_values, task_nature, su_money, acceptance_standard, task_description, task_picture_urls, is_reward_take, participators, task_percentage, solve_report, solve_picture_urls, receiver_uid, create_time, release_time) VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)",
			5, 303, "抢单任务1", 1, &domain.EmployeeInfo{
				Uid: 2499036607974745088,
			}, 6, "null", projectBelongId, pg.Array([]int{customerValueId1, customerValueId2, customerValueId3}), taskNatureId, 1000.00, "验收标准1", "任务描述1", pg.Array([]string{}), true, []*domain.EmployeeInfo{
				{
					Uid: 2499036607974745077,
				},
				{
					Uid: 2499036607974745066,
				},
			}, "null", "", pg.Array([]string{}), 2499036607974745099, time.Now(), time.Now().Add(dayAfter))
		Expect(err4).NotTo(HaveOccurred())
		Expect(err1).NotTo(HaveOccurred())
		_, err111 := pG.DB.QueryOne(
			pg.Scan(),
			"INSERT INTO bid_infos (id, task_id, bid_start_time, bid_end_time) VALUES (?, ?, ?, ?)",
			1, 4, time.Date(2020, time.Month(4), 5, 8, 0, 0, 0, time.Now().Location()), time.Date(2020, time.Month(4), 10, 8, 0, 0, 0, time.Now().Location()))
		Expect(err111).NotTo(HaveOccurred())
		_, err22 := pG.DB.QueryOne(
			pg.Scan(),
			"INSERT INTO bidder_infos (id, bid_info_id, task_id) VALUES (?, ?, ?)",
			1, 1, 4)
		Expect(err22).NotTo(HaveOccurred())
	})
	Describe("根据参数返回任务列表", func() {
		Context("传入有效的参数", func() {
			It("返回指定companyId公司的任务数据列表", func() {
				httpExpect := httpexpect.New(GinkgoT(), server.URL)
				httpExpect.GET("/tasks/").
					WithQuery("companyId", 101).
					WithQuery("offset", 0).
					WithQuery("limit", 20).
					Expect().
					Status(http.StatusOK).
					JSON().
					Object().
					ContainsKey("code").ValueEqual("code", 0).
					ContainsKey("msg").ValueEqual("msg", "ok").
					ContainsKey("data").Value("data").Object().
					ContainsKey("count").ValueEqual("count", 3).
					ContainsKey("tasks").Value("tasks").Array()
			})
			It("返回指定sponsor的任务数据列表", func() {
				httpExpect := httpexpect.New(GinkgoT(), server.URL)
				httpExpect.GET("/tasks/").
					WithQuery("companyId", 101).
					WithQuery("sponsor", 2499036607974745088).
					WithQuery("offset", 0).
					WithQuery("limit", 20).
					Expect().
					Status(http.StatusOK).
					JSON().
					Object().
					ContainsKey("code").ValueEqual("code", 0).
					ContainsKey("msg").ValueEqual("msg", "ok").
					ContainsKey("data").Value("data").Object().
					ContainsKey("count").ValueEqual("count", 2).
					ContainsKey("tasks").Value("tasks").Array()
			})
			It("返回指定taskType与taskContentMatch的任务数据列表", func() {
				httpExpect := httpexpect.New(GinkgoT(), server.URL)
				httpExpect.GET("/tasks/").
					WithQuery("companyId", 101).
					WithQuery("sponsor", 2499036607974745088).
					WithQuery("taskContentMatch", "抢单").
					WithQuery("taskType", 1).
					WithQuery("offset", 0).
					WithQuery("limit", 20).
					Expect().
					Status(http.StatusOK).
					JSON().
					Object().
					ContainsKey("code").ValueEqual("code", 0).
					ContainsKey("msg").ValueEqual("msg", "ok").
					ContainsKey("data").Value("data").Object().
					ContainsKey("count").ValueEqual("count", 2).
					ContainsKey("tasks").Value("tasks").Array()
			})
			It("返回指定taskType与taskContentMatch的任务数据列表", func() {
				httpExpect := httpexpect.New(GinkgoT(), server.URL)
				httpExpect.GET("/tasks/").
					WithQuery("companyId", 101).
					WithQuery("sponsor", 2499036607974745088).
					WithQuery("taskContentMatch", "任务2").
					WithQuery("taskType", 1).
					WithQuery("offset", 0).
					WithQuery("limit", 20).
					Expect().
					Status(http.StatusOK).
					JSON().
					Object().
					ContainsKey("code").ValueEqual("code", 0).
					ContainsKey("msg").ValueEqual("msg", "ok").
					ContainsKey("data").Value("data").Object().
					ContainsKey("count").ValueEqual("count", 1).
					ContainsKey("tasks").Value("tasks").Array()
			})
			It("返回公司悬赏的任务数据列表", func() {
				httpExpect := httpexpect.New(GinkgoT(), server.URL)
				httpExpect.GET("/tasks/").
					WithQuery("companyId", 101).
					WithQuery("sponsor", 2499036607974745088).
					WithQuery("isRewardTake", true).
					WithQuery("offset", 0).
					WithQuery("limit", 20).
					Expect().
					Status(http.StatusOK).
					JSON().
					Object().
					ContainsKey("code").ValueEqual("code", 0).
					ContainsKey("msg").ValueEqual("msg", "ok").
					ContainsKey("data").Value("data").Object().
					ContainsKey("count").ValueEqual("count", 1).
					ContainsKey("tasks").Value("tasks").Array()
			})
			It("返回指定竞标时间的任务数据列表", func() {
				httpExpect := httpexpect.New(GinkgoT(), server.URL)
				httpExpect.GET("/tasks/").
					WithQuery("companyId", 101).
					WithQuery("sponsor", 2499036607974745099).
					WithQuery("taskType", 2).
					WithQuery("bidTimeMatch", 1).
					WithQuery("offset", 0).
					WithQuery("limit", 20).
					Expect().
					Status(http.StatusOK).
					JSON().
					Object().
					ContainsKey("code").ValueEqual("code", 0).
					ContainsKey("msg").ValueEqual("msg", "ok").
					ContainsKey("data").Value("data").Object().
					ContainsKey("count").ValueEqual("count", 1).
					ContainsKey("tasks").Value("tasks").Array()
			})
			It("返回指定领取人的任务数据列表", func() {
				httpExpect := httpexpect.New(GinkgoT(), server.URL)
				httpExpect.GET("/tasks/").
					WithQuery("companyId", 101).
					WithQuery("receiver", 2499036607974745099).
					WithQuery("offset", 0).
					WithQuery("limit", 20).
					Expect().
					Status(http.StatusOK).
					JSON().
					Object().
					ContainsKey("code").ValueEqual("code", 0).
					ContainsKey("msg").ValueEqual("msg", "ok").
					ContainsKey("data").Value("data").Object().
					ContainsKey("count").ValueEqual("count", 1).
					ContainsKey("tasks").Value("tasks").Array()
			})
			It("返回指定参与者的任务数据列表", func() {
				httpExpect := httpexpect.New(GinkgoT(), server.URL)
				httpExpect.GET("/tasks/").
					WithQuery("companyId", 101).
					WithQuery("participator", 2499036607974745066).
					WithQuery("offset", 0).
					WithQuery("limit", 20).
					Expect().
					Status(http.StatusOK).
					JSON().
					Object().
					ContainsKey("code").ValueEqual("code", 0).
					ContainsKey("msg").ValueEqual("msg", "ok").
					ContainsKey("data").Value("data").Object().
					ContainsKey("count").ValueEqual("count", 1).
					ContainsKey("tasks").Value("tasks").Array()
			})
			It("返回过滤关闭状态的任务数据列表", func() {
				httpExpect := httpexpect.New(GinkgoT(), server.URL)
				httpExpect.GET("/tasks/").
					WithQuery("companyId", 303).
					WithQuery("isFilterCloseStatus", true).
					WithQuery("offset", 0).
					WithQuery("limit", 20).
					Expect().
					Status(http.StatusOK).
					JSON().
					Object().
					ContainsKey("code").ValueEqual("code", 0).
					ContainsKey("msg").ValueEqual("msg", "ok").
					ContainsKey("data").Value("data").Object().
					ContainsKey("count").ValueEqual("count", 0).
					ContainsKey("tasks").Value("tasks").Array()
			})
		})
	})
	AfterEach(func() {
		_, err := pG.DB.Exec("DELETE FROM tasks WHERE true")
		Expect(err).NotTo(HaveOccurred())
		_, err1 := pG.DB.Exec("DELETE FROM bid_infos WHERE true")
		Expect(err1).NotTo(HaveOccurred())
		_, err2 := pG.DB.Exec("DELETE FROM bidder_infos WHERE true")
		Expect(err2).NotTo(HaveOccurred())
		_, err3 := pG.DB.Exec("DELETE FROM project_belongs WHERE true")
		Expect(err3).NotTo(HaveOccurred())
		_, err4 := pG.DB.Exec("DELETE FROM task_natures WHERE true")
		Expect(err4).NotTo(HaveOccurred())
		_, err5 := pG.DB.Exec("DELETE FROM customer_values WHERE true")
		Expect(err5).NotTo(HaveOccurred())
	})
})