Skip to content

Commit

Permalink
feat: #78 create iteration
Browse files Browse the repository at this point in the history
  • Loading branch information
sinkcup committed Oct 20, 2021
1 parent 58429fc commit 6724fbe
Show file tree
Hide file tree
Showing 3 changed files with 92 additions and 0 deletions.
23 changes: 23 additions & 0 deletions app/Coding/Iteration.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
<?php

namespace App\Coding;

class Iteration extends Base
{
public function create($token, $projectName, $data)
{
$response = $this->client->request('POST', 'https://e.coding.net/open-api', [
'headers' => [
'Accept' => 'application/json',
'Authorization' => "token ${token}",
'Content-Type' => 'application/json'
],
'json' => array_merge([
'Action' => 'CreateIteration',
'ProjectName' => $projectName,
], $data),
]);
$result = json_decode($response->getBody(), true);
return $result['Response']['Iteration'];
}
}
45 changes: 45 additions & 0 deletions tests/Unit/CodingIterationTest.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
<?php

namespace Tests\Unit;

use App\Coding\Issue;
use App\Coding\Iteration;
use GuzzleHttp\Client;
use GuzzleHttp\Psr7\Response;
use Tests\TestCase;

class CodingIterationTest extends TestCase
{
public function testCreateSuccess()
{
$responseBody = file_get_contents($this->dataDir . 'coding/CreateIterationResponse.json');
$codingToken = $this->faker->md5;
$codingProjectUri = $this->faker->slug;
$data = [
'Name' => $this->faker->title,
];

$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' => 'CreateIteration',
'ProjectName' => $codingProjectUri,
], $data)
]
)
->willReturn(new Response(200, [], $responseBody));
$coding = new Iteration($clientMock);
$result = $coding->create($codingToken, $codingProjectUri, $data);
$this->assertEquals(json_decode($responseBody, true)['Response']['Iteration'], $result);
}
}
24 changes: 24 additions & 0 deletions tests/data/coding/CreateIterationResponse.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
{
"Response" : {
"Iteration" : {
"Assignee" : 0,
"Code" : 2746,
"CompletedCount" : 0,
"CompletedPercent" : 0,
"Completer" : 0,
"CreatedAt" : 1634697259529,
"Creator" : 183478,
"Deleter" : 0,
"EndAt" : -28800000,
"Goal" : "",
"Name" : "it by cli",
"ProcessingCount" : 0,
"StartAt" : -28800000,
"Starter" : 0,
"Status" : "WAIT_PROCESS",
"UpdatedAt" : 1634697259529,
"WaitProcessCount" : 0
},
"RequestId" : "58777aa6-e6e4-155a-c99f-415a33615ca6"
}
}

0 comments on commit 6724fbe

Please sign in to comment.