5 Test scheduling a package location change through the UI, then billing
6 on the day of the scheduled change.
10 use Test::More tests => 6;
12 use Date::Parse 'str2time';
13 use Date::Format 'time2str';
14 use Test::MockTime qw(set_fixed_time);
16 my $FS = FS::Test->new;
19 # set up a customer with an active package
20 my $cust = $FS->new_customer('Future location change');
21 $error = $cust->insert;
22 my $pkg = FS::cust_pkg->new({pkgpart => 2});
23 $error ||= $cust->order_pkg({ cust_pkg => $pkg });
24 my $date = str2time('2016-04-01');
25 set_fixed_time($date);
26 $error ||= $cust->bill_and_collect;
27 BAIL_OUT($error) if $error;
30 my %args = ( pkgnum => $pkg->pkgnum,
31 pkgpart => $pkg->pkgpart,
33 $FS->post('/misc/change_pkg.cgi', %args);
34 my $form = $FS->form('OrderPkgForm');
36 # Schedule the package change two days from now.
38 my $date_str = time2str('%x', $date);
41 start_date => $date_str,
43 address1 => int(rand(1000)) . ' Changed Street',
50 diag "requesting location change to $params{address1}";
52 foreach (keys %params) {
53 $form->value($_, $params{$_});
56 ok( $FS->error eq '' , 'form posted' );
57 if ( ok( $FS->page =~ m[location.reload], 'location change accepted' )) {
60 $FS->post($FS->redirect);
61 BAIL_OUT( $FS->error);
63 # check that the package change is set
64 $pkg = $pkg->replace_old;
65 my $new_pkgnum = $pkg->change_to_pkgnum;
66 ok( $new_pkgnum, 'package change is scheduled' );
68 # run it and check that the package change happened
69 diag("billing customer on $date_str");
70 set_fixed_time($date);
71 my $error = $cust->bill_and_collect;
72 BAIL_OUT($error) if $error;
74 $pkg = $pkg->replace_old;
75 ok($pkg->get('cancel'), "old package is canceled");
76 my $new_pkg = $FS->qsearchs('cust_pkg', { pkgnum => $new_pkgnum });
77 ok($new_pkg->setup, "new package is active");
78 ok($new_pkg->cust_location->address1 eq $params{'address1'}, "new location is correct")
79 or diag $new_pkg->cust_location->address1;