summaryrefslogtreecommitdiff
path: root/test/mod_last_mock.exs
diff options
context:
space:
mode:
Diffstat (limited to 'test/mod_last_mock.exs')
-rw-r--r--test/mod_last_mock.exs40
1 files changed, 27 insertions, 13 deletions
diff --git a/test/mod_last_mock.exs b/test/mod_last_mock.exs
index 7e3dc5a1..4f8da366 100644
--- a/test/mod_last_mock.exs
+++ b/test/mod_last_mock.exs
@@ -1,15 +1,29 @@
- # mod_last mock
- ######################
-
+# ----------------------------------------------------------------------
+#
+# ejabberd, Copyright (C) 2002-2016 ProcessOne
+#
+# This program is free software; you can redistribute it and/or
+# modify it under the terms of the GNU General Public License as
+# published by the Free Software Foundation; either version 2 of the
+# License, or (at your option) any later version.
+#
+# This program is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+# General Public License for more details.
+#
+# You should have received a copy of the GNU General Public License along
+# with this program; if not, write to the Free Software Foundation, Inc.,
+# 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
+#
+# ----------------------------------------------------------------------
defmodule ModLastMock do
require Record
- Record.defrecord :session, Record.extract(:session,
- from: "ejabberd_sm.hrl")
- Record.defrecord :jid, Record.extract(:jid,
- from: "jlib.hrl")
-
+ Record.defrecord :session, Record.extract(:session, from_lib: "ejabberd/include/ejabberd_sm.hrl")
+ Record.defrecord :jid, Record.extract(:jid, from_lib: "ejabberd/include/jlib.hrl")
+
@author "jsautret@process-one.net"
@agent __MODULE__
@@ -19,9 +33,9 @@ defmodule ModLastMock do
catch
:exit, _e -> :ok
end
-
+
{:ok, _pid} = Agent.start_link(fn -> %{} end, name: @agent)
-
+
mock(:mod_last, :get_last_info,
fn (user, domain) ->
Agent.get(@agent, fn last ->
@@ -32,11 +46,11 @@ defmodule ModLastMock do
end)
end)
end
-
+
def set_last(user, domain, status) do
set_last(user, domain, status, now)
end
-
+
def set_last(user, domain, status, timestamp) do
Agent.update(@agent, fn last ->
Map.put(last, {user, domain}, {timestamp, status})
@@ -50,7 +64,7 @@ defmodule ModLastMock do
{megasecs, secs, _microsecs} = :os.timestamp
megasecs * 1000000 + secs
end
-
+
# TODO refactor: Move to ejabberd_test_mock
def mock(module, function, fun) do
try do