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 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..21381c1 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] ]; @@ -176,6 +176,46 @@ public function testFetchMultipartMessagesShouldReturnAResponsePayloadIfARoomIDL } } + public function testFetchMultipartMessagesShouldReturnAResponsePayloadIfARoomIDAndNewerDirectionAreProvided() + { + $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 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();