diff --git a/app/Coding/Iteration.php b/app/Coding/Iteration.php new file mode 100644 index 0000000..a51ca34 --- /dev/null +++ b/app/Coding/Iteration.php @@ -0,0 +1,23 @@ +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']; + } +} diff --git a/tests/Unit/CodingIterationTest.php b/tests/Unit/CodingIterationTest.php new file mode 100644 index 0000000..fd0786a --- /dev/null +++ b/tests/Unit/CodingIterationTest.php @@ -0,0 +1,45 @@ +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); + } +} diff --git a/tests/data/coding/CreateIterationResponse.json b/tests/data/coding/CreateIterationResponse.json new file mode 100644 index 0000000..a73f9c8 --- /dev/null +++ b/tests/data/coding/CreateIterationResponse.json @@ -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" + } +}