From ffe87020844168550447ca2c85d40a711248443d Mon Sep 17 00:00:00 2001 From: Sebastian Molenda Date: Tue, 19 Nov 2024 14:06:21 +0100 Subject: [PATCH] fixes after review --- examples/cli/pub.php | 2 +- .../MessagePersistance/FetchMessages.php | 2 +- .../CustomMessageTypeContext.php | 29 +++++++++++++++++ .../history-custom-mssg-type.feature | 25 --------------- tests/integrational/FetchMessagesTest.php | 32 +++++++++++-------- 5 files changed, 49 insertions(+), 41 deletions(-) delete mode 100644 tests/Acceptance/CustomMessageType/history-custom-mssg-type.feature diff --git a/examples/cli/pub.php b/examples/cli/pub.php index 431d20a..ce50949 100644 --- a/examples/cli/pub.php +++ b/examples/cli/pub.php @@ -10,7 +10,7 @@ use PubNub\PubNub; use PubNub\PNConfiguration; -if ($argc < 3) { +if ($argc < 5) { echo "Usage: php pub.php \n"; exit(1); } diff --git a/src/PubNub/Endpoints/MessagePersistance/FetchMessages.php b/src/PubNub/Endpoints/MessagePersistance/FetchMessages.php index 27d8223..ecc60fb 100644 --- a/src/PubNub/Endpoints/MessagePersistance/FetchMessages.php +++ b/src/PubNub/Endpoints/MessagePersistance/FetchMessages.php @@ -33,7 +33,7 @@ class FetchMessages extends Endpoint protected bool $includeUuid = false; protected bool $includeMessageType = true; protected bool $includeMessageActions = false; - protected bool $includeCustomMessageType = true; + protected bool $includeCustomMessageType = false; protected array $customParamMapping = [ 'start' => 'start', diff --git a/tests/Acceptance/CustomMessageType/CustomMessageTypeContext.php b/tests/Acceptance/CustomMessageType/CustomMessageTypeContext.php index ce40c48..c19d838 100644 --- a/tests/Acceptance/CustomMessageType/CustomMessageTypeContext.php +++ b/tests/Acceptance/CustomMessageType/CustomMessageTypeContext.php @@ -87,6 +87,35 @@ public function iFetchMessageHistoryWithSetToForChannel(string $attribute, strin } } + /** + * @When I fetch message history with messageType for :channelName channel + */ + public function iFetchMessageHistoryWithMessagetypeForChannel($channelName) + { + $this->channelName = $channelName; + $builder = $this->pubnub->fetchMessages()->channels($this->channelName)->includeMessageType(true); + try { + $this->response = $builder->sync(); + } catch (PubNubServerException $e) { + $this->response = $e; + } + } + + /** + * @When I fetch message history with customMessageType for :channelName channel + */ + public function iFetchMessageHistoryWithCustommessagetypeForChannel($channelName) + { + $this->channelName = $channelName; + $builder = $this->pubnub->fetchMessages()->channels($this->channelName)->includeCustomMessageType(true); + + try { + $this->response = $builder->sync(); + } catch (PubNubServerException $e) { + $this->response = $e; + } + } + /** * @Then history response contains messages with :messageType1 and :messageType2 message types */ diff --git a/tests/Acceptance/CustomMessageType/history-custom-mssg-type.feature b/tests/Acceptance/CustomMessageType/history-custom-mssg-type.feature deleted file mode 100644 index f46a07c..0000000 --- a/tests/Acceptance/CustomMessageType/history-custom-mssg-type.feature +++ /dev/null @@ -1,25 +0,0 @@ -@featureSet=historyCustomMssgType @beta -Feature: History for VSP - As a PubNub user I want to fetch history with message type. - Client should be able to opt-out default `includeType`. - - Background: - Given the demo keyset with enabled storage - - @contract=fetchHistoryWithPubNubMessageTypes - Scenario: Client can fetch history with message types - When I fetch message history for 'simple-channel' channel - Then I receive a successful response - And history response contains messages with '0' and '4' message types - - @contract=fetchHistoryWithUserAndPubNubTypes - Scenario: Client can fetch history with customMessageType - When I fetch message history for 'some-channel' channel - Then I receive a successful response - And history response contains messages with 'custom-message-type' and 'user-custom-message-type' types - - @contract=fetchHistoryWithoutTypes - Scenario: Client can fetch history without customMessageType enabled by default - When I fetch message history with 'include_custom_message_type' set to 'false' for 'some-channel' channel - Then I receive a successful response - And history response contains messages without customMessageType diff --git a/tests/integrational/FetchMessagesTest.php b/tests/integrational/FetchMessagesTest.php index a2045d8..ddf4cc9 100644 --- a/tests/integrational/FetchMessagesTest.php +++ b/tests/integrational/FetchMessagesTest.php @@ -22,17 +22,18 @@ class FetchMessagesTest extends PubNubTestCase public function testFetchWithDefaults() { - $fetchMessages = new FetchMessagesExposed($this->pubnub); + $subKey = $this->pubnub_demo->getConfiguration()->getSubscribeKey(); + $fetchMessages = new FetchMessagesExposed($this->pubnub_demo); $fetchMessages ->stubFor("/v3/history/sub-key/demo/channel/TheMessageHistoryChannelHD") ->withQuery([ - "uuid" => $this->pubnub->getConfiguration()->getUserId(), + "uuid" => $this->pubnub_demo->getConfiguration()->getUserId(), "pnsdk" => $this->encodedSdkName, "include_meta" => "false", "include_uuid" => "false", "include_message_type" => "true", - "include_custom_message_type" => "true", + "include_custom_message_type" => "false", ]) ->setResponseBody('{"status": 200, "error": false, "error_message": "", "channels": {"TheMessageHistoryChannelHD":[ @@ -59,18 +60,19 @@ public function testFetchWithDefaults() public function testFetchWithCount() { - $fetchMessages = new FetchMessagesExposed($this->pubnub); + $subKey = $this->pubnub_demo->getConfiguration()->getSubscribeKey(); + $fetchMessages = new FetchMessagesExposed($this->pubnub_demo); $fetchMessages - ->stubFor("/v3/history/sub-key/demo/channel/TheMessageHistoryChannelHD") + ->stubFor("/v3/history/sub-key/{$subKey}/channel/TheMessageHistoryChannelHD") ->withQuery([ "max" => "5", - "uuid" => $this->pubnub->getConfiguration()->getUserId(), + "uuid" => $this->pubnub_demo->getConfiguration()->getUserId(), "pnsdk" => $this->encodedSdkName, "include_meta" => "false", "include_uuid" => "false", "include_message_type" => "true", - "include_custom_message_type" => "true", + "include_custom_message_type" => "false", ]) ->setResponseBody('{"status": 200, "error": false, "error_message": "", "channels": {"TheMessageHistoryChannelHD":[ @@ -92,19 +94,20 @@ public function testFetchWithCount() public function testFetchWithStartEnd() { - $fetchMessages = new FetchMessagesExposed($this->pubnub); + $subKey = $this->pubnub_demo->getConfiguration()->getSubscribeKey(); + $fetchMessages = new FetchMessagesExposed($this->pubnub_demo); $fetchMessages - ->stubFor("/v3/history/sub-key/demo/channel/TheMessageHistoryChannelHD") + ->stubFor("/v3/history/sub-key/{$subKey}/channel/TheMessageHistoryChannelHD") ->withQuery([ "start" => "17165627042258346", "end" => "17165627042258546", - "uuid" => $this->pubnub->getConfiguration()->getUserId(), + "uuid" => $this->pubnub_demo->getConfiguration()->getUserId(), "pnsdk" => $this->encodedSdkName, "include_meta" => "false", "include_uuid" => "false", "include_message_type" => "true", - "include_custom_message_type" => "true", + "include_custom_message_type" => "false", ]) ->setResponseBody('{"status": 200, "error": false, "error_message": "", "channels": {"TheMessageHistoryChannelHD":[ @@ -126,17 +129,18 @@ public function testFetchWithStartEnd() public function testFetchEncrypted() { + $subKey = $this->pubnub_enc->getConfiguration()->getSubscribeKey(); $fetchMessages = new FetchMessagesExposed($this->pubnub_enc); $fetchMessages - ->stubFor("/v3/history/sub-key/demo/channel/TheMessageHistoryChannelHD-ENCRYPTED") + ->stubFor("/v3/history/sub-key/{$subKey}/channel/TheMessageHistoryChannelHD-ENCRYPTED") ->withQuery([ - "uuid" => $this->pubnub->getConfiguration()->getUserId(), + "uuid" => $this->pubnub_enc->getConfiguration()->getUserId(), "pnsdk" => $this->encodedSdkName, "include_meta" => "false", "include_uuid" => "false", "include_message_type" => "true", - "include_custom_message_type" => "true", + "include_custom_message_type" => "false", ]) ->setResponseBody('{"status": 200, "error": false, "error_message": "", "channels": {