mirror of
https://github.com/processone/ejabberd
synced 2025-10-03 09:49:18 +02:00
mod_http_api: Sort list elements in a command result
This commit is contained in:
parent
aa78362c7f
commit
6d77ace5c9
2 changed files with 13 additions and 10 deletions
|
@ -473,14 +473,17 @@ format_result(Code, {Name, restuple}) ->
|
|||
{[{<<"res">>, Code == true orelse Code == ok},
|
||||
{<<"text">>, <<"">>}]}};
|
||||
|
||||
format_result(Els, {Name, {list, {_, {tuple, [{_, atom}, _]}} = Fmt}}) ->
|
||||
format_result(Els1, {Name, {list, {_, {tuple, [{_, atom}, _]}} = Fmt}}) ->
|
||||
Els = lists:keysort(1, Els1),
|
||||
{misc:atom_to_binary(Name), {[format_result(El, Fmt) || El <- Els]}};
|
||||
|
||||
format_result(Els, {Name, {list, {_, {tuple, [{name, string}, {value, _}]}} = Fmt}}) ->
|
||||
format_result(Els1, {Name, {list, {_, {tuple, [{name, string}, {value, _}]}} = Fmt}}) ->
|
||||
Els = lists:keysort(1, Els1),
|
||||
{misc:atom_to_binary(Name), {[format_result(El, Fmt) || El <- Els]}};
|
||||
|
||||
%% Covered by command_test_list and command_test_list_tuple
|
||||
format_result(Els, {Name, {list, Def}}) ->
|
||||
format_result(Els1, {Name, {list, Def}}) ->
|
||||
Els = lists:sort(Els1),
|
||||
{misc:atom_to_binary(Name), [element(2, format_result(El, Def)) || El <- Els]};
|
||||
|
||||
format_result(Tuple, {_Name, {tuple, [{_, atom}, ValFmt]}}) ->
|
||||
|
|
|
@ -130,7 +130,7 @@ http_restuple(Config) ->
|
|||
|
||||
http_list(Config) ->
|
||||
ListS = ["one", "first", "primary"],
|
||||
ListB = [<<"one">>, <<"first">>, <<"primary">>],
|
||||
ListB = lists:sort([<<"one">>, <<"first">>, <<"primary">>]),
|
||||
?match(ListB, query(Config, "command_test_list", #{arg_list => ListS})),
|
||||
?match(ListB, query(Config, "command_test_list", #{arg_list => ListB})).
|
||||
|
||||
|
@ -148,20 +148,20 @@ http_tuple(Config) ->
|
|||
|
||||
http_list_tuple(Config) ->
|
||||
LTA = [#{element1 => "one", element2 => "uno"},
|
||||
#{element1 => "dos", element2 => "two"},
|
||||
#{element1 => "two", element2 => "dos"},
|
||||
#{element1 => "three", element2 => "tres"}],
|
||||
LTB = [#{<<"element1">> => <<"one">>, <<"element2">> => <<"uno">>},
|
||||
#{<<"element1">> => <<"dos">>, <<"element2">> => <<"two">>},
|
||||
#{<<"element1">> => <<"three">>, <<"element2">> => <<"tres">>}],
|
||||
LTB = lists:sort([#{<<"element1">> => <<"one">>, <<"element2">> => <<"uno">>},
|
||||
#{<<"element1">> => <<"two">>, <<"element2">> => <<"dos">>},
|
||||
#{<<"element1">> => <<"three">>, <<"element2">> => <<"tres">>}]),
|
||||
?match(LTB, query(Config, "command_test_list_tuple", #{arg_list => LTA})),
|
||||
?match(LTB, query(Config, "command_test_list_tuple", #{arg_list => LTB})).
|
||||
|
||||
http_list_tuple_map(Config) ->
|
||||
LTA = #{<<"one">> => <<"uno">>,
|
||||
<<"dos">> => <<"two">>,
|
||||
<<"two">> => <<"dos">>,
|
||||
<<"three">> => <<"tres">>},
|
||||
LTB = lists:sort([#{<<"element1">> => <<"one">>, <<"element2">> => <<"uno">>},
|
||||
#{<<"element1">> => <<"dos">>, <<"element2">> => <<"two">>},
|
||||
#{<<"element1">> => <<"two">>, <<"element2">> => <<"dos">>},
|
||||
#{<<"element1">> => <<"three">>, <<"element2">> => <<"tres">>}]),
|
||||
?match(LTB, lists:sort(query(Config, "command_test_list_tuple", #{arg_list => LTA}))).
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue