diff options
author | Matthew Somerville <matthew@mysociety.org> | 2020-06-15 21:02:37 +0100 |
---|---|---|
committer | M Somerville <matthew-github@dracos.co.uk> | 2020-11-11 10:29:20 +0000 |
commit | 6337ebfd91a87eaf5efa077c5f9a9eff286c1f76 (patch) | |
tree | 956b5b6c8ed7bd0ca8a2711bc0540f1cb383fb79 | |
parent | bc19b9e00f3d59a2f0694f2fcc3aab54fef35e9e (diff) |
[Bromley] Report missed bin within 2 working days.
-rw-r--r-- | perllib/FixMyStreet/App/Controller/Waste.pm | 2 | ||||
-rw-r--r-- | perllib/FixMyStreet/Cobrand/Bromley.pm | 22 | ||||
-rw-r--r-- | perllib/FixMyStreet/Cobrand/UK.pm | 6 | ||||
-rw-r--r-- | t/app/controller/waste.t | 15 | ||||
-rw-r--r-- | templates/web/bromley/waste/services.html | 4 |
5 files changed, 48 insertions, 1 deletions
diff --git a/perllib/FixMyStreet/App/Controller/Waste.pm b/perllib/FixMyStreet/App/Controller/Waste.pm index e606b1d8c..7556781cf 100644 --- a/perllib/FixMyStreet/App/Controller/Waste.pm +++ b/perllib/FixMyStreet/App/Controller/Waste.pm @@ -217,7 +217,7 @@ sub construct_bin_report_form { my $field_list = []; foreach (@{$c->stash->{service_data}}) { - next unless $_->{last}; + next unless $_->{last} && $_->{report_allowed}; my $id = $_->{service_id}; my $name = $_->{service_name}; push @$field_list, "service-$id" => { diff --git a/perllib/FixMyStreet/Cobrand/Bromley.pm b/perllib/FixMyStreet/Cobrand/Bromley.pm index ed96eb1bb..176762323 100644 --- a/perllib/FixMyStreet/Cobrand/Bromley.pm +++ b/perllib/FixMyStreet/Cobrand/Bromley.pm @@ -10,6 +10,7 @@ use Integrations::Echo; use Sort::Key::Natural qw(natkeysort_inplace); use Try::Tiny; use FixMyStreet::DateRange; +use FixMyStreet::WorkingDays; sub council_area_id { return 2482; } sub council_area { return 'Bromley'; } @@ -507,6 +508,7 @@ sub bin_services_for_address { id => $_->{Id}, service_id => $_->{ServiceId}, service_name => $service_name_override{$_->{ServiceId}} || $_->{ServiceName}, + report_allowed => within_working_days($schedules->{last}{date}, 2), request_allowed => $request_allowed{$_->{ServiceId}}, request_containers => $containers, request_max => $quantity_max{$_->{ServiceId}}, @@ -590,4 +592,24 @@ sub bin_future_collections { return $events; } +=over + +=item within_working_days + +Given a DateTime object and a number, return true if today is less than or +equal to that number of working days (excluding weekends and bank holidays) +after the date. + +=back + +=cut + +sub within_working_days { + my ($dt, $days) = @_; + my $wd = FixMyStreet::WorkingDays->new(public_holidays => FixMyStreet::Cobrand::UK::public_holidays()); + $dt = $wd->add_days($dt, $days)->ymd; + my $today = DateTime->now->set_time_zone(FixMyStreet->local_time_zone)->ymd; + return $today le $dt; +} + 1; diff --git a/perllib/FixMyStreet/Cobrand/UK.pm b/perllib/FixMyStreet/Cobrand/UK.pm index 3ede055b9..988458e0f 100644 --- a/perllib/FixMyStreet/Cobrand/UK.pm +++ b/perllib/FixMyStreet/Cobrand/UK.pm @@ -452,6 +452,12 @@ sub check_recaptcha { unless $res->{success}; } +sub public_holidays { + my $nation = shift || 'england-and-wales'; + my $json = _get_bank_holiday_json(); + return [ map { $_->{date} } @{$json->{$nation}{events}} ]; +} + sub is_public_holiday { my %args = @_; $args{date} ||= localtime; diff --git a/t/app/controller/waste.t b/t/app/controller/waste.t index 9bc03e169..85536981b 100644 --- a/t/app/controller/waste.t +++ b/t/app/controller/waste.t @@ -1,9 +1,15 @@ +use utf8; use Test::MockModule; +use Test::MockTime qw(:all); use FixMyStreet::TestMech; FixMyStreet::App->log->disable('info'); END { FixMyStreet::App->log->enable('info'); } +# Mock fetching bank holidays +my $uk = Test::MockModule->new('FixMyStreet::Cobrand::UK'); +$uk->mock('_fetch_url', sub { '{}' }); + my $mech = FixMyStreet::TestMech->new; my $body = $mech->create_body_ok(2482, 'Bromley Council'); @@ -44,6 +50,7 @@ FixMyStreet::override_config { $mech->content_contains('can’t find your address'); }; subtest 'Address lookup' => sub { + set_fixed_time('2020-05-28T17:00:00Z'); # After sample data collection $mech->get_ok('/waste'); $mech->submit_form_ok({ with_fields => { postcode => 'BR1 1AA' } }); $mech->submit_form_ok({ with_fields => { address => '1000000002' } }); @@ -51,7 +58,15 @@ FixMyStreet::override_config { $mech->content_contains('Food Waste'); }; subtest 'Report a missed bin' => sub { + $mech->content_contains('service-101', 'Can report, last collection was 27th'); + $mech->content_contains('service-537', 'Can report, last collection was 27th'); + $mech->content_lacks('service-535', 'Cannot report, last collection was 20th'); + $mech->content_lacks('service-542', 'Cannot report, last collection was 18th'); $mech->follow_link_ok({ text => 'Report a missed collection' }); + $mech->content_contains('service-101', 'Checkbox, last collection was 27th'); + $mech->content_contains('service-537', 'Checkbox, last collection was 27th'); + $mech->content_lacks('service-535', 'No checkbox, last collection was 20th'); + $mech->content_lacks('service-542', 'No checkbox, last collection was 18th'); $mech->submit_form_ok({ form_number => 2 }); $mech->content_contains('Please specify what was missed'); $mech->submit_form_ok({ with_fields => { 'service-101' => 1 } }); diff --git a/templates/web/bromley/waste/services.html b/templates/web/bromley/waste/services.html index 2caf41738..3f9f47753 100644 --- a/templates/web/bromley/waste/services.html +++ b/templates/web/bromley/waste/services.html @@ -1,9 +1,13 @@ +[% IF unit.report_allowed %] [% any_report_allowed = 1 %] <form method="post" action="[% c.uri_for_action('waste/report', [ uprn ]) %]"> <input type="hidden" name="token" value="[% csrf_token %]"> <input type="hidden" name="service-[% unit.service_id %]" value="1"> <input type="submit" value="Report a [% unit.service_name FILTER lower %] collection as missed" class="waste-service-descriptor waste-service-link"> </form> +[% ELSE %] + <span class="waste-service-descriptor">Please note that missed collections can only be reported within 2 working days of your scheduled collection day.</span> +[% END %] <a href="[% c.uri_for_action('waste/enquiry', [ uprn ]) %]?template=problem&service_id=[% unit.service_id %]" class="waste-service-link waste-service-descriptor">Report a problem with a [% unit.service_name FILTER lower %] collection</a> [% IF unit.request_allowed %] [% any_request_allowed = 1 %] |