diff options
author | James Booth <boothj5@gmail.com> | 2013-12-16 01:04:25 +0000 |
---|---|---|
committer | James Booth <boothj5@gmail.com> | 2013-12-16 01:04:25 +0000 |
commit | 52f6ad6fe19149a351fba673aa378508cd7c0558 (patch) | |
tree | 4822fae4e243d2b4e27e4aeb78d65cdf09596aa3 /tests/test_cmd_account.c | |
parent | 52d15242abe9add6eef0accef8d91b213e826171 (diff) | |
download | profani-tty-52f6ad6fe19149a351fba673aa378508cd7c0558.tar.gz |
Added validation tests for "/account set" and "/account set jid"
Diffstat (limited to 'tests/test_cmd_account.c')
-rw-r--r-- | tests/test_cmd_account.c | 146 |
1 files changed, 146 insertions, 0 deletions
diff --git a/tests/test_cmd_account.c b/tests/test_cmd_account.c index 95924f59..2e43bca6 100644 --- a/tests/test_cmd_account.c +++ b/tests/test_cmd_account.c @@ -374,3 +374,149 @@ void cmd_account_rename_shows_message_when_not_renamed(void **state) free(help); } + +void cmd_account_set_shows_usage_when_no_args(void **state) +{ + CommandHelp *help = malloc(sizeof(CommandHelp)); + help->usage = "some usage"; + gchar *args[] = { "set", NULL }; + + expect_string(cons_show, output, "Usage: some usage"); + + gboolean result = cmd_account(args, *help); + assert_true(result); + + free(help); +} + +void cmd_account_set_shows_usage_when_one_arg(void **state) +{ + CommandHelp *help = malloc(sizeof(CommandHelp)); + help->usage = "some usage"; + gchar *args[] = { "set", "a_account", NULL }; + + expect_string(cons_show, output, "Usage: some usage"); + + gboolean result = cmd_account(args, *help); + assert_true(result); + + free(help); +} + +void cmd_account_set_shows_usage_when_two_args(void **state) +{ + CommandHelp *help = malloc(sizeof(CommandHelp)); + help->usage = "some usage"; + gchar *args[] = { "set", "a_account", "a_property", NULL }; + + expect_string(cons_show, output, "Usage: some usage"); + + gboolean result = cmd_account(args, *help); + assert_true(result); + + free(help); +} + +void cmd_account_set_checks_account_exists(void **state) +{ + CommandHelp *help = malloc(sizeof(CommandHelp)); + help->usage = "some usage"; + gchar *args[] = { "set", "a_account", "a_property", "a_value", NULL }; + + expect_string(accounts_account_exists, account_name, "a_account"); + will_return(accounts_account_exists, FALSE); + + expect_any_count(cons_show, output, 2); + + gboolean result = cmd_account(args, *help); + assert_true(result); + + free(help); +} + +void cmd_account_set_shows_message_when_account_doesnt_exist(void **state) +{ + CommandHelp *help = malloc(sizeof(CommandHelp)); + help->usage = "some usage"; + gchar *args[] = { "set", "a_account", "a_property", "a_value", NULL }; + + expect_any(accounts_account_exists, account_name); + will_return(accounts_account_exists, FALSE); + + expect_string(cons_show, output, "Account a_account doesn't exist"); + expect_string(cons_show, output, ""); + + gboolean result = cmd_account(args, *help); + assert_true(result); + + free(help); +} + +void cmd_account_set_jid_shows_message_for_malformed_jid(void **state) +{ + CommandHelp *help = malloc(sizeof(CommandHelp)); + help->usage = "some usage"; + gchar *args[] = { "set", "a_account", "jid", "@malformed", NULL }; + + expect_any(accounts_account_exists, account_name); + will_return(accounts_account_exists, TRUE); + + expect_string(cons_show, output, "Malformed jid: @malformed"); + + gboolean result = cmd_account(args, *help); + assert_true(result); + + free(help); +} + +void cmd_account_set_jid_sets_barejid(void **state) +{ + CommandHelp *help = malloc(sizeof(CommandHelp)); + help->usage = "some usage"; + gchar *args[] = { "set", "a_account", "jid", "a_local@a_domain/a_resource", NULL }; + + expect_any(accounts_account_exists, account_name); + will_return(accounts_account_exists, TRUE); + + expect_string(accounts_set_jid, account_name, "a_account"); + expect_string(accounts_set_jid, value, "a_local@a_domain"); + + expect_string(cons_show, output, "Updated jid for account a_account: a_local@a_domain"); + + expect_any(accounts_set_resource, account_name); + expect_any(accounts_set_resource, value); + + expect_any(cons_show, output); + expect_string(cons_show, output, ""); + + gboolean result = cmd_account(args, *help); + assert_true(result); + + free(help); +} + +void cmd_account_set_jid_sets_resource(void **state) +{ + CommandHelp *help = malloc(sizeof(CommandHelp)); + help->usage = "some usage"; + gchar *args[] = { "set", "a_account", "jid", "a_local@a_domain/a_resource", NULL }; + + expect_any(accounts_account_exists, account_name); + will_return(accounts_account_exists, TRUE); + + expect_any(accounts_set_jid, account_name); + expect_any(accounts_set_jid, value); + + expect_any(cons_show, output); + + expect_string(accounts_set_resource, account_name, "a_account"); + expect_string(accounts_set_resource, value, "a_resource"); + + expect_string(cons_show, output, "Updated resource for account a_account: a_resource"); + expect_string(cons_show, output, ""); + + gboolean result = cmd_account(args, *help); + assert_true(result); + + free(help); +} |