Added more tests
This commit is contained in:
parent
97b1fc5e28
commit
d464a8a235
50
tests/e2e/Base.php
Normal file
50
tests/e2e/Base.php
Normal 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;
|
||||||
|
}
|
||||||
|
}
|
101
tests/e2e/ConsoleProjectsTest.php
Normal file
101
tests/e2e/ConsoleProjectsTest.php
Normal 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']);
|
||||||
|
}
|
||||||
|
}
|
|
@ -3,55 +3,19 @@
|
||||||
namespace Tests\E2E;
|
namespace Tests\E2E;
|
||||||
|
|
||||||
use Tests\E2E\Client;
|
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()
|
public function testRegisterSuccess()
|
||||||
{
|
{
|
||||||
$response = $this->client->call(Client::METHOD_POST, '/auth/register', [
|
$response = $this->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',
|
|
||||||
]);
|
|
||||||
|
|
||||||
$this->assertEquals('http://localhost/success', $response['headers']['location']);
|
$this->assertEquals('http://localhost/success', $response['headers']['location']);
|
||||||
$this->assertEquals("\n", $response['body']);
|
$this->assertEquals("\n", $response['body']);
|
||||||
|
|
||||||
return [
|
return [
|
||||||
'demoEmail' => $this->demoEmail,
|
'email' => $this->demoEmail,
|
||||||
'demoPassword' => $this->demoPassword,
|
'password' => $this->demoPassword,
|
||||||
];
|
];
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -64,8 +28,8 @@ class ConsoleTest extends TestCase
|
||||||
'origin' => 'http://localhost',
|
'origin' => 'http://localhost',
|
||||||
'content-type' => 'application/json',
|
'content-type' => 'application/json',
|
||||||
], [
|
], [
|
||||||
'email' => $data['demoEmail'],
|
'email' => $data['email'],
|
||||||
'password' => $data['demoPassword'],
|
'password' => $data['password'],
|
||||||
'success' => 'http://localhost/success',
|
'success' => 'http://localhost/success',
|
||||||
'failure' => 'http://localhost/failure',
|
'failure' => 'http://localhost/failure',
|
||||||
]);
|
]);
|
||||||
|
@ -76,8 +40,8 @@ class ConsoleTest extends TestCase
|
||||||
$this->assertEquals("\n", $response['body']);
|
$this->assertEquals("\n", $response['body']);
|
||||||
|
|
||||||
return [
|
return [
|
||||||
'email' => $data['demoEmail'],
|
'email' => $data['email'],
|
||||||
'password' => $data['demoPassword'],
|
'password' => $data['password'],
|
||||||
'session' => $session
|
'session' => $session
|
||||||
];
|
];
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue