1
0
Fork 0
mirror of synced 2024-06-01 10:29:48 +12:00

Added more missing tests

This commit is contained in:
Eldad Fux 2020-11-30 23:41:58 +02:00
parent aa18bbfb58
commit f5df201e4a
5 changed files with 318 additions and 8 deletions

View file

@ -52,8 +52,8 @@ return [
'database.documents.create' => [
'description' => 'This event triggers when a database document is created.',
],
'database.documents.patch' => [
'description' => 'This event triggers when a database document is patched.',
'database.documents.update' => [
'description' => 'This event triggers when a database document is updated.',
],
'database.documents.delete' => [
'description' => 'This event triggers when a database document is deleted.',

View file

@ -261,7 +261,8 @@ class Response extends SwooleResponse
$output = [];
if ($model->isAny()) {
return $document->getArrayCopy();
$this->payload = $document->getArrayCopy();
return $this->payload;
}
foreach ($model->getRules() as $key => $rule) {
@ -294,7 +295,7 @@ class Response extends SwooleResponse
$this->payload = $output;
return $output;
return $this->payload;
}
/**

View file

@ -109,7 +109,7 @@ trait ProjectCustom
'database.collections.update',
'database.collections.delete',
'database.documents.create',
'database.documents.patch',
'database.documents.update',
'database.documents.delete',
'storage.files.create',
'storage.files.update',

View file

@ -7,7 +7,191 @@ use Tests\E2E\Client;
trait WebhooksBase
{
public function testCreateFile():array
public function testCreateCollection(): array
{
/**
* Test for SUCCESS
*/
$actors = $this->client->call(Client::METHOD_POST, '/database/collections', array_merge([
'content-type' => 'application/json',
'x-appwrite-project' => $this->getProject()['$id'],
'x-appwrite-key' => $this->getProject()['apiKey']
]), [
'name' => 'Actors',
'read' => ['*'],
'write' => ['*'],
'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->assertNotEmpty($actors['body']['$id']);
$webhook = $this->getLastRequest();
$this->assertEquals($webhook['method'], 'POST');
$this->assertEquals($webhook['headers']['Content-Type'], 'application/json');
$this->assertEquals($webhook['headers']['User-Agent'], 'Appwrite-Server vdev. Please report abuse at security@appwrite.io');
$this->assertEquals($webhook['headers']['X-Appwrite-Webhook-Event'], 'database.collections.create');
$this->assertEquals($webhook['headers']['X-Appwrite-Webhook-Signature'], 'not-yet-implemented');
$this->assertEquals(empty($webhook['headers']['X-Appwrite-Webhook-Userid'] ?? ''), true);
$this->assertNotEmpty($webhook['data']['$id']);
$this->assertEquals($webhook['data']['name'], 'Actors');
$this->assertIsArray($webhook['data']['$permissions']);
$this->assertIsArray($webhook['data']['$permissions']['read']);
$this->assertIsArray($webhook['data']['$permissions']['write']);
$this->assertCount(1, $webhook['data']['$permissions']['read']);
$this->assertCount(1, $webhook['data']['$permissions']['write']);
$this->assertCount(2, $webhook['data']['rules']);
return array_merge(['actorsId' => $actors['body']['$id']]);
}
/**
* @depends testCreateCollection
*/
public function testCreateDocument(array $data): array
{
$document = $this->client->call(Client::METHOD_POST, '/database/collections/' . $data['actorsId'] . '/documents', array_merge([
'content-type' => 'application/json',
'x-appwrite-project' => $this->getProject()['$id'],
], $this->getHeaders()), [
'data' => [
'firstName' => 'Chris',
'lastName' => 'Evans',
],
'read' => ['*'],
'write' => ['*'],
]);
$this->assertEquals($document['headers']['status-code'], 201);
$this->assertNotEmpty($document['body']['$id']);
$webhook = $this->getLastRequest();
$this->assertEquals($webhook['method'], 'POST');
$this->assertEquals($webhook['headers']['Content-Type'], 'application/json');
$this->assertEquals($webhook['headers']['User-Agent'], 'Appwrite-Server vdev. Please report abuse at security@appwrite.io');
$this->assertEquals($webhook['headers']['X-Appwrite-Webhook-Event'], 'database.documents.create');
$this->assertEquals($webhook['headers']['X-Appwrite-Webhook-Signature'], 'not-yet-implemented');
$this->assertEquals(empty($webhook['headers']['X-Appwrite-Webhook-Userid'] ?? ''), ('server' === $this->getSide()));
$this->assertNotEmpty($webhook['data']['$id']);
$this->assertEquals($webhook['data']['firstName'], 'Chris');
$this->assertEquals($webhook['data']['lastName'], 'Evans');
$this->assertIsArray($webhook['data']['$permissions']['read']);
$this->assertIsArray($webhook['data']['$permissions']['write']);
$this->assertCount(1, $webhook['data']['$permissions']['read']);
$this->assertCount(1, $webhook['data']['$permissions']['write']);
$data['documentId'] = $document['body']['$id'];
return $data;
}
/**
* @depends testCreateDocument
*/
public function testUpdateDocument(array $data): array
{
$document = $this->client->call(Client::METHOD_PATCH, '/database/collections/' . $data['actorsId'] . '/documents/'.$data['documentId'], array_merge([
'content-type' => 'application/json',
'x-appwrite-project' => $this->getProject()['$id'],
], $this->getHeaders()), [
'data' => [
'firstName' => 'Chris1',
'lastName' => 'Evans2',
],
'read' => ['*'],
'write' => ['*'],
]);
$this->assertEquals($document['headers']['status-code'], 200);
$this->assertNotEmpty($document['body']['$id']);
$webhook = $this->getLastRequest();
$this->assertEquals($webhook['method'], 'POST');
$this->assertEquals($webhook['headers']['Content-Type'], 'application/json');
$this->assertEquals($webhook['headers']['User-Agent'], 'Appwrite-Server vdev. Please report abuse at security@appwrite.io');
$this->assertEquals($webhook['headers']['X-Appwrite-Webhook-Event'], 'database.documents.update');
$this->assertEquals($webhook['headers']['X-Appwrite-Webhook-Signature'], 'not-yet-implemented');
$this->assertEquals(empty($webhook['headers']['X-Appwrite-Webhook-Userid'] ?? ''), ('server' === $this->getSide()));
$this->assertNotEmpty($webhook['data']['$id']);
$this->assertEquals($webhook['data']['firstName'], 'Chris1');
$this->assertEquals($webhook['data']['lastName'], 'Evans2');
$this->assertIsArray($webhook['data']['$permissions']['read']);
$this->assertIsArray($webhook['data']['$permissions']['write']);
$this->assertCount(1, $webhook['data']['$permissions']['read']);
$this->assertCount(1, $webhook['data']['$permissions']['write']);
return $data;
}
/**
* @depends testCreateCollection
*/
public function testDeleteDocument(array $data): array
{
$document = $this->client->call(Client::METHOD_POST, '/database/collections/' . $data['actorsId'] . '/documents', array_merge([
'content-type' => 'application/json',
'x-appwrite-project' => $this->getProject()['$id'],
], $this->getHeaders()), [
'data' => [
'firstName' => 'Bradly',
'lastName' => 'Cooper',
],
'read' => ['*'],
'write' => ['*'],
]);
$this->assertEquals($document['headers']['status-code'], 201);
$this->assertNotEmpty($document['body']['$id']);
$document = $this->client->call(Client::METHOD_DELETE, '/database/collections/' . $data['actorsId'] . '/documents/' . $document['body']['$id'], array_merge([
'content-type' => 'application/json',
'x-appwrite-project' => $this->getProject()['$id'],
], $this->getHeaders()));
$this->assertEquals($document['headers']['status-code'], 204);
$webhook = $this->getLastRequest();
$this->assertEquals($webhook['method'], 'POST');
$this->assertEquals($webhook['headers']['Content-Type'], 'application/json');
$this->assertEquals($webhook['headers']['User-Agent'], 'Appwrite-Server vdev. Please report abuse at security@appwrite.io');
$this->assertEquals($webhook['headers']['X-Appwrite-Webhook-Event'], 'database.documents.delete');
$this->assertEquals($webhook['headers']['X-Appwrite-Webhook-Signature'], 'not-yet-implemented');
$this->assertEquals(empty($webhook['headers']['X-Appwrite-Webhook-Userid'] ?? ''), ('server' === $this->getSide()));
$this->assertNotEmpty($webhook['data']['$id']);
$this->assertEquals($webhook['data']['firstName'], 'Bradly');
$this->assertEquals($webhook['data']['lastName'], 'Cooper');
$this->assertIsArray($webhook['data']['$permissions']['read']);
$this->assertIsArray($webhook['data']['$permissions']['write']);
$this->assertCount(1, $webhook['data']['$permissions']['read']);
$this->assertCount(1, $webhook['data']['$permissions']['write']);
return $data;
}
public function testCreateFile(): array
{
/**
* Test for SUCCESS
@ -50,7 +234,7 @@ trait WebhooksBase
/**
* @depends testCreateFile
*/
public function testUpdateFile(array $data):array
public function testUpdateFile(array $data): array
{
/**
* Test for SUCCESS
@ -88,7 +272,7 @@ trait WebhooksBase
/**
* @depends testUpdateFile
*/
public function testDeleteFile(array $data):array
public function testDeleteFile(array $data): array
{
/**
* Test for SUCCESS

View file

@ -13,6 +13,131 @@ class WebhooksCustomServerTest extends Scope
use ProjectCustom;
use SideServer;
/**
* @depends testCreateCollection
*/
public function testUpdateCollection($data): array
{
var_dump($data);
exit();
/**
* Test for SUCCESS
*/
$actors = $this->client->call(Client::METHOD_PUT, '/database/collections/'.$data['actorsId'], array_merge([
'content-type' => 'application/json',
'x-appwrite-project' => $this->getProject()['$id'],
'x-appwrite-key' => $this->getProject()['apiKey']
]), [
'name' => 'Actors1',
'read' => ['*'],
'write' => ['*'],
'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'], 200);
$this->assertNotEmpty($actors['body']['$id']);
$webhook = $this->getLastRequest();
$this->assertEquals($webhook['method'], 'POST');
$this->assertEquals($webhook['headers']['Content-Type'], 'application/json');
$this->assertEquals($webhook['headers']['User-Agent'], 'Appwrite-Server vdev. Please report abuse at security@appwrite.io');
$this->assertEquals($webhook['headers']['X-Appwrite-Webhook-Event'], 'database.collections.update');
$this->assertEquals($webhook['headers']['X-Appwrite-Webhook-Signature'], 'not-yet-implemented');
$this->assertEquals(empty($webhook['headers']['X-Appwrite-Webhook-Userid'] ?? ''), true);
$this->assertNotEmpty($webhook['data']['$id']);
$this->assertEquals($webhook['data']['name'], 'Actors1');
$this->assertIsArray($webhook['data']['$permissions']);
$this->assertIsArray($webhook['data']['$permissions']['read']);
$this->assertIsArray($webhook['data']['$permissions']['write']);
$this->assertCount(1, $webhook['data']['$permissions']['read']);
$this->assertCount(1, $webhook['data']['$permissions']['write']);
$this->assertCount(2, $webhook['data']['rules']);
return array_merge(['actorsId' => $actors['body']['$id']]);
}
public function testDeleteCollection(): array
{
/**
* Test for SUCCESS
*/
$actors = $this->client->call(Client::METHOD_POST, '/database/collections', array_merge([
'content-type' => 'application/json',
'x-appwrite-project' => $this->getProject()['$id'],
'x-appwrite-key' => $this->getProject()['apiKey']
]), [
'name' => 'Demo',
'read' => ['*'],
'write' => ['*'],
'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->assertNotEmpty($actors['body']['$id']);
$actors = $this->client->call(Client::METHOD_DELETE, '/database/collections', array_merge([
'content-type' => 'application/json',
'x-appwrite-project' => $this->getProject()['$id'],
'x-appwrite-key' => $this->getProject()['apiKey']
]), []);
$this->assertEquals($actors['headers']['status-code'], 204);
$webhook = $this->getLastRequest();
$this->assertEquals($webhook['method'], 'POST');
$this->assertEquals($webhook['headers']['Content-Type'], 'application/json');
$this->assertEquals($webhook['headers']['User-Agent'], 'Appwrite-Server vdev. Please report abuse at security@appwrite.io');
$this->assertEquals($webhook['headers']['X-Appwrite-Webhook-Event'], 'database.collections.delete');
$this->assertEquals($webhook['headers']['X-Appwrite-Webhook-Signature'], 'not-yet-implemented');
$this->assertEquals(empty($webhook['headers']['X-Appwrite-Webhook-Userid'] ?? ''), true);
$this->assertNotEmpty($webhook['data']['$id']);
$this->assertEquals($webhook['data']['name'], 'Demo');
$this->assertIsArray($webhook['data']['$permissions']);
$this->assertIsArray($webhook['data']['$permissions']['read']);
$this->assertIsArray($webhook['data']['$permissions']['write']);
$this->assertCount(1, $webhook['data']['$permissions']['read']);
$this->assertCount(1, $webhook['data']['$permissions']['write']);
$this->assertCount(2, $webhook['data']['rules']);
return array_merge(['actorsId' => $actors['body']['$id']]);
}
public function testCreateUser():array
{
$email = uniqid().'user@localhost.test';