25
1
mirror of https://github.com/processone/ejabberd.git synced 2024-11-24 16:23:40 +01:00

Add basic test for command registration

This commit is contained in:
Mickael Remond 2016-03-29 15:45:48 +02:00
parent b49a615e21
commit c7c70ffa0a

View File

@ -0,0 +1,57 @@
# ----------------------------------------------------------------------
#
# 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 EjabberdCommandsTest do
@author "mremond@process-one.net"
use ExUnit.Case, async: true
require Record
Record.defrecord :ejabberd_commands, Record.extract(:ejabberd_commands, from_lib: "ejabberd/include/ejabberd_commands.hrl")
setup_all do
:ejabberd_commands.init
end
test "Check that we can register a command" do
assert :ejabberd_commands.register_commands([user_test_command]) == :ok
commands = :ejabberd_commands.list_commands
assert Enum.member?(commands, {:test_user, [], "Test user"})
end
# test "Check that a user can use a user command" do
# [Command] = ets:lookup(ejabberd_commands, test_user),
# AccessCommands = ejabberd_commands:get_access_commands(undefined),
# ejabberd_commands:check_access_commands(AccessCommands, {<<"test">>,<<"localhost">>, {oauth,<<"MyToken">>}, false}, test_user, Command, []).
# end
defp user_test_command do
ejabberd_commands(name: :test_user, tags: [:roster],
desc: "Test user",
policy: :user,
module: __MODULE__,
function: :test_user,
args: [],
result: {:contacts, {:list, {:contact, {:tuple, [
{:jid, :string},
{:nick, :string}
]}}}})
end
end