Skip to content

Commit

Permalink
feat: #80 issue type status
Browse files Browse the repository at this point in the history
  • Loading branch information
sinkcup committed Oct 21, 2021
1 parent a3576b5 commit 47fefac
Show file tree
Hide file tree
Showing 4 changed files with 170 additions and 41 deletions.
18 changes: 18 additions & 0 deletions app/Coding/ProjectSetting.php
Original file line number Diff line number Diff line change
Expand Up @@ -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'];
}
}
73 changes: 73 additions & 0 deletions tests/Unit/CodingProjectSettingTest.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,73 @@
<?php

namespace Tests\Unit;

use App\Coding\ProjectSetting;
use GuzzleHttp\Client;
use GuzzleHttp\Psr7\Response;
use Tests\TestCase;

class CodingProjectSettingTest extends TestCase
{
public function testGetIssueTypesSuccess()
{
$responseBody = file_get_contents($this->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);
}
}
41 changes: 0 additions & 41 deletions tests/Unit/CodingProjectTest.php

This file was deleted.

79 changes: 79 additions & 0 deletions tests/data/coding/DescribeProjectIssueStatusListResponse.json
Original file line number Diff line number Diff line change
@@ -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
}
}
]
}
}

0 comments on commit 47fefac

Please sign in to comment.