feat(archive): month snapshots on the same node, drop extra-node and HTML /view.
Fixes EventHub/EventHubBack#76 Co-authored-by: Cursor <cursoragent@cursor.com>
This commit is contained in:
@@ -0,0 +1,43 @@
|
||||
-module(logic_month_archive_tests).
|
||||
-include_lib("eunit/include/eunit.hrl").
|
||||
-include("records.hrl").
|
||||
|
||||
-define(TABLES, [event, month_snapshot, booking, calendar]).
|
||||
-define(CAL, <<"cal_arch_1">>).
|
||||
|
||||
setup() ->
|
||||
eh_test_support:start_mnesia(),
|
||||
eh_test_support:ensure_tables(?TABLES),
|
||||
Tmp = filename:join("/tmp", "eh_arch_" ++ integer_to_list(erlang:unique_integer([positive]))),
|
||||
ok = filelib:ensure_dir(filename:join(Tmp, "dummy")),
|
||||
true = os:putenv("UPLOAD_DIR", Tmp),
|
||||
ok.
|
||||
|
||||
cleanup(_) ->
|
||||
eh_test_support:clear_tables(?TABLES),
|
||||
eh_test_support:delete_tables(?TABLES),
|
||||
eh_test_support:stop_mnesia(),
|
||||
ok.
|
||||
|
||||
logic_month_archive_test_() ->
|
||||
{foreach, fun setup/0, fun cleanup/1, [
|
||||
{"closed month is not writable", fun test_assert_writable/0},
|
||||
{"snapshot removes hot event and serves json", fun test_snapshot_roundtrip/0}
|
||||
]}.
|
||||
|
||||
test_assert_writable() ->
|
||||
{{Y, M, _}, _} = calendar:universal_time(),
|
||||
?assertEqual(ok, logic_month_archive:assert_writable({{Y, M, 15}, {12, 0, 0}})),
|
||||
?assertEqual({error, archived},
|
||||
logic_month_archive:assert_writable({{2020, 1, 10}, {12, 0, 0}})).
|
||||
|
||||
test_snapshot_roundtrip() ->
|
||||
{ok, Ev} = core_event:create(?CAL, <<"old">>, {{2020, 6, 10}, {10, 0, 0}}, 60),
|
||||
ok = logic_month_archive:snapshot_month(?CAL, 2020, 6),
|
||||
?assertEqual([], mnesia:dirty_read(event, Ev#event.id)),
|
||||
Json = logic_month_archive:events_json_in_range(
|
||||
?CAL, {{2020, 6, 1}, {0, 0, 0}}, {{2020, 6, 30}, {23, 59, 59}}),
|
||||
?assertEqual(1, length(Json)),
|
||||
[Map] = Json,
|
||||
Id = maps:get(<<"id">>, Map, maps:get(id, Map, undefined)),
|
||||
?assertEqual(Ev#event.id, Id).
|
||||
Reference in New Issue
Block a user