Добавить автомодерацию: политики, порог жалоб, settings/hits API и тесты.
Refs EventHub/EventHubBack#37 Refs EventHub/EventHubBack#38 Refs EventHub/EventHubBack#39 Refs EventHub/EventHubBack#40
This commit is contained in:
@@ -0,0 +1,64 @@
|
||||
-module(core_automod_tests).
|
||||
-include_lib("eunit/include/eunit.hrl").
|
||||
-include("records.hrl").
|
||||
|
||||
-define(TABLES, [automod_settings, automod_hit]).
|
||||
|
||||
setup() ->
|
||||
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.
|
||||
|
||||
core_automod_test_() ->
|
||||
{foreach, fun setup/0, fun cleanup/1, [
|
||||
{"settings defaults", fun test_defaults/0},
|
||||
{"settings update fields", fun test_update/0},
|
||||
{"hit create list resolve", fun test_hits/0},
|
||||
{"hit filters", fun test_hit_filters/0}
|
||||
]}.
|
||||
|
||||
test_defaults() ->
|
||||
core_automod_settings:ensure_defaults(),
|
||||
S = core_automod_settings:get(),
|
||||
?assertEqual(flag, S#automod_settings.keyword_action),
|
||||
?assertEqual(word_boundary, S#automod_settings.match_mode),
|
||||
?assertEqual(3, S#automod_settings.report_threshold).
|
||||
|
||||
test_update() ->
|
||||
core_automod_settings:ensure_defaults(),
|
||||
{ok, S} = core_automod_settings:update([
|
||||
{keyword_action, censor},
|
||||
{match_mode, substring},
|
||||
{report_threshold, 4}
|
||||
], <<"adm">>),
|
||||
?assertEqual(censor, S#automod_settings.keyword_action),
|
||||
?assertEqual(substring, S#automod_settings.match_mode),
|
||||
?assertEqual(4, S#automod_settings.report_threshold),
|
||||
?assertEqual(<<"adm">>, S#automod_settings.updated_by).
|
||||
|
||||
test_hits() ->
|
||||
{ok, H} = core_automod_hit:create(event, <<"eid">>, keyword, [<<"w">>], flag),
|
||||
?assertEqual(open, H#automod_hit.status),
|
||||
{ok, Got} = core_automod_hit:get_by_id(H#automod_hit.id),
|
||||
?assertEqual(<<"eid">>, Got#automod_hit.entity_id),
|
||||
{ok, Done} = core_automod_hit:resolve(H#automod_hit.id, approved, <<"adm">>),
|
||||
?assertEqual(approved, Done#automod_hit.status),
|
||||
?assertEqual(<<"adm">>, Done#automod_hit.resolved_by),
|
||||
?assertMatch({error, already_resolved},
|
||||
core_automod_hit:resolve(H#automod_hit.id, rejected, <<"adm">>)).
|
||||
|
||||
test_hit_filters() ->
|
||||
{ok, _} = core_automod_hit:create(event, <<"e1">>, keyword, [], flag),
|
||||
{ok, H2} = core_automod_hit:create(review, <<"r1">>, report_threshold, [], hide),
|
||||
{ok, _} = core_automod_hit:resolve(H2#automod_hit.id, rejected, <<"a">>),
|
||||
Open = core_automod_hit:list([{status, open}]),
|
||||
?assertEqual(1, length(Open)),
|
||||
Reviews = core_automod_hit:list([{entity_type, review}]),
|
||||
?assertEqual(1, length(Reviews)),
|
||||
Thr = core_automod_hit:list([{trigger, report_threshold}]),
|
||||
?assertEqual(1, length(Thr)).
|
||||
Reference in New Issue
Block a user