Skip to content

Commit

Permalink
[Peterborough] Update amend/refund/cancel times.
Browse files Browse the repository at this point in the history
Switch to working day before.

Co-Authored-By: Moray Jones <[email protected]>
  • Loading branch information
dracos and MorayMySoc committed Nov 8, 2024
1 parent 68c9273 commit a020eb8
Show file tree
Hide file tree
Showing 16 changed files with 216 additions and 128 deletions.
7 changes: 4 additions & 3 deletions perllib/FixMyStreet/Cobrand/Peterborough/Bulky.pm
Original file line number Diff line number Diff line change
Expand Up @@ -54,12 +54,13 @@ sub bulky_workpack_name {
qr/Waste-(BULKY WASTE|WHITES)-(?<date_suffix>\d{6})/;
}

=item * User can cancel bulky collection up to 15:00 before the day of
collection
=item * User can amend/refund/cancel up to 14:00 the working day before the bulky collection
=cut

sub bulky_cancellation_cutoff_time { { hours => 15, minutes => 0 } }
sub bulky_cancellation_cutoff_time { { hours => 14, minutes => 0, working_days => 1 } }
sub bulky_amendment_cutoff_time { { hours => 14, minutes => 0, working_days => 1 } }
sub bulky_refund_cutoff_time { { hours => 14, minutes => 0, working_days => 1 } }

=item * Bulky collections start at 6:45 each (working) day
Expand Down
22 changes: 18 additions & 4 deletions perllib/FixMyStreet/Roles/Cobrand/BulkyWaste.pm
Original file line number Diff line number Diff line change
Expand Up @@ -337,15 +337,29 @@ will be one day later than tomorrow after 7am).

