Stage 10 final
This commit is contained in:
108
test/unit/logic_notification_tests.erl
Normal file
108
test/unit/logic_notification_tests.erl
Normal file
@@ -0,0 +1,108 @@
|
||||
-module(logic_notification_tests).
|
||||
-include_lib("eunit/include/eunit.hrl").
|
||||
-include("records.hrl").
|
||||
|
||||
setup() ->
|
||||
pg:start_link(),
|
||||
mnesia:start(),
|
||||
mnesia:create_table(booking, [{attributes, record_info(fields, booking)}, {ram_copies, [node()]}]),
|
||||
mnesia:create_table(calendar, [{attributes, record_info(fields, calendar)}, {ram_copies, [node()]}]),
|
||||
mnesia:create_table(event, [{attributes, record_info(fields, event)}, {ram_copies, [node()]}]),
|
||||
ok.
|
||||
|
||||
cleanup(_) ->
|
||||
mnesia:delete_table(event),
|
||||
mnesia:delete_table(calendar),
|
||||
mnesia:delete_table(booking),
|
||||
mnesia:stop(),
|
||||
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 = {{2026, 6, 1}, {10, 0, 0}},
|
||||
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).
|
||||
Reference in New Issue
Block a user