Failure tests for variables
This commit is contained in:
parent
6df1d35712
commit
087b7df52a
2 changed files with 117 additions and 19 deletions
|
@ -1312,7 +1312,7 @@ App::post('/v1/functions/:functionId/variables')
|
||||||
->label('sdk.response.model', Response::MODEL_VARIABLE)
|
->label('sdk.response.model', Response::MODEL_VARIABLE)
|
||||||
->param('functionId', null, new UID(), 'Function unique ID.', false)
|
->param('functionId', null, new UID(), 'Function unique ID.', false)
|
||||||
->param('key', null, new Text(Database::LENGTH_KEY), 'Variable key. Max length: ' . Database::LENGTH_KEY . ' chars.', false)
|
->param('key', null, new Text(Database::LENGTH_KEY), 'Variable key. Max length: ' . Database::LENGTH_KEY . ' chars.', false)
|
||||||
->param('value', null, new Text(16384), 'Variable value. Max length: 16384 chars.', false)
|
->param('value', null, new Text(8192), 'Variable value. Max length: 8192 chars.', false)
|
||||||
->inject('response')
|
->inject('response')
|
||||||
->inject('dbForProject')
|
->inject('dbForProject')
|
||||||
->action(function (string $functionId, string $key, string $value, Response $response, Database $dbForProject) {
|
->action(function (string $functionId, string $key, string $value, Response $response, Database $dbForProject) {
|
||||||
|
@ -1452,7 +1452,7 @@ App::put('/v1/functions/:functionId/variables/:variableId')
|
||||||
->param('functionId', null, new UID(), 'Function unique ID.', false)
|
->param('functionId', null, new UID(), 'Function unique ID.', false)
|
||||||
->param('variableId', null, new UID(), 'Variable 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.', true)
|
||||||
->param('value', null, new Text(16384), 'Variable value. Max length: 16384 chars.', true)
|
->param('value', null, new Text(8192), 'Variable value. Max length: 8192 chars.', true)
|
||||||
->inject('response')
|
->inject('response')
|
||||||
->inject('dbForProject')
|
->inject('dbForProject')
|
||||||
->action(function (string $functionId, string $variableId, ?string $key, ?string $value, Response $response, Database $dbForProject) {
|
->action(function (string $functionId, string $variableId, ?string $key, ?string $value, Response $response, Database $dbForProject) {
|
||||||
|
@ -1520,7 +1520,6 @@ App::delete('/v1/functions/:functionId/variables/:variableId')
|
||||||
|
|
||||||
if ($variable === false || $variable->isEmpty()) {
|
if ($variable === false || $variable->isEmpty()) {
|
||||||
throw new Exception(Exception::VARIABLE_NOT_FOUND);
|
throw new Exception(Exception::VARIABLE_NOT_FOUND);
|
||||||
```
|
|
||||||
}
|
}
|
||||||
|
|
||||||
$dbForProject->deleteDocument('variables', $variable->getId());
|
$dbForProject->deleteDocument('variables', $variable->getId());
|
||||||
|
|
|
@ -107,6 +107,10 @@ class FunctionsConsoleClientTest extends Scope
|
||||||
*/
|
*/
|
||||||
public function testCreateFunctionVariable(array $data)
|
public function testCreateFunctionVariable(array $data)
|
||||||
{
|
{
|
||||||
|
/**
|
||||||
|
* Test for SUCCESS
|
||||||
|
*/
|
||||||
|
|
||||||
$response = $this->client->call(Client::METHOD_POST, '/functions/' . $data['functionId'] . '/variables', array_merge([
|
$response = $this->client->call(Client::METHOD_POST, '/functions/' . $data['functionId'] . '/variables', array_merge([
|
||||||
'content-type' => 'application/json',
|
'content-type' => 'application/json',
|
||||||
'x-appwrite-project' => $this->getProject()['$id'],
|
'x-appwrite-project' => $this->getProject()['$id'],
|
||||||
|
@ -116,39 +120,61 @@ class FunctionsConsoleClientTest extends Scope
|
||||||
]);
|
]);
|
||||||
|
|
||||||
$this->assertEquals(201, $response['headers']['status-code']);
|
$this->assertEquals(201, $response['headers']['status-code']);
|
||||||
|
$variableId = $response['body']['$id'];
|
||||||
return array_merge(
|
|
||||||
$data,
|
|
||||||
[
|
|
||||||
'variableId' => $response['body']['$id']
|
|
||||||
]
|
|
||||||
);
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Test for FAILURE
|
* Test for FAILURE
|
||||||
* @depends testCreateFunctionVariable
|
|
||||||
*/
|
*/
|
||||||
public function testCreateDuplicateVariable(array $data)
|
|
||||||
{
|
|
||||||
$response = $this->client->call(Client::METHOD_POST, '/functions/' . $data['functionId'] . '/variables', array_merge([
|
$response = $this->client->call(Client::METHOD_POST, '/functions/' . $data['functionId'] . '/variables', array_merge([
|
||||||
'content-type' => 'application/json',
|
'content-type' => 'application/json',
|
||||||
'x-appwrite-project' => $this->getProject()['$id'],
|
'x-appwrite-project' => $this->getProject()['$id'],
|
||||||
], $this->getHeaders()), [
|
], $this->getHeaders()), [
|
||||||
'key' => 'APP_TEST',
|
'key' => 'APP_TEST',
|
||||||
'value' => 'TESTINGVALUE'
|
'value' => 'ANOTHER_TESTINGVALUE'
|
||||||
]);
|
]);
|
||||||
|
|
||||||
$this->assertEquals(409, $response['headers']['status-code']);
|
$this->assertEquals(409, $response['headers']['status-code']);
|
||||||
|
|
||||||
return $data;
|
return array_merge(
|
||||||
|
$data,
|
||||||
|
[
|
||||||
|
'variableId' => $variableId
|
||||||
|
]
|
||||||
|
);
|
||||||
|
|
||||||
|
$longKey = str_repeat("A", 256);
|
||||||
|
$response = $this->client->call(Client::METHOD_POST, '/functions/' . $data['functionId'] . '/variables', array_merge([
|
||||||
|
'content-type' => 'application/json',
|
||||||
|
'x-appwrite-project' => $this->getProject()['$id'],
|
||||||
|
], $this->getHeaders()), [
|
||||||
|
'key' => $longKey,
|
||||||
|
'value' => 'TESTINGVALUE'
|
||||||
|
]);
|
||||||
|
|
||||||
|
$this->assertEquals(400, $response['headers']['status-code']);
|
||||||
|
|
||||||
|
$longValue = str_repeat("#", 8193);
|
||||||
|
$response = $this->client->call(Client::METHOD_POST, '/functions/' . $data['functionId'] . '/variables', array_merge([
|
||||||
|
'content-type' => 'application/json',
|
||||||
|
'x-appwrite-project' => $this->getProject()['$id'],
|
||||||
|
], $this->getHeaders()), [
|
||||||
|
'key' => 'LONGKEY',
|
||||||
|
'value' => $longValue
|
||||||
|
]);
|
||||||
|
|
||||||
|
$this->assertEquals(400, $response['headers']['status-code']);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @depends testCreateDuplicateVariable
|
* @depends testCreateFunctionVariable
|
||||||
*/
|
*/
|
||||||
public function testListVariables(array $data)
|
public function testListVariables(array $data)
|
||||||
{
|
{
|
||||||
|
/**
|
||||||
|
* Test for SUCCESS
|
||||||
|
*/
|
||||||
|
|
||||||
$response = $this->client->call(Client::METHOD_GET, '/functions/' . $data['functionId'] . '/variables', array_merge([
|
$response = $this->client->call(Client::METHOD_GET, '/functions/' . $data['functionId'] . '/variables', array_merge([
|
||||||
'content-type' => 'application/json',
|
'content-type' => 'application/json',
|
||||||
'x-appwrite-project' => $this->getProject()['$id'],
|
'x-appwrite-project' => $this->getProject()['$id'],
|
||||||
|
@ -201,6 +227,19 @@ class FunctionsConsoleClientTest extends Scope
|
||||||
$this->assertEquals(200, $response['headers']['status-code']);
|
$this->assertEquals(200, $response['headers']['status-code']);
|
||||||
$this->assertCount(1, $response['body']['variables']);
|
$this->assertCount(1, $response['body']['variables']);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Test for FAILURE
|
||||||
|
*/
|
||||||
|
|
||||||
|
$response = $this->client->call(Client::METHOD_GET, '/functions/' . $data['functionId'] . '/variables', array_merge([
|
||||||
|
'content-type' => 'application/json',
|
||||||
|
'x-appwrite-project' => $this->getProject()['$id'],
|
||||||
|
], $this->getHeaders()), [
|
||||||
|
'queries' => [ 'equal("value", "MY_SECRET")' ]
|
||||||
|
]);
|
||||||
|
|
||||||
|
$this->assertEquals(400, $response['headers']['status-code']);
|
||||||
|
|
||||||
return $data;
|
return $data;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -209,6 +248,10 @@ class FunctionsConsoleClientTest extends Scope
|
||||||
*/
|
*/
|
||||||
public function testGetVariable(array $data)
|
public function testGetVariable(array $data)
|
||||||
{
|
{
|
||||||
|
/**
|
||||||
|
* Test for SUCCESS
|
||||||
|
*/
|
||||||
|
|
||||||
$response = $this->client->call(Client::METHOD_GET, '/functions/' . $data['functionId'] . '/variables/' . $data['variableId'], array_merge([
|
$response = $this->client->call(Client::METHOD_GET, '/functions/' . $data['functionId'] . '/variables/' . $data['variableId'], array_merge([
|
||||||
'content-type' => 'application/json',
|
'content-type' => 'application/json',
|
||||||
'x-appwrite-project' => $this->getProject()['$id'],
|
'x-appwrite-project' => $this->getProject()['$id'],
|
||||||
|
@ -218,6 +261,17 @@ class FunctionsConsoleClientTest extends Scope
|
||||||
$this->assertEquals("APP_TEST", $response['body']['key']);
|
$this->assertEquals("APP_TEST", $response['body']['key']);
|
||||||
$this->assertEquals("TESTINGVALUE", $response['body']['value']);
|
$this->assertEquals("TESTINGVALUE", $response['body']['value']);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Test for FAILURE
|
||||||
|
*/
|
||||||
|
|
||||||
|
$response = $this->client->call(Client::METHOD_GET, '/functions/' . $data['functionId'] . '/variables/NON_EXISTING_VARIABLE', array_merge([
|
||||||
|
'content-type' => 'application/json',
|
||||||
|
'x-appwrite-project' => $this->getProject()['$id'],
|
||||||
|
], $this->getHeaders()));
|
||||||
|
|
||||||
|
$this->assertEquals(404, $response['headers']['status-code']);
|
||||||
|
|
||||||
return $data;
|
return $data;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -226,6 +280,10 @@ class FunctionsConsoleClientTest extends Scope
|
||||||
*/
|
*/
|
||||||
public function testUpdateVariable(array $data)
|
public function testUpdateVariable(array $data)
|
||||||
{
|
{
|
||||||
|
/**
|
||||||
|
* Test for SUCCESS
|
||||||
|
*/
|
||||||
|
|
||||||
$response = $this->client->call(Client::METHOD_PUT, '/functions/' . $data['functionId'] . '/variables/' . $data['variableId'], array_merge([
|
$response = $this->client->call(Client::METHOD_PUT, '/functions/' . $data['functionId'] . '/variables/' . $data['variableId'], array_merge([
|
||||||
'content-type' => 'application/json',
|
'content-type' => 'application/json',
|
||||||
'x-appwrite-project' => $this->getProject()['$id'],
|
'x-appwrite-project' => $this->getProject()['$id'],
|
||||||
|
@ -245,6 +303,32 @@ class FunctionsConsoleClientTest extends Scope
|
||||||
$this->assertEquals("APP_TEST_UPDATE", $variable['body']['key']);
|
$this->assertEquals("APP_TEST_UPDATE", $variable['body']['key']);
|
||||||
$this->assertEquals("TESTINGVALUEUPDATED", $variable['body']['value']);
|
$this->assertEquals("TESTINGVALUEUPDATED", $variable['body']['value']);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Test for FAILURE
|
||||||
|
*/
|
||||||
|
|
||||||
|
$longKey = str_repeat("A", 256);
|
||||||
|
$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' => $longKey,
|
||||||
|
'value' => 'TESTINGVALUEUPDATED'
|
||||||
|
]);
|
||||||
|
|
||||||
|
$this->assertEquals(400, $response['headers']['status-code']);
|
||||||
|
|
||||||
|
$longValue = str_repeat("#", 8193);
|
||||||
|
$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',
|
||||||
|
'value' => $longValue
|
||||||
|
]);
|
||||||
|
|
||||||
|
$this->assertEquals(400, $response['headers']['status-code']);
|
||||||
|
|
||||||
return $data;
|
return $data;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -253,6 +337,10 @@ class FunctionsConsoleClientTest extends Scope
|
||||||
*/
|
*/
|
||||||
public function testDeleteVariable(array $data)
|
public function testDeleteVariable(array $data)
|
||||||
{
|
{
|
||||||
|
/**
|
||||||
|
* Test for SUCCESS
|
||||||
|
*/
|
||||||
|
|
||||||
$response = $this->client->call(Client::METHOD_DELETE, '/functions/' . $data['functionId'] . '/variables/' . $data['variableId'], array_merge([
|
$response = $this->client->call(Client::METHOD_DELETE, '/functions/' . $data['functionId'] . '/variables/' . $data['variableId'], array_merge([
|
||||||
'content-type' => 'application/json',
|
'content-type' => 'application/json',
|
||||||
'x-appwrite-project' => $this->getProject()['$id'],
|
'x-appwrite-project' => $this->getProject()['$id'],
|
||||||
|
@ -268,6 +356,17 @@ class FunctionsConsoleClientTest extends Scope
|
||||||
$this->assertEquals(200, $response['headers']['status-code']);
|
$this->assertEquals(200, $response['headers']['status-code']);
|
||||||
$this->assertEquals(0, sizeof($response['body']['variables']));
|
$this->assertEquals(0, sizeof($response['body']['variables']));
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Test for FAILURE
|
||||||
|
*/
|
||||||
|
|
||||||
|
$response = $this->client->call(Client::METHOD_DELETE, '/functions/' . $data['functionId'] . '/variables/NON_EXISTING_VARIABLE', array_merge([
|
||||||
|
'content-type' => 'application/json',
|
||||||
|
'x-appwrite-project' => $this->getProject()['$id'],
|
||||||
|
], $this->getHeaders()));
|
||||||
|
|
||||||
|
$this->assertEquals(404, $response['headers']['status-code']);
|
||||||
|
|
||||||
return $data;
|
return $data;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue