Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion tests/CrowdinApiClient/Api/AdvisorApiTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,7 @@ public function testCreateCheckForAllInspectors(): void
$this->mockRequest([
'path' => '/projects/2/advisors/checks',
'method' => 'post',
'body' => '[]',
'body' => json_encode([]),
'response' => $this->checkResponse(),
]);

Expand Down
110 changes: 75 additions & 35 deletions tests/CrowdinApiClient/Api/AiGatewayApiTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,16 +11,24 @@ public function testGatewayGet(): void
$this->mockRequest([
'path' => '/users/1/ai/providers/2/gateway/chat/completions',
'method' => 'get',
'response' => '{
"data": {
"id": "chatcmpl-abc123",
"object": "chat.completion",
"choices": [{"message": {"role": "assistant", "content": "Hello!"}}]
}
}',
'response' => json_encode([
'data' => [
'id' => 'chatcmpl-abc123',
'object' => 'chat.completion',
'choices' => [
[
'message' => [
'role' => 'assistant',
'content' => 'Hello!',
],
],
],
],
]),
]);

$response = $this->crowdin->aiGateway->gatewayGet(1, 2, 'chat/completions');

$this->assertInstanceOf(AiGatewayResponse::class, $response);
$this->assertEquals('chatcmpl-abc123', $response->getData()['id']);
$this->assertEquals('chat.completion', $response->getData()['object']);
Expand All @@ -42,16 +50,24 @@ public function testGatewayPost(): void
'path' => '/users/1/ai/providers/2/gateway/chat/completions',
'method' => 'post',
'body' => json_encode($data),
'response' => '{
"data": {
"id": "chatcmpl-abc123",
"object": "chat.completion",
"choices": [{"message": {"role": "assistant", "content": "Hello!"}}]
}
}',
'response' => json_encode([
'data' => [
'id' => 'chatcmpl-abc123',
'object' => 'chat.completion',
'choices' => [
[
'message' => [
'role' => 'assistant',
'content' => 'Hello!',
],
],
],
],
]),
]);

$response = $this->crowdin->aiGateway->gatewayPost(1, 2, 'chat/completions', $data);

$this->assertInstanceOf(AiGatewayResponse::class, $response);
$this->assertEquals('chatcmpl-abc123', $response->getData()['id']);
}
Expand All @@ -72,16 +88,24 @@ public function testGatewayPut(): void
'path' => '/users/1/ai/providers/2/gateway/chat/completions',
'method' => 'put',
'body' => json_encode($data),
'response' => '{
"data": {
"id": "chatcmpl-abc123",
"object": "chat.completion",
"choices": [{"message": {"role": "assistant", "content": "Hello!"}}]
}
}',
'response' => json_encode([
'data' => [
'id' => 'chatcmpl-abc123',
'object' => 'chat.completion',
'choices' => [
[
'message' => [
'role' => 'assistant',
'content' => 'Hello!',
],
],
],
],
]),
]);

$response = $this->crowdin->aiGateway->gatewayPut(1, 2, 'chat/completions', $data);

$this->assertInstanceOf(AiGatewayResponse::class, $response);
$this->assertEquals('chatcmpl-abc123', $response->getData()['id']);
}
Expand All @@ -102,16 +126,24 @@ public function testGatewayPatch(): void
'path' => '/users/1/ai/providers/2/gateway/chat/completions',
'method' => 'patch',
'body' => json_encode($data),
'response' => '{
"data": {
"id": "chatcmpl-abc123",
"object": "chat.completion",
"choices": [{"message": {"role": "assistant", "content": "Hello!"}}]
}
}',
'response' => json_encode([
'data' => [
'id' => 'chatcmpl-abc123',
'object' => 'chat.completion',
'choices' => [
[
'message' => [
'role' => 'assistant',
'content' => 'Hello!',
],
],
],
],
]),
]);

$response = $this->crowdin->aiGateway->gatewayPatch(1, 2, 'chat/completions', $data);

$this->assertInstanceOf(AiGatewayResponse::class, $response);
$this->assertEquals('chatcmpl-abc123', $response->getData()['id']);
}
Expand All @@ -121,16 +153,24 @@ public function testGatewayDelete(): void
$this->mockRequest([
'path' => '/users/1/ai/providers/2/gateway/chat/completions',
'method' => 'delete',
'response' => '{
"data": {
"id": "chatcmpl-abc123",
"object": "chat.completion",
"choices": [{"message": {"role": "assistant", "content": "Hello!"}}]
}
}',
'response' => json_encode([
'data' => [
'id' => 'chatcmpl-abc123',
'object' => 'chat.completion',
'choices' => [
[
'message' => [
'role' => 'assistant',
'content' => 'Hello!',
],
],
],
],
]),
]);

$response = $this->crowdin->aiGateway->gatewayDelete(1, 2, 'chat/completions');

$this->assertInstanceOf(AiGatewayResponse::class, $response);
$this->assertEquals('chatcmpl-abc123', $response->getData()['id']);
}
Expand Down
166 changes: 85 additions & 81 deletions tests/CrowdinApiClient/Api/BranchApiTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -16,40 +16,39 @@ public function testList()
$this->mockRequest([
'uri' => 'https://api.crowdin.com/api/v2/projects/2/branches',
'method' => 'get',
'response' => '{
"data": [
{
"data": {
"id": 34,
"projectId": 2,
"name": "develop-master",
"title": "Master branch",
"exportPattern": "%three_letters_code%",
"priority": "normal",
"createdAt": "2019-09-16T13:48:04+00:00",
"updatedAt": "2019-09-19T13:25:27+00:00"
}
}
],
"pagination": [
{
"offset": 0,
"limit": 0
}
]
}'
'response' => json_encode([
'data' => [
[
'data' => [
'id' => 34,
'projectId' => 2,
'name' => 'develop-master',
'title' => 'Master branch',
'exportPattern' => '%three_letters_code%',
'priority' => 'normal',
'createdAt' => '2019-09-16T13:48:04+00:00',
'updatedAt' => '2019-09-19T13:25:27+00:00',
],
],
],
'pagination' => [
[
'offset' => 0,
'limit' => 0,
],
],
]),
]);

