# -*-perl-*- use strict; use Test::More 'no_plan'; use lib "$ENV{LJHOME}/cgi-bin"; require 'ljlib.pl'; use LJ::Console; use LJ::Test qw (temp_user temp_comm); local $LJ::T_NO_COMMAND_PRINT = 1; my $u = temp_user(); my $u2 = temp_user(); LJ::set_remote($u); my $run = sub { my $cmd = shift; return LJ::Console->run_commands_text($cmd); }; ## FRAUD WATCH ## is($run->("fraud_watch " . $u2->user . " add"), "error: You are not authorized to run this command."); $u->grant_priv("moneyenter"); is($run->("fraud_watch " . $u2->user . " add"), "success: Fraud watch added for " . $u2->user); ok($u2->prop("fraud_watch"), "Fraudwatch set correctly."); is($run->("fraud_watch " . $u2->user . " remove"), "success: Fraud watch removed for " . $u2->user); ok(!$u2->prop("fraud_watch"), "Fraudwatch unset correctly."); $u->revoke_priv("moneyenter"); ## ALLOW PAYMENTS ## is($run->("allow_pay permit " . $u2->user), "error: You are not authorized to run this command."); $u->grant_priv("moneyenter"); is($run->("allow_pay permit " . $u2->user), "success: Permitting payments for user " . $u2->user); ok($u2->prop("allow_pay") eq "Y", "Payments permitted."); is($run->("allow_pay deny " . $u2->user), "success: Denying payments for user " . $u2->user); ok($u2->prop("allow_pay") eq "N", "Payments no longer permitted."); $u->revoke_priv("moneyenter"); # COUPON REVOKE my $dbh = LJ::get_db_writer(); $dbh->do("INSERT INTO coupon (cpid, auth, rcptid) VALUES (505050, 'banananas', ?)", undef, $u2->id); is($run->("coupon_revoke " . $u2->user . " 505050-banananas"), "error: You are not authorized to run this command."); $u->grant_priv("moneyenter"); is($run->("coupon_revoke " . $u2->user . " 505050-bananana"), "error: Invalid coupon. Already revoked?"); is($run->("coupon_revoke " . $u->user . " 505050-banananas"), "error: Coupon owner is not '" . $u->user . "'"); is($run->("coupon_revoke " . $u2->user . " 505050-banananas"), "success: Coupon 505050-banananas successfully revoked from " . $u2->user); $u->revoke_priv("moneyenter"); ## INVENTORY $dbh->do("INSERT INTO inventory (item, subitem, qty, avail, price) VALUES " . "('food', 'banana', 12, 12, '12.50')"); is($run->("inventory show"), "error: You are not authorized to run this command."); $u->grant_priv("moneyenter"); is($run->("inventory add food-orange 15"), "error: Item not found. No change made."); is($run->("inventory remove food-orange 17"), "error: Item not found. No change made."); is($run->("inventory price food-orange 6.00"), "error: Item not found. No change made."); ok($run->("inventory show") =~ /12 *12 *\$12\.50 *food-banana/, "This inventory has bananas"); is($run->("inventory add food-banana 15"), "success: food-banana changed."); ok($run->("inventory show") =~ /27 *27 *\$12\.50 *food-banana/, "Inventory increased"); is($run->("inventory remove food-banana 17"), "success: food-banana changed."); ok($run->("inventory show") =~ /10 *10 *\$12\.50 *food-banana/, "Inventory decreased"); is($run->("inventory price food-banana 6.00"), "success: food-banana price changed."); ok($run->("inventory show") =~ /10 *10 *\$ 6\.00 *food-banana/, "Price changed."); $dbh->do("DELETE FROM inventory WHERE item='food' AND subitem='banana'");