Skip to content

Commit

Permalink
fix: missing customMessageType support in history (#129)
Browse files Browse the repository at this point in the history
  • Loading branch information
mohitpubnub authored Dec 11, 2024
1 parent a333aaa commit 14fb57b
Show file tree
Hide file tree
Showing 11 changed files with 181 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -2,23 +2,37 @@ 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';
import 'step_when_subscribe.dart';

final List<StepDefinitionGeneric<PubNubWorld>> customMessageTypeSteps = [
StepGivenTheDemoKeyset(),
StepGivenTheStorageEnabledKeyset(),
StepWhenIPublishWithCustomType(),
StepThenIReceiveSuccessfulResponsePublish(),
StepThenIReceivePublishErrorResponse(),
StepWhenISignalWithCustomType(),
StepWhenISubscribeChannalForCustomMessageType(),
StepWhenFetchMessagesWithMessageType(),
StepThenIReceiveMessagesInSubscriptionResponse(),
StepThenReceivedMessagesHasMessageTypes(),
StepWhenFetchMessagesWithCustomMessageType(),
StepThenHistoryReceivedMessagesHasMessageTypesInt(),
StepWhenFetchMessagesWithParams(),
StepWhenISendFileCustomType(),
StepThenReceivedMessagesNoCustomMessageTypes(),
StepThenHistoryReceivedMessagesHasCustomMessageTypes()
];
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
import 'package:gherkin/gherkin.dart';
import 'package:pubnub/pubnub.dart';

import '../../world.dart';

class StepGivenTheStorageEnabledKeyset extends GivenWithWorld<PubNubWorld> {
@override
RegExp get pattern => RegExp(r'the demo keyset with enabled storage');

@override
Future<void> executeStep() async {
world.keyset = Keyset(
publishKey: 'demo',
subscribeKey: 'demo',
userId: UserId('testCustomType'));
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
import 'package:gherkin/gherkin.dart';
import 'package:test/expect.dart';

import '../../world.dart';

class StepThenHistoryReceivedMessagesHasCustomMessageTypes
extends Then2WithWorld<String, String, PubNubWorld> {
@override
RegExp get pattern => RegExp(
r'history response contains messages with {string} and {string} types');

@override
Future<void> executeStep(
String customMessageTypeOne, String customMessageTypeTwo) async {
world.historyMessages.forEach((message) {
this.expect(message.customMessageType,
anyOf([customMessageTypeOne, customMessageTypeTwo]));
});
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
import 'package:gherkin/gherkin.dart';
import 'package:test/expect.dart';

import '../../world.dart';

class StepThenHistoryReceivedMessagesHasMessageTypesInt
extends Then2WithWorld<String, String, PubNubWorld> {
@override
RegExp get pattern =>
RegExp(r'history response contains messages with {string} and {string} message types');

@override
Future<void> executeStep(
String customMessageTypeOne, String customMessageTypeTwo) async {
world.historyMessages.forEach((message) {
this.expect(message.messageType,
anyOf([customMessageTypeOne, customMessageTypeTwo]));
});
}
}
Original file line number Diff line number Diff line change
@@ -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<PubNubWorld> {
@override
RegExp get pattern =>
RegExp(r'history response contains messages without customMessageType');

@override
Future<void> executeStep(
) async {
world.messages.forEach((message) {
expect(
message.customMessageType,
null);
});
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
import 'package:gherkin/gherkin.dart';
import 'package:pubnub/pubnub.dart';

import '../../world.dart';

class StepWhenFetchMessagesWithMessageType
extends When1WithWorld<String, PubNubWorld> {
@override
RegExp get pattern =>
RegExp(r'I fetch message history with messageType for {string} channel');

@override
Future<void> 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<BatchHistoryResultEntry>)
);
world.latestResult = batchResult;
world.latestResultType = 'fetchMessages';
} catch (e) {
world.latestResultType = 'fetchMessagesWithMessageTypeTypeFailure';
world.latestResult = e;
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
import 'package:gherkin/gherkin.dart';
import 'package:pubnub/pubnub.dart';

import '../../world.dart';

class StepWhenFetchMessagesWithParams
extends When3WithWorld<String,String, String, PubNubWorld> {
@override
RegExp get pattern =>
RegExp(r'I fetch message history with {string} set to {string} for {string} channel');

@override
Future<void> 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<BatchHistoryResultEntry>));
world.latestResult = batchResult;
world.latestResultType = 'fetchMessages';
} catch (e) {
world.latestResultType = 'fetchMessagesWithMessageTypeTypeFailure';
world.latestResult = e;
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
import 'package:gherkin/gherkin.dart';
import 'package:pubnub/pubnub.dart';

import '../../world.dart';

class StepWhenFetchMessagesWithCustomMessageType
extends When1WithWorld<String, PubNubWorld> {
@override
RegExp get pattern =>
RegExp(r'When I fetch message history with customMessageType for {string} channel');

@override
Future<void> 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<BatchHistoryResultEntry>));
world.latestResult = batchResult;
world.latestResultType = 'fetchMessages';
} catch (e) {
world.latestResultType = 'fetchMessagesWithMessageTypeTypeFailure';
world.latestResult = e;
}
}
}
1 change: 1 addition & 0 deletions acceptance_tests/lib/src/world.dart
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ class PubNubWorld extends World {
Subscription? currentSubscription;

List<Envelope> messages = [];
List<BatchHistoryResultEntry> historyMessages = [];
Completer<Envelope> firstMessageCompleter = Completer();
Future<Envelope> get firstMessage => firstMessageCompleter.future;

Expand Down
4 changes: 4 additions & 0 deletions pubnub/lib/src/dx/_endpoints/history.dart
Original file line number Diff line number Diff line change
Expand Up @@ -88,6 +88,7 @@ class BatchHistoryParams extends Parameters {
bool? includeMessageActions;
bool? includeUUID;
bool? includeMessageType;
bool? includeCustomMessageType;

BatchHistoryParams(this.keyset, this.channels,
{this.max,
Expand All @@ -97,6 +98,7 @@ class BatchHistoryParams extends Parameters {
this.includeMeta,
this.includeMessageActions,
this.includeMessageType,
this.includeCustomMessageType,
this.includeUUID})
: assert(channels.isNotEmpty);

Expand All @@ -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}'
Expand Down
2 changes: 2 additions & 0 deletions pubnub/lib/src/dx/batch/batch.dart
Original file line number Diff line number Diff line change
Expand Up @@ -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];

Expand All @@ -53,6 +54,7 @@ class BatchDx {
includeMeta: includeMeta,
includeMessageActions: includeMessageActions,
includeMessageType: includeMessageType,
includeCustomMessageType: includeCustomMessageType,
includeUUID: includeUUID);

return defaultFlow<BatchHistoryParams, BatchHistoryResult>(
Expand Down

0 comments on commit 14fb57b

Please sign in to comment.