1
0
Fork 0
mirror of synced 2024-07-02 21:20:58 +12:00

chore: add encrypt param on update string attr + unit tests

This commit is contained in:
Bishwajeet Parhi 2023-07-08 20:58:41 +05:30
parent 96f1284cbf
commit f71fdfb0b9
2 changed files with 42 additions and 1 deletions

View file

@ -351,6 +351,7 @@ function updateAttribute(
id: $key,
required: $required,
default: $default,
filters: [$filter],
formatOptions: $options ?? null
);
}
@ -1788,10 +1789,18 @@ App::patch('/v1/databases/:databaseId/collections/:collectionId/attributes/strin
->param('key', '', new Key(), 'Attribute Key.')
->param('required', null, new Boolean(), 'Is attribute required?')
->param('default', null, new Nullable(new Text(0, 0)), 'Default value for attribute when not provided. Cannot be set when attribute is required.')
->param('encrypt', null, new Boolean(), 'Encrypt attribute? Encrypting an attribute means that the attribute can not be queried.', true)
->inject('response')
->inject('dbForProject')
->inject('events')
->action(function (string $databaseId, string $collectionId, string $key, ?bool $required, ?string $default, Response $response, Database $dbForProject, Event $events) {
->action(function (string $databaseId, string $collectionId, string $key, ?bool $required, ?string $default, ?bool $encrypt, Response $response, Database $dbForProject, Event $events) {
$filter = '';
if ($encrypt != null) {
$filter = $encrypt ? 'encrypt' : 'decrypt';
}
$attribute = updateAttribute(
databaseId: $databaseId,
collectionId: $collectionId,
@ -1799,6 +1808,7 @@ App::patch('/v1/databases/:databaseId/collections/:collectionId/attributes/strin
dbForProject: $dbForProject,
events: $events,
type: Database::VAR_STRING,
filter: empty($filter) ? null : $filter,
default: $default,
required: $required
);

View file

@ -695,6 +695,37 @@ class DatabasesCustomServerTest extends Scope
$this->assertEquals(200, $document['headers']['status-code']);
$this->assertEquals('Jonah', $document['body']['firstName']);
$this->assertEquals('Jameson', $document['body']['lastName']);
/**
* Update Attribute
*/
$updatedFirstname = $this->client->call(Client::METHOD_PATCH, $attributesPath . '/string/' . $firstName['body']['key'], array_merge([
'content-type' => 'application/json',
'x-appwrite-project' => $this->getProject()['$id'],
'x-appwrite-key' => $this->getProject()['apiKey']
]), [
'required' => false,
'encrypt' => true,
'default' => ''
]);
$this->assertEquals(200, $updatedFirstname['headers']['status-code']);
$this->assertEquals('firstName', $updatedFirstname['body']['key']);
$this->assertEquals('string', $updatedFirstname['body']['type']);
$updatedLastName = $this->client->call(Client::METHOD_PATCH, $attributesPath . '/string/' . $lastName['body']['key'], array_merge([
'content-type' => 'application/json',
'x-appwrite-project' => $this->getProject()['$id'],
'x-appwrite-key' => $this->getProject()['apiKey'],
]), [
'required' => false,
'encrypt' => false,
'default' => ''
]);
$this->assertEquals(200, $updatedLastName['headers']['status-code']);
$this->assertEquals('lastName', $updatedLastName['body']['key']);
$this->assertEquals('string', $updatedLastName['body']['type']);
}
public function testDeleteAttribute(): array