|
54 | 54 | -export([process/2]). |
55 | 55 |
|
56 | 56 | -ifdef(TEST). |
57 | | --export([create_roster_invite/2, create_account_invite/4, gen_invite/1, gen_invite/2, get_invites/2, |
58 | | - is_token_valid/3]). |
59 | | --include_lib("eunit/include/eunit.hrl"). |
| 57 | +-export([create_roster_invite/2, create_account_invite/4, find_invites_tree_root_t/4, gen_invite/1, |
| 58 | + gen_invite/2, get_invites/2, get_invites_tree_as_root_t/2, is_token_valid/3]). |
60 | 59 | -endif. |
61 | 60 |
|
62 | 61 | -include("logger.hrl"). |
@@ -955,48 +954,6 @@ maybe_block_speedy_goat(Now, CreatedAt, Lvl) when Lvl == ?SPEEDY_GOAT_LEVELS -> |
955 | 954 | maybe_block_speedy_goat(_, _, _) -> |
956 | 955 | ok. |
957 | 956 |
|
958 | | --ifdef(TEST). |
959 | | - |
960 | | -find_invites_tree_root_t_test_() -> |
961 | | - {setup, |
962 | | - fun() -> |
963 | | - meck:new(db, [non_strict]), |
964 | | - meck:expect(db, |
965 | | - get_invite_by_invitee_t, |
966 | | - fun (_, <<"4@host">>) -> |
967 | | - #invite_token{inviter = {<<"3">>, <<"host">>}}; |
968 | | - (_, <<"3@host">>) -> |
969 | | - #invite_token{inviter = {<<"2">>, <<"host">>}}; |
970 | | - (_, <<"2@host">>) -> |
971 | | - #invite_token{inviter = {<<"1">>, <<"host">>}}; |
972 | | - (_, _) -> |
973 | | - {error, not_found} |
974 | | - end), |
975 | | - meck:new(gen_mod, [passthrough]), |
976 | | - meck:expect(gen_mod, db_mod, 2, db), |
977 | | - meck:new(calendar, [unstick, passthrough]), |
978 | | - meck:expect(calendar, now_to_datetime, 1, then), |
979 | | - meck:expect(calendar, datetime_to_gregorian_seconds, fun(then) -> 1 end), |
980 | | - [db, gen_mod, calendar] |
981 | | - end, |
982 | | - fun meck:unload/1, |
983 | | - fun(_) -> |
984 | | - [%% lvl not reached |
985 | | - ?_assertMatch({<<"1">>, <<"host">>}, |
986 | | - find_invites_tree_root_t(2, host, {<<"3">>, <<"host">>}, 0)), |
987 | | - %% lvl reached |
988 | | - ?_assertThrow(speedy_goat, find_invites_tree_root_t(2, host, {<<"4">>, <<"host">>}, 0)), |
989 | | - %% lvl reached but later |
990 | | - ?_assertMatch({<<"1">>, <<"host">>}, |
991 | | - find_invites_tree_root_t(?SPEEDY_GOAT_SECONDS + 1, |
992 | | - host, |
993 | | - {<<"4">>, <<"host">>}, |
994 | | - 0)), |
995 | | - ?_assert(meck:validate(db))] |
996 | | - end}. |
997 | | - |
998 | | --endif. |
999 | | - |
1000 | 957 | -spec get_invites_tree_as_root_t(binary(), {binary(), binary()}) -> [invite_token()]. |
1001 | 958 | get_invites_tree_as_root_t(Host, Inviter) -> |
1002 | 959 | Invites = get_invites_t(Host, Inviter), |
@@ -1029,45 +986,6 @@ get_invites_tree_as_root_t(Host, |
1029 | 986 | get_invites_tree_as_root_t(Host, Inviter, Invites, [Invite | Acc]) |
1030 | 987 | end. |
1031 | 988 |
|
1032 | | --ifdef(TEST). |
1033 | | - |
1034 | | -get_invites_tree_as_root_t_test_() -> |
1035 | | - {setup, |
1036 | | - fun() -> |
1037 | | - meck:new(db, [non_strict]), |
1038 | | - meck:expect(db, |
1039 | | - get_invites_t, |
1040 | | - fun (_, {<<"1">>, _}) -> |
1041 | | - [#invite_token{invitee = <<"2@host">>, type = account_only}, |
1042 | | - #invite_token{invitee = <<"rosterinvite@forcecrash">>}]; |
1043 | | - (_, {<<"2">>, _}) -> |
1044 | | - [#invite_token{invitee = <<"3@host">>, type = account_only}, |
1045 | | - #invite_token{invitee = <<"4@host">>, type = account_only}]; |
1046 | | - (_, {<<"3">>, _}) -> |
1047 | | - [#invite_token{invitee = <<"5@host">>, type = account_subscription}, |
1048 | | - #invite_token{invitee = <<"6@host">>, account_name = <<"6">>}, |
1049 | | - #invite_token{type = account_only}]; |
1050 | | - (_, {_, <<"host">>}) -> |
1051 | | - [] |
1052 | | - end), |
1053 | | - meck:new(gen_mod, [passthrough]), |
1054 | | - meck:expect(gen_mod, db_mod, 2, db), |
1055 | | - meck:expect(jid, |
1056 | | - decode, |
1057 | | - fun(Str) -> |
1058 | | - [LUser, LServer] = |
1059 | | - [list_to_binary(T) || T <- string:tokens(binary_to_list(Str), "@")], |
1060 | | - #jid{luser = LUser, lserver = LServer} |
1061 | | - end), |
1062 | | - [db, gen_mod, jid] |
1063 | | - end, |
1064 | | - fun meck:unload/1, |
1065 | | - fun(_) -> |
1066 | | - [?_assertMatch(6, length(get_invites_tree_as_root_t(<<"host">>, {<<"1">>, <<"host">>})))] |
1067 | | - end}. |
1068 | | - |
1069 | | --endif. |
1070 | | - |
1071 | 989 | maybe_throw({error, _} = Error) -> |
1072 | 990 | throw(Error); |
1073 | 991 | maybe_throw(Good) -> |
|
0 commit comments