From e03748e74aedd97896b7f248b924c0508791bf9a Mon Sep 17 00:00:00 2001 From: Christy Jacob Date: Mon, 11 Jan 2021 19:18:01 +0530 Subject: [PATCH 1/3] fix: output of parse was not being used --- src/Appwrite/Utopia/Response.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/Appwrite/Utopia/Response.php b/src/Appwrite/Utopia/Response.php index ce22df225e..7e49df9197 100644 --- a/src/Appwrite/Utopia/Response.php +++ b/src/Appwrite/Utopia/Response.php @@ -257,7 +257,7 @@ class Response extends SwooleResponse $item = self::getFilter()->parse($output, $model); } - $this->json($output); + $this->json($item); } From dde064665bef3c8855243efe0c6277461ccb894e Mon Sep 17 00:00:00 2001 From: Christy Jacob Date: Mon, 11 Jan 2021 19:20:54 +0530 Subject: [PATCH 2/3] fix: output of parse was not being used --- src/Appwrite/Utopia/Response.php | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/src/Appwrite/Utopia/Response.php b/src/Appwrite/Utopia/Response.php index 7e49df9197..23a878046c 100644 --- a/src/Appwrite/Utopia/Response.php +++ b/src/Appwrite/Utopia/Response.php @@ -252,12 +252,12 @@ 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($item); + $this->json($output); } From 432901dfbba9e6f3e7c7dc234a66a8a56daaf3d7 Mon Sep 17 00:00:00 2001 From: Christy Jacob Date: Mon, 11 Jan 2021 22:18:08 +0530 Subject: [PATCH 3/3] feat: added e2e test for response filters --- tests/e2e/General/HTTPTest.php | 37 ++++++++++++++++++++++++++++++++++ 1 file changed, 37 insertions(+) diff --git a/tests/e2e/General/HTTPTest.php b/tests/e2e/General/HTTPTest.php index 46672c1a71..1282a9e480 100644 --- a/tests/e2e/General/HTTPTest.php +++ b/tests/e2e/General/HTTPTest.php @@ -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'); + } } \ No newline at end of file