$data = $this->crowdin->branch->list(2);

$this->assertInstanceOf(ModelCollection::class, $data);
$this->assertCount(1, $data);
/**
* @var Branch $branchModel
*/

/** @var Branch $branchModel */
$branchModel = $data[0];
$this->assertInstanceOf(Branch::class, $branchModel);

$this->assertInstanceOf(Branch::class, $branchModel);
$this->assertEquals(34, $branchModel->getId());
$this->assertEquals(2, $branchModel->getProjectId());
$this->assertEquals('develop-master', $branchModel->getName());
Expand Down Expand Up @@ -102,24 +101,25 @@ public function testSearch(): void

public function testGet()
{
$this->mockRequestGet('/projects/2/branches/34',
'{
"data": {
"id": 34,
"projectId": 2,
"name": "develop-master",
"title": "Master branch",
"exportPattern": "%three_letters_code%",
"priority": "normal",
"createdAt": "2019-09-16T13:48:04+00:00",
"updatedAt": "2019-09-19T13:25:27+00:00"
}
}');
$this->mockRequestGet(
'/projects/2/branches/34',
json_encode([
'data' => [
'id' => 34,
'projectId' => 2,
'name' => 'develop-master',
'title' => 'Master branch',
'exportPattern' => '%three_letters_code%',
'priority' => 'normal',
'createdAt' => '2019-09-16T13:48:04+00:00',
'updatedAt' => '2019-09-19T13:25:27+00:00',
],
])
);

$branch = $this->crowdin->branch->get(2, 34);

$this->assertInstanceOf(Branch::class, $branch);

$this->assertEquals(34, $branch->getId());
$this->assertEquals(2, $branch->getProjectId());
$this->assertEquals('develop-master', $branch->getName());
Expand All @@ -143,18 +143,18 @@ public function testCreate()
'path' => '/projects/2/branches',
'method' => 'post',
'body' => json_encode($params),
'response' => '{
"data": {
"id": 34,
"projectId": 2,
"name": "develop-master",
"title": "Master branch",
"exportPattern": "%three_letters_code%",
"priority": "normal",
"createdAt": "2019-09-16T13:48:04+00:00",
"updatedAt": "2019-09-19T13:25:27+00:00"
}
}'
'response' => json_encode([
'data' => [
'id' => 34,
'projectId' => 2,
'name' => 'develop-master',
'title' => 'Master branch',
'exportPattern' => '%three_letters_code%',
'priority' => 'normal',
'createdAt' => '2019-09-16T13:48:04+00:00',
'updatedAt' => '2019-09-19T13:25:27+00:00',
],
]),
]);

$branch = $this->crowdin->branch->create(2, $params);
Expand Down Expand Up @@ -429,39 +429,43 @@ public function testGetMergeSummary(): void
public function testUpdate()
{
$mock = $this->mockClient
->willReturn('{
"data": {
"id": 34,
"projectId": 2,
"name": "develop-master",
"title": "Master branch",
"exportPattern": "%three_letters_code%",
"priority": "normal",
"createdAt": "2019-09-16T13:48:04+00:00",
"updatedAt": "2019-09-19T13:25:27+00:00"
}
}');
->willReturn(
json_encode([
'data' => [
'id' => 34,
'projectId' => 2,
'name' => 'develop-master',
'title' => 'Master branch',
'exportPattern' => '%three_letters_code%',
'priority' => 'normal',
'createdAt' => '2019-09-16T13:48:04+00:00',
'updatedAt' => '2019-09-19T13:25:27+00:00',
],
])
);

$branch = $this->crowdin->branch->get(2, 34);

$branch->setName('develop-master-edit');

$mock->will($this->returnCallback(function ($method, $uri, $options) {
$this->assertEquals('patch', $method);
$this->assertEquals('https://api.crowdin.com/api/v2/projects/2/branches/34', $uri);
return '{
"data": {
"id": 34,
"projectId": 2,
"name": "develop-master-edit",
"title": "Master branch",
"exportPattern": "%three_letters_code%",
"priority": "normal",
"createdAt": "2019-09-16T13:48:04+00:00",
"updatedAt": "2019-09-19T13:25:27+00:00"
}
}';
}));
$mock->will(
$this->returnCallback(function ($method, $uri) {
$this->assertEquals('patch', $method);
$this->assertEquals('https://api.crowdin.com/api/v2/projects/2/branches/34', $uri);

return json_encode([
'data' => [
'id' => 34,
'projectId' => 2,
'name' => 'develop-master-edit',
'title' => 'Master branch',
'exportPattern' => '%three_letters_code%',
'priority' => 'normal',
'createdAt' => '2019-09-16T13:48:04+00:00',
'updatedAt' => '2019-09-19T13:25:27+00:00',
],
]);
})
);

$branchNew = $this->crowdin->branch->update($branch);

Expand Down
Loading
Loading