-
Notifications
You must be signed in to change notification settings - Fork 23
/
Copy pathoffline_SUITE.erl
88 lines (66 loc) · 2.75 KB
/
offline_SUITE.erl
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
%%%===================================================================
%%% @copyright (C) 2011, Erlang Solutions Ltd.
%%% @doc Suite for testing mod_offline* modules
%%% @end
%%%===================================================================
-module(offline_SUITE).
-compile(export_all).
-include_lib("escalus/include/escalus.hrl").
-include_lib("common_test/include/ct.hrl").
%%%===================================================================
%%% Suite configuration
%%%===================================================================
all() ->
[{group, mod_offline_tests}].
all_tests() ->
[simple_message].
groups() ->
[{mod_offline_tests, [sequence], all_tests()}].
suite() ->
escalus:suite().
%%%===================================================================
%%% Init & teardown
%%%===================================================================
init_per_suite(Config0) ->
Config1 = escalus:init_per_suite(Config0),
escalus:create_users(Config1, {by_name, [alice, bob]}).
end_per_suite(Config) ->
escalus:delete_users(Config, {by_name, [alice, bob]}),
escalus:end_per_suite(Config).
init_per_group(_GroupName, Config) ->
Config.
end_per_group(_GroupName, _Config) ->
ok.
init_per_testcase(CaseName, Config) ->
escalus:init_per_testcase(CaseName, Config).
end_per_testcase(CaseName, Config) ->
escalus:end_per_testcase(CaseName, Config).
%%%===================================================================
%%% offline tests
%%%===================================================================
simple_message(Config) ->
%% Alice sends a message to Bob, who is offline
escalus:story(Config, [{alice, 1}], fun(Alice) ->
escalus:send(Alice, escalus_stanza:chat_to(bob, <<"Hi, Offline!">>))
end),
%% Bob logs in
Bob = login_send_presence(Config, bob),
%% He receives his initial presence and the message
Stanzas = escalus:wait_for_stanzas(Bob, 2),
escalus_new_assert:mix_match([is_presence,
is_chat(<<"Hi, Offline!">>)],
Stanzas),
escalus_cleaner:clean(Config).
%%%===================================================================
%%% Custom predicates
%%%===================================================================
is_chat(Content) ->
fun(Stanza) -> escalus_pred:is_chat_message(Content, Stanza) end.
%%%===================================================================
%%% Helpers
%%%===================================================================
login_send_presence(Config, User) ->
Spec = escalus_users:get_userspec(Config, User),
{ok, Client} = escalus_client:start(Config, Spec, <<"dummy">>),
escalus:send(Client, escalus_stanza:presence(<<"available">>)),
Client.