2023-10-09 22:45:36 +13:00
|
|
|
<?php
|
|
|
|
|
|
|
|
namespace Tests\E2E\Services\VCS;
|
|
|
|
|
|
|
|
use Tests\E2E\Scopes\Scope;
|
|
|
|
use Tests\E2E\Client;
|
|
|
|
use Tests\E2E\Scopes\ProjectCustom;
|
|
|
|
use Tests\E2E\Scopes\SideConsole;
|
2023-10-11 09:01:22 +13:00
|
|
|
use Utopia\App;
|
2023-10-09 22:45:36 +13:00
|
|
|
|
|
|
|
class VCSConsoleClientTest extends Scope
|
|
|
|
{
|
|
|
|
use ProjectCustom;
|
|
|
|
use SideConsole;
|
|
|
|
|
2023-10-11 09:01:22 +13:00
|
|
|
public ?string $installationId = null;
|
|
|
|
public ?string $providerRepositoryId = null;
|
|
|
|
|
|
|
|
protected function setUp(): void
|
|
|
|
{
|
|
|
|
parent::setUp();
|
|
|
|
$this->installationId = App::getEnv('_APP_VCS_TEST_INSTALLATION_ID');
|
|
|
|
$this->providerRepositoryId = App::getEnv('_APP_VCS_TEST_PROVIDER_REPOSITORY_ID');
|
|
|
|
}
|
|
|
|
|
|
|
|
public function testDetectRuntime()
|
2023-10-09 22:45:36 +13:00
|
|
|
{
|
|
|
|
/**
|
|
|
|
* Test for SUCCESS
|
|
|
|
*/
|
|
|
|
|
2023-10-11 09:01:22 +13:00
|
|
|
$runtime = $this->client->call(Client::METHOD_POST, '/vcs/github/installations/' . $this->installationId . '/providerRepositories/' . $this->providerRepositoryId . '/detection', array_merge([
|
2023-10-09 22:45:36 +13:00
|
|
|
'content-type' => 'application/json',
|
|
|
|
'x-appwrite-project' => $this->getProject()['$id'],
|
|
|
|
], $this->getHeaders()), [
|
2023-10-11 09:01:22 +13:00
|
|
|
'installationId' => $this->installationId,
|
|
|
|
'providerRepositoryId' => $this->providerRepositoryId
|
2023-10-09 22:45:36 +13:00
|
|
|
]);
|
|
|
|
|
|
|
|
$this->assertEquals(200, $runtime['headers']['status-code']);
|
|
|
|
$this->assertEquals($runtime['body']['runtime'], 'ruby-3.1');
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Test for FAILURE
|
|
|
|
*/
|
|
|
|
|
|
|
|
// $runtime = $this->client->call(Client::METHOD_POST, '/vcs/github/installations/' . $installationId . '/providerRepositories/' . $providerRepositoryId .'/detection', array_merge([
|
|
|
|
// 'content-type' => 'application/json',
|
|
|
|
// 'x-appwrite-project' => $this->getProject()['$id'],
|
|
|
|
// ], $this->getHeaders()), [
|
|
|
|
// 'installationId' => $installationId,
|
|
|
|
// 'providerRepositoryId' => $providerRepositoryId,
|
|
|
|
// 'providerRootDirectory' => 'src'
|
|
|
|
// ]);
|
|
|
|
|
|
|
|
// $this->assertEquals(404, $runtime['headers']['status-code']);
|
|
|
|
}
|
|
|
|
|
2023-10-11 09:01:22 +13:00
|
|
|
public function testListRepositories()
|
2023-10-09 22:45:36 +13:00
|
|
|
{
|
|
|
|
/**
|
|
|
|
* Test for SUCCESS
|
|
|
|
*/
|
|
|
|
|
2023-10-11 09:01:22 +13:00
|
|
|
$repositories = $this->client->call(Client::METHOD_GET, '/vcs/github/installations/' . $this->installationId . '/providerRepositories', array_merge([
|
2023-10-09 22:45:36 +13:00
|
|
|
'content-type' => 'application/json',
|
|
|
|
'x-appwrite-project' => $this->getProject()['$id'],
|
|
|
|
], $this->getHeaders()), [
|
2023-10-11 09:01:22 +13:00
|
|
|
'installationId' => $this->installationId
|
2023-10-09 22:45:36 +13:00
|
|
|
]);
|
|
|
|
|
|
|
|
$this->assertEquals(200, $repositories['headers']['status-code']);
|
|
|
|
$this->assertEquals($repositories['body']['total'], 3);
|
|
|
|
|
2023-10-11 09:01:22 +13:00
|
|
|
$searchedRepositories = $this->client->call(Client::METHOD_GET, '/vcs/github/installations/' . $this->installationId . '/providerRepositories', array_merge([
|
2023-10-09 22:45:36 +13:00
|
|
|
'content-type' => 'application/json',
|
|
|
|
'x-appwrite-project' => $this->getProject()['$id'],
|
|
|
|
], $this->getHeaders()), [
|
2023-10-11 09:01:22 +13:00
|
|
|
'installationId' => $this->installationId,
|
2023-10-09 22:45:36 +13:00
|
|
|
'search' => 'func'
|
|
|
|
]);
|
|
|
|
|
|
|
|
$this->assertEquals(200, $searchedRepositories['headers']['status-code']);
|
|
|
|
$this->assertEquals($searchedRepositories['body']['total'], 1);
|
|
|
|
}
|
|
|
|
|
2023-10-11 09:01:22 +13:00
|
|
|
public function testGetRepository(string $providerRepositoryId2 = '700020051')
|
2023-10-09 22:45:36 +13:00
|
|
|
{
|
|
|
|
/**
|
|
|
|
* Test for SUCCESS
|
|
|
|
*/
|
|
|
|
|
2023-10-11 09:01:22 +13:00
|
|
|
$repository = $this->client->call(Client::METHOD_GET, '/vcs/github/installations/' . $this->installationId . '/providerRepositories/' . $this->providerRepositoryId, array_merge([
|
2023-10-09 22:45:36 +13:00
|
|
|
'content-type' => 'application/json',
|
|
|
|
'x-appwrite-project' => $this->getProject()['$id'],
|
|
|
|
], $this->getHeaders()), [
|
2023-10-11 09:01:22 +13:00
|
|
|
'installationId' => $this->installationId,
|
|
|
|
'providerRepositoryId' => $this->providerRepositoryId
|
2023-10-09 22:45:36 +13:00
|
|
|
]);
|
|
|
|
|
|
|
|
$this->assertEquals(200, $repository['headers']['status-code']);
|
|
|
|
$this->assertEquals($repository['body']['name'], 'ruby-starter');
|
|
|
|
|
2023-10-11 09:01:22 +13:00
|
|
|
$repository = $this->client->call(Client::METHOD_GET, '/vcs/github/installations/' . $this->installationId . '/providerRepositories/' . $providerRepositoryId2, array_merge([
|
2023-10-09 22:45:36 +13:00
|
|
|
'content-type' => 'application/json',
|
|
|
|
'x-appwrite-project' => $this->getProject()['$id'],
|
|
|
|
], $this->getHeaders()), [
|
2023-10-11 09:01:22 +13:00
|
|
|
'installationId' => $this->installationId,
|
2023-10-09 22:45:36 +13:00
|
|
|
'providerRepositoryId' => $providerRepositoryId2
|
|
|
|
]);
|
|
|
|
|
|
|
|
$this->assertEquals(200, $repository['headers']['status-code']);
|
|
|
|
$this->assertEquals($repository['body']['name'], 'function-1.4');
|
|
|
|
}
|
|
|
|
|
2023-10-11 09:01:22 +13:00
|
|
|
public function testListRepositoryBranches()
|
2023-10-09 22:45:36 +13:00
|
|
|
{
|
|
|
|
/**
|
|
|
|
* Test for SUCCESS
|
|
|
|
*/
|
|
|
|
|
2023-10-11 09:01:22 +13:00
|
|
|
$repositoryBranches = $this->client->call(Client::METHOD_GET, '/vcs/github/installations/' . $this->installationId . '/providerRepositories/' . $this->providerRepositoryId . '/branches', array_merge([
|
2023-10-09 22:45:36 +13:00
|
|
|
'content-type' => 'application/json',
|
|
|
|
'x-appwrite-project' => $this->getProject()['$id'],
|
|
|
|
], $this->getHeaders()), [
|
2023-10-11 09:01:22 +13:00
|
|
|
'installationId' => $this->installationId,
|
|
|
|
'providerRepositoryId' => $this->providerRepositoryId
|
2023-10-09 22:45:36 +13:00
|
|
|
]);
|
|
|
|
|
|
|
|
$this->assertEquals(200, $repositoryBranches['headers']['status-code']);
|
|
|
|
$this->assertEquals($repositoryBranches['body']['total'], 2);
|
|
|
|
$this->assertEquals($repositoryBranches['body']['branches'][0]['name'], 'main');
|
|
|
|
$this->assertEquals($repositoryBranches['body']['branches'][1]['name'], 'test');
|
|
|
|
}
|
|
|
|
|
2023-10-11 09:01:22 +13:00
|
|
|
public function testGetInstallation()
|
|
|
|
{
|
|
|
|
/**
|
|
|
|
* Test for SUCCESS
|
|
|
|
*/
|
|
|
|
|
|
|
|
$installation = $this->client->call(Client::METHOD_GET, '/vcs/installations/' . $this->installationId, array_merge([
|
|
|
|
'content-type' => 'application/json',
|
|
|
|
'x-appwrite-project' => $this->getProject()['$id'],
|
|
|
|
], $this->getHeaders()), [
|
|
|
|
'installationId' => $this->installationId
|
|
|
|
]);
|
|
|
|
|
|
|
|
$this->assertEquals(200, $installation['headers']['status-code']);
|
|
|
|
}
|
2023-10-09 22:45:36 +13:00
|
|
|
}
|