Merge pull request #814 from christyjacob4/feat-na-response-filters

feat: e2e test for response filters
This commit is contained in:
Eldad A. Fux 2021-01-11 23:35:04 +02:00 committed by GitHub
commit 07a9fd1078
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
2 changed files with 39 additions and 2 deletions

View file

@ -252,9 +252,9 @@ class Response extends SwooleResponse
{
$output = $this->output($document, $model);
// If filter is set, parse the item
// If filter is set, parse the output
if(self::isFilter()){
$item = self::getFilter()->parse($output, $model);
$output = self::getFilter()->parse($output, $model);
}
$this->json(!empty($output) ? $output : new stdClass());

View file

@ -149,4 +149,41 @@ class HTTPTest extends Scope
unlink(realpath(__DIR__ . '/../../resources/open-api3.json'));
}
public function testResponseHeader() {
/**
* Test without header
*/
$response = $this->client->call(Client::METHOD_GET, '/locale/continents', array_merge([
'content-type' => 'application/json',
'x-appwrite-project' => 'console',
], $this->getHeaders()));
$body = $response['body'];
$this->assertEquals(200, $response['headers']['status-code']);
$this->assertEquals($body['sum'], 7);
$this->assertEquals($body['continents'][0]['name'], 'Africa');
$this->assertEquals($body['continents'][0]['code'], 'AF');
$this->assertEquals($body['continents'][1]['name'], 'Antarctica');
$this->assertEquals($body['continents'][1]['code'], 'AN');
$this->assertEquals($body['continents'][2]['name'], 'Asia');
$this->assertEquals($body['continents'][2]['code'], 'AS');
/**
* Test with header
*/
$response = $this->client->call(Client::METHOD_GET, '/locale/continents', array_merge([
'content-type' => 'application/json',
'x-appwrite-project' => 'console',
'x-appwrite-response-format' => '0.6.2'
], $this->getHeaders()));
$body = $response['body'];
$this->assertEquals(200, $response['headers']['status-code']);
$this->assertEquals($body['sum'], 7);
$this->assertEquals($body['continents']['AF'], 'Africa');
$this->assertEquals($body['continents']['AN'], 'Antarctica');
$this->assertEquals($body['continents']['AS'], 'Asia');
}
}