Skip to content

Commit

Permalink
More database tests
Browse files Browse the repository at this point in the history
  • Loading branch information
eldadfux committed Sep 17, 2019
1 parent b5e4789 commit 50b1eb9
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 18 deletions.
9 changes: 1 addition & 8 deletions tests/e2e/BaseProjects.php
Expand Up @@ -9,20 +9,13 @@ 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);
}
Expand All @@ -36,7 +29,7 @@ public function tearDown()

public function projectRegister($projectId)
{
$response = $this->projectClient->call(Client::METHOD_POST, '/auth/register', [
$response = $this->client->call(Client::METHOD_POST, '/auth/register', [
'origin' => 'http://localhost',
'content-type' => 'application/json',
'x-appwrite-project' => $projectId,
Expand Down
32 changes: 22 additions & 10 deletions tests/e2e/ProjectDatabaseTest.php
Expand Up @@ -71,24 +71,36 @@ public function testRegisterSuccess()
'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-' . $project['body']['$uid']],
'projectSession' => $this->client->parseCookie($user['headers']['set-cookie'])['a-session-' . $project['body']['$uid']],
];
}

/**
* @depends testRegisterSuccess
*/
public function testProjectsList($data) {
$response = $this->client->call(Client::METHOD_GET, '/projects', [
'origin' => 'http://localhost',
public function testCollectionCreateSuccess($data) {
$collection = $this->client->call(Client::METHOD_POST, '/database', [
'content-type' => 'application/json',
'cookie' => 'a-session-console=' . $data['session'],
], []);
'x-appwrite-project' => $data['projectUid'],
'x-appwrite-key' => $data['projectAPIKeySecret'],
], [
'name' => 'Test Collection',
'read' => ['*'],
'write' => ['role:1', 'role:2'],
]);

$this->assertEquals(200, $response['headers']['status-code']);
$this->assertIsArray($response['body']);
}
$this->assertEquals($collection['headers']['status-code'], 201);
$this->assertEquals($collection['body']['$collection'], 0);
$this->assertEquals($collection['body']['name'], 'Test Collection');
$this->assertIsArray($collection['body']['$permissions']);
$this->assertIsArray($collection['body']['$permissions']['read']);
$this->assertIsArray($collection['body']['$permissions']['write']);
$this->assertEquals(count($collection['body']['$permissions']['read']), 1);
$this->assertEquals(count($collection['body']['$permissions']['write']), 2);

return [
'collectionId' => $collection['body']['$uid']
];
}
}

0 comments on commit 50b1eb9

Please sign in to comment.