Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix unhandled exception when joinRef is null #31

Merged
merged 1 commit into from
Jun 20, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion lib/src/phoenix_channel.dart
Original file line number Diff line number Diff line change
Expand Up @@ -115,7 +115,7 @@ class PhoenixChannel {

/// @nodoc
bool isMember(
String topicParam, String event, Map payload, String joinRefParam) {
String topicParam, String event, Map payload, String? joinRefParam) {
if (_topic != topicParam) {
return false;
}
Expand Down
56 changes: 31 additions & 25 deletions test/phoenix_channel_test.dart
Original file line number Diff line number Diff line change
Expand Up @@ -68,31 +68,37 @@ void main() {
});
});

test("parses raw message and triggers channel event", () async {
final message = PhoenixSerializer.encode(new PhoenixMessage(
"1", "ref", "topic", "event", {"payload": "payload"}));

await socket!.connect();
final targetChannel = socket!.channel("topic");
var callbackInvoked = false;
var calledWithPayload;
targetChannel.on("event", (payload, ref, joinRef) {
callbackInvoked = true;
calledWithPayload = payload;
[
PhoenixMessage("1", "ref", "topic", "event", {"payload": "payload"}),
PhoenixMessage(null, "ref", "topic", "event", {"payload": "payload"}),
].forEach((msg) {
test(
"parses raw message and triggers channel event: joinRef is ${msg.joinRef}",
() async {
final message = PhoenixSerializer.encode(msg);

await socket!.connect();
final targetChannel = socket!.channel("topic");
var callbackInvoked = false;
var calledWithPayload;
targetChannel.on("event", (payload, ref, joinRef) {
callbackInvoked = true;
calledWithPayload = payload;
});

final otherChannel = socket!.channel("off-topic");
var otherCallbackInvoked = false;
otherChannel.on("event", (event, payload, ref) {
otherCallbackInvoked = true;
});

server.sendMessage(message);

await new Future<Null>.delayed(new Duration(milliseconds: 100));

expect(callbackInvoked, true);
expect(calledWithPayload, msg.payload);
expect(otherCallbackInvoked, false);
});

final otherChannel = socket!.channel("off-topic");
var otherCallbackInvoked = false;
otherChannel.on("event", (event, payload, ref) {
otherCallbackInvoked = true;
});

server.sendMessage(message);

await new Future<Null>.delayed(new Duration(milliseconds: 100));

expect(callbackInvoked, true);
expect(calledWithPayload, {'payload': 'payload'});
expect(otherCallbackInvoked, false);
});
}
2 changes: 1 addition & 1 deletion test/phoenix_presence_test.dart
Original file line number Diff line number Diff line change
Expand Up @@ -319,7 +319,7 @@ class MockChannel implements PhoenixChannel {
bool get isLeaving => false;

@override
bool isMember(String topicParam, String event, Map payload, String joinRefParam) {
bool isMember(String topicParam, String event, Map payload, String? joinRefParam) {
return true;
}

Expand Down