Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit 2c1373a

Browse files
feat: #73 create issue failed
1 parent bc3774e commit 2c1373a

File tree

3 files changed

+52
-2
lines changed

3 files changed

+52
-2
lines changed

‎app/Coding/Issue.php

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,8 @@
22

33
namespace App\Coding;
44

5+
use Exception;
6+
57
class Issue extends Base
68
{
79
public function create($token, $projectName, $data)
@@ -17,6 +19,10 @@ public function create($token, $projectName, $data)
1719
'ProjectName' => $projectName,
1820
], $data),
1921
]);
20-
return json_decode($response->getBody(), true)['Response']['Issue'];
22+
$result = json_decode($response->getBody(), true);
23+
if (isset($result['Response']['Error']['Message'])) {
24+
throw new Exception($result['Response']['Error']['Message']);
25+
}
26+
return $result['Response']['Issue'];
2127
}
2228
}

‎tests/Unit/CodingIssueTest.php

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

1010
class CodingIssueTest extends TestCase
1111
{
12-
public function testCreate()
12+
public function testCreateSuccess()
1313
{
1414
$responseBody = file_get_contents($this->dataDir . 'coding/CreateIssueResponse.json');
1515
$codingToken = $this->faker->md5;
@@ -43,4 +43,39 @@ public function testCreate()
4343
$result = $coding->create($codingToken, $codingProjectUri, $data);
4444
$this->assertEquals(json_decode($responseBody, true)['Response']['Issue'], $result);
4545
}
46+
47+
public function testCreateFailed()
48+
{
49+
$responseBody = file_get_contents($this->dataDir . 'coding/CreateIssueFailedResponse.json');
50+
$codingToken = $this->faker->md5;
51+
$codingProjectUri = $this->faker->slug;
52+
$data = [
53+
'Type' => 'REQUIREMENT',
54+
'Name' => $this->faker->title,
55+
'Priority' => $this->faker->randomElement([0, 1, 2, 3]),
56+
];
57+
58+
$clientMock = $this->getMockBuilder(Client::class)->getMock();
59+
$clientMock->expects($this->once())
60+
->method('request')
61+
->with(
62+
'POST',
63+
'https://e.coding.net/open-api',
64+
[
65+
'headers' => [
66+
'Accept' => 'application/json',
67+
'Authorization' => "token ${codingToken}",
68+
'Content-Type' => 'application/json'
69+
],
70+
'json' => array_merge([
71+
'Action' => 'CreateIssue',
72+
'ProjectName' => $codingProjectUri,
73+
], $data)
74+
]
75+
)
76+
->willReturn(new Response(200, [], $responseBody));
77+
$coding = new Issue($clientMock);
78+
$this->expectException(\Exception::class);
79+
$coding->create($codingToken, $codingProjectUri, $data);
80+
}
4681
}
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
{
2+
"Response" : {
3+
"Error" : {
4+
"Code" : "FailedOperation",
5+
"Message" : "issue_custom_field_required"
6+
},
7+
"RequestId" : "504114e3-bcb7-5b51-6ff7-7bb5cb04f121"
8+
}
9+
}

0 commit comments

Comments
(0)

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