1
0
Fork 0
mirror of synced 2024-06-25 09:40:29 +12:00

Added DB search tests

This commit is contained in:
eldadfux 2019-09-20 15:46:57 +03:00
parent d3c83dbf49
commit d02c813f0a
2 changed files with 75 additions and 2 deletions

View file

@ -209,7 +209,7 @@ $utopia->init(function() use ($utopia, $request, $response, $register, &$user, $
$abuse = new Abuse($timeLimit);
if($timeLimit->limit() && $request->getServer('_APP_OPTIONS_ABUSE', 'enabled') !== 'disabled') {
if($timeLimit->limit()) {
$response
->addHeader('X-RateLimit-Limit', $timeLimit->limit())
->addHeader('X-RateLimit-Remaining', $timeLimit->remaining())
@ -217,7 +217,7 @@ $utopia->init(function() use ($utopia, $request, $response, $register, &$user, $
;
}
if($abuse->check()) {
if($abuse->check() && $request->getServer('_APP_OPTIONS_ABUSE', 'enabled') !== 'disabled') {
throw new Exception('Too many requests', 429);
}
});

View file

@ -259,4 +259,77 @@ class ProjectDatabaseTest extends BaseProjects
$this->assertEquals(2019, $documents['body']['documents'][1]['releaseYear']);
$this->assertCount(2, $documents['body']['documents']);
}
/**
* @depends testDocumentCreateSuccess
*/
public function testDocumentsListSuccessFirstAndLast($data) {
$documents = $this->client->call(Client::METHOD_GET, '/database/' . $data['collectionId'] . '/documents', [
'content-type' => 'application/json',
'x-appwrite-project' => $data['projectUid'],
'x-appwrite-key' => $data['projectAPIKeySecret'],
], [
'limit' => 1,
'order-field' => 'releaseYear',
'order-type' => 'ASC',
'order-cast' => 'int',
'first' => true,
]);
$this->assertEquals(1944, $documents['body']['releaseYear']);
$documents = $this->client->call(Client::METHOD_GET, '/database/' . $data['collectionId'] . '/documents', [
'content-type' => 'application/json',
'x-appwrite-project' => $data['projectUid'],
'x-appwrite-key' => $data['projectAPIKeySecret'],
], [
'limit' => 2,
'offset' => 1,
'order-field' => 'releaseYear',
'order-type' => 'ASC',
'order-cast' => 'int',
'last' => true,
]);
$this->assertEquals(2019, $documents['body']['releaseYear']);
}
/**
* @depends testDocumentCreateSuccess
*/
public function testDocumentsListSuccessSerach($data) {
$documents = $this->client->call(Client::METHOD_GET, '/database/' . $data['collectionId'] . '/documents', [
'content-type' => 'application/json',
'x-appwrite-project' => $data['projectUid'],
'x-appwrite-key' => $data['projectAPIKeySecret'],
], [
'search' => 'Captain America',
]);
$this->assertEquals(1944, $documents['body']['documents'][0]['releaseYear']);
$this->assertCount(1, $documents['body']['documents']);
$documents = $this->client->call(Client::METHOD_GET, '/database/' . $data['collectionId'] . '/documents', [
'content-type' => 'application/json',
'x-appwrite-project' => $data['projectUid'],
'x-appwrite-key' => $data['projectAPIKeySecret'],
], [
'search' => 'Homecoming',
]);
$this->assertEquals(2017, $documents['body']['documents'][0]['releaseYear']);
$this->assertCount(1, $documents['body']['documents']);
$documents = $this->client->call(Client::METHOD_GET, '/database/' . $data['collectionId'] . '/documents', [
'content-type' => 'application/json',
'x-appwrite-project' => $data['projectUid'],
'x-appwrite-key' => $data['projectAPIKeySecret'],
], [
'search' => 'spider',
]);
$this->assertEquals(2019, $documents['body']['documents'][0]['releaseYear']);
$this->assertEquals(2017, $documents['body']['documents'][1]['releaseYear']);
$this->assertCount(2, $documents['body']['documents']);
}
}