mirror of
https://github.com/appwrite/appwrite.git
synced 2026-05-26 13:51:13 +00:00
Add site variables tests
This commit is contained in:
@@ -59,11 +59,10 @@ class Create extends Base
|
||||
->param('secret', false, new Boolean(), 'Is secret? Secret variables can only be updated or deleted, they cannot be read.', true)
|
||||
->inject('response')
|
||||
->inject('dbForProject')
|
||||
->inject('dbForPlatform')
|
||||
->callback([$this, 'action']);
|
||||
}
|
||||
|
||||
public function action(string $siteId, string $key, string $value, bool $secret, Response $response, Database $dbForProject, Database $dbForPlatform)
|
||||
public function action(string $siteId, string $key, string $value, bool $secret, Response $response, Database $dbForProject)
|
||||
{
|
||||
$site = $dbForProject->getDocument('sites', $siteId);
|
||||
|
||||
|
||||
@@ -103,6 +103,46 @@ trait SitesBase
|
||||
return $variable;
|
||||
}
|
||||
|
||||
protected function getVariable(string $siteId, string $variableId): mixed
|
||||
{
|
||||
$variable = $this->client->call(Client::METHOD_GET, '/sites/' . $siteId . '/variables/' . $variableId, array_merge([
|
||||
'content-type' => 'application/json',
|
||||
'x-appwrite-project' => $this->getProject()['$id'],
|
||||
], $this->getHeaders()));
|
||||
|
||||
return $variable;
|
||||
}
|
||||
|
||||
protected function listVariables(string $siteId, mixed $params = []): mixed
|
||||
{
|
||||
$variables = $this->client->call(Client::METHOD_GET, '/sites/' . $siteId . '/variables', array_merge([
|
||||
'content-type' => 'application/json',
|
||||
'x-appwrite-project' => $this->getProject()['$id'],
|
||||
], $this->getHeaders()), $params);
|
||||
|
||||
return $variables;
|
||||
}
|
||||
|
||||
protected function updateVariable(string $siteId, string $variableId, mixed $params): mixed
|
||||
{
|
||||
$variable = $this->client->call(Client::METHOD_PUT, '/sites/' . $siteId . '/variables/' . $variableId, array_merge([
|
||||
'content-type' => 'application/json',
|
||||
'x-appwrite-project' => $this->getProject()['$id'],
|
||||
], $this->getHeaders()), $params);
|
||||
|
||||
return $variable;
|
||||
}
|
||||
|
||||
protected function deleteVariable(string $siteId, string $variableId): mixed
|
||||
{
|
||||
$variable = $this->client->call(Client::METHOD_DELETE, '/sites/' . $siteId . '/variables/' . $variableId, array_merge([
|
||||
'content-type' => 'application/json',
|
||||
'x-appwrite-project' => $this->getProject()['$id'],
|
||||
], $this->getHeaders()));
|
||||
|
||||
return $variable;
|
||||
}
|
||||
|
||||
protected function getSite(string $siteId): mixed
|
||||
{
|
||||
$site = $this->client->call(Client::METHOD_GET, '/sites/' . $siteId, array_merge([
|
||||
|
||||
@@ -65,6 +65,149 @@ class SitesCustomServerTest extends Scope
|
||||
$this->cleanupSite($siteId);
|
||||
}
|
||||
|
||||
public function testVariables(): void
|
||||
{
|
||||
// create site
|
||||
$site = $this->createSite([
|
||||
'buildRuntime' => 'ssr-22',
|
||||
'fallbackFile' => null,
|
||||
'framework' => 'other',
|
||||
'name' => 'Test Site',
|
||||
'outputDirectory' => './',
|
||||
'siteId' => ID::unique()
|
||||
]);
|
||||
|
||||
$siteId = $site['body']['$id'] ?? '';
|
||||
|
||||
$this->assertEquals(201, $site['headers']['status-code']);
|
||||
$this->assertNotEmpty($site['body']['$id']);
|
||||
$this->assertEquals('Test Site', $site['body']['name']);
|
||||
|
||||
// create variable
|
||||
$variable = $this->createVariable($siteId, [
|
||||
'key' => 'siteKey1',
|
||||
'value' => 'siteValue1',
|
||||
]);
|
||||
|
||||
$this->assertEquals(201, $variable['headers']['status-code']);
|
||||
$this->assertNotEmpty($variable['body']['$id']);
|
||||
$this->assertEquals('siteKey1', $variable['body']['key']);
|
||||
$this->assertEquals('siteValue1', $variable['body']['value']);
|
||||
|
||||
$variable2 = $this->createVariable($siteId, [
|
||||
'key' => 'siteKey2',
|
||||
'value' => 'siteValue2',
|
||||
]);
|
||||
|
||||
$this->assertEquals(201, $variable2['headers']['status-code']);
|
||||
$this->assertNotEmpty($variable2['body']['$id']);
|
||||
$this->assertEquals('siteKey2', $variable2['body']['key']);
|
||||
$this->assertEquals('siteValue2', $variable2['body']['value']);
|
||||
|
||||
// create secret variable
|
||||
$secretVariable = $this->createVariable($siteId, [
|
||||
'key' => 'siteKey3',
|
||||
'value' => 'siteValue3',
|
||||
'secret' => true,
|
||||
]);
|
||||
|
||||
$this->assertEquals(201, $secretVariable['headers']['status-code']);
|
||||
$this->assertNotEmpty($secretVariable['body']['$id']);
|
||||
$this->assertEquals('siteKey3', $secretVariable['body']['key']);
|
||||
$this->assertEquals('', $secretVariable['body']['value']);
|
||||
$this->assertEquals(true, $secretVariable['body']['secret']);
|
||||
|
||||
// get variable
|
||||
$variable = $this->getVariable($siteId, $variable['body']['$id']);
|
||||
|
||||
$this->assertEquals(200, $variable['headers']['status-code']);
|
||||
$this->assertNotEmpty($variable['body']['$id']);
|
||||
$this->assertEquals('siteKey1', $variable['body']['key']);
|
||||
$this->assertEquals('siteValue1', $variable['body']['value']);
|
||||
$this->assertEquals(false, $variable['body']['secret']);
|
||||
|
||||
// get secret variable
|
||||
$secretVariable = $this->getVariable($siteId, $secretVariable['body']['$id']);
|
||||
|
||||
$this->assertEquals(200, $secretVariable['headers']['status-code']);
|
||||
$this->assertNotEmpty($secretVariable['body']['$id']);
|
||||
$this->assertEquals('siteKey3', $secretVariable['body']['key']);
|
||||
$this->assertEquals('', $secretVariable['body']['value']);
|
||||
$this->assertEquals(true, $secretVariable['body']['secret']);
|
||||
|
||||
// update variable
|
||||
$variable = $this->updateVariable($siteId, $variable['body']['$id'], [
|
||||
'key' => 'siteKey1Updated',
|
||||
'value' => 'siteValue1Updated',
|
||||
]);
|
||||
|
||||
$this->assertEquals(200, $variable['headers']['status-code']);
|
||||
$this->assertNotEmpty($variable['body']['$id']);
|
||||
$this->assertEquals('siteKey1Updated', $variable['body']['key']);
|
||||
$this->assertEquals('siteValue1Updated', $variable['body']['value']);
|
||||
|
||||
// update variable to secret
|
||||
$variable = $this->updateVariable($siteId, $variable['body']['$id'], [
|
||||
'key' => 'siteKey1Updated',
|
||||
'secret' => true,
|
||||
]);
|
||||
|
||||
$this->assertEquals(200, $variable['headers']['status-code']);
|
||||
$this->assertNotEmpty($variable['body']['$id']);
|
||||
$this->assertEquals('siteKey1Updated', $variable['body']['key']);
|
||||
$this->assertEquals('', $variable['body']['value']);
|
||||
$this->assertEquals(true, $variable['body']['secret']);
|
||||
|
||||
// update value of secret variable
|
||||
$secretVariable = $this->updateVariable($siteId, $secretVariable['body']['$id'], [
|
||||
'key' => 'siteKey3',
|
||||
'value' => 'siteValue3Updated',
|
||||
'secret' => true
|
||||
]);
|
||||
|
||||
$this->assertEquals(200, $secretVariable['headers']['status-code']);
|
||||
$this->assertNotEmpty($secretVariable['body']['$id']);
|
||||
$this->assertEquals('siteKey3', $secretVariable['body']['key']);
|
||||
$this->assertEquals('', $secretVariable['body']['value']);
|
||||
$this->assertEquals(true, $secretVariable['body']['secret']);
|
||||
|
||||
// update secret variable to non-secret
|
||||
$temp = $this->updateVariable($siteId, $secretVariable['body']['$id'], [
|
||||
'key' => 'siteKey3',
|
||||
'secret' => false,
|
||||
]);
|
||||
|
||||
$this->assertEquals(400, $temp['headers']['status-code']);
|
||||
|
||||
// get secret variable
|
||||
$secretVariable = $this->getVariable($siteId, $secretVariable['body']['$id']);
|
||||
|
||||
$this->assertEquals(200, $secretVariable['headers']['status-code']);
|
||||
$this->assertNotEmpty($secretVariable['body']['$id']);
|
||||
$this->assertEquals('siteKey3', $secretVariable['body']['key']);
|
||||
$this->assertEquals('', $secretVariable['body']['value']);
|
||||
$this->assertEquals(true, $secretVariable['body']['secret']);
|
||||
|
||||
// list variables
|
||||
$variables = $this->listVariables($siteId);
|
||||
|
||||
$this->assertEquals(200, $variables['headers']['status-code']);
|
||||
$this->assertCount(3, $variables['body']['variables']);
|
||||
|
||||
// delete variable
|
||||
$this->deleteVariable($siteId, $variable['body']['$id']);
|
||||
$this->deleteVariable($siteId, $variable2['body']['$id']);
|
||||
$this->deleteVariable($siteId, $secretVariable['body']['$id']);
|
||||
|
||||
// list variables
|
||||
$variables = $this->listVariables($siteId);
|
||||
|
||||
$this->assertEquals(200, $variables['headers']['status-code']);
|
||||
$this->assertCount(0, $variables['body']['variables']);
|
||||
|
||||
$this->cleanupSite($siteId);
|
||||
}
|
||||
|
||||
public function testListSites(): void
|
||||
{
|
||||
/**
|
||||
|
||||
Reference in New Issue
Block a user