more robust testing platform, #37340
[freeside.git] / FS / t / suite / 02-bill_customer.t
1 #!/usr/bin/perl
2
3 use FS::Test;
4 use Test::More tests => 6;
5 use Test::MockTime 'set_fixed_time';
6 use Date::Parse 'str2time';
7 use FS::cust_main;
8
9 my $FS = FS::Test->new;
10
11 # After test 01: cust#2 has a package set to bill on 2016-03-20.
12 # Set local time.
13 my $date = '2016-03-20';
14 set_fixed_time(str2time($date));
15 my $cust_main = FS::cust_main->by_key(2);
16 my @return;
17
18 # Bill the customer.
19 my $error = $cust_main->bill( return_bill => \@return );
20 ok($error eq '', "billed on $date") or diag($error);
21
22 # should be an invoice now
23 my $cust_bill = $return[0];
24 isa_ok($cust_bill, 'FS::cust_bill');
25
26 # $60/month * (30 days - 19 days)/30 days = $42
27 ok( $cust_bill->charged == 42.00, 'prorated first month correctly' );
28
29 # the package bill date should now be 2016-04-01
30 my @lineitems = $cust_bill->cust_bill_pkg;
31 ok( scalar(@lineitems) == 1, 'one package was billed' );
32 my $pkg = $lineitems[0]->cust_pkg;
33 ok( $pkg->status eq 'active', 'package is now active' );
34 ok( $pkg->bill == str2time('2016-04-01'), 'package bill date set correctly' );
35
36 1;