fix: add sub api doc & test suite (#5634)

* fix: add sub api doc & test suite
This commit is contained in:
DDDHuang 2021-09-03 10:57:54 +08:00 committed by GitHub
parent f4eae8c0cb
commit be0fd6fddd
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 20 additions and 5 deletions

View File

@ -96,13 +96,13 @@ parameters() ->
#{
name => topic,
in => query,
description => <<"Topic">>,
description => <<"Topic, url encoding">>,
schema => #{type => string}
}
#{
name => match_topic,
in => query,
description => <<"Match topic string">>,
description => <<"Match topic string, url encoding">>,
schema => #{type => string}
} | page_params()
].

View File

@ -24,8 +24,10 @@
-define(USERNAME, <<"api_username">>).
%% notice: integer topic for sort response
-define(TOPIC1, <<"0000">>).
-define(TOPIC2, <<"0001">>).
-define(TOPIC1, <<"/t/0000">>).
-define(TOPIC2, <<"/t/0001">>).
-define(TOPIC_SORT, #{?TOPIC1 => 1, ?TOPIC2 => 2}).
all() ->
emqx_ct:all(?MODULE).
@ -53,11 +55,24 @@ t_subscription_api(_) ->
?assertEqual(length(Subscriptions), 2),
Sort =
fun(#{<<"topic">> := T1}, #{<<"topic">> := T2}) ->
binary_to_integer(T1) =< binary_to_integer(T2)
maps:get(T1, ?TOPIC_SORT) =< maps:get(T2, ?TOPIC_SORT)
end,
[Subscriptions1, Subscriptions2] = lists:sort(Sort, Subscriptions),
?assertEqual(maps:get(<<"topic">>, Subscriptions1), ?TOPIC1),
?assertEqual(maps:get(<<"topic">>, Subscriptions2), ?TOPIC2),
?assertEqual(maps:get(<<"clientid">>, Subscriptions1), ?CLIENTID),
?assertEqual(maps:get(<<"clientid">>, Subscriptions2), ?CLIENTID),
QsTopic = "topic=" ++ <<"%2Ft%2F0001">>,
Headers = emqx_mgmt_api_test_util:auth_header_(),
{ok, ResponseTopic1} = emqx_mgmt_api_test_util:request_api(get, Path, QsTopic, Headers),
DataTopic1 = emqx_json:decode(ResponseTopic1, [return_maps]),
Meta1 = maps:get(<<"meta">>, DataTopic1),
?assertEqual(1, maps:get(<<"page">>, Meta1)),
?assertEqual(emqx_mgmt:max_row_limit(), maps:get(<<"limit">>, Meta1)),
?assertEqual(1, maps:get(<<"count">>, Meta1)),
Subscriptions_qs1 = maps:get(<<"data">>, DataTopic1),
?assertEqual(length(Subscriptions_qs1), 1),
emqtt:disconnect(Client).