1: -module(offline_stub_SUITE).
    2: -compile([export_all, nowarn_export_all]).
    3: 
    4: %%%===================================================================
    5: %%% Suite configuration
    6: %%%===================================================================
    7: 
    8: all() ->
    9:     [with_mod_offline_stub,
   10:      without_mod_offline_stub].
   11: 
   12: suite() ->
   13:     escalus:suite().
   14: 
   15: %%%===================================================================
   16: %%% Init & teardown
   17: %%%===================================================================
   18: 
   19: init_per_suite(Config) ->
   20:     escalus:init_per_suite(Config).
   21: 
   22: end_per_suite(Config) ->
   23:     escalus_fresh:clean(),
   24:     escalus:end_per_suite(Config).
   25: 
   26: init_per_testcase(Name, Config0) ->
   27:     HostType = domain_helper:host_type(),
   28:     Config1 = dynamic_modules:save_modules(HostType, Config0),
   29:     dynamic_modules:ensure_stopped(HostType, [mod_offline]),
   30:     case Name of
   31:         with_mod_offline_stub ->
   32:             dynamic_modules:ensure_modules(HostType, [{mod_offline_stub, []}]);
   33:         _ -> ok
   34:     end,
   35:     escalus:init_per_testcase(Name, Config1).
   36: 
   37: end_per_testcase(Name, Config) ->
   38:     HostType = domain_helper:host_type(),
   39:     dynamic_modules:restore_modules(Config),
   40:     escalus:end_per_testcase(Name, Config).
   41: 
   42: %%%===================================================================
   43: %%% offline tests
   44: %%%===================================================================
   45: 
   46: with_mod_offline_stub(Config) ->
   47:     Story =
   48:         fun(FreshConfig, Alice, Bob) ->
   49:             logout(FreshConfig, Bob),
   50:             escalus:send(Alice, escalus_stanza:chat_to(Bob, <<"msgtxt">>)),
   51:             [] = escalus:wait_for_stanzas(Alice, 1, 1000)
   52:         end,
   53:     escalus:fresh_story_with_config(Config, [{alice, 1}, {bob, 1}], Story).
   54: 
   55: without_mod_offline_stub(Config) ->
   56:     Story =
   57:         fun(FreshConfig, Alice, Bob) ->
   58:             logout(FreshConfig, Bob),
   59:             escalus:send(Alice, escalus_stanza:chat_to(Bob, <<"msgtxt">>)),
   60:             Err = escalus:wait_for_stanza(Alice),
   61:             escalus:assert(is_error, [<<"cancel">>, <<"service-unavailable">>], Err)
   62:         end,
   63:     escalus:fresh_story_with_config(Config, [{alice, 1}, {bob, 1}], Story).
   64: 
   65: %%%===================================================================
   66: %%% Helpers
   67: %%%===================================================================
   68: logout(Config, User) ->
   69:     mongoose_helper:logout_user(Config, User).