Skip to content

Commit d556035

Browse files
committed
feat: #33 update issue
1 parent 44f8292 commit d556035

File tree

4 files changed

+192
-1
lines changed

4 files changed

+192
-1
lines changed

src/Issue.php

Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -81,4 +81,44 @@ public function get(array $data)
8181
$response = $this->core->request('DescribeIssue', $data);
8282
return $response['Issue'];
8383
}
84+
85+
public function update(array $data)
86+
{
87+
$this->validate($data, [
88+
'ProjectName' => 'string|required',
89+
'IssueCode' => 'integer',
90+
'ParentCode' => 'nullable|integer',
91+
'Name' => 'nullable|string',
92+
'StatusId' => 'nullable|integer',
93+
'AssigneeId' => 'nullable|integer',
94+
'DueDate' => 'nullable|date_format:Y-m-d|after:StartDate',
95+
'StartDate' => 'nullable|date_format:Y-m-d',
96+
'WorkingHours' => 'nullable|numeric',
97+
// 项目模块 ID
98+
'ProjectModuleId' => 'nullable|integer',
99+
// 事项关注人 ID 列表
100+
'WatcherIds' => 'nullable|array',
101+
'WatcherIds.*' => 'integer',
102+
// 删除的事项关注人 Id 列表
103+
'DelWatcherIds' => 'nullable|array',
104+
// 项目缺陷类型 ID
105+
'DefectTypeId' => 'nullable|integer',
106+
// 项目需求类型 ID
107+
'RequirementTypeId' => 'nullable|integer',
108+
'Priority' => [
109+
'string',
110+
'nullable',
111+
Rule::in(array_values(self::PRIORITY)),
112+
],
113+
'StoryPoint' => 'nullable|string',
114+
'LabelIds' => 'nullable|array',
115+
'DelLabelIds' => 'nullable|array',
116+
'FileIds' => 'nullable|array',
117+
'DelFileIds' => 'nullable|array',
118+
// 自定义属性值列表 Array of IssueCustomFieldForm
119+
'CustomFieldValues' => 'nullable|array',
120+
]);
121+
$response = $this->core->request('ModifyIssue', $data);
122+
return $response['Issue'];
123+
}
84124
}

tests/Acceptance/IssueTest.php

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77

88
class IssueTest extends TestCase
99
{
10-
public function testCreateAndDelete()
10+
public function testCrud()
1111
{
1212
$data = [
1313
'ProjectName' => $this->projectName,
@@ -26,6 +26,12 @@ public function testCreateAndDelete()
2626
];
2727
$result = $issue->get($params);
2828
$this->assertEquals($data['Name'], $result['Name']);
29+
$this->assertEmpty($result['StoryPoint']);
30+
31+
$params['StoryPoint'] = '1.0';
32+
$result = $issue->update($params);
33+
$this->assertEquals('1.0', $result['StoryPoint']);
34+
2935
$this->assertTrue($issue->delete($params));
3036
}
3137
}

tests/Unit/IssueTest.php

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -129,4 +129,25 @@ public function testGet()
129129
$result = $issue->get($data);
130130
$this->assertEquals($response['Issue'], $result);
131131
}
132+
133+
public function testUpdate()
134+
{
135+
$response = json_decode(
136+
file_get_contents($this->dataPath('ModifyIssueResponse.json')),
137+
true
138+
)['Response'];
139+
$data = [
140+
'ProjectName' => $this->projectName,
141+
'IssueCode' => $this->faker->randomNumber(),
142+
'StoryPoint' => "1.0",
143+
];
144+
$this->coreMock->shouldReceive('request')->times(1)->withArgs([
145+
'ModifyIssue',
146+
$data
147+
])->andReturn($response);
148+
149+
$issue = new Issue($this->token, $this->coreMock);
150+
$result = $issue->update($data);
151+
$this->assertEquals($response['Issue'], $result);
152+
}
132153
}

tests/data/ModifyIssueResponse.json

