1
0
Fork 0
mirror of synced 2024-06-25 17:50:38 +12:00

Added DB tests

This commit is contained in:
eldadfux 2019-09-17 07:21:20 +03:00
parent 59ec4470b1
commit 7c7a616109
5 changed files with 152 additions and 29 deletions

View file

@ -5,7 +5,7 @@ namespace Tests\E2E;
use Tests\E2E\Client;
use PHPUnit\Framework\TestCase;
class Base extends TestCase
class BaseConsole extends TestCase
{
/**
* @var Client

View file

@ -0,0 +1,54 @@
<?php
namespace Tests\E2E;
use Tests\E2E\Client;
class BaseProjects extends BaseConsole
{
/**
* @var Client
*/
protected $projectClient = null;
protected $projectsDemoEmail = '';
protected $projectsDemoPassword = '';
public function setUp()
{
parent::setUp();
$this->projectClient = new Client();
$this->projectClient
->setEndpoint($this->endpoint)
;
$this->projectsDemoEmail = 'user.' . rand(0,1000000) . '@appwrite.io';
$this->projectsDemoPassword = 'password.' . rand(0,1000000);
}
public function tearDown()
{
parent::tearDown();
$this->client = null;
}
public function projectRegister($projectId)
{
$response = $this->projectClient->call(Client::METHOD_POST, '/auth/register', [
'origin' => 'http://localhost',
'content-type' => 'application/json',
'x-appwrite-project' => $projectId,
], [
'email' => $this->projectsDemoEmail,
'password' => $this->projectsDemoPassword,
'redirect' => 'http://localhost/confirm',
'success' => 'http://localhost/success',
'failure' => 'http://localhost/failure',
'name' => 'Porject Demo User',
]);
return $response;
}
}

View file

@ -4,33 +4,8 @@ namespace Tests\E2E;
use Tests\E2E\Client;
class ConsoleProjectsTest extends Base
{
/**
* @var Client
*/
protected $client = null;
protected $endpoint = 'http://localhost/v1';
protected $demoEmail = '';
protected $demoPassword = '';
public function setUp()
{
$this->client = new Client();
$this->client
->setEndpoint($this->endpoint)
;
$this->demoEmail = 'user.' . rand(0,1000000) . '@appwrite.io';
$this->demoPassword = 'password.' . rand(0,1000000);
}
public function tearDown()
{
$this->client = null;
}
class ConsoleProjectsTest extends BaseConsole
{
public function testRegisterSuccess()
{
$response = $this->register();

View file

@ -4,7 +4,7 @@ namespace Tests\E2E;
use Tests\E2E\Client;
class ConsoleTest extends Base
class ConsoleTest extends BaseConsole
{
public function testRegisterSuccess()
{

View file

@ -0,0 +1,94 @@
<?php
namespace Tests\E2E;
use Tests\E2E\Client;
class ProjectDatabaseTest extends BaseProjects
{
public function testRegisterSuccess()
{
$response = $this->register();
$this->assertEquals('http://localhost/success', $response['headers']['location']);
$this->assertEquals("\n", $response['body']);
$session = $this->client->parseCookie($response['headers']['set-cookie'])['a-session-console'];
$team = $this->client->call(Client::METHOD_POST, '/teams', [
'origin' => 'http://localhost',
'content-type' => 'application/json',
'cookie' => 'a-session-console=' . $session,
], [
'name' => 'Demo Project Team',
]);
$this->assertEquals(201, $team['headers']['status-code']);
$this->assertEquals('Demo Project Team', $team['body']['name']);
$this->assertNotEmpty($team['body']['$uid']);
$project = $this->client->call(Client::METHOD_POST, '/projects', [
'origin' => 'http://localhost',
'content-type' => 'application/json',
'cookie' => 'a-session-console=' . $session,
], [
'name' => 'Demo Project',
'teamId' => $team['body']['$uid'],
'description' => 'Demo Project Description',
'logo' => '',
'url' => 'https://appwrite.io',
'legalName' => '',
'legalCountry' => '',
'legalState' => '',
'legalCity' => '',
'legalAddress' => '',
'legalTaxId' => '',
]);
$this->assertEquals(201, $project['headers']['status-code']);
$this->assertNotEmpty($project['body']);
$key = $this->client->call(Client::METHOD_POST, '/projects/' . $project['body']['$uid'] . '/keys', [
'origin' => 'http://localhost',
'content-type' => 'application/json',
'cookie' => 'a-session-console=' . $session,
], [
'name' => 'Demo Project Key',
'scopes' => ['collections.read', 'collections.write', 'documents.read', 'documents.write',],
]);
$this->assertEquals(201, $project['headers']['status-code']);
$this->assertNotEmpty($key['body']);
$this->assertNotEmpty($key['body']['secret']);
$user = $this->projectRegister($project['body']['$uid']);
$this->assertEquals('http://localhost/success', $user['headers']['location']);
$this->assertEquals("\n", $user['body']);
return [
'email' => $this->demoEmail,
'password' => $this->demoPassword,
'session' => $session,
'projectUid' => $project['body']['$uid'],
'projectAPIKeyUid' => $key['body']['$uid'],
'projectAPIKeySecret' => $key['body']['secret'],
'projectSession' => $this->projectClient->parseCookie($user['headers']['set-cookie'])['a-session-console'],
];
}
/**
* @depends testRegisterSuccess
*/
public function testProjectsList($data) {
$response = $this->client->call(Client::METHOD_GET, '/projects', [
'origin' => 'http://localhost',
'content-type' => 'application/json',
'cookie' => 'a-session-console=' . $data['session'],
], []);
$this->assertEquals(200, $response['headers']['status-code']);
$this->assertIsArray($response['body']);
}
}