From 8c8acac186025b5042ab39620edf1e9d7a164353 Mon Sep 17 00:00:00 2001 From: Tobias Lindahl Date: Thu, 7 May 2020 16:19:00 +0200 Subject: [PATCH 1/3] Add testing of call bubbles --- spec/nynja_rest.yaml | 9 ++---- test/server_SUITE.erl | 64 +++++++++++++++++++++++++++++++++++++++++-- 2 files changed, 64 insertions(+), 9 deletions(-) diff --git a/spec/nynja_rest.yaml b/spec/nynja_rest.yaml index 5bd30be29..c7faf902f 100644 --- a/spec/nynja_rest.yaml +++ b/spec/nynja_rest.yaml @@ -825,12 +825,9 @@ paths: status: type: integer data: - type: object - properties: - failed: - type: array - items: - $ref: '#/components/schemas/FailedPhoneEntry' + type: array + items: + type: integer '400': description: "Malformed request" diff --git a/test/server_SUITE.erl b/test/server_SUITE.erl index 997044676..c6bbf3b6e 100644 --- a/test/server_SUITE.erl +++ b/test/server_SUITE.erl @@ -30,6 +30,7 @@ , p2p_chat_message_post_errors/1 , room_chat_message/1 , room_chat_message_errors/1 + , call_bubble_message/1 ]). all() -> @@ -42,7 +43,7 @@ groups() -> p2p_chat_message_get, p2p_chat_message_get_errors, p2p_chat_message_post, p2p_chat_message_post_errors, room_chat_message, room_chat_message_errors, - create_and_join_room_cri + create_and_join_room_cri, call_bubble_message ]} ]. @@ -306,7 +307,6 @@ create_and_join_room_cri(Cfg) -> {ok, 400, _} = request('PostCRIRoom', #{phoneid => <<"123", RosterId1/binary>>}, [basic_auth() | Cfg]), - ct:log("Succeed in creating room"), {ok, 200, #{data := #{ room_id := RoomId}}} = request('PostCRIRoom', #{phoneid => RosterId1}, [basic_auth() | Cfg]), @@ -328,7 +328,7 @@ create_and_join_room_cri(Cfg) -> [basic_auth() | Cfg]), wait_for_cri_room_member(RoomId, RosterId1, RosterId2, Cfg), - ok. + {User1, User2, RoomId}. wait_for_cri_room_member(RoomId, RosterId1, RosterId2, Cfg) -> %% The call to add member is asynchronous, so we retry @@ -735,6 +735,64 @@ room_chat_message_errors(Cfg) -> ok. +call_bubble_message(Cfg) -> + + %% Create a call room, join it and add the other user to it + {AdminUser, User, RoomId} = create_and_join_room_cri(Cfg), + AdminRosterId = nynja:user_roster(AdminUser), + RosterId = nynja:user_roster(User), + + StartTime = erlang:system_time(second) - 100, + + %% Now create a call bubble for this room + Spec = #{ type => <<"conference">> + , count => 2 + , recipients => [AdminRosterId, RosterId] + , feed_id => RoomId + , start_time => StartTime + , status => <<"answered">> + , content_type => <<"audioCall">> + , ended_by => <<"caller">> + }, + {ok, 200, #{ status := 200 + , data := Array}} + = request('PostCRIBubbles', Spec#{phoneid => AdminRosterId}, [basic_auth()|Cfg]), + + %% The answer is a list representation of the bert encoded message. + _ = binary_to_term(list_to_binary(Array)), + + %% Wait for the bubble to be sent to the user + wait_for_call_bubble(User, StartTime, #muc{name = RoomId}), + ok. + +wait_for_call_bubble(User, StartTime, FeedId) -> + wait_for_call_bubble(User, StartTime, FeedId, 5). + +wait_for_call_bubble(_User,_StartTime,_FeedId, 0) -> + error(timeout); +wait_for_call_bubble(User, StartTime, FeedId, N) -> + StartTimeBin = integer_to_binary(StartTime), + case nynja:ws_receive(User, 1, 200) of + [#mqtt_packet{payload = + #'Message'{ feed_id = FeedId + , files = [#'Desc'{ mime = <<"audioCall">> + , data = Data}]}}] -> + IsBubble = fun(#'Feature'{ key = <<"START_TIME">> + , value = ST}) -> + ST =:= StartTimeBin; + (_) -> false + end, + case lists:any(IsBubble, Data) of + true -> + ok; + false -> + wait_for_call_bubble(User, StartTime, FeedId, N - 1) + end; + [#mqtt_packet{}] -> + wait_for_call_bubble(User, StartTime, FeedId, N - 1); + timeout -> + wait_for_call_bubble(User, StartTime, FeedId, N - 1) + end. %%% ------------- helpers --------------------- -- GitLab From a39a686d7637f63469ab1d7a78659436b1043f69 Mon Sep 17 00:00:00 2001 From: Thomas Arts Date: Thu, 7 May 2020 17:20:54 +0200 Subject: [PATCH 2/3] new api_nynja --- test/api_nynja.erl | 15 +++++---------- 1 file changed, 5 insertions(+), 10 deletions(-) diff --git a/test/api_nynja.erl b/test/api_nynja.erl index a955ee03f..a868ebd19 100644 --- a/test/api_nynja.erl +++ b/test/api_nynja.erl @@ -1,6 +1,6 @@ %% coding: latin-1 -%% This code is generated from ../server22/spec/nynja_rest.yaml -%% on 2020-05-06 11:19:32 UTC +%% This code is generated from ../server/spec/nynja_rest.yaml +%% on 2020-05-07 15:17:56 UTC %% Using openapi rebar3 plugin version: #6ad56be %% Do not manually change this code! %% @@ -410,14 +410,9 @@ operations() -> #{schema => #{<<"properties">> => #{<<"data">> => - #{<<"properties">> => - #{<<"failed">> => - #{<<"items">> => - #{<<"$ref">> => - <<"/components/schemas/FailedPhoneEntry">>}, - <<"type">> => - <<"array">>}}, - <<"type">> => <<"object">>}, + #{<<"items">> => + #{<<"type">> => <<"integer">>}, + <<"type">> => <<"array">>}, <<"status">> => #{<<"type">> => <<"integer">>}}, <<"type">> => <<"object">>}}}], -- GitLab From 4cee8df790e9d0e76a11468f523d734734bb7278 Mon Sep 17 00:00:00 2001 From: Tobias Lindahl Date: Thu, 7 May 2020 18:01:00 +0200 Subject: [PATCH 3/3] Add emptying of websocket in test case to sync against sent command --- test/server_SUITE.erl | 2 ++ 1 file changed, 2 insertions(+) diff --git a/test/server_SUITE.erl b/test/server_SUITE.erl index c6bbf3b6e..65e7fa1c3 100644 --- a/test/server_SUITE.erl +++ b/test/server_SUITE.erl @@ -532,6 +532,8 @@ p2p_chat_message_common(Cfg) -> , text => <<"Hi there">> }, [basic_auth()|Cfg]), + %% Empty the websocket to sync against next command + nynja:ws_receive(Receiver, any, 100), %% Now ban the friend. nynja:friend_req_ban(Receiver, nynja:user_roster(Sender)), -- GitLab