Lines changed: 124 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,124 @@
1+
{
2+
"Response" : {
3+
"Issue" : {
4+
"Assignee" : {
5+
"Avatar" : "https://coding-net-production-static-ci.codehub.cn/2cb665a3-bebc-4b09-aa00-2b6df3e33edc.jpg?imageMogr2/auto-orient/format/jpeg/cut/400x400x0x0",
6+
"Email" : "",
7+
"GlobalKey" : "",
8+
"Id" : 183478,
9+
"Name" : "sinkcup",
10+
"Phone" : "",
11+
"Status" : 1,
12+
"TeamGlobalKey" : "",
13+
"TeamId" : 0
14+
},
15+
"Code" : 1,
16+
"CompletedAt" : 0,
17+
"CreatedAt" : 1639820653000,
18+
"Creator" : {
19+
"Avatar" : "https://coding-net-production-static-ci.codehub.cn/2cb665a3-bebc-4b09-aa00-2b6df3e33edc.jpg?imageMogr2/auto-orient/format/jpeg/cut/400x400x0x0",
20+
"Email" : "",
21+
"GlobalKey" : "",
22+
"Id" : 183478,
23+
"Name" : "sinkcup",
24+
"Phone" : "",
25+
"Status" : 1,
26+
"TeamGlobalKey" : "",
27+
"TeamId" : 0
28+
},
29+
"CustomFields" : [],
30+
"DefectType" : {
31+
"IconUrl" : "",
32+
"Id" : 0,
33+
"Name" : ""
34+
},
35+
"Description" : "",
36+
"DueDate" : 0,
37+
"Epic" : {
38+
"Assignee" : {
39+
"Avatar" : "",
40+
"Email" : "",
41+
"GlobalKey" : "",
42+
"Id" : 0,
43+
"Name" : "",
44+
"Phone" : "",
45+
"Status" : 0,
46+
"TeamGlobalKey" : "",
47+
"TeamId" : 0
48+
},
49+
"Code" : 0,
50+
"IssueStatusId" : 0,
51+
"IssueStatusName" : "",
52+
"Name" : "",
53+
"Priority" : "",
54+
"Type" : ""
55+
},
56+
"Files" : [],
57+
"IssueStatusId" : 1227034,
58+
"IssueStatusName" : "未开始",
59+
"IssueStatusType" : "TODO",
60+
"IssueTypeDetail" : {
61+
"Description" : "任务是指为实现某个目标或需求所进行的具体活动。",
62+
"Id" : 213220,
63+
"IsSystem" : true,
64+
"IssueType" : "MISSION",
65+
"Name" : "任务"
66+
},
67+
"IssueTypeId" : 213220,
68+
"Iteration" : {
69+
"Code" : 0,
70+
"Name" : "",
71+
"Status" : ""
72+
},
73+
"IterationId" : 0,
74+
"Labels" : [],
75+
"Name" : "foo",
76+
"Parent" : {
77+
"Assignee" : {
78+
"Avatar" : "",
79+
"Email" : "",
80+
"GlobalKey" : "",
81+
"Id" : 0,
82+
"Name" : "",
83+
"Phone" : "",
84+
"Status" : 0,
85+
"TeamGlobalKey" : "",
86+
"TeamId" : 0
87+
},
88+
"Code" : 0,
89+
"IssueStatusId" : 0,
90+
"IssueStatusName" : "",
91+
"IssueStatusType" : "",
92+
"IssueTypeDetail" : {
93+
"Description" : "",
94+
"Id" : 0,
95+
"IsSystem" : false,
96+
"IssueType" : "",
97+
"Name" : ""
98+
},
99+
"Name" : "",
100+
"Priority" : "",
101+
"Type" : ""
102+
},
103+
"ParentType" : "MISSION",
104+
"Priority" : "1",
105+
"ProjectModule" : {
106+
"Id" : 0,
107+
"Name" : ""
108+
},
109+
"RequirementType" : {
110+
"Id" : 0,
111+
"Name" : ""
112+
},
113+
"StartDate" : 0,
114+
"StoryPoint" : "1.0",
115+
"SubTasks" : [],
116+
"ThirdLinks" : [],
117+
"Type" : "MISSION",
118+
"UpdatedAt" : 1640673221097,
119+
"Watchers" : [],
120+
"WorkingHours" : 0
121+
},
122+
"RequestId" : "4a86eaae-e867-1520-f7c2-7d3051f86d48"
123+
}
124+
}

0 commit comments

Comments
 (0)