diff --git a/tests/e2e/Base.php b/tests/e2e/Base.php new file mode 100644 index 000000000..5e576614d --- /dev/null +++ b/tests/e2e/Base.php @@ -0,0 +1,50 @@ +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; + } +} \ No newline at end of file diff --git a/tests/e2e/ConsoleProjectsTest.php b/tests/e2e/ConsoleProjectsTest.php new file mode 100644 index 000000000..4bce7c901 --- /dev/null +++ b/tests/e2e/ConsoleProjectsTest.php @@ -0,0 +1,101 @@ +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']); + } +} \ No newline at end of file diff --git a/tests/e2e/ConsoleTest.php b/tests/e2e/ConsoleTest.php index d2c53e145..4a827987c 100644 --- a/tests/e2e/ConsoleTest.php +++ b/tests/e2e/ConsoleTest.php @@ -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 ]; }