Files
EventHubBack/test/unit/admin_ws_handler_tests.erl

34 lines
898 B
Erlang

-module(admin_ws_handler_tests).
-include_lib("eunit/include/eunit.hrl").
-record(state, {
admin_id :: binary() | undefined
}).
setup() ->
pg:start_link(),
ok.
cleanup(_) ->
ok.
admin_ws_handler_test_() ->
{foreach,
fun setup/0,
fun cleanup/1,
[
{"Admin WebSocket info notification", fun test_admin_websocket_info/0}
]}.
test_admin_websocket_info() ->
State = #state{admin_id = <<"admin123">>},
Data = #{report_id => <<"rep123">>, reason => <<"Spam">>},
Msg = {admin_notification, report_created, Data},
case admin_ws_handler:websocket_info(Msg, State) of
{reply, {text, Reply}, _} ->
Decoded = jsx:decode(Reply, [return_maps]),
?assertEqual(<<"report_created">>, maps:get(<<"type">>, Decoded)),
?assertEqual(<<"rep123">>, maps:get(<<"report_id">>, maps:get(<<"data">>, Decoded)));
_ -> ?assert(false, "Expected reply")
end.