1
0
Fork 0
mirror of synced 2024-06-09 22:34:46 +12:00

Added more tests

This commit is contained in:
eldadfux 2019-09-15 23:17:10 +03:00
parent 97b1fc5e28
commit d464a8a235
3 changed files with 159 additions and 44 deletions

50
tests/e2e/Base.php Normal file
View file

@ -0,0 +1,50 @@
<?php
namespace Tests\E2E;
use Tests\E2E\Client;
use PHPUnit\Framework\TestCase;
class Base extends TestCase
{
/**
* @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;
}
public function register() {
$response = $this->client->call(Client::METHOD_POST, '/auth/register', [
'origin' => 'http://localhost',
'content-type' => 'application/json',
], [
'email' => $this->demoEmail,
'password' => $this->demoPassword,
'redirect' => 'http://localhost/confirm',
'success' => 'http://localhost/success',
'failure' => 'http://localhost/failure',
'name' => 'Demo User',
]);
return $response;
}
}

View file

@ -0,0 +1,101 @@
<?php
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;
}
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'];
return [
'email' => $this->demoEmail,
'password' => $this->demoPassword,
'session' => $session
];
}
/**
* @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']);
}
/**
* @depends testRegisterSuccess
*/
public function testProjectsCreateSuccess($data) {
$team = $this->client->call(Client::METHOD_POST, '/teams', [
'origin' => 'http://localhost',
'content-type' => 'application/json',
'cookie' => 'a-session-console=' . $data['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']);
$response = $this->client->call(Client::METHOD_POST, '/projects', [
'origin' => 'http://localhost',
'content-type' => 'application/json',
'cookie' => 'a-session-console=' . $data['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, $response['headers']['status-code']);
$this->assertNotEmpty($response['body']);
}
}

View file

@ -3,55 +3,19 @@
namespace Tests\E2E;
use Tests\E2E\Client;
use PHPUnit\Framework\TestCase;
class ConsoleTest extends TestCase
class ConsoleTest 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;
}
public function testRegisterSuccess()
{
$response = $this->client->call(Client::METHOD_POST, '/auth/register', [
'origin' => 'http://localhost',
'content-type' => 'application/json',
], [
'email' => $this->demoEmail,
'password' => $this->demoPassword,
'redirect' => 'http://localhost/confirm',
'success' => 'http://localhost/success',
'failure' => 'http://localhost/failure',
'name' => 'Demo User',
]);
$response = $this->register();
$this->assertEquals('http://localhost/success', $response['headers']['location']);
$this->assertEquals("\n", $response['body']);
return [
'demoEmail' => $this->demoEmail,
'demoPassword' => $this->demoPassword,
'email' => $this->demoEmail,
'password' => $this->demoPassword,
];
}
@ -64,8 +28,8 @@ class ConsoleTest extends TestCase
'origin' => 'http://localhost',
'content-type' => 'application/json',
], [
'email' => $data['demoEmail'],
'password' => $data['demoPassword'],
'email' => $data['email'],
'password' => $data['password'],
'success' => 'http://localhost/success',
'failure' => 'http://localhost/failure',
]);
@ -76,8 +40,8 @@ class ConsoleTest extends TestCase
$this->assertEquals("\n", $response['body']);
return [
'email' => $data['demoEmail'],
'password' => $data['demoPassword'],
'email' => $data['email'],
'password' => $data['password'],
'session' => $session
];
}