Skip to content

Commit 5c6734f

Browse files
committed
feat: #80 issue type status
1 parent 27bf9be commit 5c6734f

File tree

4 files changed

+170
-41
lines changed

4 files changed

+170
-41
lines changed

app/Coding/ProjectSetting.php

+18
Original file line numberDiff line numberDiff line change
@@ -20,4 +20,22 @@ public function getIssueTypes($token, $projectName)
2020
$result = json_decode($response->getBody(), true);
2121
return $result['Response']['IssueTypes'];
2222
}
23+
24+
public function getIssueTypeStatus(string $token, string $projectName, string $issueType)
25+
{
26+
$response = $this->client->request('POST', 'https://e.coding.net/open-api', [
27+
'headers' => [
28+
'Accept' => 'application/json',
29+
'Authorization' => "token ${token}",
30+
'Content-Type' => 'application/json'
31+
],
32+
'json' => [
33+
'Action' => 'DescribeProjectIssueStatusList',
34+
'ProjectName' => $projectName,
35+
'IssueType' => $issueType,
36+
],
37+
]);
38+
$result = json_decode($response->getBody(), true);
39+
return $result['Response']['ProjectIssueStatusList'];
40+
}
2341
}
+73
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,73 @@
1+
<?php
2+
3+
namespace Tests\Unit;
4+
5+
use App\Coding\ProjectSetting;
6+
use GuzzleHttp\Client;
7+
use GuzzleHttp\Psr7\Response;
8+
use Tests\TestCase;
9+
10+
class CodingProjectSettingTest extends TestCase
11+
{
12+
public function testGetIssueTypesSuccess()
13+
{
14+
$responseBody = file_get_contents($this->dataDir . 'coding/DescribeProjectIssueTypeListResponse.json');
15+
$codingToken = $this->faker->md5;
16+
$codingProjectUri = $this->faker->slug;
17+
18+
$clientMock = $this->getMockBuilder(Client::class)->getMock();
19+
$clientMock->expects($this->once())
20+
->method('request')
21+
->with(
22+
'POST',
23+
'https://e.coding.net/open-api',
24+
[
25+
'headers' => [
26+
'Accept' => 'application/json',
27+
'Authorization' => "token ${codingToken}",
28+
'Content-Type' => 'application/json'
29+
],
30+
'json' => array_merge([
31+
'Action' => 'DescribeProjectIssueTypeList',
32+
'ProjectName' => $codingProjectUri,
33+
])
34+
]
35+
)
36+
->willReturn(new Response(200, [], $responseBody));
37+
$coding = new ProjectSetting($clientMock);
38+
$result = $coding->getIssueTypes($codingToken, $codingProjectUri);
39+
$this->assertEquals(json_decode($responseBody, true)['Response']['IssueTypes'], $result);
40+
}
41+
42+
public function testGetIssueTypeStatusSuccess()
43+
{
44+
$responseBody = file_get_contents($this->dataDir . 'coding/DescribeProjectIssueStatusListResponse.json');
45+
$codingToken = $this->faker->md5;
46+
$codingProjectUri = $this->faker->slug;
47+
48+
$issueType = $this->faker->randomElement(['DEFECT', 'REQUIREMENT', 'MISSION', 'EPIC', 'SUB_TASK']);
49+
$clientMock = $this->getMockBuilder(Client::class)->getMock();
50+
$clientMock->expects($this->once())
51+
->method('request')
52+
->with(
53+
'POST',
54+
'https://e.coding.net/open-api',
55+
[
56+
'headers' => [
57+
'Accept' => 'application/json',
58+
'Authorization' => "token ${codingToken}",
59+
'Content-Type' => 'application/json'
60+
],
61+
'json' => array_merge([
62+
'Action' => 'DescribeProjectIssueStatusList',
63+
'ProjectName' => $codingProjectUri,
64+
'IssueType' => $issueType,
65+
])
66+
]
67+
)
68+
->willReturn(new Response(200, [], $responseBody));
69+
$coding = new ProjectSetting($clientMock);
70+
$result = $coding->getIssueTypeStatus($codingToken, $codingProjectUri, $issueType);
71+
$this->assertEquals(json_decode($responseBody, true)['Response']['ProjectIssueStatusList'], $result);
72+
}
73+
}

tests/Unit/CodingProjectTest.php

-41
This file was deleted.
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,79 @@
1+
{
2+
"Response": {
3+
"RequestId": "dc827006-32db-a74f-eeae-13bec31c8b92",
4+
"ProjectIssueStatusList": [
5+
{
6+
"IssueType": "REQUIREMENT",
7+
"IssueStatusId": 4,
8+
"IsDefault": true,
9+
"CreatedAt": 1597283400000,
10+
"UpdatedAt": 1597283400000,
11+
"Sort": 0,
12+
"IssueStatus": {
13+
"Id": 4,
14+
"Index": 3,
15+
"Name": "未开始",
16+
"Type": "TODO",
17+
"Description": "",
18+
"IsSystem": true,
19+
"CreatedAt": 1597283396000,
20+
"UpdatedAt": 1597283396000
21+
}
22+
},
23+
{
24+
"IssueType": "REQUIREMENT",
25+
"IssueStatusId": 9,
26+
"IsDefault": false,
27+
"CreatedAt": 1597283400000,
28+
"UpdatedAt": 1597283400000,
29+
"Sort": 0,
30+
"IssueStatus": {
31+
"Id": 9,
32+
"Index": 8,
33+
"Name": "开发中",
34+
"Type": "PROCESSING",
35+
"Description": "",
36+
"IsSystem": true,
37+
"CreatedAt": 1597283396000,
38+
"UpdatedAt": 1597283396000
39+
}
40+
},
41+
{
42+
"IssueType": "REQUIREMENT",
43+
"IssueStatusId": 10,
44+
"IsDefault": false,
45+
"CreatedAt": 1597283400000,
46+
"UpdatedAt": 1597283400000,
47+
"Sort": 0,
48+
"IssueStatus": {
49+
"Id": 10,
50+
"Index": 9,
51+
"Name": "测试中",
52+
"Type": "PROCESSING",
53+
"Description": "",
54+
"IsSystem": true,
55+
"CreatedAt": 1597283396000,
56+
"UpdatedAt": 1597283396000
57+
}
58+
},
59+
{
60+
"IssueType": "REQUIREMENT",
61+
"IssueStatusId": 13,
62+
"IsDefault": false,
63+
"CreatedAt": 1597283400000,
64+
"UpdatedAt": 1597283400000,
65+
"Sort": 0,
66+
"IssueStatus": {
67+
"Id": 13,
68+
"Index": 12,
69+
"Name": "已完成",
70+
"Type": "COMPLETED",
71+
"Description": "",
72+
"IsSystem": true,
73+
"CreatedAt": 1597283396000,
74+
"UpdatedAt": 1597283396000
75+
}
76+
}
77+
]
78+
}
79+
}

0 commit comments

Comments
 (0)