Create 1.4 request filters

This commit is contained in:
Steven Nguyen 2023-08-11 17:41:48 -07:00
parent fedac9592b
commit a012a42008
No known key found for this signature in database
3 changed files with 104 additions and 0 deletions

View file

@ -36,6 +36,7 @@ use Appwrite\Utopia\Request\Filters\V12 as RequestV12;
use Appwrite\Utopia\Request\Filters\V13 as RequestV13;
use Appwrite\Utopia\Request\Filters\V14 as RequestV14;
use Appwrite\Utopia\Request\Filters\V15 as RequestV15;
use Appwrite\Utopia\Request\Filters\V16 as RequestV16;
use Utopia\Validator\Text;
use Utopia\Validator\WhiteList;
@ -222,6 +223,9 @@ App::init()
case version_compare($requestFormat, '0.15.3', '<'):
Request::setFilter(new RequestV15());
break;
case version_compare($requestFormat, '1.4.0', '<'):
Request::setFilter(new RequestV16());
break;
default:
Request::setFilter(null);
}

View file

@ -0,0 +1,49 @@
<?php
namespace Appwrite\Utopia\Request\Filters;
use Appwrite\Utopia\Request\Filter;
class V16 extends Filter
{
// Convert 1.0 params to 1.4
public function parse(array $content, string $model): array
{
switch ($model) {
case 'functions.create':
// TODO: How to handle this?
$content['entrypoint'] = ' ';
break;
case 'functions.update':
// TODO: How to handle this?
$content['runtime'] = ' ';
break;
case 'functions.createExecution':
$content['body'] = $content['data'];
unset($content['data']);
break;
case 'projects.createDomain':
// TODO: How to handle this?
// This endpoint was deleted
break;
case 'projects.listDomains':
// TODO: How to handle this?
// This endpoint was deleted
break;
case 'projects.getDomain':
// TODO: How to handle this?
// This endpoint was deleted
break;
case 'projects.updateDomainVerification':
// TODO: How to handle this?
// This endpoint was deleted
break;
case 'projects.deleteDomain':
// TODO: How to handle this?
// This endpoint was deleted
break;
}
return $content;
}
}

View file

@ -0,0 +1,51 @@
<?php
namespace Tests\Unit\Utopia\Request\Filters;
use Appwrite\Utopia\Request\Filter;
use Appwrite\Utopia\Request\Filters\V16;
use Appwrite\Utopia\Response\Model;
use PHPUnit\Framework\TestCase;
class V16Test extends TestCase
{
/**
* @var Filter
*/
protected $filter;
public function setUp(): void
{
$this->filter = new V16();
}
public function tearDown(): void
{
}
public function createExecutionProvider(): array
{
return [
'data' => [
[
'data' => 'Lorem ipsum'
],
[
'body' => 'Lorem ipsum'
],
],
];
}
/**
* @dataProvider createExecutionProvider
*/
public function testCreateExecution(array $content, array $expected): void
{
$model = 'functions.createExecution';
$result = $this->filter->parse($content, $model);
$this->assertEquals($expected, $result);
}
}