diff --git a/acceptance_tests/lib/src/steps/customMessageType/customMessageType_steps.dart b/acceptance_tests/lib/src/steps/customMessageType/customMessageType_steps.dart index 8f95fc6f..c5210eeb 100644 --- a/acceptance_tests/lib/src/steps/customMessageType/customMessageType_steps.dart +++ b/acceptance_tests/lib/src/steps/customMessageType/customMessageType_steps.dart @@ -2,10 +2,17 @@ import '../../world.dart'; import 'package:gherkin/gherkin.dart'; import 'step_given_keyset.dart'; +import 'step_given_storage_enabled.dart'; import 'step_then_error_response.dart'; +import 'step_then_history_customMessageTypes.dart'; +import 'step_then_history_messages.dart'; import 'step_then_messagesContainsType.dart'; +import 'step_then_no_CustomType.dart'; import 'step_then_receive.dart'; import 'step_then_success_response.dart'; +import 'step_when_fetchMessages.dart'; +import 'step_when_fetch_custom_channel.dart'; +import 'step_when_fetch_with_custom.dart'; import 'step_when_publish_with_type.dart'; import 'step_when_sendFile.dart'; import 'step_when_signal_with_type.dart'; @@ -13,12 +20,19 @@ import 'step_when_subscribe.dart'; final List> customMessageTypeSteps = [ StepGivenTheDemoKeyset(), + StepGivenTheStorageEnabledKeyset(), StepWhenIPublishWithCustomType(), StepThenIReceiveSuccessfulResponsePublish(), StepThenIReceivePublishErrorResponse(), StepWhenISignalWithCustomType(), StepWhenISubscribeChannalForCustomMessageType(), + StepWhenFetchMessagesWithMessageType(), StepThenIReceiveMessagesInSubscriptionResponse(), StepThenReceivedMessagesHasMessageTypes(), + StepWhenFetchMessagesWithCustomMessageType(), + StepThenHistoryReceivedMessagesHasMessageTypesInt(), + StepWhenFetchMessagesWithParams(), StepWhenISendFileCustomType(), + StepThenReceivedMessagesNoCustomMessageTypes(), + StepThenHistoryReceivedMessagesHasCustomMessageTypes() ]; \ No newline at end of file diff --git a/acceptance_tests/lib/src/steps/customMessageType/step_given_storage_enabled.dart b/acceptance_tests/lib/src/steps/customMessageType/step_given_storage_enabled.dart new file mode 100644 index 00000000..6ddef942 --- /dev/null +++ b/acceptance_tests/lib/src/steps/customMessageType/step_given_storage_enabled.dart @@ -0,0 +1,17 @@ +import 'package:gherkin/gherkin.dart'; +import 'package:pubnub/pubnub.dart'; + +import '../../world.dart'; + +class StepGivenTheStorageEnabledKeyset extends GivenWithWorld { + @override + RegExp get pattern => RegExp(r'the demo keyset with enabled storage'); + + @override + Future executeStep() async { + world.keyset = Keyset( + publishKey: 'demo', + subscribeKey: 'demo', + userId: UserId('testCustomType')); + } +} diff --git a/acceptance_tests/lib/src/steps/customMessageType/step_then_history_customMessageTypes.dart b/acceptance_tests/lib/src/steps/customMessageType/step_then_history_customMessageTypes.dart new file mode 100644 index 00000000..8b8b5d09 --- /dev/null +++ b/acceptance_tests/lib/src/steps/customMessageType/step_then_history_customMessageTypes.dart @@ -0,0 +1,20 @@ +import 'package:gherkin/gherkin.dart'; +import 'package:test/expect.dart'; + +import '../../world.dart'; + +class StepThenHistoryReceivedMessagesHasCustomMessageTypes + extends Then2WithWorld { + @override + RegExp get pattern => RegExp( + r'history response contains messages with {string} and {string} types'); + + @override + Future executeStep( + String customMessageTypeOne, String customMessageTypeTwo) async { + world.historyMessages.forEach((message) { + this.expect(message.customMessageType, + anyOf([customMessageTypeOne, customMessageTypeTwo])); + }); + } +} diff --git a/acceptance_tests/lib/src/steps/customMessageType/step_then_history_messages.dart b/acceptance_tests/lib/src/steps/customMessageType/step_then_history_messages.dart new file mode 100644 index 00000000..c5d074bc --- /dev/null +++ b/acceptance_tests/lib/src/steps/customMessageType/step_then_history_messages.dart @@ -0,0 +1,20 @@ +import 'package:gherkin/gherkin.dart'; +import 'package:test/expect.dart'; + +import '../../world.dart'; + +class StepThenHistoryReceivedMessagesHasMessageTypesInt + extends Then2WithWorld { + @override + RegExp get pattern => + RegExp(r'history response contains messages with {string} and {string} message types'); + + @override + Future executeStep( + String customMessageTypeOne, String customMessageTypeTwo) async { + world.historyMessages.forEach((message) { + this.expect(message.messageType, + anyOf([customMessageTypeOne, customMessageTypeTwo])); + }); + } +} diff --git a/acceptance_tests/lib/src/steps/customMessageType/step_then_no_CustomType.dart b/acceptance_tests/lib/src/steps/customMessageType/step_then_no_CustomType.dart new file mode 100644 index 00000000..7d5c8463 --- /dev/null +++ b/acceptance_tests/lib/src/steps/customMessageType/step_then_no_CustomType.dart @@ -0,0 +1,22 @@ +// history response contains messages without customMessageType +import 'package:gherkin/gherkin.dart'; +import 'package:test/expect.dart'; + +import '../../world.dart'; + +class StepThenReceivedMessagesNoCustomMessageTypes + extends ThenWithWorld { + @override + RegExp get pattern => + RegExp(r'history response contains messages without customMessageType'); + + @override + Future executeStep( + ) async { + world.messages.forEach((message) { + expect( + message.customMessageType, + null); + }); + } +} diff --git a/acceptance_tests/lib/src/steps/customMessageType/step_when_fetchMessages.dart b/acceptance_tests/lib/src/steps/customMessageType/step_when_fetchMessages.dart new file mode 100644 index 00000000..cb594ff0 --- /dev/null +++ b/acceptance_tests/lib/src/steps/customMessageType/step_when_fetchMessages.dart @@ -0,0 +1,27 @@ +import 'package:gherkin/gherkin.dart'; +import 'package:pubnub/pubnub.dart'; + +import '../../world.dart'; + +class StepWhenFetchMessagesWithMessageType + extends When1WithWorld { + @override + RegExp get pattern => + RegExp(r'I fetch message history with messageType for {string} channel'); + + @override + Future executeStep(String channel) async { + try { + var batchResult = await world.pubnub.batch.fetchMessages({channel}, + includeMessageType: true); + (world.latestResult as BatchHistoryResult).channels.keys.forEach( (c) => + world.historyMessages.addAll(batchResult.channels[c] as Iterable) + ); + world.latestResult = batchResult; + world.latestResultType = 'fetchMessages'; + } catch (e) { + world.latestResultType = 'fetchMessagesWithMessageTypeTypeFailure'; + world.latestResult = e; + } + } +} diff --git a/acceptance_tests/lib/src/steps/customMessageType/step_when_fetch_custom_channel.dart b/acceptance_tests/lib/src/steps/customMessageType/step_when_fetch_custom_channel.dart new file mode 100644 index 00000000..0108a07d --- /dev/null +++ b/acceptance_tests/lib/src/steps/customMessageType/step_when_fetch_custom_channel.dart @@ -0,0 +1,27 @@ +import 'package:gherkin/gherkin.dart'; +import 'package:pubnub/pubnub.dart'; + +import '../../world.dart'; + +class StepWhenFetchMessagesWithParams + extends When3WithWorld { + @override + RegExp get pattern => + RegExp(r'I fetch message history with {string} set to {string} for {string} channel'); + + @override + Future executeStep(String includeCustomMessageType, String paramValue, String channel) async { + try { + var batchResult = await world.pubnub.batch + .fetchMessages({channel}, includeCustomMessageType: bool.parse(paramValue)); + (world.latestResult as BatchHistoryResult).channels.keys.forEach((c) => + world.historyMessages.addAll( + batchResult.channels[c] as Iterable)); + world.latestResult = batchResult; + world.latestResultType = 'fetchMessages'; + } catch (e) { + world.latestResultType = 'fetchMessagesWithMessageTypeTypeFailure'; + world.latestResult = e; + } + } +} diff --git a/acceptance_tests/lib/src/steps/customMessageType/step_when_fetch_with_custom.dart b/acceptance_tests/lib/src/steps/customMessageType/step_when_fetch_with_custom.dart new file mode 100644 index 00000000..ae6c6ab0 --- /dev/null +++ b/acceptance_tests/lib/src/steps/customMessageType/step_when_fetch_with_custom.dart @@ -0,0 +1,27 @@ +import 'package:gherkin/gherkin.dart'; +import 'package:pubnub/pubnub.dart'; + +import '../../world.dart'; + +class StepWhenFetchMessagesWithCustomMessageType + extends When1WithWorld { + @override + RegExp get pattern => + RegExp(r'When I fetch message history with customMessageType for {string} channel'); + + @override + Future executeStep(String channel) async { + try { + var batchResult = await world.pubnub.batch + .fetchMessages({channel}, includeMessageType: true, includeCustomMessageType: true); + (world.latestResult as BatchHistoryResult).channels.keys.forEach((c) => + world.historyMessages.addAll( + batchResult.channels[c] as Iterable)); + world.latestResult = batchResult; + world.latestResultType = 'fetchMessages'; + } catch (e) { + world.latestResultType = 'fetchMessagesWithMessageTypeTypeFailure'; + world.latestResult = e; + } + } +} diff --git a/acceptance_tests/lib/src/world.dart b/acceptance_tests/lib/src/world.dart index 9b1b2615..f494a65b 100644 --- a/acceptance_tests/lib/src/world.dart +++ b/acceptance_tests/lib/src/world.dart @@ -25,6 +25,7 @@ class PubNubWorld extends World { Subscription? currentSubscription; List messages = []; + List historyMessages = []; Completer firstMessageCompleter = Completer(); Future get firstMessage => firstMessageCompleter.future; diff --git a/pubnub/lib/src/dx/_endpoints/history.dart b/pubnub/lib/src/dx/_endpoints/history.dart index 3eec8bc7..dcba6b22 100644 --- a/pubnub/lib/src/dx/_endpoints/history.dart +++ b/pubnub/lib/src/dx/_endpoints/history.dart @@ -88,6 +88,7 @@ class BatchHistoryParams extends Parameters { bool? includeMessageActions; bool? includeUUID; bool? includeMessageType; + bool? includeCustomMessageType; BatchHistoryParams(this.keyset, this.channels, {this.max, @@ -97,6 +98,7 @@ class BatchHistoryParams extends Parameters { this.includeMeta, this.includeMessageActions, this.includeMessageType, + this.includeCustomMessageType, this.includeUUID}) : assert(channels.isNotEmpty); @@ -119,6 +121,8 @@ class BatchHistoryParams extends Parameters { if (includeMeta != null) 'include_meta': '$includeMeta', if (includeMessageType != null) 'include_message_type': '$includeMessageType', + if (includeCustomMessageType != null) + 'include_custom_message_type': '$includeCustomMessageType', if (includeUUID != null) 'include_uuid': '$includeUUID', if (keyset.authKey != null) 'auth': '${keyset.authKey}', 'uuid': '${keyset.uuid}' diff --git a/pubnub/lib/src/dx/batch/batch.dart b/pubnub/lib/src/dx/batch/batch.dart index 59986850..3309f5a8 100644 --- a/pubnub/lib/src/dx/batch/batch.dart +++ b/pubnub/lib/src/dx/batch/batch.dart @@ -29,6 +29,7 @@ class BatchDx { bool? includeMeta, bool includeMessageActions = false, bool includeMessageType = true, + bool includeCustomMessageType = false, bool includeUUID = true}) async { keyset ??= _core.keysets[using]; @@ -53,6 +54,7 @@ class BatchDx { includeMeta: includeMeta, includeMessageActions: includeMessageActions, includeMessageType: includeMessageType, + includeCustomMessageType: includeCustomMessageType, includeUUID: includeUUID); return defaultFlow(