diff --git a/app/Coding/ProjectSetting.php b/app/Coding/ProjectSetting.php index ecfaa48..f0034ea 100644 --- a/app/Coding/ProjectSetting.php +++ b/app/Coding/ProjectSetting.php @@ -20,4 +20,22 @@ public function getIssueTypes($token, $projectName) $result = json_decode($response->getBody(), true); return $result['Response']['IssueTypes']; } + + public function getIssueTypeStatus(string $token, string $projectName, string $issueType) + { + $response = $this->client->request('POST', 'https://e.coding.net/open-api', [ + 'headers' => [ + 'Accept' => 'application/json', + 'Authorization' => "token ${token}", + 'Content-Type' => 'application/json' + ], + 'json' => [ + 'Action' => 'DescribeProjectIssueStatusList', + 'ProjectName' => $projectName, + 'IssueType' => $issueType, + ], + ]); + $result = json_decode($response->getBody(), true); + return $result['Response']['ProjectIssueStatusList']; + } } diff --git a/tests/Unit/CodingProjectSettingTest.php b/tests/Unit/CodingProjectSettingTest.php new file mode 100644 index 0000000..215da09 --- /dev/null +++ b/tests/Unit/CodingProjectSettingTest.php @@ -0,0 +1,73 @@ +dataDir . 'coding/DescribeProjectIssueTypeListResponse.json'); + $codingToken = $this->faker->md5; + $codingProjectUri = $this->faker->slug; + + $clientMock = $this->getMockBuilder(Client::class)->getMock(); + $clientMock->expects($this->once()) + ->method('request') + ->with( + 'POST', + 'https://e.coding.net/open-api', + [ + 'headers' => [ + 'Accept' => 'application/json', + 'Authorization' => "token ${codingToken}", + 'Content-Type' => 'application/json' + ], + 'json' => array_merge([ + 'Action' => 'DescribeProjectIssueTypeList', + 'ProjectName' => $codingProjectUri, + ]) + ] + ) + ->willReturn(new Response(200, [], $responseBody)); + $coding = new ProjectSetting($clientMock); + $result = $coding->getIssueTypes($codingToken, $codingProjectUri); + $this->assertEquals(json_decode($responseBody, true)['Response']['IssueTypes'], $result); + } + + public function testGetIssueTypeStatusSuccess() + { + $responseBody = file_get_contents($this->dataDir . 'coding/DescribeProjectIssueStatusListResponse.json'); + $codingToken = $this->faker->md5; + $codingProjectUri = $this->faker->slug; + + $issueType = $this->faker->randomElement(['DEFECT', 'REQUIREMENT', 'MISSION', 'EPIC', 'SUB_TASK']); + $clientMock = $this->getMockBuilder(Client::class)->getMock(); + $clientMock->expects($this->once()) + ->method('request') + ->with( + 'POST', + 'https://e.coding.net/open-api', + [ + 'headers' => [ + 'Accept' => 'application/json', + 'Authorization' => "token ${codingToken}", + 'Content-Type' => 'application/json' + ], + 'json' => array_merge([ + 'Action' => 'DescribeProjectIssueStatusList', + 'ProjectName' => $codingProjectUri, + 'IssueType' => $issueType, + ]) + ] + ) + ->willReturn(new Response(200, [], $responseBody)); + $coding = new ProjectSetting($clientMock); + $result = $coding->getIssueTypeStatus($codingToken, $codingProjectUri, $issueType); + $this->assertEquals(json_decode($responseBody, true)['Response']['ProjectIssueStatusList'], $result); + } +} diff --git a/tests/Unit/CodingProjectTest.php b/tests/Unit/CodingProjectTest.php deleted file mode 100644 index c49ba83..0000000 --- a/tests/Unit/CodingProjectTest.php +++ /dev/null @@ -1,41 +0,0 @@ -dataDir . 'coding/DescribeProjectIssueTypeListResponse.json'); - $codingToken = $this->faker->md5; - $codingProjectUri = $this->faker->slug; - - $clientMock = $this->getMockBuilder(Client::class)->getMock(); - $clientMock->expects($this->once()) - ->method('request') - ->with( - 'POST', - 'https://e.coding.net/open-api', - [ - 'headers' => [ - 'Accept' => 'application/json', - 'Authorization' => "token ${codingToken}", - 'Content-Type' => 'application/json' - ], - 'json' => array_merge([ - 'Action' => 'DescribeProjectIssueTypeList', - 'ProjectName' => $codingProjectUri, - ]) - ] - ) - ->willReturn(new Response(200, [], $responseBody)); - $coding = new ProjectSetting($clientMock); - $result = $coding->getIssueTypes($codingToken, $codingProjectUri); - $this->assertEquals(json_decode($responseBody, true)['Response']['IssueTypes'], $result); - } -} diff --git a/tests/data/coding/DescribeProjectIssueStatusListResponse.json b/tests/data/coding/DescribeProjectIssueStatusListResponse.json new file mode 100644 index 0000000..5699748 --- /dev/null +++ b/tests/data/coding/DescribeProjectIssueStatusListResponse.json @@ -0,0 +1,79 @@ +{ + "Response": { + "RequestId": "dc827006-32db-a74f-eeae-13bec31c8b92", + "ProjectIssueStatusList": [ + { + "IssueType": "REQUIREMENT", + "IssueStatusId": 4, + "IsDefault": true, + "CreatedAt": 1597283400000, + "UpdatedAt": 1597283400000, + "Sort": 0, + "IssueStatus": { + "Id": 4, + "Index": 3, + "Name": "未开始", + "Type": "TODO", + "Description": "", + "IsSystem": true, + "CreatedAt": 1597283396000, + "UpdatedAt": 1597283396000 + } + }, + { + "IssueType": "REQUIREMENT", + "IssueStatusId": 9, + "IsDefault": false, + "CreatedAt": 1597283400000, + "UpdatedAt": 1597283400000, + "Sort": 0, + "IssueStatus": { + "Id": 9, + "Index": 8, + "Name": "开发中", + "Type": "PROCESSING", + "Description": "", + "IsSystem": true, + "CreatedAt": 1597283396000, + "UpdatedAt": 1597283396000 + } + }, + { + "IssueType": "REQUIREMENT", + "IssueStatusId": 10, + "IsDefault": false, + "CreatedAt": 1597283400000, + "UpdatedAt": 1597283400000, + "Sort": 0, + "IssueStatus": { + "Id": 10, + "Index": 9, + "Name": "测试中", + "Type": "PROCESSING", + "Description": "", + "IsSystem": true, + "CreatedAt": 1597283396000, + "UpdatedAt": 1597283396000 + } + }, + { + "IssueType": "REQUIREMENT", + "IssueStatusId": 13, + "IsDefault": false, + "CreatedAt": 1597283400000, + "UpdatedAt": 1597283400000, + "Sort": 0, + "IssueStatus": { + "Id": 13, + "Index": 12, + "Name": "已完成", + "Type": "COMPLETED", + "Description": "", + "IsSystem": true, + "CreatedAt": 1597283396000, + "UpdatedAt": 1597283396000 + } + } + ] + } +}