diff --git a/app/config/errors.php b/app/config/errors.php index cb005b8d7c..e4dc3d5b4d 100644 --- a/app/config/errors.php +++ b/app/config/errors.php @@ -544,11 +544,6 @@ return [ 'description' => 'Variable with the same ID already exists in your project.', 'code' => 409, ], - Exception::VARIABLE_MISSING_PAYLOAD => [ - 'name' => Exception::VARIABLE_MISSING_PAYLOAD, - 'description' => 'The variable key or value is missing.', - 'code' => 400, - ], Exception::DOMAIN_VERIFICATION_FAILED => [ 'name' => Exception::DOMAIN_VERIFICATION_FAILED, 'description' => 'Domain verification for the requested domain has failed.', diff --git a/app/controllers/api/functions.php b/app/controllers/api/functions.php index 2f81b63f68..5663656e1e 100644 --- a/app/controllers/api/functions.php +++ b/app/controllers/api/functions.php @@ -1444,14 +1444,11 @@ App::put('/v1/functions/:functionId/variables/:variableId') ->label('sdk.response.model', Response::MODEL_VARIABLE) ->param('functionId', null, new UID(), 'Function unique ID.', false) ->param('variableId', null, new UID(), 'Variable unique ID.', false) - ->param('key', null, new Text(255), 'Variable key. Max length: 255 chars.', true) + ->param('key', null, new Text(255), 'Variable key. Max length: 255 chars.', false) ->param('value', null, new Text(8192), 'Variable value. Max length: 8192 chars.', true) ->inject('response') ->inject('dbForProject') - ->action(function (string $functionId, string $variableId, ?string $key, ?string $value, Response $response, Database $dbForProject) { - if (empty($key) && empty($value)) { - throw new Exception(Exception::VARIABLE_MISSING_PAYLOAD, 'Missing key or value. Define at least one.'); - } + ->action(function (string $functionId, string $variableId, string $key, ?string $value, Response $response, Database $dbForProject) { $function = $dbForProject->getDocument('functions', $functionId); @@ -1469,7 +1466,7 @@ App::put('/v1/functions/:functionId/variables/:variableId') } $variable - ->setAttribute('key', $key ?? $variable->getAttribute('key')) + ->setAttribute('key', $key) ->setAttribute('value', $value ?? $variable->getAttribute('value')) ->setAttribute('search', implode(' ', [$variableId, $function->getId(), $key])) ; diff --git a/composer.lock b/composer.lock index ebecc59afb..d861097c24 100644 --- a/composer.lock +++ b/composer.lock @@ -2841,12 +2841,12 @@ "source": { "type": "git", "url": "https://github.com/appwrite/sdk-generator.git", - "reference": "6e630a62f522ac68a7056bebf81cd032c7a053ba" + "reference": "6597948263e88f73dbdd5c70259dd54aff2dfcf8" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/appwrite/sdk-generator/zipball/6e630a62f522ac68a7056bebf81cd032c7a053ba", - "reference": "6e630a62f522ac68a7056bebf81cd032c7a053ba", + "url": "https://api.github.com/repos/appwrite/sdk-generator/zipball/6597948263e88f73dbdd5c70259dd54aff2dfcf8", + "reference": "6597948263e88f73dbdd5c70259dd54aff2dfcf8", "shasum": "" }, "require": { @@ -2884,7 +2884,7 @@ "issues": "https://github.com/appwrite/sdk-generator/issues", "source": "https://github.com/appwrite/sdk-generator/tree/master" }, - "time": "2022-08-29T10:43:33+00:00" + "time": "2022-08-30T18:29:13+00:00" }, { "name": "doctrine/instantiator", @@ -3534,16 +3534,16 @@ }, { "name": "phpunit/php-code-coverage", - "version": "9.2.16", + "version": "9.2.17", "source": { "type": "git", "url": "https://github.com/sebastianbergmann/php-code-coverage.git", - "reference": "2593003befdcc10db5e213f9f28814f5aa8ac073" + "reference": "aa94dc41e8661fe90c7316849907cba3007b10d8" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/sebastianbergmann/php-code-coverage/zipball/2593003befdcc10db5e213f9f28814f5aa8ac073", - "reference": "2593003befdcc10db5e213f9f28814f5aa8ac073", + "url": "https://api.github.com/repos/sebastianbergmann/php-code-coverage/zipball/aa94dc41e8661fe90c7316849907cba3007b10d8", + "reference": "aa94dc41e8661fe90c7316849907cba3007b10d8", "shasum": "" }, "require": { @@ -3599,7 +3599,7 @@ ], "support": { "issues": "https://github.com/sebastianbergmann/php-code-coverage/issues", - "source": "https://github.com/sebastianbergmann/php-code-coverage/tree/9.2.16" + "source": "https://github.com/sebastianbergmann/php-code-coverage/tree/9.2.17" }, "funding": [ { @@ -3607,7 +3607,7 @@ "type": "github" } ], - "time": "2022-08-20T05:26:47+00:00" + "time": "2022-08-30T12:24:04+00:00" }, { "name": "phpunit/php-file-iterator", diff --git a/phpunit.xml b/phpunit.xml index fd59a8f236..97bec18b42 100644 --- a/phpunit.xml +++ b/phpunit.xml @@ -6,7 +6,7 @@ convertNoticesToExceptions="true" convertWarningsToExceptions="true" processIsolation="false" - stopOnFailure="false" + stopOnFailure="true" > diff --git a/src/Appwrite/Extend/Exception.php b/src/Appwrite/Extend/Exception.php index e1a3da934e..a32bbb5e97 100644 --- a/src/Appwrite/Extend/Exception.php +++ b/src/Appwrite/Extend/Exception.php @@ -168,7 +168,6 @@ class Exception extends \Exception /** Variables */ public const VARIABLE_NOT_FOUND = 'variable_not_found'; public const VARIABLE_ALREADY_EXISTS = 'variable_already_exists'; - public const VARIABLE_MISSING_PAYLOAD = 'variable_missing_payload'; /** Platform */ public const PLATFORM_NOT_FOUND = 'platform_not_found'; diff --git a/tests/e2e/Services/Functions/FunctionsConsoleClientTest.php b/tests/e2e/Services/Functions/FunctionsConsoleClientTest.php index 9cace135e5..a6e0434f67 100644 --- a/tests/e2e/Services/Functions/FunctionsConsoleClientTest.php +++ b/tests/e2e/Services/Functions/FunctionsConsoleClientTest.php @@ -303,6 +303,8 @@ class FunctionsConsoleClientTest extends Scope ]); $this->assertEquals(200, $response['headers']['status-code']); + $this->assertEquals("APP_TEST_UPDATE", $response['body']['key']); + $this->assertEquals("TESTINGVALUEUPDATED", $response['body']['value']); $variable = $this->client->call(Client::METHOD_GET, '/functions/' . $data['functionId'] . '/variables/' . $data['variableId'], array_merge([ 'content-type' => 'application/json', @@ -313,10 +315,46 @@ class FunctionsConsoleClientTest extends Scope $this->assertEquals("APP_TEST_UPDATE", $variable['body']['key']); $this->assertEquals("TESTINGVALUEUPDATED", $variable['body']['value']); + $response = $this->client->call(Client::METHOD_PUT, '/functions/' . $data['functionId'] . '/variables/' . $data['variableId'], array_merge([ + 'content-type' => 'application/json', + 'x-appwrite-project' => $this->getProject()['$id'], + ], $this->getHeaders()), [ + 'key' => 'APP_TEST_UPDATE_2', + ]); + + $this->assertEquals(200, $response['headers']['status-code']); + $this->assertEquals("APP_TEST_UPDATE_2", $response['body']['key']); + $this->assertEquals("TESTINGVALUEUPDATED", $response['body']['value']); + + $variable = $this->client->call(Client::METHOD_GET, '/functions/' . $data['functionId'] . '/variables/' . $data['variableId'], array_merge([ + 'content-type' => 'application/json', + 'x-appwrite-project' => $this->getProject()['$id'], + ], $this->getHeaders())); + + $this->assertEquals(200, $variable['headers']['status-code']); + $this->assertEquals("APP_TEST_UPDATE_2", $variable['body']['key']); + $this->assertEquals("TESTINGVALUEUPDATED", $variable['body']['value']); + /** * Test for FAILURE */ + $response = $this->client->call(Client::METHOD_PUT, '/functions/' . $data['functionId'] . '/variables/' . $data['variableId'], array_merge([ + 'content-type' => 'application/json', + 'x-appwrite-project' => $this->getProject()['$id'], + ], $this->getHeaders())); + + $this->assertEquals(400, $response['headers']['status-code']); + + $response = $this->client->call(Client::METHOD_PUT, '/functions/' . $data['functionId'] . '/variables/' . $data['variableId'], array_merge([ + 'content-type' => 'application/json', + 'x-appwrite-project' => $this->getProject()['$id'], + ], $this->getHeaders()), [ + 'value' => 'TESTINGVALUEUPDATED_2' + ]); + + $this->assertEquals(400, $response['headers']['status-code']); + $longKey = str_repeat("A", 256); $response = $this->client->call(Client::METHOD_PUT, '/functions/' . $data['functionId'] . '/variables/' . $data['variableId'], array_merge([ 'content-type' => 'application/json',