Skip to content

Commit

Permalink
Allow to provide options into change_room_config
Browse files Browse the repository at this point in the history
  • Loading branch information
arcusfelis committed Aug 30, 2022
1 parent 6f60ac2 commit 069cc6b
Show file tree
Hide file tree
Showing 3 changed files with 61 additions and 4 deletions.
54 changes: 54 additions & 0 deletions big_tests/tests/graphql_muc_light_SUITE.erl
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,7 @@ admin_muc_light_tests() ->
admin_create_room_with_custom_fields,
admin_create_identified_room,
admin_change_room_config,
admin_change_room_config_with_custom_fields,
admin_change_room_config_errors,
admin_invite_user,
admin_invite_user_errors,
Expand Down Expand Up @@ -204,6 +205,24 @@ user_change_room_config_story(Config, Alice) ->
Res = user_change_room_configuration(Alice, jid:to_binary(RoomJID), Name2, Subject2, Config),
?assertMatch(#{<<"name">> := Name2, <<"subject">> := Subject2}, get_ok_value(?CHANGE_CONFIG_PATH, Res)).

user_change_room_config_with_custom_fields(Config) ->
escalus:fresh_story_with_config(Config, [{alice, 1}], fun user_change_room_config_with_custom_fields_story/2).

user_change_room_config_with_custom_fields_story(Config, Alice) ->
AliceBin = escalus_client:short_jid(Alice),
MUCServer = ?config(muc_light_host, Config),
% Create a new room
{ok, #{jid := RoomJID}} = create_room(MUCServer, <<"ornithology">>, <<"birds">>, AliceBin),
% Try to change the room configuration
Name2 = <<"changed room">>,
Subject2 = <<"not testing">>,
Opts2 = #{<<"music">> => <<"sad">>},
Res = user_change_room_configuration_with_custom_fields(Alice, jid:to_binary(RoomJID), Name2, Subject2, Config, Opts2),
Opts3 = [#{<<"key">> => <<"music">>, <<"value">> => <<"sad">>},
#{<<"key">> => <<"roomname">>, <<"value">> => Name2},
#{<<"key">> => <<"subject">>, <<"value">> => Subject2}],
?assertMatch(#{<<"name">> := Name2, <<"subject">> := Subject2, <<"options">> := Opts3}, get_ok_value(?CHANGE_CONFIG_PATH, Res)).

user_change_room_config_errors(Config) ->
escalus:fresh_story_with_config(Config, [{alice, 1}, {bob, 1}],
fun user_change_room_config_errors_story/3).
Expand Down Expand Up @@ -626,6 +645,31 @@ admin_change_room_config_story(Config, Alice) ->
?assertMatch(#{<<"name">> := Name2, <<"subject">> := Subject2},
get_ok_value(?CHANGE_CONFIG_PATH, Res)).

admin_change_room_config_with_custom_fields(Config) ->
escalus:fresh_story_with_config(Config, [{alice, 1}], fun admin_change_room_config_with_custom_fields_story/2).

admin_change_room_config_with_custom_fields_story(Config, Alice) ->
AliceBin = escalus_client:short_jid(Alice),
MUCServer = ?config(muc_light_host, Config),
Name = <<"first room">>,
Subject = <<"testing">>,
Opts = #{<<"background">> => <<"red">>},
% Create a new room
Res = create_room_with_custom_fields(MUCServer, Name, AliceBin, Subject, null, Config, Opts),
#{<<"jid">> := RoomJID} = get_ok_value(?CREATE_ROOM_PATH, Res),
% Try to change the room configuration
Name2 = <<"changed room">>,
Subject2 = <<"not testing">>,
Opts2 = #{<<"music">> => <<"sad">>},
Res2 = change_room_configuration_with_custom_fields(jid:to_binary(RoomJID), AliceBin, Name2, Subject2, Config, Opts2),
%% It overwrites old config for all fields
Opts3 = [% #{<<"key">> => <<"background">>, <<"value">> => <<"red">>},
#{<<"key">> => <<"music">>, <<"value">> => <<"sad">>},
#{<<"key">> => <<"roomname">>, <<"value">> => Name2},
#{<<"key">> => <<"subject">>, <<"value">> => Subject2}],
?assertMatch(#{<<"name">> := Name2, <<"subject">> := Subject2, <<"options">> := Opts3},
get_ok_value(?CHANGE_CONFIG_PATH, Res2)).

admin_change_room_config_errors(Config) ->
escalus:fresh_story_with_config(Config, [{alice, 1}, {bob, 1}],
fun admin_change_room_config_errors_story/3).
Expand Down Expand Up @@ -927,6 +971,11 @@ change_room_configuration(RoomJID, OwnerJID, Name, Subject, Config) ->
<<"subject">> => Subject},
execute_command(<<"muc_light">>, <<"changeRoomConfiguration">>, Vars, Config).

change_room_configuration_with_custom_fields(RoomJID, OwnerJID, Name, Subject, Config, Opts) ->
Vars = #{<<"room">> => RoomJID, <<"name">> => Name, <<"owner">> => OwnerJID,
<<"subject">> => Subject, <<"options">> => format_options(Opts)},
execute_command(<<"muc_light">>, <<"changeRoomConfiguration">>, Vars, Config).

invite_user(RoomJID, Sender, Recipient, Config) ->
Vars = #{<<"room">> => RoomJID, <<"sender">> => Sender, <<"recipient">> => Recipient},
execute_command(<<"muc_light">>, <<"inviteUser">>, Vars, Config).
Expand Down Expand Up @@ -981,6 +1030,11 @@ user_change_room_configuration(User, RoomJID, Name, Subject, Config) ->
Vars = #{<<"room">> => RoomJID, <<"name">> => Name, <<"subject">> => Subject},
execute_user_command(<<"muc_light">>, <<"changeRoomConfiguration">>, User, Vars, Config).

user_change_room_configuration_with_custom_fields(User, RoomJID, Name, Subject, Config, Options) ->
Vars = #{<<"room">> => RoomJID, <<"name">> => Name, <<"subject">> => Subject,
<<"options">> => format_options(Options)},
execute_user_command(<<"muc_light">>, <<"changeRoomConfiguration">>, User, Vars, Config).

format_options(Map) ->
[#{<<"key">> => K, <<"value">> => V} || {K, V} <- maps:to_list(Map)].

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -40,8 +40,10 @@ create_room(#{<<"id">> := RoomID, <<"mucDomain">> := MUCDomain, <<"name">> := Ro

-spec change_room_config(map()) -> {ok, map()} | {error, resolver_error()}.
change_room_config(#{<<"room">> := RoomJID, <<"name">> := RoomName,
<<"owner">> := OwnerJID, <<"subject">> := Subject}) ->
Config = #{<<"roomname">> => RoomName, <<"subject">> => Subject},
<<"owner">> := OwnerJID, <<"subject">> := Subject,
<<"options">> := Options}) ->
OptMap = options_to_map(Options),
Config = OptMap#{<<"roomname">> => RoomName, <<"subject">> => Subject},
case mod_muc_light_api:change_room_config(RoomJID, OwnerJID, Config) of
{ok, Room} ->
{ok, make_room(Room)};
Expand Down
5 changes: 3 additions & 2 deletions src/graphql/user/mongoose_graphql_muc_light_user_mutation.erl
Original file line number Diff line number Diff line change
Expand Up @@ -40,8 +40,9 @@ create_room(#{user := UserJID}, #{<<"id">> := RoomID, <<"mucDomain">> := MUCDoma

-spec change_room_config(map(), map()) -> {ok, map()} | {error, resolver_error()}.
change_room_config(#{user := UserJID}, #{<<"room">> := RoomJID, <<"name">> := RoomName,
<<"subject">> := Subject}) ->
Config = #{<<"roomname">> => RoomName, <<"subject">> => Subject},
<<"subject">> := Subject, <<"options">> := Options}) ->
OptMap = options_to_map(Options),
Config = OptMap#{<<"roomname">> => RoomName, <<"subject">> => Subject},
case mod_muc_light_api:change_room_config(RoomJID, UserJID, Config) of
{ok, Room} ->
{ok, make_room(Room)};
Expand Down

0 comments on commit 069cc6b

Please sign in to comment.