diff --git a/src/Issue.php b/src/Issue.php index 031fcc7..372a619 100644 --- a/src/Issue.php +++ b/src/Issue.php @@ -81,4 +81,44 @@ public function get(array $data) $response = $this->core->request('DescribeIssue', $data); return $response['Issue']; } + + public function update(array $data) + { + $this->validate($data, [ + 'ProjectName' => 'string|required', + 'IssueCode' => 'integer', + 'ParentCode' => 'nullable|integer', + 'Name' => 'nullable|string', + 'StatusId' => 'nullable|integer', + 'AssigneeId' => 'nullable|integer', + 'DueDate' => 'nullable|date_format:Y-m-d|after:StartDate', + 'StartDate' => 'nullable|date_format:Y-m-d', + 'WorkingHours' => 'nullable|numeric', + // 项目模块 ID + 'ProjectModuleId' => 'nullable|integer', + // 事项关注人 ID 列表 + 'WatcherIds' => 'nullable|array', + 'WatcherIds.*' => 'integer', + // 删除的事项关注人 Id 列表 + 'DelWatcherIds' => 'nullable|array', + // 项目缺陷类型 ID + 'DefectTypeId' => 'nullable|integer', + // 项目需求类型 ID + 'RequirementTypeId' => 'nullable|integer', + 'Priority' => [ + 'string', + 'nullable', + Rule::in(array_values(self::PRIORITY)), + ], + 'StoryPoint' => 'nullable|string', + 'LabelIds' => 'nullable|array', + 'DelLabelIds' => 'nullable|array', + 'FileIds' => 'nullable|array', + 'DelFileIds' => 'nullable|array', + // 自定义属性值列表 Array of IssueCustomFieldForm + 'CustomFieldValues' => 'nullable|array', + ]); + $response = $this->core->request('ModifyIssue', $data); + return $response['Issue']; + } } diff --git a/tests/Acceptance/IssueTest.php b/tests/Acceptance/IssueTest.php index e963b0b..c180990 100644 --- a/tests/Acceptance/IssueTest.php +++ b/tests/Acceptance/IssueTest.php @@ -7,7 +7,7 @@ class IssueTest extends TestCase { - public function testCreateAndDelete() + public function testCrud() { $data = [ 'ProjectName' => $this->projectName, @@ -26,6 +26,12 @@ public function testCreateAndDelete() ]; $result = $issue->get($params); $this->assertEquals($data['Name'], $result['Name']); + $this->assertEmpty($result['StoryPoint']); + + $params['StoryPoint'] = '1.0'; + $result = $issue->update($params); + $this->assertEquals('1.0', $result['StoryPoint']); + $this->assertTrue($issue->delete($params)); } } diff --git a/tests/Unit/IssueTest.php b/tests/Unit/IssueTest.php index bd569d8..954d4a6 100644 --- a/tests/Unit/IssueTest.php +++ b/tests/Unit/IssueTest.php @@ -129,4 +129,25 @@ public function testGet() $result = $issue->get($data); $this->assertEquals($response['Issue'], $result); } + + public function testUpdate() + { + $response = json_decode( + file_get_contents($this->dataPath('ModifyIssueResponse.json')), + true + )['Response']; + $data = [ + 'ProjectName' => $this->projectName, + 'IssueCode' => $this->faker->randomNumber(), + 'StoryPoint' => "1.0", + ]; + $this->coreMock->shouldReceive('request')->times(1)->withArgs([ + 'ModifyIssue', + $data + ])->andReturn($response); + + $issue = new Issue($this->token, $this->coreMock); + $result = $issue->update($data); + $this->assertEquals($response['Issue'], $result); + } } diff --git a/tests/data/ModifyIssueResponse.json b/tests/data/ModifyIssueResponse.json new file mode 100644 index 0000000..f164028 --- /dev/null +++ b/tests/data/ModifyIssueResponse.json @@ -0,0 +1,124 @@ +{ + "Response" : { + "Issue" : { + "Assignee" : { + "Avatar" : "https://coding-net-production-static-ci.codehub.cn/2cb665a3-bebc-4b09-aa00-2b6df3e33edc.jpg?imageMogr2/auto-orient/format/jpeg/cut/400x400x0x0", + "Email" : "", + "GlobalKey" : "", + "Id" : 183478, + "Name" : "sinkcup", + "Phone" : "", + "Status" : 1, + "TeamGlobalKey" : "", + "TeamId" : 0 + }, + "Code" : 1, + "CompletedAt" : 0, + "CreatedAt" : 1639820653000, + "Creator" : { + "Avatar" : "https://coding-net-production-static-ci.codehub.cn/2cb665a3-bebc-4b09-aa00-2b6df3e33edc.jpg?imageMogr2/auto-orient/format/jpeg/cut/400x400x0x0", + "Email" : "", + "GlobalKey" : "", + "Id" : 183478, + "Name" : "sinkcup", + "Phone" : "", + "Status" : 1, + "TeamGlobalKey" : "", + "TeamId" : 0 + }, + "CustomFields" : [], + "DefectType" : { + "IconUrl" : "", + "Id" : 0, + "Name" : "" + }, + "Description" : "", + "DueDate" : 0, + "Epic" : { + "Assignee" : { + "Avatar" : "", + "Email" : "", + "GlobalKey" : "", + "Id" : 0, + "Name" : "", + "Phone" : "", + "Status" : 0, + "TeamGlobalKey" : "", + "TeamId" : 0 + }, + "Code" : 0, + "IssueStatusId" : 0, + "IssueStatusName" : "", + "Name" : "", + "Priority" : "", + "Type" : "" + }, + "Files" : [], + "IssueStatusId" : 1227034, + "IssueStatusName" : "未开始", + "IssueStatusType" : "TODO", + "IssueTypeDetail" : { + "Description" : "任务是指为实现某个目标或需求所进行的具体活动。", + "Id" : 213220, + "IsSystem" : true, + "IssueType" : "MISSION", + "Name" : "任务" + }, + "IssueTypeId" : 213220, + "Iteration" : { + "Code" : 0, + "Name" : "", + "Status" : "" + }, + "IterationId" : 0, + "Labels" : [], + "Name" : "foo", + "Parent" : { + "Assignee" : { + "Avatar" : "", + "Email" : "", + "GlobalKey" : "", + "Id" : 0, + "Name" : "", + "Phone" : "", + "Status" : 0, + "TeamGlobalKey" : "", + "TeamId" : 0 + }, + "Code" : 0, + "IssueStatusId" : 0, + "IssueStatusName" : "", + "IssueStatusType" : "", + "IssueTypeDetail" : { + "Description" : "", + "Id" : 0, + "IsSystem" : false, + "IssueType" : "", + "Name" : "" + }, + "Name" : "", + "Priority" : "", + "Type" : "" + }, + "ParentType" : "MISSION", + "Priority" : "1", + "ProjectModule" : { + "Id" : 0, + "Name" : "" + }, + "RequirementType" : { + "Id" : 0, + "Name" : "" + }, + "StartDate" : 0, + "StoryPoint" : "1.0", + "SubTasks" : [], + "ThirdLinks" : [], + "Type" : "MISSION", + "UpdatedAt" : 1640673221097, + "Watchers" : [], + "WorkingHours" : 0 + }, + "RequestId" : "4a86eaae-e867-1520-f7c2-7d3051f86d48" + } +}

AltStyle によって変換されたページ (->オリジナル) /