Skip to content
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.

Commit cbe4115

Browse files
author
Rafał Słota
authoredJul 20, 2018
Merge eff14d4 into d33282a
2 parents d33282a + eff14d4 commit cbe4115

File tree

1 file changed

+80
-0
lines changed

1 file changed

+80
-0
lines changed
 

Diff for: ‎big_tests/tests/push_SUITE.erl

+80
Original file line numberDiff line numberDiff line change
@@ -54,6 +54,7 @@ groups() ->
5454
pm_no_msg_notifications_if_user_online,
5555
pm_msg_notify_if_user_offline,
5656
pm_msg_notify_if_user_offline_with_publish_options,
57+
pm_msg_notify_if_user_offline_with_publish_options_multi_device,
5758
pm_msg_notify_stops_after_disabling
5859
]},
5960
{muclight_msg_notifications, [parallel], [
@@ -418,6 +419,80 @@ pm_msg_notify_if_user_offline_with_publish_options(Config) ->
418419
ok
419420
end).
420421

422+
pm_msg_notify_if_user_offline_with_publish_options_multi_device(Config) ->
423+
escalus:story(
424+
Config, [{bob, 1}, {alice, 1}],
425+
fun(Bob, Alice) ->
426+
PubsubJID1 = pubsub_jid(Config, 1),
427+
PubsubJID2 = pubsub_jid(Config, 2),
428+
429+
PublishOpts1 = lists:usort([
430+
{<<"field1">>, <<"value1">>}, {<<"field2">>, <<"value2">>}
431+
]),
432+
PublishOpts2 = lists:usort([
433+
{<<"field1">>, <<"value2">>}, {<<"field4">>, <<"value4">>}
434+
]),
435+
PublishOpts3 = lists:usort([
436+
{<<"field1">>, <<"value1_updated">>},
437+
{<<"field2">>, <<"value2_updated">>}
438+
]),
439+
PublishOpts4 = lists:usort([
440+
{<<"field1">>, <<"value5">>},
441+
{<<"field2">>, <<"value6">>}
442+
]),
443+
444+
Devices = #{
445+
1 => % New device
446+
#{pubsub => PubsubJID1, opts => PublishOpts1, node => <<"NodeId1">>},
447+
2 => % New device (different pubsub node)
448+
#{pubsub => PubsubJID1, opts => PublishOpts2, node => <<"NodeId2">>},
449+
3 => % Updated device 1
450+
#{pubsub => PubsubJID1, opts => PublishOpts3, node => <<"NodeId1">>},
451+
4 => % New device (different pubsub addr)
452+
#{pubsub => PubsubJID2, opts => PublishOpts4, node => <<"NodeId1">>}
453+
},
454+
455+
lists:foreach(fun({N, #{pubsub := PubsubJID, opts := PublishOpts, node := Node}}) ->
456+
escalus:send(Bob, enable_stanza(PubsubJID, Node, [{<<"id">>, N} | PublishOpts])),
457+
escalus:assert(is_iq_result, escalus:wait_for_stanza(Bob))
458+
end, maps:to_list(Devices)),
459+
460+
become_unavailable(Bob),
461+
escalus:send(Alice, escalus_stanza:chat_to(Bob, <<"OH, HAI!">>)),
462+
463+
Published1 = received_route(),
464+
Published2 = received_route(),
465+
Published3 = received_route(),
466+
Published4 = received_route(),
467+
468+
?assertMatch(false, Published4),
469+
470+
lists:foreach(fun(Published) ->
471+
?assertMatch(#route{}, Published),
472+
473+
#route{to = RealPubsubJID, packet = Packet} = Published,
474+
Form = exml_query:path(Packet, [{element, <<"pubsub">>},
475+
{element, <<"publish-options">>},
476+
{element, <<"x">>}]),
477+
Fields = parse_form(Form),
478+
NS = push_helper:ns_pubsub_pub_options(),
479+
?assertMatch(NS, proplists:get_value(<<"FORM_TYPE">>, Fields)),
480+
481+
TestDevice = maps:get(proplists:get_value(<<"id">>, Fields), Devices),
482+
PubsubJID = maps:get(pubsub, TestDevice),
483+
PublishOpts = maps:get(opts, TestDevice),
484+
Value1 = proplists:get_value(<<"field1">>, PublishOpts),
485+
Value2 = proplists:get_value(<<"field2">>, PublishOpts),
486+
487+
?assertMatch(PubsubJID, rpc(jid, to_binary, [RealPubsubJID])),
488+
?assertMatch(Value1, proplists:get_value(<<"field1">>, Fields)),
489+
?assertMatch(Value2, proplists:get_value(<<"field2">>, Fields))
490+
491+
end, [Published1, Published2, Published3]),
492+
493+
ok
494+
end).
495+
421496
pm_msg_notify_stops_after_disabling(Config) ->
422497
escalus:story(
423498
Config, [{bob, 1}, {alice, 1}],
@@ -629,6 +704,11 @@ pubsub_jid(Config) ->
629704
CaseName = proplists:get_value(case_name, Config),
630705
<<"pubsub@", (atom_to_binary(CaseName, utf8))/binary>>.
631706

707+
pubsub_jid(Config, N) ->
708+
CaseName = proplists:get_value(case_name, Config),
709+
<<"pubsub@", (atom_to_binary(CaseName, utf8))/binary, "_",
710+
(integer_to_binary(N, utf8))/binary>>.
711+
632712
room_name(Config) ->
633713
CaseName = proplists:get_value(case_name, Config),
634714
<<"room_", (atom_to_binary(CaseName, utf8))/binary>>.

0 commit comments

Comments
 (0)
Please sign in to comment.