2019-09-17 16:21:20 +12:00
|
|
|
<?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']);
|
2019-10-02 05:24:55 +13:00
|
|
|
$this->assertEquals("", $response['body']);
|
2019-09-17 16:21:20 +12:00
|
|
|
|
|
|
|
$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']);
|
2019-10-02 05:24:55 +13:00
|
|
|
$this->assertEquals("", $user['body']);
|
2019-09-17 16:21:20 +12:00
|
|
|
|
|
|
|
return [
|
|
|
|
'email' => $this->demoEmail,
|
|
|
|
'password' => $this->demoPassword,
|
|
|
|
'session' => $session,
|
|
|
|
'projectUid' => $project['body']['$uid'],
|
|
|
|
'projectAPIKeySecret' => $key['body']['secret'],
|
2019-09-17 18:23:11 +12:00
|
|
|
'projectSession' => $this->client->parseCookie($user['headers']['set-cookie'])['a-session-' . $project['body']['$uid']],
|
2019-09-17 16:21:20 +12:00
|
|
|
];
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @depends testRegisterSuccess
|
|
|
|
*/
|
2019-09-30 19:13:40 +13:00
|
|
|
public function testCollectionCreateSuccess($data)
|
|
|
|
{
|
2019-09-21 02:01:47 +12:00
|
|
|
$actors = $this->client->call(Client::METHOD_POST, '/database', [
|
|
|
|
'content-type' => 'application/json',
|
|
|
|
'x-appwrite-project' => $data['projectUid'],
|
|
|
|
'x-appwrite-key' => $data['projectAPIKeySecret'],
|
|
|
|
], [
|
|
|
|
'name' => 'Actors',
|
|
|
|
'read' => ['*'],
|
|
|
|
'write' => ['role:1', 'role:2'],
|
|
|
|
'rules' => [
|
|
|
|
[
|
|
|
|
'label' => 'First Name',
|
|
|
|
'key' => 'firstName',
|
|
|
|
'type' => 'text',
|
|
|
|
'default' => '',
|
|
|
|
'required' => true,
|
|
|
|
'array' => false
|
|
|
|
],
|
|
|
|
[
|
|
|
|
'label' => 'Last Name',
|
|
|
|
'key' => 'lastName',
|
|
|
|
'type' => 'text',
|
|
|
|
'default' => '',
|
|
|
|
'required' => true,
|
|
|
|
'array' => false
|
|
|
|
],
|
|
|
|
],
|
|
|
|
]);
|
|
|
|
|
|
|
|
$this->assertEquals($actors['headers']['status-code'], 201);
|
|
|
|
$this->assertEquals($actors['body']['$collection'], 0);
|
|
|
|
$this->assertEquals($actors['body']['name'], 'Actors');
|
|
|
|
$this->assertIsArray($actors['body']['$permissions']);
|
|
|
|
$this->assertIsArray($actors['body']['$permissions']['read']);
|
|
|
|
$this->assertIsArray($actors['body']['$permissions']['write']);
|
|
|
|
$this->assertEquals(count($actors['body']['$permissions']['read']), 1);
|
|
|
|
$this->assertEquals(count($actors['body']['$permissions']['write']), 2);
|
|
|
|
|
|
|
|
$movies = $this->client->call(Client::METHOD_POST, '/database', [
|
2019-09-17 16:21:20 +12:00
|
|
|
'content-type' => 'application/json',
|
2019-09-17 18:23:11 +12:00
|
|
|
'x-appwrite-project' => $data['projectUid'],
|
|
|
|
'x-appwrite-key' => $data['projectAPIKeySecret'],
|
|
|
|
], [
|
2019-09-20 18:33:11 +12:00
|
|
|
'name' => 'Movies',
|
2019-09-17 18:23:11 +12:00
|
|
|
'read' => ['*'],
|
|
|
|
'write' => ['role:1', 'role:2'],
|
2019-09-20 18:33:11 +12:00
|
|
|
'rules' => [
|
|
|
|
[
|
|
|
|
'label' => 'Name',
|
|
|
|
'key' => 'name',
|
|
|
|
'type' => 'text',
|
|
|
|
'default' => '',
|
2019-09-21 02:01:47 +12:00
|
|
|
'required' => true,
|
2019-09-20 18:33:11 +12:00
|
|
|
'array' => false
|
|
|
|
],
|
|
|
|
[
|
|
|
|
'label' => 'Release Year',
|
|
|
|
'key' => 'releaseYear',
|
|
|
|
'type' => 'numeric',
|
|
|
|
'default' => 0,
|
|
|
|
'required' => false,
|
|
|
|
'array' => false
|
|
|
|
],
|
2019-09-21 02:01:47 +12:00
|
|
|
[
|
|
|
|
'label' => 'Actors',
|
|
|
|
'key' => 'actors',
|
|
|
|
'type' => 'document',
|
|
|
|
'default' => [],
|
|
|
|
'required' => false,
|
|
|
|
'array' => true,
|
|
|
|
'list' => [$actors['body']['$uid']],
|
|
|
|
],
|
2019-09-20 18:33:11 +12:00
|
|
|
],
|
2019-09-17 18:23:11 +12:00
|
|
|
]);
|
2019-09-17 16:21:20 +12:00
|
|
|
|
2019-09-21 02:01:47 +12:00
|
|
|
$this->assertEquals($movies['headers']['status-code'], 201);
|
|
|
|
$this->assertEquals($movies['body']['$collection'], 0);
|
|
|
|
$this->assertEquals($movies['body']['name'], 'Movies');
|
|
|
|
$this->assertIsArray($movies['body']['$permissions']);
|
|
|
|
$this->assertIsArray($movies['body']['$permissions']['read']);
|
|
|
|
$this->assertIsArray($movies['body']['$permissions']['write']);
|
|
|
|
$this->assertEquals(count($movies['body']['$permissions']['read']), 1);
|
|
|
|
$this->assertEquals(count($movies['body']['$permissions']['write']), 2);
|
2019-09-17 16:21:20 +12:00
|
|
|
|
2019-09-21 02:01:47 +12:00
|
|
|
return array_merge($data, ['moviesId' => $movies['body']['$uid'], 'actorsId' => $actors['body']['$uid']]);
|
2019-09-20 18:33:11 +12:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @depends testCollectionCreateSuccess
|
|
|
|
*/
|
2019-09-30 19:13:40 +13:00
|
|
|
public function testDocumentCreateSuccess($data)
|
|
|
|
{
|
2019-09-21 02:01:47 +12:00
|
|
|
$document1 = $this->client->call(Client::METHOD_POST, '/database/' . $data['moviesId'] . '/documents', [
|
2019-09-20 18:33:11 +12:00
|
|
|
'content-type' => 'application/json',
|
|
|
|
'x-appwrite-project' => $data['projectUid'],
|
|
|
|
'x-appwrite-key' => $data['projectAPIKeySecret'],
|
|
|
|
], [
|
|
|
|
'data' => [
|
2019-09-20 23:10:25 +12:00
|
|
|
'name' => 'Captain America',
|
|
|
|
'releaseYear' => 1944,
|
2019-09-21 02:01:47 +12:00
|
|
|
'actors' => [
|
|
|
|
[
|
|
|
|
'$collection' => $data['actorsId'],
|
|
|
|
'$permissions' => ['read' => [], 'write' => []],
|
|
|
|
'firstName' => 'Chris',
|
|
|
|
'lastName' => 'Evans',
|
|
|
|
],
|
|
|
|
[
|
|
|
|
'$collection' => $data['actorsId'],
|
|
|
|
'$permissions' => ['read' => [], 'write' => []],
|
|
|
|
'firstName' => 'Samuel',
|
|
|
|
'lastName' => 'Jackson',
|
|
|
|
],
|
|
|
|
]
|
2019-09-20 23:10:25 +12:00
|
|
|
]
|
|
|
|
]);
|
|
|
|
|
2019-09-21 02:01:47 +12:00
|
|
|
$document2 = $this->client->call(Client::METHOD_POST, '/database/' . $data['moviesId'] . '/documents', [
|
2019-09-20 23:10:25 +12:00
|
|
|
'content-type' => 'application/json',
|
|
|
|
'x-appwrite-project' => $data['projectUid'],
|
|
|
|
'x-appwrite-key' => $data['projectAPIKeySecret'],
|
|
|
|
], [
|
|
|
|
'data' => [
|
|
|
|
'name' => 'Spider-Man: Far From Home',
|
2019-09-20 18:33:11 +12:00
|
|
|
'releaseYear' => 2019,
|
2019-09-21 06:01:17 +12:00
|
|
|
'actors' => [
|
|
|
|
[
|
|
|
|
'$collection' => $data['actorsId'],
|
|
|
|
'$permissions' => ['read' => [], 'write' => []],
|
|
|
|
'firstName' => 'Tom',
|
|
|
|
'lastName' => 'Holland',
|
|
|
|
],
|
|
|
|
[
|
|
|
|
'$collection' => $data['actorsId'],
|
|
|
|
'$permissions' => ['read' => [], 'write' => []],
|
|
|
|
'firstName' => 'Zendaya',
|
|
|
|
'lastName' => 'Maree Stoermer',
|
|
|
|
],
|
|
|
|
[
|
|
|
|
'$collection' => $data['actorsId'],
|
|
|
|
'$permissions' => ['read' => [], 'write' => []],
|
|
|
|
'firstName' => 'Samuel',
|
|
|
|
'lastName' => 'Jackson',
|
|
|
|
],
|
|
|
|
]
|
2019-09-20 18:33:11 +12:00
|
|
|
]
|
|
|
|
]);
|
|
|
|
|
2019-09-21 02:01:47 +12:00
|
|
|
$document3 = $this->client->call(Client::METHOD_POST, '/database/' . $data['moviesId'] . '/documents', [
|
2019-09-20 23:10:25 +12:00
|
|
|
'content-type' => 'application/json',
|
|
|
|
'x-appwrite-project' => $data['projectUid'],
|
|
|
|
'x-appwrite-key' => $data['projectAPIKeySecret'],
|
|
|
|
], [
|
|
|
|
'data' => [
|
|
|
|
'name' => 'Spider-Man: Homecoming',
|
|
|
|
'releaseYear' => 2017,
|
2019-09-21 06:01:17 +12:00
|
|
|
'actors' => [
|
|
|
|
[
|
|
|
|
'$collection' => $data['actorsId'],
|
|
|
|
'$permissions' => ['read' => [], 'write' => []],
|
|
|
|
'firstName' => 'Tom',
|
|
|
|
'lastName' => 'Holland',
|
|
|
|
],
|
|
|
|
[
|
|
|
|
'$collection' => $data['actorsId'],
|
|
|
|
'$permissions' => ['read' => [], 'write' => []],
|
|
|
|
'firstName' => 'Zendaya',
|
|
|
|
'lastName' => 'Maree Stoermer',
|
|
|
|
],
|
|
|
|
],
|
2019-09-20 23:10:25 +12:00
|
|
|
]
|
|
|
|
]);
|
|
|
|
|
2019-09-21 02:01:47 +12:00
|
|
|
$document4 = $this->client->call(Client::METHOD_POST, '/database/' . $data['moviesId'] . '/documents', [
|
|
|
|
'content-type' => 'application/json',
|
|
|
|
'x-appwrite-project' => $data['projectUid'],
|
|
|
|
'x-appwrite-key' => $data['projectAPIKeySecret'],
|
|
|
|
], [
|
|
|
|
'data' => [
|
|
|
|
'releaseYear' => 2020, // Missing title, expect an 400 error
|
|
|
|
]
|
|
|
|
]);
|
|
|
|
|
2019-09-20 23:10:25 +12:00
|
|
|
$this->assertEquals($document1['headers']['status-code'], 201);
|
2019-09-21 02:01:47 +12:00
|
|
|
$this->assertEquals($document1['body']['$collection'], $data['moviesId']);
|
2019-09-20 23:10:25 +12:00
|
|
|
$this->assertEquals($document1['body']['name'], 'Captain America');
|
|
|
|
$this->assertEquals($document1['body']['releaseYear'], 1944);
|
|
|
|
$this->assertIsArray($document1['body']['$permissions']);
|
|
|
|
$this->assertIsArray($document1['body']['$permissions']['read']);
|
|
|
|
$this->assertIsArray($document1['body']['$permissions']['write']);
|
|
|
|
$this->assertEquals(count($document1['body']['$permissions']['read']), 0);
|
|
|
|
$this->assertEquals(count($document1['body']['$permissions']['write']), 0);
|
2019-09-21 02:01:47 +12:00
|
|
|
$this->assertEquals(count($document1['body']['actors']), 2);
|
2019-09-21 06:01:17 +12:00
|
|
|
|
2019-09-20 23:10:25 +12:00
|
|
|
$this->assertEquals($document2['headers']['status-code'], 201);
|
2019-09-21 02:01:47 +12:00
|
|
|
$this->assertEquals($document2['body']['$collection'], $data['moviesId']);
|
2019-09-20 23:10:25 +12:00
|
|
|
$this->assertEquals($document2['body']['name'], 'Spider-Man: Far From Home');
|
|
|
|
$this->assertEquals($document2['body']['releaseYear'], 2019);
|
|
|
|
$this->assertIsArray($document2['body']['$permissions']);
|
|
|
|
$this->assertIsArray($document2['body']['$permissions']['read']);
|
|
|
|
$this->assertIsArray($document2['body']['$permissions']['write']);
|
|
|
|
$this->assertEquals(count($document2['body']['$permissions']['read']), 0);
|
|
|
|
$this->assertEquals(count($document2['body']['$permissions']['write']), 0);
|
2019-09-21 06:01:17 +12:00
|
|
|
$this->assertEquals(count($document2['body']['actors']), 3);
|
|
|
|
$this->assertEquals($document2['body']['actors'][0]['firstName'], 'Tom');
|
|
|
|
$this->assertEquals($document2['body']['actors'][0]['lastName'], 'Holland');
|
|
|
|
$this->assertEquals($document2['body']['actors'][1]['firstName'], 'Zendaya');
|
|
|
|
$this->assertEquals($document2['body']['actors'][1]['lastName'], 'Maree Stoermer');
|
|
|
|
$this->assertEquals($document2['body']['actors'][2]['firstName'], 'Samuel');
|
|
|
|
$this->assertEquals($document2['body']['actors'][2]['lastName'], 'Jackson');
|
|
|
|
|
2019-09-20 23:10:25 +12:00
|
|
|
$this->assertEquals($document3['headers']['status-code'], 201);
|
2019-09-21 02:01:47 +12:00
|
|
|
$this->assertEquals($document3['body']['$collection'], $data['moviesId']);
|
2019-09-20 23:10:25 +12:00
|
|
|
$this->assertEquals($document3['body']['name'], 'Spider-Man: Homecoming');
|
|
|
|
$this->assertEquals($document3['body']['releaseYear'], 2017);
|
|
|
|
$this->assertIsArray($document3['body']['$permissions']);
|
|
|
|
$this->assertIsArray($document3['body']['$permissions']['read']);
|
|
|
|
$this->assertIsArray($document3['body']['$permissions']['write']);
|
|
|
|
$this->assertEquals(count($document3['body']['$permissions']['read']), 0);
|
|
|
|
$this->assertEquals(count($document3['body']['$permissions']['write']), 0);
|
2019-09-21 06:01:17 +12:00
|
|
|
$this->assertEquals(count($document3['body']['actors']), 2);
|
|
|
|
$this->assertEquals($document3['body']['actors'][0]['firstName'], 'Tom');
|
|
|
|
$this->assertEquals($document3['body']['actors'][0]['lastName'], 'Holland');
|
|
|
|
$this->assertEquals($document3['body']['actors'][1]['firstName'], 'Zendaya');
|
|
|
|
$this->assertEquals($document3['body']['actors'][1]['lastName'], 'Maree Stoermer');
|
|
|
|
|
2019-09-21 02:01:47 +12:00
|
|
|
$this->assertEquals($document4['headers']['status-code'], 400);
|
2019-09-20 23:10:25 +12:00
|
|
|
|
|
|
|
return $data;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @depends testDocumentCreateSuccess
|
|
|
|
*/
|
2019-09-30 19:13:40 +13:00
|
|
|
public function testDocumentsListSuccessOrderAndCasting($data)
|
|
|
|
{
|
2019-09-21 02:01:47 +12:00
|
|
|
$documents = $this->client->call(Client::METHOD_GET, '/database/' . $data['moviesId'] . '/documents', [
|
2019-09-20 23:10:25 +12:00
|
|
|
'content-type' => 'application/json',
|
|
|
|
'x-appwrite-project' => $data['projectUid'],
|
|
|
|
'x-appwrite-key' => $data['projectAPIKeySecret'],
|
|
|
|
], [
|
|
|
|
'order-field' => 'releaseYear',
|
|
|
|
'order-type' => 'ASC',
|
|
|
|
'order-cast' => 'int',
|
|
|
|
]);
|
|
|
|
|
|
|
|
$this->assertEquals(1944, $documents['body']['documents'][0]['releaseYear']);
|
|
|
|
$this->assertEquals(2017, $documents['body']['documents'][1]['releaseYear']);
|
|
|
|
$this->assertEquals(2019, $documents['body']['documents'][2]['releaseYear']);
|
|
|
|
$this->assertCount(3, $documents['body']['documents']);
|
|
|
|
|
2019-09-21 02:01:47 +12:00
|
|
|
$documents = $this->client->call(Client::METHOD_GET, '/database/' . $data['moviesId'] . '/documents', [
|
2019-09-20 23:10:25 +12:00
|
|
|
'content-type' => 'application/json',
|
|
|
|
'x-appwrite-project' => $data['projectUid'],
|
|
|
|
'x-appwrite-key' => $data['projectAPIKeySecret'],
|
|
|
|
], [
|
|
|
|
'order-field' => 'releaseYear',
|
|
|
|
'order-type' => 'DESC',
|
|
|
|
'order-cast' => 'int',
|
|
|
|
]);
|
|
|
|
|
|
|
|
$this->assertEquals(1944, $documents['body']['documents'][2]['releaseYear']);
|
|
|
|
$this->assertEquals(2017, $documents['body']['documents'][1]['releaseYear']);
|
|
|
|
$this->assertEquals(2019, $documents['body']['documents'][0]['releaseYear']);
|
|
|
|
$this->assertCount(3, $documents['body']['documents']);
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @depends testDocumentCreateSuccess
|
|
|
|
*/
|
2019-09-30 19:13:40 +13:00
|
|
|
public function testDocumentsListSuccessLimitAndOffset($data)
|
|
|
|
{
|
2019-09-21 02:01:47 +12:00
|
|
|
$documents = $this->client->call(Client::METHOD_GET, '/database/' . $data['moviesId'] . '/documents', [
|
2019-09-20 23:10:25 +12:00
|
|
|
'content-type' => 'application/json',
|
|
|
|
'x-appwrite-project' => $data['projectUid'],
|
|
|
|
'x-appwrite-key' => $data['projectAPIKeySecret'],
|
|
|
|
], [
|
|
|
|
'limit' => 1,
|
|
|
|
'order-field' => 'releaseYear',
|
|
|
|
'order-type' => 'ASC',
|
|
|
|
'order-cast' => 'int',
|
|
|
|
]);
|
|
|
|
|
|
|
|
$this->assertEquals(1944, $documents['body']['documents'][0]['releaseYear']);
|
|
|
|
$this->assertCount(1, $documents['body']['documents']);
|
|
|
|
|
2019-09-21 02:01:47 +12:00
|
|
|
$documents = $this->client->call(Client::METHOD_GET, '/database/' . $data['moviesId'] . '/documents', [
|
2019-09-20 23:10:25 +12:00
|
|
|
'content-type' => 'application/json',
|
|
|
|
'x-appwrite-project' => $data['projectUid'],
|
|
|
|
'x-appwrite-key' => $data['projectAPIKeySecret'],
|
|
|
|
], [
|
|
|
|
'limit' => 2,
|
|
|
|
'offset' => 1,
|
|
|
|
'order-field' => 'releaseYear',
|
|
|
|
'order-type' => 'ASC',
|
|
|
|
'order-cast' => 'int',
|
|
|
|
]);
|
|
|
|
|
|
|
|
$this->assertEquals(2017, $documents['body']['documents'][0]['releaseYear']);
|
|
|
|
$this->assertEquals(2019, $documents['body']['documents'][1]['releaseYear']);
|
|
|
|
$this->assertCount(2, $documents['body']['documents']);
|
2019-09-17 18:23:11 +12:00
|
|
|
}
|
2019-09-21 00:46:57 +12:00
|
|
|
|
|
|
|
/**
|
|
|
|
* @depends testDocumentCreateSuccess
|
|
|
|
*/
|
2019-09-30 19:13:40 +13:00
|
|
|
public function testDocumentsListSuccessFirstAndLast($data)
|
|
|
|
{
|
2019-09-21 02:01:47 +12:00
|
|
|
$documents = $this->client->call(Client::METHOD_GET, '/database/' . $data['moviesId'] . '/documents', [
|
2019-09-21 00:46:57 +12:00
|
|
|
'content-type' => 'application/json',
|
|
|
|
'x-appwrite-project' => $data['projectUid'],
|
|
|
|
'x-appwrite-key' => $data['projectAPIKeySecret'],
|
|
|
|
], [
|
|
|
|
'limit' => 1,
|
|
|
|
'order-field' => 'releaseYear',
|
|
|
|
'order-type' => 'ASC',
|
|
|
|
'order-cast' => 'int',
|
|
|
|
'first' => true,
|
|
|
|
]);
|
|
|
|
|
|
|
|
$this->assertEquals(1944, $documents['body']['releaseYear']);
|
|
|
|
|
2019-09-21 02:01:47 +12:00
|
|
|
$documents = $this->client->call(Client::METHOD_GET, '/database/' . $data['moviesId'] . '/documents', [
|
2019-09-21 00:46:57 +12:00
|
|
|
'content-type' => 'application/json',
|
|
|
|
'x-appwrite-project' => $data['projectUid'],
|
|
|
|
'x-appwrite-key' => $data['projectAPIKeySecret'],
|
|
|
|
], [
|
|
|
|
'limit' => 2,
|
|
|
|
'offset' => 1,
|
|
|
|
'order-field' => 'releaseYear',
|
|
|
|
'order-type' => 'ASC',
|
|
|
|
'order-cast' => 'int',
|
|
|
|
'last' => true,
|
|
|
|
]);
|
|
|
|
|
|
|
|
$this->assertEquals(2019, $documents['body']['releaseYear']);
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @depends testDocumentCreateSuccess
|
|
|
|
*/
|
2019-09-30 19:13:40 +13:00
|
|
|
public function testDocumentsListSuccessSerach($data)
|
|
|
|
{
|
2019-09-21 02:01:47 +12:00
|
|
|
$documents = $this->client->call(Client::METHOD_GET, '/database/' . $data['moviesId'] . '/documents', [
|
2019-09-21 00:46:57 +12:00
|
|
|
'content-type' => 'application/json',
|
|
|
|
'x-appwrite-project' => $data['projectUid'],
|
|
|
|
'x-appwrite-key' => $data['projectAPIKeySecret'],
|
|
|
|
], [
|
|
|
|
'search' => 'Captain America',
|
|
|
|
]);
|
|
|
|
|
|
|
|
$this->assertEquals(1944, $documents['body']['documents'][0]['releaseYear']);
|
|
|
|
$this->assertCount(1, $documents['body']['documents']);
|
|
|
|
|
2019-09-21 02:01:47 +12:00
|
|
|
$documents = $this->client->call(Client::METHOD_GET, '/database/' . $data['moviesId'] . '/documents', [
|
2019-09-21 00:46:57 +12:00
|
|
|
'content-type' => 'application/json',
|
|
|
|
'x-appwrite-project' => $data['projectUid'],
|
|
|
|
'x-appwrite-key' => $data['projectAPIKeySecret'],
|
|
|
|
], [
|
|
|
|
'search' => 'Homecoming',
|
|
|
|
]);
|
|
|
|
|
|
|
|
$this->assertEquals(2017, $documents['body']['documents'][0]['releaseYear']);
|
|
|
|
$this->assertCount(1, $documents['body']['documents']);
|
|
|
|
|
2019-09-21 02:01:47 +12:00
|
|
|
$documents = $this->client->call(Client::METHOD_GET, '/database/' . $data['moviesId'] . '/documents', [
|
2019-09-21 00:46:57 +12:00
|
|
|
'content-type' => 'application/json',
|
|
|
|
'x-appwrite-project' => $data['projectUid'],
|
|
|
|
'x-appwrite-key' => $data['projectAPIKeySecret'],
|
|
|
|
], [
|
|
|
|
'search' => 'spider',
|
|
|
|
]);
|
|
|
|
|
|
|
|
$this->assertEquals(2019, $documents['body']['documents'][0]['releaseYear']);
|
|
|
|
$this->assertEquals(2017, $documents['body']['documents'][1]['releaseYear']);
|
|
|
|
$this->assertCount(2, $documents['body']['documents']);
|
|
|
|
}
|
2019-09-21 06:01:17 +12:00
|
|
|
|
|
|
|
/**
|
|
|
|
* @depends testDocumentCreateSuccess
|
|
|
|
*/
|
2019-09-30 19:13:40 +13:00
|
|
|
public function testDocumentsListSuccessFilters($data)
|
|
|
|
{
|
2019-09-21 06:01:17 +12:00
|
|
|
$documents = $this->client->call(Client::METHOD_GET, '/database/' . $data['moviesId'] . '/documents', [
|
|
|
|
'content-type' => 'application/json',
|
|
|
|
'x-appwrite-project' => $data['projectUid'],
|
|
|
|
'x-appwrite-key' => $data['projectAPIKeySecret'],
|
|
|
|
], [
|
|
|
|
'filters' => [
|
|
|
|
'actors.firstName=Tom'
|
|
|
|
],
|
|
|
|
]);
|
|
|
|
|
|
|
|
$this->assertCount(2, $documents['body']['documents']);
|
|
|
|
$this->assertEquals('Spider-Man: Far From Home', $documents['body']['documents'][0]['name']);
|
|
|
|
$this->assertEquals('Spider-Man: Homecoming', $documents['body']['documents'][1]['name']);
|
|
|
|
|
|
|
|
$documents = $this->client->call(Client::METHOD_GET, '/database/' . $data['moviesId'] . '/documents', [
|
|
|
|
'content-type' => 'application/json',
|
|
|
|
'x-appwrite-project' => $data['projectUid'],
|
|
|
|
'x-appwrite-key' => $data['projectAPIKeySecret'],
|
|
|
|
], [
|
|
|
|
'filters' => [
|
|
|
|
'releaseYear=1944'
|
|
|
|
],
|
|
|
|
]);
|
|
|
|
|
|
|
|
$this->assertCount(1, $documents['body']['documents']);
|
|
|
|
$this->assertEquals('Captain America', $documents['body']['documents'][0]['name']);
|
|
|
|
|
|
|
|
$documents = $this->client->call(Client::METHOD_GET, '/database/' . $data['moviesId'] . '/documents', [
|
|
|
|
'content-type' => 'application/json',
|
|
|
|
'x-appwrite-project' => $data['projectUid'],
|
|
|
|
'x-appwrite-key' => $data['projectAPIKeySecret'],
|
|
|
|
], [
|
|
|
|
'filters' => [
|
|
|
|
'releaseYear!=1944'
|
|
|
|
],
|
|
|
|
]);
|
|
|
|
|
|
|
|
$this->assertCount(2, $documents['body']['documents']);
|
|
|
|
$this->assertEquals('Spider-Man: Far From Home', $documents['body']['documents'][0]['name']);
|
|
|
|
$this->assertEquals('Spider-Man: Homecoming', $documents['body']['documents'][1]['name']);
|
|
|
|
}
|
2019-09-30 19:13:40 +13:00
|
|
|
}
|