Added DB tests - work in progress
This commit is contained in:
parent
e30deaf7b7
commit
ea71048905
525
tests/e2e/Services/Database/DatabaseBase.php
Normal file
525
tests/e2e/Services/Database/DatabaseBase.php
Normal file
|
@ -0,0 +1,525 @@
|
|||
<?php
|
||||
|
||||
namespace Tests\E2E\Services\Database;
|
||||
|
||||
use Tests\E2E\Client;
|
||||
|
||||
trait DatabaseBase
|
||||
{
|
||||
public function testCreateCollection():array
|
||||
{
|
||||
/**
|
||||
* Test for SUCCESS
|
||||
*/
|
||||
$actors = $this->client->call(Client::METHOD_POST, '/database', array_merge([
|
||||
'content-type' => 'application/json',
|
||||
'x-appwrite-project' => $this->getProject()['$uid'],
|
||||
'x-appwrite-key' => $this->getProject()['apiKey']
|
||||
]), [
|
||||
'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->assertCount(1, $actors['body']['$permissions']['read']);
|
||||
$this->assertCount(2, $actors['body']['$permissions']['write']);
|
||||
|
||||
$movies = $this->client->call(Client::METHOD_POST, '/database', array_merge([
|
||||
'content-type' => 'application/json',
|
||||
'x-appwrite-project' => $this->getProject()['$uid'],
|
||||
'x-appwrite-key' => $this->getProject()['apiKey']
|
||||
]), [
|
||||
'name' => 'Movies',
|
||||
'read' => ['*'],
|
||||
'write' => ['role:1', 'role:2'],
|
||||
'rules' => [
|
||||
[
|
||||
'label' => 'Name',
|
||||
'key' => 'name',
|
||||
'type' => 'text',
|
||||
'default' => '',
|
||||
'required' => true,
|
||||
'array' => false
|
||||
],
|
||||
[
|
||||
'label' => 'Release Year',
|
||||
'key' => 'releaseYear',
|
||||
'type' => 'numeric',
|
||||
'default' => 0,
|
||||
'required' => false,
|
||||
'array' => false
|
||||
],
|
||||
[
|
||||
'label' => 'Actors',
|
||||
'key' => 'actors',
|
||||
'type' => 'document',
|
||||
'default' => [],
|
||||
'required' => false,
|
||||
'array' => true,
|
||||
'list' => [$actors['body']['$uid']],
|
||||
],
|
||||
],
|
||||
]);
|
||||
|
||||
$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->assertCount(1, $movies['body']['$permissions']['read']);
|
||||
$this->assertCount(2, $movies['body']['$permissions']['write']);
|
||||
|
||||
return array_merge(['moviesId' => $movies['body']['$uid'], 'actorsId' => $actors['body']['$uid']]);
|
||||
}
|
||||
|
||||
/**
|
||||
* @depends testCreateCollection
|
||||
*/
|
||||
public function testCreateDocument(array $data):array
|
||||
{
|
||||
$document1 = $this->client->call(Client::METHOD_POST, '/database/' . $data['moviesId'] . '/documents', array_merge([
|
||||
'content-type' => 'application/json',
|
||||
'x-appwrite-project' => $this->getProject()['$uid'],
|
||||
], $this->getHeaders()), [
|
||||
'data' => [
|
||||
'name' => 'Captain America',
|
||||
'releaseYear' => 1944,
|
||||
'actors' => [
|
||||
[
|
||||
'$collection' => $data['actorsId'],
|
||||
'$permissions' => ['read' => [], 'write' => []],
|
||||
'firstName' => 'Chris',
|
||||
'lastName' => 'Evans',
|
||||
],
|
||||
[
|
||||
'$collection' => $data['actorsId'],
|
||||
'$permissions' => ['read' => [], 'write' => []],
|
||||
'firstName' => 'Samuel',
|
||||
'lastName' => 'Jackson',
|
||||
],
|
||||
]
|
||||
]
|
||||
]);
|
||||
|
||||
$document2 = $this->client->call(Client::METHOD_POST, '/database/' . $data['moviesId'] . '/documents', array_merge([
|
||||
'content-type' => 'application/json',
|
||||
'x-appwrite-project' => $this->getProject()['$uid'],
|
||||
], $this->getHeaders()), [
|
||||
'data' => [
|
||||
'name' => 'Spider-Man: Far From Home',
|
||||
'releaseYear' => 2019,
|
||||
'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',
|
||||
],
|
||||
]
|
||||
]
|
||||
]);
|
||||
|
||||
$document3 = $this->client->call(Client::METHOD_POST, '/database/' . $data['moviesId'] . '/documents', array_merge([
|
||||
'content-type' => 'application/json',
|
||||
'x-appwrite-project' => $this->getProject()['$uid'],
|
||||
], $this->getHeaders()), [
|
||||
'data' => [
|
||||
'name' => 'Spider-Man: Homecoming',
|
||||
'releaseYear' => 2017,
|
||||
'actors' => [
|
||||
[
|
||||
'$collection' => $data['actorsId'],
|
||||
'$permissions' => ['read' => [], 'write' => []],
|
||||
'firstName' => 'Tom',
|
||||
'lastName' => 'Holland',
|
||||
],
|
||||
[
|
||||
'$collection' => $data['actorsId'],
|
||||
'$permissions' => ['read' => [], 'write' => []],
|
||||
'firstName' => 'Zendaya',
|
||||
'lastName' => 'Maree Stoermer',
|
||||
],
|
||||
],
|
||||
]
|
||||
]);
|
||||
|
||||
$document4 = $this->client->call(Client::METHOD_POST, '/database/' . $data['moviesId'] . '/documents', array_merge([
|
||||
'content-type' => 'application/json',
|
||||
'x-appwrite-project' => $this->getProject()['$uid'],
|
||||
], $this->getHeaders()), [
|
||||
'data' => [
|
||||
'releaseYear' => 2020, // Missing title, expect an 400 error
|
||||
]
|
||||
]);
|
||||
|
||||
$this->assertEquals($document1['headers']['status-code'], 201);
|
||||
$this->assertEquals($document1['body']['$collection'], $data['moviesId']);
|
||||
$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->assertCount(0, $document1['body']['$permissions']['read']);
|
||||
$this->assertCount(0, $document1['body']['$permissions']['write']);
|
||||
$this->assertCount(2, $document1['body']['actors']);
|
||||
|
||||
$this->assertEquals($document2['headers']['status-code'], 201);
|
||||
$this->assertEquals($document2['body']['$collection'], $data['moviesId']);
|
||||
$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->assertCount(0, $document2['body']['$permissions']['read']);
|
||||
$this->assertCount(0, $document2['body']['$permissions']['write']);
|
||||
$this->assertCount(3, $document2['body']['actors']);
|
||||
$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');
|
||||
|
||||
$this->assertEquals($document3['headers']['status-code'], 201);
|
||||
$this->assertEquals($document3['body']['$collection'], $data['moviesId']);
|
||||
$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->assertCount(0, $document3['body']['$permissions']['read']);
|
||||
$this->assertCount(0, $document3['body']['$permissions']['write']);
|
||||
$this->assertCount(2, $document3['body']['actors']);
|
||||
$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');
|
||||
|
||||
$this->assertEquals($document4['headers']['status-code'], 400);
|
||||
|
||||
return $data;
|
||||
}
|
||||
|
||||
/**
|
||||
* @depends testCreateDocument
|
||||
*/
|
||||
public function testListDocuments(array $data):array
|
||||
{
|
||||
$documents = $this->client->call(Client::METHOD_GET, '/database/' . $data['moviesId'] . '/documents', array_merge([
|
||||
'content-type' => 'application/json',
|
||||
'x-appwrite-project' => $this->getProject()['$uid'],
|
||||
], $this->getHeaders()), [
|
||||
'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']);
|
||||
|
||||
$documents = $this->client->call(Client::METHOD_GET, '/database/' . $data['moviesId'] . '/documents', array_merge([
|
||||
'content-type' => 'application/json',
|
||||
'x-appwrite-project' => $this->getProject()['$uid'],
|
||||
], $this->getHeaders()), [
|
||||
'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']);
|
||||
|
||||
return [];
|
||||
}
|
||||
|
||||
/**
|
||||
* @depends testCreateDocument
|
||||
*/
|
||||
public function testListDocumentsLimitAndOffset(array $data):array
|
||||
{
|
||||
$documents = $this->client->call(Client::METHOD_GET, '/database/' . $data['moviesId'] . '/documents', array_merge([
|
||||
'content-type' => 'application/json',
|
||||
'x-appwrite-project' => $this->getProject()['$uid'],
|
||||
], $this->getHeaders()), [
|
||||
'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']);
|
||||
|
||||
$documents = $this->client->call(Client::METHOD_GET, '/database/' . $data['moviesId'] . '/documents', array_merge([
|
||||
'content-type' => 'application/json',
|
||||
'x-appwrite-project' => $this->getProject()['$uid'],
|
||||
], $this->getHeaders()), [
|
||||
'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']);
|
||||
|
||||
return [];
|
||||
}
|
||||
|
||||
/**
|
||||
* @depends testCreateDocument
|
||||
*/
|
||||
public function testListDocumentsFirstAndLast(array $data):array
|
||||
{
|
||||
$documents = $this->client->call(Client::METHOD_GET, '/database/' . $data['moviesId'] . '/documents', array_merge([
|
||||
'content-type' => 'application/json',
|
||||
'x-appwrite-project' => $this->getProject()['$uid'],
|
||||
], $this->getHeaders()), [
|
||||
'limit' => 1,
|
||||
'order-field' => 'releaseYear',
|
||||
'order-type' => 'ASC',
|
||||
'order-cast' => 'int',
|
||||
'first' => true,
|
||||
]);
|
||||
|
||||
$this->assertEquals(1944, $documents['body']['releaseYear']);
|
||||
|
||||
$documents = $this->client->call(Client::METHOD_GET, '/database/' . $data['moviesId'] . '/documents', array_merge([
|
||||
'content-type' => 'application/json',
|
||||
'x-appwrite-project' => $this->getProject()['$uid'],
|
||||
], $this->getHeaders()), [
|
||||
'limit' => 2,
|
||||
'offset' => 1,
|
||||
'order-field' => 'releaseYear',
|
||||
'order-type' => 'ASC',
|
||||
'order-cast' => 'int',
|
||||
'last' => true,
|
||||
]);
|
||||
|
||||
$this->assertEquals(2019, $documents['body']['releaseYear']);
|
||||
|
||||
return [];
|
||||
}
|
||||
|
||||
/**
|
||||
* @depends testCreateDocument
|
||||
*/
|
||||
public function testDocumentsListSuccessSearch(array $data):array
|
||||
{
|
||||
$documents = $this->client->call(Client::METHOD_GET, '/database/' . $data['moviesId'] . '/documents', array_merge([
|
||||
'content-type' => 'application/json',
|
||||
'x-appwrite-project' => $this->getProject()['$uid'],
|
||||
], $this->getHeaders()), [
|
||||
'search' => 'Captain America',
|
||||
]);
|
||||
|
||||
$this->assertEquals(1944, $documents['body']['documents'][0]['releaseYear']);
|
||||
$this->assertCount(1, $documents['body']['documents']);
|
||||
|
||||
$documents = $this->client->call(Client::METHOD_GET, '/database/' . $data['moviesId'] . '/documents', array_merge([
|
||||
'content-type' => 'application/json',
|
||||
'x-appwrite-project' => $this->getProject()['$uid'],
|
||||
], $this->getHeaders()), [
|
||||
'search' => 'Homecoming',
|
||||
]);
|
||||
|
||||
$this->assertEquals(2017, $documents['body']['documents'][0]['releaseYear']);
|
||||
$this->assertCount(1, $documents['body']['documents']);
|
||||
|
||||
$documents = $this->client->call(Client::METHOD_GET, '/database/' . $data['moviesId'] . '/documents', array_merge([
|
||||
'content-type' => 'application/json',
|
||||
'x-appwrite-project' => $this->getProject()['$uid'],
|
||||
], $this->getHeaders()), [
|
||||
'search' => 'spider',
|
||||
]);
|
||||
|
||||
$this->assertEquals(2019, $documents['body']['documents'][0]['releaseYear']);
|
||||
$this->assertEquals(2017, $documents['body']['documents'][1]['releaseYear']);
|
||||
$this->assertCount(2, $documents['body']['documents']);
|
||||
|
||||
return [];
|
||||
}
|
||||
|
||||
/**
|
||||
* @depends testCreateDocument
|
||||
*/
|
||||
public function testListDocumentsFilters(array $data):array
|
||||
{
|
||||
$documents = $this->client->call(Client::METHOD_GET, '/database/' . $data['moviesId'] . '/documents', array_merge([
|
||||
'content-type' => 'application/json',
|
||||
'x-appwrite-project' => $this->getProject()['$uid'],
|
||||
], $this->getHeaders()), [
|
||||
'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', array_merge([
|
||||
'content-type' => 'application/json',
|
||||
'x-appwrite-project' => $this->getProject()['$uid'],
|
||||
], $this->getHeaders()), [
|
||||
'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', array_merge([
|
||||
'content-type' => 'application/json',
|
||||
'x-appwrite-project' => $this->getProject()['$uid'],
|
||||
], $this->getHeaders()), [
|
||||
'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']);
|
||||
|
||||
return [];
|
||||
}
|
||||
|
||||
/**
|
||||
* @depends testCreateDocument
|
||||
*/
|
||||
public function testUpdateDocument(array $data):array
|
||||
{
|
||||
$document = $this->client->call(Client::METHOD_POST, '/database/' . $data['moviesId'] . '/documents', array_merge([
|
||||
'content-type' => 'application/json',
|
||||
'x-appwrite-project' => $this->getProject()['$uid'],
|
||||
], $this->getHeaders()), [
|
||||
'data' => [
|
||||
'name' => 'Thor: Ragnaroc',
|
||||
'releaseYear' => 2017,
|
||||
]
|
||||
]);
|
||||
|
||||
$id = $document['body']['$uid'];
|
||||
$collection = $document['body']['$collection'];
|
||||
|
||||
$this->assertEquals($document['headers']['status-code'], 201);
|
||||
$this->assertEquals($document['body']['name'], 'Thor: Ragnaroc');
|
||||
$this->assertEquals($document['body']['releaseYear'], 2017);
|
||||
|
||||
$document = $this->client->call(Client::METHOD_PATCH, '/database/' . $collection . '/documents/' . $id, array_merge([
|
||||
'content-type' => 'application/json',
|
||||
'x-appwrite-project' => $this->getProject()['$uid'],
|
||||
], $this->getHeaders()), [
|
||||
'data' => [
|
||||
'name' => 'Thor: Ragnarok'
|
||||
]
|
||||
]);
|
||||
|
||||
$this->assertEquals($document['headers']['status-code'], 200);
|
||||
$this->assertEquals($document['body']['name'], 'Thor: Ragnarok');
|
||||
$this->assertEquals($document['body']['releaseYear'], 2017);
|
||||
|
||||
$document = $this->client->call(Client::METHOD_GET, '/database/' . $collection . '/documents/' . $id, array_merge([
|
||||
'content-type' => 'application/json',
|
||||
'x-appwrite-project' => $this->getProject()['$uid'],
|
||||
], $this->getHeaders()));
|
||||
|
||||
$id = $document['body']['$uid'];
|
||||
$collection = $document['body']['$collection'];
|
||||
|
||||
$this->assertEquals($document['headers']['status-code'], 200);
|
||||
$this->assertEquals($document['body']['name'], 'Thor: Ragnarok');
|
||||
$this->assertEquals($document['body']['releaseYear'], 2017);
|
||||
|
||||
return [];
|
||||
}
|
||||
|
||||
/**
|
||||
* @depends testCreateDocument
|
||||
*/
|
||||
public function testDeleteDocument(array $data):array
|
||||
{
|
||||
$document = $this->client->call(Client::METHOD_POST, '/database/' . $data['moviesId'] . '/documents', array_merge([
|
||||
'content-type' => 'application/json',
|
||||
'x-appwrite-project' => $this->getProject()['$uid'],
|
||||
], $this->getHeaders()), [
|
||||
'data' => [
|
||||
'name' => 'Thor: Ragnarok',
|
||||
'releaseYear' => 2017,
|
||||
]
|
||||
]);
|
||||
|
||||
$id = $document['body']['$uid'];
|
||||
$collection = $document['body']['$collection'];
|
||||
|
||||
$this->assertEquals($document['headers']['status-code'], 201);
|
||||
|
||||
$document = $this->client->call(Client::METHOD_GET, '/database/' . $collection . '/documents/' . $id, array_merge([
|
||||
'content-type' => 'application/json',
|
||||
'x-appwrite-project' => $this->getProject()['$uid'],
|
||||
], $this->getHeaders()));
|
||||
|
||||
$this->assertEquals($document['headers']['status-code'], 200);
|
||||
|
||||
$document = $this->client->call(Client::METHOD_DELETE, '/database/' . $collection . '/documents/' . $id, array_merge([
|
||||
'content-type' => 'application/json',
|
||||
'x-appwrite-project' => $this->getProject()['$uid'],
|
||||
], $this->getHeaders()));
|
||||
|
||||
$this->assertEquals($document['headers']['status-code'], 204);
|
||||
|
||||
$document = $this->client->call(Client::METHOD_GET, '/database/' . $collection . '/documents/' . $id, array_merge([
|
||||
'content-type' => 'application/json',
|
||||
'x-appwrite-project' => $this->getProject()['$uid'],
|
||||
], $this->getHeaders()));
|
||||
|
||||
$this->assertEquals($document['headers']['status-code'], 404);
|
||||
|
||||
return [];
|
||||
}
|
||||
}
|
14
tests/e2e/Services/Database/DatabaseConsoleClientTest.php
Normal file
14
tests/e2e/Services/Database/DatabaseConsoleClientTest.php
Normal file
|
@ -0,0 +1,14 @@
|
|||
<?php
|
||||
|
||||
namespace Tests\E2E\Services\Database;
|
||||
|
||||
use Tests\E2E\Scopes\Scope;
|
||||
use Tests\E2E\Scopes\ProjectConsole;
|
||||
use Tests\E2E\Scopes\SideClient;
|
||||
|
||||
class DatabaseConsoleClientTest extends Scope
|
||||
{
|
||||
use DatabaseBase;
|
||||
use ProjectConsole;
|
||||
use SideClient;
|
||||
}
|
14
tests/e2e/Services/Database/DatabaseCustomClientTest.php
Normal file
14
tests/e2e/Services/Database/DatabaseCustomClientTest.php
Normal file
|
@ -0,0 +1,14 @@
|
|||
<?php
|
||||
|
||||
namespace Tests\E2E\Services\Database;
|
||||
|
||||
use Tests\E2E\Scopes\Scope;
|
||||
use Tests\E2E\Scopes\ProjectCustom;
|
||||
use Tests\E2E\Scopes\SideClient;
|
||||
|
||||
class DatabaseCustomClientTest extends Scope
|
||||
{
|
||||
use DatabaseBase;
|
||||
use ProjectCustom;
|
||||
use SideClient;
|
||||
}
|
14
tests/e2e/Services/Database/DatabaseCustomServerTest.php
Normal file
14
tests/e2e/Services/Database/DatabaseCustomServerTest.php
Normal file
|
@ -0,0 +1,14 @@
|
|||
<?php
|
||||
|
||||
namespace Tests\E2E\Services\Database;
|
||||
|
||||
use Tests\E2E\Scopes\ProjectCustom;
|
||||
use Tests\E2E\Scopes\Scope;
|
||||
use Tests\E2E\Scopes\SideServer;
|
||||
|
||||
class DatabaseCustomServerTest extends Scope
|
||||
{
|
||||
use DatabaseBase;
|
||||
use ProjectCustom;
|
||||
use SideServer;
|
||||
}
|
|
@ -18,8 +18,7 @@ class ProjectDatabaseTest extends BaseProjects
|
|||
{
|
||||
$actors = $this->client->call(Client::METHOD_POST, '/database', [
|
||||
'content-type' => 'application/json',
|
||||
'x-appwrite-project' => $data['projectUid'],
|
||||
'x-appwrite-key' => $data['projectAPIKeySecret'],
|
||||
'x-appwrite-project' => $this->getProject()['$uid'],
|
||||
], [
|
||||
'name' => 'Actors',
|
||||
'read' => ['*'],
|
||||
|
@ -55,8 +54,7 @@ class ProjectDatabaseTest extends BaseProjects
|
|||
|
||||
$movies = $this->client->call(Client::METHOD_POST, '/database', [
|
||||
'content-type' => 'application/json',
|
||||
'x-appwrite-project' => $data['projectUid'],
|
||||
'x-appwrite-key' => $data['projectAPIKeySecret'],
|
||||
'x-appwrite-project' => $this->getProject()['$uid'],
|
||||
], [
|
||||
'name' => 'Movies',
|
||||
'read' => ['*'],
|
||||
|
@ -109,8 +107,7 @@ class ProjectDatabaseTest extends BaseProjects
|
|||
{
|
||||
$document1 = $this->client->call(Client::METHOD_POST, '/database/' . $data['moviesId'] . '/documents', [
|
||||
'content-type' => 'application/json',
|
||||
'x-appwrite-project' => $data['projectUid'],
|
||||
'x-appwrite-key' => $data['projectAPIKeySecret'],
|
||||
'x-appwrite-project' => $this->getProject()['$uid'],
|
||||
], [
|
||||
'data' => [
|
||||
'name' => 'Captain America',
|
||||
|
@ -134,8 +131,7 @@ class ProjectDatabaseTest extends BaseProjects
|
|||
|
||||
$document2 = $this->client->call(Client::METHOD_POST, '/database/' . $data['moviesId'] . '/documents', [
|
||||
'content-type' => 'application/json',
|
||||
'x-appwrite-project' => $data['projectUid'],
|
||||
'x-appwrite-key' => $data['projectAPIKeySecret'],
|
||||
'x-appwrite-project' => $this->getProject()['$uid'],
|
||||
], [
|
||||
'data' => [
|
||||
'name' => 'Spider-Man: Far From Home',
|
||||
|
@ -165,8 +161,7 @@ class ProjectDatabaseTest extends BaseProjects
|
|||
|
||||
$document3 = $this->client->call(Client::METHOD_POST, '/database/' . $data['moviesId'] . '/documents', [
|
||||
'content-type' => 'application/json',
|
||||
'x-appwrite-project' => $data['projectUid'],
|
||||
'x-appwrite-key' => $data['projectAPIKeySecret'],
|
||||
'x-appwrite-project' => $this->getProject()['$uid'],
|
||||
], [
|
||||
'data' => [
|
||||
'name' => 'Spider-Man: Homecoming',
|
||||
|
@ -190,8 +185,7 @@ class ProjectDatabaseTest extends BaseProjects
|
|||
|
||||
$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'],
|
||||
'x-appwrite-project' => $this->getProject()['$uid'],
|
||||
], [
|
||||
'data' => [
|
||||
'releaseYear' => 2020, // Missing title, expect an 400 error
|
||||
|
@ -253,8 +247,7 @@ class ProjectDatabaseTest extends BaseProjects
|
|||
{
|
||||
$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'],
|
||||
'x-appwrite-project' => $this->getProject()['$uid'],
|
||||
], [
|
||||
'order-field' => 'releaseYear',
|
||||
'order-type' => 'ASC',
|
||||
|
@ -268,8 +261,7 @@ class ProjectDatabaseTest extends BaseProjects
|
|||
|
||||
$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'],
|
||||
'x-appwrite-project' => $this->getProject()['$uid'],
|
||||
], [
|
||||
'order-field' => 'releaseYear',
|
||||
'order-type' => 'DESC',
|
||||
|
@ -289,8 +281,7 @@ class ProjectDatabaseTest extends BaseProjects
|
|||
{
|
||||
$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'],
|
||||
'x-appwrite-project' => $this->getProject()['$uid'],
|
||||
], [
|
||||
'limit' => 1,
|
||||
'order-field' => 'releaseYear',
|
||||
|
@ -303,8 +294,7 @@ class ProjectDatabaseTest extends BaseProjects
|
|||
|
||||
$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'],
|
||||
'x-appwrite-project' => $this->getProject()['$uid'],
|
||||
], [
|
||||
'limit' => 2,
|
||||
'offset' => 1,
|
||||
|
@ -325,8 +315,7 @@ class ProjectDatabaseTest extends BaseProjects
|
|||
{
|
||||
$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'],
|
||||
'x-appwrite-project' => $this->getProject()['$uid'],
|
||||
], [
|
||||
'limit' => 1,
|
||||
'order-field' => 'releaseYear',
|
||||
|
@ -339,8 +328,7 @@ class ProjectDatabaseTest extends BaseProjects
|
|||
|
||||
$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'],
|
||||
'x-appwrite-project' => $this->getProject()['$uid'],
|
||||
], [
|
||||
'limit' => 2,
|
||||
'offset' => 1,
|
||||
|
@ -360,8 +348,7 @@ class ProjectDatabaseTest extends BaseProjects
|
|||
{
|
||||
$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'],
|
||||
'x-appwrite-project' => $this->getProject()['$uid'],
|
||||
], [
|
||||
'search' => 'Captain America',
|
||||
]);
|
||||
|
@ -371,8 +358,7 @@ class ProjectDatabaseTest extends BaseProjects
|
|||
|
||||
$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'],
|
||||
'x-appwrite-project' => $this->getProject()['$uid'],
|
||||
], [
|
||||
'search' => 'Homecoming',
|
||||
]);
|
||||
|
@ -382,8 +368,7 @@ class ProjectDatabaseTest extends BaseProjects
|
|||
|
||||
$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'],
|
||||
'x-appwrite-project' => $this->getProject()['$uid'],
|
||||
], [
|
||||
'search' => 'spider',
|
||||
]);
|
||||
|
@ -400,8 +385,7 @@ class ProjectDatabaseTest extends BaseProjects
|
|||
{
|
||||
$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'],
|
||||
'x-appwrite-project' => $this->getProject()['$uid'],
|
||||
], [
|
||||
'filters' => [
|
||||
'actors.firstName=Tom'
|
||||
|
@ -414,8 +398,7 @@ class ProjectDatabaseTest extends BaseProjects
|
|||
|
||||
$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'],
|
||||
'x-appwrite-project' => $this->getProject()['$uid'],
|
||||
], [
|
||||
'filters' => [
|
||||
'releaseYear=1944'
|
||||
|
@ -427,8 +410,7 @@ class ProjectDatabaseTest extends BaseProjects
|
|||
|
||||
$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'],
|
||||
'x-appwrite-project' => $this->getProject()['$uid'],
|
||||
], [
|
||||
'filters' => [
|
||||
'releaseYear!=1944'
|
||||
|
@ -447,8 +429,7 @@ class ProjectDatabaseTest extends BaseProjects
|
|||
{
|
||||
$document = $this->client->call(Client::METHOD_POST, '/database/' . $data['moviesId'] . '/documents', [
|
||||
'content-type' => 'application/json',
|
||||
'x-appwrite-project' => $data['projectUid'],
|
||||
'x-appwrite-key' => $data['projectAPIKeySecret'],
|
||||
'x-appwrite-project' => $this->getProject()['$uid'],
|
||||
], [
|
||||
'data' => [
|
||||
'name' => 'Thor: Ragnaroc',
|
||||
|
@ -465,8 +446,7 @@ class ProjectDatabaseTest extends BaseProjects
|
|||
|
||||
$document = $this->client->call(Client::METHOD_PATCH, '/database/' . $collection . '/documents/' . $id, [
|
||||
'content-type' => 'application/json',
|
||||
'x-appwrite-project' => $data['projectUid'],
|
||||
'x-appwrite-key' => $data['projectAPIKeySecret'],
|
||||
'x-appwrite-project' => $this->getProject()['$uid'],
|
||||
], [
|
||||
'data' => [
|
||||
'name' => 'Thor: Ragnarok'
|
||||
|
@ -479,8 +459,7 @@ class ProjectDatabaseTest extends BaseProjects
|
|||
|
||||
$document = $this->client->call(Client::METHOD_GET, '/database/' . $collection . '/documents/' . $id, [
|
||||
'content-type' => 'application/json',
|
||||
'x-appwrite-project' => $data['projectUid'],
|
||||
'x-appwrite-key' => $data['projectAPIKeySecret'],
|
||||
'x-appwrite-project' => $this->getProject()['$uid'],
|
||||
]);
|
||||
|
||||
$id = $document['body']['$uid'];
|
||||
|
@ -499,8 +478,7 @@ class ProjectDatabaseTest extends BaseProjects
|
|||
{
|
||||
$document = $this->client->call(Client::METHOD_POST, '/database/' . $data['moviesId'] . '/documents', [
|
||||
'content-type' => 'application/json',
|
||||
'x-appwrite-project' => $data['projectUid'],
|
||||
'x-appwrite-key' => $data['projectAPIKeySecret'],
|
||||
'x-appwrite-project' => $this->getProject()['$uid'],
|
||||
], [
|
||||
'data' => [
|
||||
'name' => 'Thor: Ragnarok',
|
||||
|
@ -515,24 +493,21 @@ class ProjectDatabaseTest extends BaseProjects
|
|||
|
||||
$document = $this->client->call(Client::METHOD_GET, '/database/' . $collection . '/documents/' . $id, [
|
||||
'content-type' => 'application/json',
|
||||
'x-appwrite-project' => $data['projectUid'],
|
||||
'x-appwrite-key' => $data['projectAPIKeySecret'],
|
||||
'x-appwrite-project' => $this->getProject()['$uid'],
|
||||
]);
|
||||
|
||||
$this->assertEquals($document['headers']['status-code'], 200);
|
||||
|
||||
$document = $this->client->call(Client::METHOD_DELETE, '/database/' . $collection . '/documents/' . $id, [
|
||||
'content-type' => 'application/json',
|
||||
'x-appwrite-project' => $data['projectUid'],
|
||||
'x-appwrite-key' => $data['projectAPIKeySecret'],
|
||||
'x-appwrite-project' => $this->getProject()['$uid'],
|
||||
]);
|
||||
|
||||
$this->assertEquals($document['headers']['status-code'], 204);
|
||||
|
||||
$document = $this->client->call(Client::METHOD_GET, '/database/' . $collection . '/documents/' . $id, [
|
||||
'content-type' => 'application/json',
|
||||
'x-appwrite-project' => $data['projectUid'],
|
||||
'x-appwrite-key' => $data['projectAPIKeySecret'],
|
||||
'x-appwrite-project' => $this->getProject()['$uid'],
|
||||
]);
|
||||
|
||||
$this->assertEquals($document['headers']['status-code'], 404);
|
||||
|
|
Loading…
Reference in a new issue