Skip to content

Commit 9a7679a

Browse files
committed
feat: #22 get wiki by id
1 parent fb50bf9 commit 9a7679a

File tree

3 files changed

+106
-1
lines changed

3 files changed

+106
-1
lines changed

app/Coding.php

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -167,4 +167,23 @@ public function createWikiByUploadZip(string $token, string $projectName, string
167167
'FileName' => $zipFilename,
168168
]);
169169
}
170+
171+
public function getWiki(string $token, string $projectName, int $id, int $version = 1)
172+
{
173+
$response = $this->client->request('POST', 'https://e.coding.net/open-api', [
174+
'headers' => [
175+
'Accept' => 'application/json',
176+
'Authorization' => "token ${token}",
177+
'Content-Type' => 'application/json'
178+
],
179+
'json' => [
180+
'Action' => 'DescribeWiki',
181+
'ProjectName' => $projectName,
182+
'Iid' => $id,
183+
'VersionId' => $version,
184+
],
185+
]);
186+
$result = json_decode($response->getBody(), true);
187+
return $result['Response']['Data'];
188+
}
170189
}

tests/Unit/CodingTest.php

Lines changed: 35 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ protected function setUp(): void
2929
parent::setUp();
3030
$codingToken = $this->faker->md5;
3131
config(['coding.token' => $codingToken]);
32-
$codingTeamDomain = $this->faker->domainWord;
32+
$codingTeamDomain = $this->faker->domainWord;
3333
config(['coding.team_domain' => $codingTeamDomain]);
3434
$codingProjectUri = $this->faker->slug;
3535
config(['coding.project_uri' => $codingProjectUri]);
@@ -207,4 +207,38 @@ public function testCreateWikiByUploadZip()
207207
$result = $mock->createWikiByUploadZip('token', 'project', $filePath, $this->faker->randomNumber());
208208
$this->assertArrayHasKey('JobId', $result);
209209
}
210+
211+
public function testGetWiki()
212+
{
213+
$responseBody = file_get_contents($this->dataDir . 'coding/DescribeWikiResponse.json');
214+
$codingToken = $this->faker->md5;
215+
$codingProjectUri = $this->faker->slug;
216+
$id = $this->faker->randomNumber();
217+
$version = $this->faker->randomNumber();
218+
219+
$clientMock = $this->getMockBuilder(Client::class)->getMock();
220+
$clientMock->expects($this->once())
221+
->method('request')
222+
->with(
223+
'POST',
224+
'https://e.coding.net/open-api',
225+
[
226+
'headers' => [
227+
'Accept' => 'application/json',
228+
'Authorization' => "token ${codingToken}",
229+
'Content-Type' => 'application/json'
230+
],
231+
'json' => [
232+
'Action' => 'DescribeWiki',
233+
'ProjectName' => $codingProjectUri,
234+
'Iid' => $id,
235+
'VersionId' => $version,
236+
],
237+
]
238+
)
239+
->willReturn(new Response(200, [], $responseBody));
240+
$coding = new Coding($clientMock);
241+
$result = $coding->getWiki($codingToken, $codingProjectUri, $id, $version);
242+
$this->assertEquals(json_decode($responseBody, true)['Response']['Data'], $result);
243+
}
210244
}
Lines changed: 52 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,52 @@
1+
{
2+
"Response" : {
3+
"Data" : {
4+
"CanMaintain" : true,
5+
"CanRead" : true,
6+
"Content" : "foo foo",
7+
"CreatedAt" : 1626070084000,
8+
"Creator" : {
9+
"Avatar" : "https://coding-net-production-static-ci.codehub.cn/2cb665a3-bebc-4b09-aa00-2b6df3e33edc.jpg?imageMogr2/auto-orient/format/jpeg/cut/400x400x0x0",
10+
"Email" : "",
11+
"GlobalKey" : "KMRnIKgzbV",
12+
"Id" : 183478,
13+
"Name" : "sinkcup",
14+
"Phone" : "",
15+
"RequestId" : "",
16+
"Status" : "ACTIVE",
17+
"TeamId" : 0
18+
},
19+
"CreatorId" : 0,
20+
"CurrentUserRoleId" : 0,
21+
"CurrentVersion" : 1,
22+
"Editor" : {
23+
"Avatar" : "https://coding-net-production-static-ci.codehub.cn/2cb665a3-bebc-4b09-aa00-2b6df3e33edc.jpg?imageMogr2/auto-orient/format/jpeg/cut/400x400x0x0",
24+
"Email" : "",
25+
"GlobalKey" : "KMRnIKgzbV",
26+
"Id" : 183478,
27+
"Name" : "sinkcup",
28+
"Phone" : "",
29+
"RequestId" : "",
30+
"Status" : "ACTIVE",
31+
"TeamId" : 0
32+
},
33+
"EditorId" : 0,
34+
"HistoriesCount" : 1,
35+
"HistoryId" : 2755733,
36+
"Html" : "<p>foo foo</p>",
37+
"Id" : 1362209,
38+
"Iid" : 148,
39+
"LastVersion" : 1,
40+
"Msg" : "",
41+
"Order" : 120,
42+
"ParentIid" : 0,
43+
"ParentShared" : false,
44+
"ParentVisibleRange" : "PUBLIC",
45+
"Path" : "148",
46+
"Title" : "foo by curl",
47+
"UpdatedAt" : 1626070084000,
48+
"VisibleRange" : "INHERIT"
49+
},
50+
"RequestId" : "555fd71a-8719-f74f-49b2-097726e5ebe9"
51+
}
52+
}

0 commit comments

Comments
 (0)