tests: update attributes
This commit is contained in:
parent
ec7e28b3e7
commit
acd18b4d9d
1 changed files with 84 additions and 0 deletions
|
@ -1238,4 +1238,88 @@ class DatabasesCustomServerTest extends Scope
|
|||
|
||||
$this->assertEquals(204, $collection['headers']['status-code']);
|
||||
}
|
||||
|
||||
public function testAttributeUpdate()
|
||||
{
|
||||
$database = $this->client->call(Client::METHOD_POST, '/databases', array_merge([
|
||||
'content-type' => 'application/json',
|
||||
'x-appwrite-project' => $this->getProject()['$id'],
|
||||
'x-appwrite-key' => $this->getProject()['apiKey']
|
||||
]), [
|
||||
'databaseId' => ID::unique(),
|
||||
'name' => 'updateAttributes',
|
||||
]);
|
||||
$this->assertEquals(201, $database['headers']['status-code']);
|
||||
|
||||
$databaseId = $database['body']['$id'];
|
||||
$collection = $this->client->call(Client::METHOD_POST, '/databases/' . $databaseId . '/collections', array_merge([
|
||||
'content-type' => 'application/json',
|
||||
'x-appwrite-project' => $this->getProject()['$id'],
|
||||
'x-appwrite-key' => $this->getProject()['apiKey']
|
||||
]), [
|
||||
'collectionId' => ID::custom('updateAttributes'),
|
||||
'name' => 'updateAttributes'
|
||||
]);
|
||||
|
||||
$this->assertEquals(201, $collection['headers']['status-code']);
|
||||
|
||||
$collectionId = $collection['body']['$id'];
|
||||
|
||||
$attribute = $this->client->call(Client::METHOD_POST, '/databases/' . $databaseId . '/collections/' . $collectionId . '/attributes/string', array_merge([
|
||||
'content-type' => 'application/json',
|
||||
'x-appwrite-project' => $this->getProject()['$id'],
|
||||
'x-appwrite-key' => $this->getProject()['apiKey']
|
||||
]), [
|
||||
'key' => 'string',
|
||||
'size' => 1024,
|
||||
'required' => false,
|
||||
'default' => 'lorem'
|
||||
]);
|
||||
|
||||
$key = $attribute['body']['key'];
|
||||
|
||||
$this->assertEquals(202, $attribute['headers']['status-code']);
|
||||
|
||||
sleep(5);
|
||||
|
||||
$updateString = $this->client->call(Client::METHOD_PATCH, '/databases/' . $databaseId . '/collections/' . $collectionId . '/attributes/' . $key . '/string', array_merge([
|
||||
'content-type' => 'application/json',
|
||||
'x-appwrite-project' => $this->getProject()['$id'],
|
||||
'x-appwrite-key' => $this->getProject()['apiKey']
|
||||
]), [
|
||||
'required' => false,
|
||||
'default' => 'ipsum'
|
||||
]);
|
||||
|
||||
$this->assertEquals(202, $updateString['headers']['status-code']);
|
||||
|
||||
$newString = $this->client->call(Client::METHOD_GET, '/databases/' . $databaseId . '/collections/' . $collectionId . '/attributes/' . $key, array_merge([
|
||||
'content-type' => 'application/json',
|
||||
'x-appwrite-project' => $this->getProject()['$id'],
|
||||
'x-appwrite-key' => $this->getProject()['apiKey']
|
||||
]));
|
||||
|
||||
$this->assertFalse($newString['body']['required']);
|
||||
$this->assertEquals('ipsum', $newString['body']['default']);
|
||||
|
||||
$updateString = $this->client->call(Client::METHOD_PATCH, '/databases/' . $databaseId . '/collections/' . $collectionId . '/attributes/' . $key . '/string', array_merge([
|
||||
'content-type' => 'application/json',
|
||||
'x-appwrite-project' => $this->getProject()['$id'],
|
||||
'x-appwrite-key' => $this->getProject()['apiKey']
|
||||
]), [
|
||||
'required' => true,
|
||||
'default' => ''
|
||||
]);
|
||||
|
||||
$this->assertEquals(202, $updateString['headers']['status-code']);
|
||||
|
||||
$newString = $this->client->call(Client::METHOD_GET, '/databases/' . $databaseId . '/collections/' . $collectionId . '/attributes/' . $key, array_merge([
|
||||
'content-type' => 'application/json',
|
||||
'x-appwrite-project' => $this->getProject()['$id'],
|
||||
'x-appwrite-key' => $this->getProject()['apiKey']
|
||||
]));
|
||||
|
||||
$this->assertTrue($newString['body']['required']);
|
||||
$this->assertEquals('', $newString['body']['default']);
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue