about summary refs log tree commit diff stats
diff options
context:
space:
mode:
authorJames Booth <boothj5@gmail.com>2013-12-15 23:55:59 +0000
committerJames Booth <boothj5@gmail.com>2013-12-15 23:55:59 +0000
commit3c0bbed7178168d9be2cc6a6e120994ba2d0b96b (patch)
treebf9025ad6a691ebd58896fa78a185f13d029a11b
parent4216949b2ea220b0e32fb740d7d7f871f42ab747 (diff)
downloadprofani-tty-3c0bbed7178168d9be2cc6a6e120994ba2d0b96b.tar.gz
Added tests for "/account disable"
-rw-r--r--tests/config/mock_accounts.c1
-rw-r--r--tests/test_cmd_account.c64
-rw-r--r--tests/test_cmd_account.h4
-rw-r--r--tests/testsuite.c4
4 files changed, 73 insertions, 0 deletions
diff --git a/tests/config/mock_accounts.c b/tests/config/mock_accounts.c
index 792712ba..c0faa5ab 100644
--- a/tests/config/mock_accounts.c
+++ b/tests/config/mock_accounts.c
@@ -71,6 +71,7 @@ gboolean accounts_enable(const char * const name)
 
 gboolean accounts_disable(const char * const name)
 {
+    check_expected(name);
     return (gboolean)mock();
 }
 
diff --git a/tests/test_cmd_account.c b/tests/test_cmd_account.c
index 04b0e19a..a20111f1 100644
--- a/tests/test_cmd_account.c
+++ b/tests/test_cmd_account.c
@@ -229,3 +229,67 @@ void cmd_account_enable_shows_message_when_account_doesnt_exist(void **state)
 
     free(help);
 }
+
+void cmd_account_disable_shows_usage_when_no_arg(void **state)
+{
+    CommandHelp *help = malloc(sizeof(CommandHelp));
+    help->usage = "some usage";
+    gchar *args[] = { "disable", NULL };
+
+    expect_string(cons_show, output, "Usage: some usage");
+
+    gboolean result = cmd_account(args, *help);
+    assert_true(result);
+
+    free(help);
+}
+
+void cmd_account_disable_disables_account(void **state)
+{
+    CommandHelp *help = malloc(sizeof(CommandHelp));
+    gchar *args[] = { "disable", "account_name" };
+
+    expect_string(accounts_disable, name, "account_name");
+    will_return(accounts_disable, TRUE);
+
+    expect_any_count(cons_show, output, 2);
+
+    gboolean result = cmd_account(args, *help);
+    assert_true(result);
+
+    free(help);
+}
+
+void cmd_account_disable_shows_message_when_disabled(void **state)
+{
+    CommandHelp *help = malloc(sizeof(CommandHelp));
+    gchar *args[] = { "disable", "account_name" };
+
+    expect_any(accounts_disable, name);
+    will_return(accounts_disable, TRUE);
+
+    expect_string(cons_show, output, "Account disabled.");
+    expect_string(cons_show, output, "");
+
+    gboolean result = cmd_account(args, *help);
+    assert_true(result);
+
+    free(help);
+}
+
+void cmd_account_disable_shows_message_when_account_doesnt_exist(void **state)
+{
+    CommandHelp *help = malloc(sizeof(CommandHelp));
+    gchar *args[] = { "disable", "account_name" };
+
+    expect_any(accounts_disable, name);
+    will_return(accounts_disable, FALSE);
+
+    expect_string(cons_show, output, "No such account: account_name");
+    expect_string(cons_show, output, "");
+
+    gboolean result = cmd_account(args, *help);
+    assert_true(result);
+
+    free(help);
+}
diff --git a/tests/test_cmd_account.h b/tests/test_cmd_account.h
index b2b54382..f04485bb 100644
--- a/tests/test_cmd_account.h
+++ b/tests/test_cmd_account.h
@@ -11,3 +11,7 @@ void cmd_account_enable_shows_usage_when_no_arg(void **state);
 void cmd_account_enable_enables_account(void **state);
 void cmd_account_enable_shows_message_when_enabled(void **state);
 void cmd_account_enable_shows_message_when_account_doesnt_exist(void **state);
+void cmd_account_disable_shows_usage_when_no_arg(void **state);
+void cmd_account_disable_disables_account(void **state);
+void cmd_account_disable_shows_message_when_disabled(void **state);
+void cmd_account_disable_shows_message_when_account_doesnt_exist(void **state);
diff --git a/tests/testsuite.c b/tests/testsuite.c
index 6d4190bd..864cea2e 100644
--- a/tests/testsuite.c
+++ b/tests/testsuite.c
@@ -41,6 +41,10 @@ int main(int argc, char* argv[]) {
         unit_test(cmd_account_enable_enables_account),
         unit_test(cmd_account_enable_shows_message_when_enabled),
         unit_test(cmd_account_enable_shows_message_when_account_doesnt_exist),
+        unit_test(cmd_account_disable_shows_usage_when_no_arg),
+        unit_test(cmd_account_disable_disables_account),
+        unit_test(cmd_account_disable_shows_message_when_disabled),
+        unit_test(cmd_account_disable_shows_message_when_account_doesnt_exist),
 
         unit_test(cmd_rooms_shows_message_when_disconnected),
         unit_test(cmd_rooms_shows_message_when_disconnecting),