#!/usr/bin/perl use strict; use Test::More 'no_plan'; use lib "$ENV{LJHOME}/cgi-bin"; require "ljlib.pl"; require "paylib.pl"; use LJ::Test qw(temp_user memcache_stress); use Class::Autouse qw ( LJ::SMS::Message LJ::SMS::MessageHandler ); use Carp qw (croak); my $lastmsg = ""; my $lastmsgobj = undef; # trap message sending $LJ::_T_SMS_SEND = sub { my $msg = shift; $lastmsgobj = $msg; $lastmsg = $msg->body_text; }; sub run_tests { foreach my $qty (qw(100 250)) { my $price = LJ::Pay::extra_sms_price($qty); my $u = temp_user(); $u->set_sms_number('+15555551212', verified => 'Y') or die "unable to set sms number"; my $pmt = LJ::Pay::new_sms_payment($u, $qty); # bill user via SMS payment gateway my $msg = $pmt->bill_via_sms("Send STOP at any time to cancel."); # note: this test fails on dev environments because they are explicitly # set to be equal (to avoid accidentally billing a dev instance!) if ($LJ::IS_DEV_SERVER) { ok(eq_hash($LJ::SMS_PAYMENT_CONFIG{$price}, $LJ::SMS_GATEWAY_CONFIG{default}), "payment config doesn't differ from default gateway"); } else { ok(! eq_hash($LJ::SMS_PAYMENT_CONFIG{$price}, $LJ::SMS_GATEWAY_CONFIG{default}), "payment config differs from default gateway"); } is_deeply($lastmsgobj->gateway->{config}, $LJ::SMS_PAYMENT_CONFIG{$price}, "$qty: sent through correct gateway"); ok($lastmsg eq $msg->body_text, "$qty: message sent"); $lastmsgobj->save_to_db; my $dbmsg = LJ::SMS::Message->load($u, $msg->id); ok($dbmsg && $dbmsg->id == $msg->id && $dbmsg->meta('payid') == $pmt->{payid}, "$qty: message saved"); } } run_tests();