sub bulky_collection_window_start_date {
my ($self, $now) = @_;
my $start_date = $now->clone->truncate( to => 'day' )->add( days => 1 );
my $start_date = $now->clone->truncate( to => 'day' );

# If now is past cutoff time, push start date one day later
my $cutoff_time = $self->bulky_cancellation_cutoff_time();
my $days_before = $cutoff_time->{days_before} // 1;
my $cutoff_date_now = $now->clone->subtract( days => $days_before );
my $cutoff_date = $self->_bulky_cancellation_cutoff_date($now);
if ($cutoff_date_now >= $cutoff_date) {
my $cutoff_date_now = $cutoff_date->clone->set( hour => $now->hour, minute => $now->minute );

if (!$cutoff_time->{working_days}) {
if ($cutoff_date_now >= $cutoff_date) {
$start_date->add( days => 1 );
}
$start_date->add( days => $days_before );
} else {
my $wd = FixMyStreet::WorkingDays->new(
public_holidays => FixMyStreet::Cobrand::UK::public_holidays(),
);
if ($cutoff_date_now >= $cutoff_date || $wd->is_non_working_day($start_date)) {
$start_date = $wd->add_days($start_date, 1);
}
$start_date = $wd->add_days($start_date, $days_before);
}

return $start_date;
}

Expand Down Expand Up @@ -484,7 +498,7 @@ sub within_bulky_refund_window {

sub _bulky_refund_cutoff_date {
my ($self, $collection_date) = @_;
return _bulky_time_object_to_datetime($collection_date, $self->bulky_collection_time());
return _bulky_time_object_to_datetime($collection_date, $self->bulky_refund_cutoff_time());
}

sub bulky_nice_collection_date {
Expand Down
18 changes: 12 additions & 6 deletions perllib/FixMyStreet/WorkingDays.pm
Original file line number Diff line number Diff line change
Expand Up @@ -38,12 +38,7 @@ sub add_days {
$dt = $dt->clone;
while ( $days > 0 ) {
$dt->add ( days => $subtract ? -1 : 1 );
next if $self->is_public_holiday($dt);
if ($self->saturdays) {
next if $self->is_sunday($dt);
} else {
next if $self->is_weekend($dt);
}
next if $self->is_non_working_day($dt);
$days--;
}
return $dt;
Expand All @@ -61,6 +56,17 @@ sub sub_days {
return $self->add_days(@_, 1);
}

=item is_non_working_day
Given a DateTime object, return true if it's a non-working day.
=cut

sub is_non_working_day {
my ( $self, $dt ) = @_;
return $self->is_public_holiday($dt) || $self->is_sunday($dt) || (!$self->saturdays && $self->is_weekend($dt));
}

=item is_public_holiday
Given a DateTime object, return true if it is a public holiday.
Expand Down
44 changes: 18 additions & 26 deletions t/app/controller/waste_peterborough_bulky.t
Original file line number Diff line number Diff line change
Expand Up @@ -349,8 +349,6 @@ FixMyStreet::override_config {
$mech->content_contains('Before you start your booking');
$mech->content_contains('a href="peterborough-bulky-waste-tandc.com"');
$mech->content_contains('You can request up to <strong>five items per collection');
$mech->content_contains('You can amend the items in your booking up until 3pm the day before the collection is scheduled');
$mech->content_contains('the day before collection is scheduled are entitled to a refund');
$mech->content_lacks('The price you pay depends how many items you would like collected:');
$mech->content_lacks('Up to 4 items');
$mech->content_lacks('Bookings are final and non refundable');
Expand Down Expand Up @@ -432,7 +430,7 @@ FixMyStreet::override_config {
$mech->content_contains('£23.50');
$mech->content_contains("<dd>$date_dow $date_day August 2022</dd>");
my $day_before = $date_day - 1;
$mech->content_contains("15:00 on $day_before August 2022");
$mech->content_contains("14:00 on $day_before August 2022");
$mech->content_lacks('Cancel this booking');
$mech->content_lacks('Show upcoming bin days');
$mech->content_contains('a href="peterborough-bulky-waste-tandc.com"');
Expand Down Expand Up @@ -559,8 +557,6 @@ FixMyStreet::override_config {
# Collection date: 2022-08-26T00:00:00
# Time/date that is within the cancellation & refund window:
my $good_date = '2022-08-25T05:44:59Z'; # 06:44:59 UK time
# Time/date that is within the cancellation but not refund window:
my $no_refund_date = '2022-08-25T12:00:00Z'; # 13:00:00 UK time
# Time/date that isn't:
my $bad_date = '2022-08-25T15:00:00Z';

Expand Down Expand Up @@ -604,8 +600,8 @@ FixMyStreet::override_config {

set_fixed_time($good_date);
$mech->get_ok('/report/' . $report->id);
$mech->content_contains("You can cancel this booking till");
$mech->content_contains("15:00 on 25 August 2022");
$mech->content_contains("You can cancel and receive a refund up to");
$mech->content_contains("14:00 on 25 August 2022");

# Presence of external_id in report implies we have sent request
# to Bartec
Expand All @@ -621,8 +617,8 @@ FixMyStreet::override_config {
# Cannot cancel if cancellation window passed
set_fixed_time($bad_date);
$mech->get_ok('/report/' . $report->id);
$mech->content_lacks("You can cancel this booking till");
$mech->content_lacks("15:00 on 25 August 2022");
$mech->content_lacks("You can cancel and receive a refund up to");
$mech->content_lacks("14:00 on 25 August 2022");
$mech->content_lacks('/waste/PE1%203NA:100090215480/bulky/cancel/' . $report->id);
$mech->content_lacks('Cancel this booking');

Expand Down Expand Up @@ -655,7 +651,7 @@ FixMyStreet::override_config {
# Cancellation messaging & options
$mech->content_lacks('This collection has been cancelled');
$mech->content_lacks('View cancellation report');
$mech->content_contains("You can cancel this booking till");
$mech->content_contains("You can cancel and receive a refund up to");
$mech->content_contains('/waste/PE1%203NA:100090215480/bulky/cancel/' . $report->id);
$mech->content_contains('Cancel this booking');
};
Expand All @@ -670,7 +666,7 @@ FixMyStreet::override_config {
# Cancellation messaging & options
$mech->content_lacks('This collection has been cancelled');
$mech->content_lacks('View cancellation report');
$mech->content_contains("You can cancel this booking till");
$mech->content_contains("You can cancel and receive a refund up to");
$mech->content_contains('/waste/PE1%203NA:100090215480/bulky/cancel/' . $report->id);
$mech->content_contains('Cancel this booking');
};
Expand Down Expand Up @@ -764,7 +760,7 @@ FixMyStreet::override_config {
$mech->content_contains('you can add up to 2 more items');
$mech->content_contains('£0.00 (£23.50 already paid)');
$mech->content_contains("<dd>Friday 26 August 2022</dd>");
$mech->content_contains("15:00 on 25 August 2022");
$mech->content_contains("14:00 on 25 August 2022");
$mech->content_lacks('Cancel this booking');
$mech->content_lacks('Show upcoming bin days');
$mech->submit_form_ok({ with_fields => { tandc => 1 } });
Expand Down Expand Up @@ -805,7 +801,7 @@ FixMyStreet::override_config {
$mech->content_contains('you can add up to 3 more items');
$mech->content_contains('£0.00 (£23.50 already paid)');
$mech->content_contains("<dd>Friday 26 August 2022</dd>");
$mech->content_contains("15:00 on 25 August 2022");
$mech->content_contains("14:00 on 25 August 2022");
$mech->content_lacks('Cancel this booking');
$mech->content_lacks('Show upcoming bin days');

Expand Down Expand Up @@ -882,7 +878,7 @@ FixMyStreet::override_config {
my $email = $mech->get_email->as_string;
like $email, qr/1 Pope Way/;
like $email, qr/Collection date: Friday 26 August 2022/;
like $email, qr{rborough.example.org/waste/PE1%203NA%3A100090215480/bulky/cancel/$report_id};
like $email, qr{/waste/PE1%203NA%3A100090215480/bulky/cancel/$report_id};
$mech->clear_emails_ok;
};

Expand Down Expand Up @@ -958,7 +954,7 @@ FixMyStreet::override_config {
$mech->content_contains('you can add up to 4 more items');
$mech->content_contains('£23.50');
$mech->content_contains("<dd>Friday 02 September 2022</dd>");
$mech->content_contains("15:00 on 01 September 2022");
$mech->content_contains("14:00 on 01 September 2022");
$mech->content_lacks('Cancel this booking');
$mech->content_lacks('Show upcoming bin days');
$mech->submit_form_ok({ with_fields => { tandc => 1 } });
Expand Down Expand Up @@ -1065,10 +1061,7 @@ FixMyStreet::override_config {
$mech->content_lacks( 'bulky/cancel/' . $report->id . '">Cancel booking',
'Cancel option unavailable if outside cancellation window' );

set_fixed_time($no_refund_date);
$mech->get_ok("$base_path/bulky/cancel/" . $report->id);
$mech->content_lacks("If you cancel this booking you will receive a refund");
$mech->content_contains("No Refund Will Be Issued");
set_fixed_time($good_date);

$report->update_extra_field({ name => 'CHARGEABLE', value => 'FREE'});
$report->update;
Expand All @@ -1078,7 +1071,6 @@ FixMyStreet::override_config {
$report->update_extra_field({ name => 'CHARGEABLE', value => 'CHARGED'});
$report->update;

set_fixed_time($good_date);
$mech->get_ok("$base_path/bulky/cancel/" . $report->id);
$mech->content_contains("If you cancel this booking you will receive a refund");
$mech->submit_form_ok( { with_fields => { confirm => 1 } } );
Expand Down Expand Up @@ -1168,26 +1160,26 @@ FixMyStreet::override_config {
$mech->get_ok($path);
$mech->content_contains('This collection has been cancelled');
$mech->content_lacks('View cancellation report');
$mech->content_lacks("You can cancel this booking till");
$mech->content_lacks("15:00 on 25 August 2022");
$mech->content_lacks("You can cancel and receive a refund up to");
$mech->content_lacks("14:00 on 25 August 2022");
$mech->content_lacks('Cancel this booking');

# Superuser
$mech->log_in_ok( $super->email );
$mech->get_ok($path);
$mech->content_contains('This collection has been cancelled');
$mech->content_contains('View cancellation report');
$mech->content_lacks("You can cancel this booking till");
$mech->content_lacks("15:00 on 25 August 2022");
$mech->content_lacks("You can cancel and receive a refund up to");
$mech->content_lacks("14:00 on 25 August 2022");
$mech->content_lacks('Cancel this booking');

# P'bro staff
$mech->log_in_ok( $staff->email );
$mech->get_ok($path);
$mech->content_contains('This collection has been cancelled');
$mech->content_contains('View cancellation report');
$mech->content_lacks("You can cancel this booking till");
$mech->content_lacks("15:00 on 25 August 2022");
$mech->content_lacks("You can cancel and receive a refund up to");
$mech->content_lacks("14:00 on 25 August 2022");
$mech->content_lacks('Cancel this booking');
};

Expand Down
Loading

0 comments on commit a020eb8

Please sign in to comment.