From 02c14c9662ef6015802e24a6bc8272157033ac13 Mon Sep 17 00:00:00 2001 From: James Fairhurst Date: Mon, 11 Mar 2019 13:05:36 +0000 Subject: [PATCH 1/4] Fix fetchMultipartMessages query params As the `getOptionalFields` method didn't return anything the api request didn't have any passed query params. --- src/Chatkit.php | 1 + tests/v3/MessageTest.php | 20 ++++++++++++++++++++ 2 files changed, 21 insertions(+) diff --git a/src/Chatkit.php b/src/Chatkit.php index 8f1c962..e28dd13 100755 --- a/src/Chatkit.php +++ b/src/Chatkit.php @@ -1140,6 +1140,7 @@ protected function getOptionalFields($field_names, $options) { $fields[$field_name] = $options[$field_name]; } } + return $fields; } /** diff --git a/tests/v3/MessageTest.php b/tests/v3/MessageTest.php index a8c3fcf..2ac910b 100644 --- a/tests/v3/MessageTest.php +++ b/tests/v3/MessageTest.php @@ -176,6 +176,26 @@ public function testFetchMultipartMessagesShouldReturnAResponsePayloadIfARoomIDL } } + public function testFetchMultipartMessagesShouldReturnAResponsePayloadIfARoomIDAndDirectionAreProvided() + { + $user_id = $this->makeUser(); + $room_id = $this->makeRoom($user_id); + + $messages = $this->makeMessages($room_id, [ [$user_id => 'hi first'], + [$user_id => 'hi last'], + ]); + + $get_msg_res = $this->chatkit->fetchMultipartMessages([ + 'room_id' => $room_id, + 'direction' => 'newer', + ]); + + $this->assertEquals(200, $get_msg_res['status']); + $this->assertEquals(count($messages), count($get_msg_res['body'])); + $this->assertEquals(array_values($messages)[0], $get_msg_res['body'][0]['parts'][0]['content']); + $this->assertEquals(array_values($messages)[1], $get_msg_res['body'][1]['parts'][0]['content']); + } + public function testFetchMultipartMessagesShouldReturnAResponsePayloadIfAnAttachmentProvided() { $user_id = $this->makeUser(); From 18418846b61e312fe7f0f1fa825bb7645c06dcab Mon Sep 17 00:00:00 2001 From: James Fairhurst Date: Mon, 11 Mar 2019 13:14:20 +0000 Subject: [PATCH 2/4] Fix failing test Was incorrectly using the count of the initial messages instead of the expected sliced messages. Originally passed as the query params where not being included in the request limiting the messages. --- tests/v3/MessageTest.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tests/v3/MessageTest.php b/tests/v3/MessageTest.php index 2ac910b..ea9c1f9 100644 --- a/tests/v3/MessageTest.php +++ b/tests/v3/MessageTest.php @@ -159,7 +159,7 @@ public function testFetchMultipartMessagesShouldReturnAResponsePayloadIfARoomIDL ]); $this->assertEquals(200, $get_msg_res['status']); - $this->assertEquals(count($messages), count($get_msg_res['body'])); + $this->assertEquals(count($sliced_messages), count($get_msg_res['body'])); $parts = [ $get_msg_res['body'][0]['parts'][0], $get_msg_res['body'][1]['parts'][0] ]; From 2f21ae1b6ec97836f2c9994248b0bd6be5432a72 Mon Sep 17 00:00:00 2001 From: James Fairhurst Date: Mon, 11 Mar 2019 13:17:13 +0000 Subject: [PATCH 3/4] Add additional fetchMultipartMessages direction test Cover both newer & older directions --- tests/v3/MessageTest.php | 22 +++++++++++++++++++++- 1 file changed, 21 insertions(+), 1 deletion(-) diff --git a/tests/v3/MessageTest.php b/tests/v3/MessageTest.php index ea9c1f9..21381c1 100644 --- a/tests/v3/MessageTest.php +++ b/tests/v3/MessageTest.php @@ -176,7 +176,7 @@ public function testFetchMultipartMessagesShouldReturnAResponsePayloadIfARoomIDL } } - public function testFetchMultipartMessagesShouldReturnAResponsePayloadIfARoomIDAndDirectionAreProvided() + public function testFetchMultipartMessagesShouldReturnAResponsePayloadIfARoomIDAndNewerDirectionAreProvided() { $user_id = $this->makeUser(); $room_id = $this->makeRoom($user_id); @@ -196,6 +196,26 @@ public function testFetchMultipartMessagesShouldReturnAResponsePayloadIfARoomIDA $this->assertEquals(array_values($messages)[1], $get_msg_res['body'][1]['parts'][0]['content']); } + public function testFetchMultipartMessagesShouldReturnAResponsePayloadIfARoomIDAndOlderDirectionAreProvided() + { + $user_id = $this->makeUser(); + $room_id = $this->makeRoom($user_id); + + $messages = $this->makeMessages($room_id, [ [$user_id => 'hi first'], + [$user_id => 'hi last'], + ]); + + $get_msg_res = $this->chatkit->fetchMultipartMessages([ + 'room_id' => $room_id, + 'direction' => 'older', + ]); + + $this->assertEquals(200, $get_msg_res['status']); + $this->assertEquals(count($messages), count($get_msg_res['body'])); + $this->assertEquals(array_values($messages)[0], $get_msg_res['body'][1]['parts'][0]['content']); + $this->assertEquals(array_values($messages)[1], $get_msg_res['body'][0]['parts'][0]['content']); + } + public function testFetchMultipartMessagesShouldReturnAResponsePayloadIfAnAttachmentProvided() { $user_id = $this->makeUser(); From c51cfa6db9240f8523df92f379776df06779beb3 Mon Sep 17 00:00:00 2001 From: James Fairhurst Date: Mon, 11 Mar 2019 13:21:54 +0000 Subject: [PATCH 4/4] Update CHANGELOG.md --- CHANGELOG.md | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index d1b3acb..db912a9 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -6,6 +6,10 @@ and this project adheres to [Semantic Versioning](http://semver.org/spec/v2.0.0. ## [Unreleased](https://github.com/pusher/chatkit-server-php/compare/1.2.0...HEAD) +### Fixed + +- `fetchMultipartMessages` now uses passed query params + ## [1.2.0](https://github.com/pusher/chatkit-server-php/compare/1.1.0...1.2.0) - 2019-03-08 ### Added