Added DB search tests
This commit is contained in:
parent
d3c83dbf49
commit
d02c813f0a
2 changed files with 75 additions and 2 deletions
|
@ -209,7 +209,7 @@ $utopia->init(function() use ($utopia, $request, $response, $register, &$user, $
|
||||||
|
|
||||||
$abuse = new Abuse($timeLimit);
|
$abuse = new Abuse($timeLimit);
|
||||||
|
|
||||||
if($timeLimit->limit() && $request->getServer('_APP_OPTIONS_ABUSE', 'enabled') !== 'disabled') {
|
if($timeLimit->limit()) {
|
||||||
$response
|
$response
|
||||||
->addHeader('X-RateLimit-Limit', $timeLimit->limit())
|
->addHeader('X-RateLimit-Limit', $timeLimit->limit())
|
||||||
->addHeader('X-RateLimit-Remaining', $timeLimit->remaining())
|
->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);
|
throw new Exception('Too many requests', 429);
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
|
@ -259,4 +259,77 @@ class ProjectDatabaseTest extends BaseProjects
|
||||||
$this->assertEquals(2019, $documents['body']['documents'][1]['releaseYear']);
|
$this->assertEquals(2019, $documents['body']['documents'][1]['releaseYear']);
|
||||||
$this->assertCount(2, $documents['body']['documents']);
|
$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']);
|
||||||
|
}
|
||||||
}
|
}
|
Loading…
Reference in a new issue