create_task_test.go
7.1 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
package task
import (
"github.com/go-pg/pg"
"gitlab.fjmaimaimai.com/linmadan/mmm-worth/pkg/domain"
"net/http"
"time"
"github.com/gavv/httpexpect"
. "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 employees (id, uid, employee_name, employee_account, su_money) VALUES (?, ?, ?, ?, ?)",
1, 2499036607974745088, "testEmployeeName", "testEmployeeAccount", 0)
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,
}, 2, &domain.ReferenceResource{
ReferenceResourceType: 1,
ReferenceResourceItems: []*domain.ReferenceResourceItem{
{
ReferenceResourceId: 4,
},
},
}, 1, pg.Array([]int{1, 2}), 1, 1000.00, "验收标准1", "任务描述1", pg.Array([]string{}), false, "null", "null", "", pg.Array([]string{}), time.Now(), time.Now())
Expect(err1).NotTo(HaveOccurred())
})
Describe("提交数据创建新任务", func() {
Context("提交正确的抢单类型任务数据", func() {
It("返回抢单类型任务数据", func() {
httpExpect := httpexpect.New(GinkgoT(), server.URL)
body := map[string]interface{}{
"companyId": 101,
"taskName": "抢单任务",
"taskType": 1,
"sponsor": 2499036607974745088,
"referenceResourceType": 1,
"referenceResourceItems": []map[string]interface{}{
{"referenceResourceId": 1, "serialNumber": 1, "title": "问题标题1"},
{"referenceResourceId": 2, "serialNumber": 2, "title": "问题标题2"},
{"referenceResourceId": 3, "serialNumber": 3, "title": "问题标题3"},
},
"projectBelong": 1,
"customerValues": []int{
1,
2,
3,
},
"taskNature": 1,
"suMoney": 1000.00,
"acceptanceStandard": "验收标准",
"taskDescription": "任务描述",
"taskPictureUrls": []string{
"url-1",
"url-2",
"url-3",
},
"isRewardTake": false,
}
httpExpect.POST("/tasks/").
WithJSON(body).
Expect().
Status(http.StatusOK).
JSON().
Object().
ContainsKey("code").ValueEqual("code", 0).
ContainsKey("msg").ValueEqual("msg", "ok").
ContainsKey("data").Value("data").Object().
ContainsKey("taskId").ValueNotEqual("taskId", BeZero())
})
})
Context("提交正确的竞标类型任务数据", func() {
It("返回竞标类型任务数据", func() {
httpExpect := httpexpect.New(GinkgoT(), server.URL)
dayAfter, _ := time.ParseDuration("72h")
body := map[string]interface{}{
"companyId": 101,
"taskName": "竞标任务",
"taskType": 2,
"sponsor": 2499036607974745088,
"referenceResourceType": 2,
"referenceResourceItems": []map[string]interface{}{
{"serialNumber": 1, "title": "机会标题1"},
{"serialNumber": 2, "title": "机会标题2"},
{"serialNumber": 3, "title": "机会标题3"},
},
"projectBelong": 1,
"customerValues": []int{
1,
2,
3,
},
"taskNature": 1,
"suMoney": 1000.00,
"acceptanceStandard": "验收标准",
"taskDescription": "任务描述",
"taskPictureUrls": []string{
"url-1",
"url-2",
"url-3",
},
"isRewardTake": true,
"bidStartTime": time.Now(),
"bidEndTime": time.Now().Add(dayAfter),
}
httpExpect.POST("/tasks/").
WithJSON(body).
Expect().
Status(http.StatusOK).
JSON().
Object().
ContainsKey("code").ValueEqual("code", 0).
ContainsKey("msg").ValueEqual("msg", "ok").
ContainsKey("data").Value("data").Object().
ContainsKey("taskId").ValueNotEqual("taskId", BeZero())
})
})
Context("提交正确的指派类型任务数据", func() {
It("返回指派类型任务数据", func() {
httpExpect := httpexpect.New(GinkgoT(), server.URL)
body := map[string]interface{}{
"companyId": 101,
"taskName": "竞标任务",
"taskType": 2,
"sponsor": 2499036607974745088,
"referenceResourceType": 2,
"referenceResourceItems": []map[string]interface{}{
{"serialNumber": 1, "title": "机会标题1"},
{"serialNumber": 2, "title": "机会标题2"},
{"serialNumber": 3, "title": "机会标题3"},
},
"projectBelong": 1,
"customerValues": []int{
1,
2,
3,
},
"taskNature": 1,
"suMoney": 1000.00,
"acceptanceStandard": "验收标准",
"taskDescription": "任务描述",
"taskPictureUrls": []string{
"url-1",
"url-2",
"url-3",
},
"assignedPerson": 2499036607974745088,
"plannedCompletionTime": time.Now(),
}
httpExpect.POST("/tasks/").
WithJSON(body).
Expect().
Status(http.StatusOK).
JSON().
Object().
ContainsKey("code").ValueEqual("code", 0).
ContainsKey("msg").ValueEqual("msg", "ok").
ContainsKey("data").Value("data").Object().
ContainsKey("taskId").ValueNotEqual("taskId", BeZero())
})
})
Context("提交已经被引用的问题ID任务数据", func() {
It("创建失败", func() {
httpExpect := httpexpect.New(GinkgoT(), server.URL)
body := map[string]interface{}{
"companyId": 101,
"taskName": "抢单任务",
"taskType": 1,
"sponsor": 2499036607974745088,
"referenceResourceType": 1,
"referenceResourceItems": []map[string]interface{}{
{"referenceResourceId": 4, "serialNumber": 4, "title": "问题标题4"},
},
"projectBelong": 1,
"customerValues": []int{
1,
2,
3,
},
"taskNature": 1,
"suMoney": 1000.00,
"acceptanceStandard": "验收标准",
"taskDescription": "任务描述",
"taskPictureUrls": []string{
"url-1",
"url-2",
"url-3",
},
"isRewardTake": false,
}
httpExpect.POST("/tasks/").
WithJSON(body).
Expect().
Status(http.StatusOK).
JSON().
Object().
ContainsKey("code").ValueEqual("code", 501).
ContainsKey("msg").ValueEqual("msg", "内部服务出错:问题资源已经被引用,创建任务失败")
})
})
})
AfterEach(func() {
_, err := pG.DB.Exec("DELETE FROM tasks WHERE true")
Expect(err).NotTo(HaveOccurred())
_, err1 := pG.DB.Exec("DELETE FROM employees WHERE true")
Expect(err1).NotTo(HaveOccurred())
})
})