Files
EventHubBack/test/unit/logic_notification_tests.erl
T

106 lines
2.9 KiB
Erlang

-module(logic_notification_tests).
-include_lib("eunit/include/eunit.hrl").
-include("records.hrl").
-define(TABLES, [booking, calendar, event]).
setup() ->
pg:start_link(),
eh_test_support:start_mnesia(),
eh_test_support:ensure_tables(?TABLES),
ok.
cleanup(_) ->
eh_test_support:delete_tables(?TABLES),
eh_test_support:stop_mnesia(),
ok.
logic_notification_test_() ->
{foreach,
fun setup/0,
fun cleanup/1,
[
{"Notify booking", fun test_notify_booking/0},
{"Notify calendar update", fun test_notify_calendar_update/0},
{"Notify event update", fun test_notify_event_update/0},
{"Notify admin", fun test_notify_admin/0}
]}.
create_test_booking() ->
Booking = #booking{
id = base64:encode(crypto:strong_rand_bytes(16), #{mode => urlsafe, padding => false}),
event_id = <<"event123">>,
user_id = <<"user123">>,
status = pending,
confirmed_at = undefined,
created_at = calendar:universal_time(),
updated_at = calendar:universal_time()
},
mnesia:dirty_write(Booking),
Booking.
create_test_calendar() ->
Calendar = #calendar{
id = base64:encode(crypto:strong_rand_bytes(16), #{mode => urlsafe, padding => false}),
owner_id = <<"owner123">>,
title = <<"Test Calendar">>,
description = <<"">>,
tags = [],
type = personal,
confirmation = manual,
rating_avg = 0.0,
rating_count = 0,
status = active,
created_at = calendar:universal_time(),
updated_at = calendar:universal_time()
},
mnesia:dirty_write(Calendar),
Calendar.
create_test_event() ->
Event = #event{
id = base64:encode(crypto:strong_rand_bytes(16), #{mode => urlsafe, padding => false}),
calendar_id = <<"cal123">>,
title = <<"Test Event">>,
description = <<"">>,
event_type = single,
start_time = eh_test_support:future_start(),
duration = 60,
recurrence_rule = undefined,
master_id = undefined,
is_instance = false,
specialist_id = undefined,
location = undefined,
tags = [],
capacity = undefined,
online_link = undefined,
status = active,
rating_avg = 0.0,
rating_count = 0,
created_at = calendar:universal_time(),
updated_at = calendar:universal_time()
},
mnesia:dirty_write(Event),
Event.
test_notify_booking() ->
Booking = create_test_booking(),
UserId = <<"user123">>,
Result = logic_notification:notify_booking(UserId, Booking),
?assert(is_list(Result)).
test_notify_calendar_update() ->
Calendar = create_test_calendar(),
Result = logic_notification:notify_calendar_update(Calendar),
?assert(is_list(Result)).
test_notify_event_update() ->
Event = create_test_event(),
Result = logic_notification:notify_event_update(Event),
?assert(is_list(Result)).
test_notify_admin() ->
Result = logic_notification:notify_admin(report_created, #{report_id => <<"rep123">>}),
?assertEqual(ok, Result).