Skip to content

Commit bf61ea3

Browse files
committed
feat: #13 create upload token
1 parent 3358b89 commit bf61ea3

File tree

2 files changed

+49
-0
lines changed

2 files changed

+49
-0
lines changed

app/Coding.php

+17
Original file line numberDiff line numberDiff line change
@@ -28,4 +28,21 @@ public function createWiki($token, $projectName, $data)
2828
]);
2929
return json_decode($response->getBody(), true)['Response']['Data'];
3030
}
31+
32+
public function createUploadToken($token, $projectName, $fileName)
33+
{
34+
$response = $this->client->request('POST', 'https://e.coding.net/open-api', [
35+
'headers' => [
36+
'Accept' => 'application/json',
37+
'Authorization' => "token ${token}",
38+
'Content-Type' => 'application/json'
39+
],
40+
'json' => [
41+
'Action' => 'CreateWiki',
42+
'ProjectName' => $projectName,
43+
'FileName' => $fileName,
44+
],
45+
]);
46+
return json_decode($response->getBody(), true)['Response']['Token'];
47+
}
3148
}

tests/Unit/CodingTest.php

+32
Original file line numberDiff line numberDiff line change
@@ -43,4 +43,36 @@ public function testCreateWiki()
4343
$result = $coding->createWiki($codingToken, $codingProjectUri, $article);
4444
$this->assertEquals(json_decode($responseBody, true)['Response']['Data'], $result);
4545
}
46+
47+
public function testCreateUploadToken()
48+
{
49+
$responseBody = file_get_contents($this->dataDir . 'coding/createUploadTokenResponse.json');
50+
$codingToken = $this->faker->md5;
51+
$codingProjectUri = $this->faker->slug;
52+
$fileName = $this->faker->word;
53+
54+
$clientMock = $this->getMockBuilder(Client::class)->getMock();
55+
$clientMock->expects($this->once())
56+
->method('request')
57+
->with(
58+
'POST',
59+
'https://e.coding.net/open-api',
60+
[
61+
'headers' => [
62+
'Accept' => 'application/json',
63+
'Authorization' => "token ${codingToken}",
64+
'Content-Type' => 'application/json'
65+
],
66+
'json' => [
67+
'Action' => 'CreateWiki',
68+
'ProjectName' => $codingProjectUri,
69+
'FileName' => $fileName,
70+
],
71+
]
72+
)
73+
->willReturn(new Response(200, [], $responseBody));
74+
$coding = new Coding($clientMock);
75+
$result = $coding->createUploadToken($codingToken, $codingProjectUri, $fileName);
76+
$this->assertEquals(json_decode($responseBody, true)['Response']['Token'], $result);
77+
}
4678
}

0 commit comments

Comments
 (0)