diff options
-rw-r--r-- | .cypress/cypress/integration/buckinghamshire.js | 34 | ||||
-rwxr-xr-x | bin/fixmystreet.com/buckinghamshire-flytipping | 20 | ||||
-rw-r--r-- | perllib/FixMyStreet/Cobrand/Buckinghamshire.pm | 49 | ||||
-rw-r--r-- | t/cobrand/bucks.t | 105 | ||||
-rw-r--r-- | web/cobrands/buckinghamshire/assets.js | 29 |
5 files changed, 86 insertions, 151 deletions
diff --git a/.cypress/cypress/integration/buckinghamshire.js b/.cypress/cypress/integration/buckinghamshire.js index 281f76a21..90aa6809d 100644 --- a/.cypress/cypress/integration/buckinghamshire.js +++ b/.cypress/cypress/integration/buckinghamshire.js @@ -1,4 +1,4 @@ -describe('flytipping', function() { +describe('buckinghamshire cobrand', function() { beforeEach(function() { cy.server(); @@ -12,37 +12,6 @@ describe('flytipping', function() { cy.get('[name=pc]').parents('form').submit(); }); - it('handles flytipping on a road correctly', function() { - cy.get('.olMapViewport #fms_pan_zoom_zoomin').click(); - cy.wait('@roads-layer'); - cy.get('#map_box').click(290, 307); - cy.wait('@report-ajax'); - cy.get('select:eq(4)').select('Flytipping'); - cy.get('#form_road-placement').select('off-road'); - cy.contains('sent to Chiltern District Council and also'); - cy.get('#form_road-placement').select('road'); - cy.contains('sent to Buckinghamshire Council and also'); - }); - - it('handles flytipping off a road correctly', function() { - cy.get('#map_box').click(200, 307); - cy.wait('@report-ajax'); - cy.get('select:eq(4)').select('Flytipping'); - cy.contains('sent to Chiltern District Council and also'); - - cy.get('[name=title]').type('Title'); - cy.get('[name=detail]').type('Detail'); - cy.get('.js-new-report-user-show').click(); - cy.get('.js-new-report-show-sign-in').should('be.visible').click(); - cy.get('#form_username_sign_in').type('user@example.org'); - cy.get('[name=password_sign_in]').type('password'); - cy.get('[name=password_sign_in]').parents('form').submit(); - cy.get('#map_sidebar').should('contain', 'check and confirm your details'); - cy.wait('@report-ajax'); - cy.get('#map_sidebar').parents('form').submit(); - cy.get('body').should('contain', 'Thank you for your report'); - }); - it('sets the site_code correctly', function() { cy.get('.olMapViewport #fms_pan_zoom_zoomin').click(); cy.wait('@roads-layer'); @@ -57,7 +26,6 @@ describe('flytipping', function() { cy.wait('@report-ajax'); cy.get('select:eq(4)').select('Flytipping'); cy.wait('@around-ajax'); - cy.get('.js-hide-duplicate-suggestions:first').should('be.visible').click(); cy.get('[name=title]').type('Title'); cy.get('[name=detail]').type('Detail'); diff --git a/bin/fixmystreet.com/buckinghamshire-flytipping b/bin/fixmystreet.com/buckinghamshire-flytipping index 70a37ea34..d42467521 100755 --- a/bin/fixmystreet.com/buckinghamshire-flytipping +++ b/bin/fixmystreet.com/buckinghamshire-flytipping @@ -57,12 +57,22 @@ sub find_problems { $time_param = { '<', \$to }; } - # Fetch all Flytipping problems sent only to districts, between $from and $to - my $q = FixMyStreet::DB->resultset("Problem")->search( - \[ "? @> regexp_split_to_array(bodies_str, ',')", [ {} => \@district_ids ] ] - )->search({ + # Fetch all Flytipping problems made off-road (i.e. those that previously + # would been sent only to districts) any any older ones which actually were + # sent to districts, between $from and $to + my $q = FixMyStreet::DB->resultset("Problem")->search([ + # Reports sent to district, made before the unitary switchover + -and => [ + \[ "? @> regexp_split_to_array(bodies_str, ',')", [ {} => \@district_ids ] ], + category => 'Flytipping' + ], + # Reports sent to Bucks Council after unitary switchover + { + bodies_str => $body->id, + category => 'Flytipping (off-road)' + } + ])->search({ state => [ FixMyStreet::DB::Result::Problem->open_states() ], - category => 'Flytipping', confirmed => $time_param, }); diff --git a/perllib/FixMyStreet/Cobrand/Buckinghamshire.pm b/perllib/FixMyStreet/Cobrand/Buckinghamshire.pm index 081628ec4..188a503c1 100644 --- a/perllib/FixMyStreet/Cobrand/Buckinghamshire.pm +++ b/perllib/FixMyStreet/Cobrand/Buckinghamshire.pm @@ -99,41 +99,15 @@ sub open311_contact_meta_override { } if $service->{service_name} eq 'Flytipping'; } -sub process_open311_extras { - my ($self, $c, $body, $extra) = @_; - - return unless $c->stash->{report}; # Don't care about updates - - $self->flytipping_body_fix( - $c->stash->{report}, - $c->get_param('road-placement'), - $c->stash->{field_errors}, - ); -} - -sub flytipping_body_fix { - my ($self, $report, $road_placement, $errors) = @_; +sub report_new_munge_before_insert { + my ($self, $report) = @_; return unless $report->category eq 'Flytipping'; - if ($report->bodies_str =~ /,/) { - # Sent to both councils in the area - my @bodies = values %{$report->bodies}; - my $county = (grep { $_->name =~ /^Buckinghamshire/ } @bodies)[0]; - my $district = (grep { $_->name !~ /^Buckinghamshire/ } @bodies)[0]; - # Decide which to send to based upon the answer to the extra question: - if ($road_placement eq 'road') { - $report->bodies_str($county->id); - } elsif ($road_placement eq 'off-road') { - $report->bodies_str($district->id); - } - } else { - # If the report is only being sent to the district, we do - # not care about the road question, if it is missing - if (!$report->to_body_named('Buckinghamshire')) { - delete $errors->{'xroad-placement'}; - } - } + my $placement = $self->{c}->get_param('road-placement'); + return unless $placement && $placement eq 'off-road'; + + $report->category('Flytipping (off-road)'); } sub filter_report_description { @@ -410,15 +384,8 @@ sub get_geocoder { 'OSM' } sub categories_restriction { my ($self, $rs) = @_; - # Buckinghamshire is a two-tier council, but mostly want to display - # county-level categories on their cobrand. - return $rs->search( - [ - { 'body_areas.area_id' => 2217 }, - { category => [ 'Flytipping', 'Car Parks' ] }, - ], - { join => { body => 'body_areas' } } - ); + + return $rs->search( { category => { '!=', 'Flytipping (off-road)'} } ); } sub lookup_site_code_config { { diff --git a/t/cobrand/bucks.t b/t/cobrand/bucks.t index a52a8ea56..230a52f99 100644 --- a/t/cobrand/bucks.t +++ b/t/cobrand/bucks.t @@ -4,18 +4,34 @@ use FixMyStreet::Script::Reports; my $mech = FixMyStreet::TestMech->new; +# disable info logs for this test run +FixMyStreet::App->log->disable('info'); +END { FixMyStreet::App->log->enable('info'); } + my $body = $mech->create_body_ok(2217, 'Buckinghamshire', { - send_method => 'Open311', api_key => 'key', endpoint => 'endpoint', jurisdiction => 'fms' }); + send_method => 'Open311', api_key => 'key', endpoint => 'endpoint', jurisdiction => 'fms', can_be_devolved => 1 }); my $counciluser = $mech->create_user_ok('counciluser@example.com', name => 'Council User', from_body => $body); - -$mech->create_contact_ok(body_id => $body->id, category => 'Flytipping', email => "FLY"); +my $publicuser = $mech->create_user_ok('fmsuser@example.org', name => 'Simon Neil'); + +my $contact = $mech->create_contact_ok(body_id => $body->id, category => 'Flytipping', email => "FLY"); +$contact->set_extra_fields({ + code => 'road-placement', + datatype => 'singlevaluelist', + description => 'Is the fly-tip located on', + order => 100, + required => 'true', + variable => 'true', + values => [ + { key => 'road', name => 'The road' }, + { key => 'off-road', name => 'Off the road/on a verge' }, + ], +}); +$contact->update; $mech->create_contact_ok(body_id => $body->id, category => 'Potholes', email => "POT"); $mech->create_contact_ok(body_id => $body->id, category => 'Blocked drain', email => "DRA"); - -my $district = $mech->create_body_ok(2257, 'Chiltern'); -$mech->create_contact_ok(body_id => $district->id, category => 'Car Parks', email => "car\@chiltern"); -$mech->create_contact_ok(body_id => $district->id, category => 'Flytipping', email => "flytipping\@chiltern"); -$mech->create_contact_ok(body_id => $district->id, category => 'Graffiti', email => "graffiti\@chiltern"); +$mech->create_contact_ok(body_id => $body->id, category => 'Car Parks', email => "car\@chiltern", send_method => 'Email'); +$mech->create_contact_ok(body_id => $body->id, category => 'Graffiti', email => "graffiti\@chiltern", send_method => 'Email'); +$mech->create_contact_ok(body_id => $body->id, category => 'Flytipping (off-road)', email => "districts_flytipping", send_method => 'Email'); my $cobrand = Test::MockModule->new('FixMyStreet::Cobrand::Buckinghamshire'); $cobrand->mock('lookup_site_code', sub { @@ -33,6 +49,13 @@ FixMyStreet::override_config { flytipping => 'flytipping@example.org', flood => 'floods@example.org', } + }, + borough_email_addresses => { + buckinghamshire => { + districts_flytipping => [ + { email => "flytipping\@chiltern", areas => [ 2257 ] }, + ] + } } } }, sub { @@ -45,18 +68,20 @@ subtest 'cobrand displays council name' => sub { subtest 'cobrand displays correct categories' => sub { my $json = $mech->get_ok_json('/report/new/ajax?latitude=51.615559&longitude=-0.556903'); - is @{$json->{bodies}}, 2, 'Both Chiltern and Bucks returned'; + is @{$json->{bodies}}, 1, 'Bucks returned'; like $json->{category}, qr/Car Parks/, 'Car Parks displayed'; like $json->{category}, qr/Flytipping/, 'Flytipping displayed'; like $json->{category}, qr/Blocked drain/, 'Blocked drain displayed'; - unlike $json->{category}, qr/Graffiti/, 'Graffiti not displayed'; + like $json->{category}, qr/Graffiti/, 'Graffiti displayed'; + unlike $json->{category}, qr/Flytipping \(off-road\)/, 'Flytipping (off-road) not displayed'; $json = $mech->get_ok_json('/report/new/category_extras?latitude=51.615559&longitude=-0.556903'); - is @{$json->{bodies}}, 2, 'Still both Chiltern and Bucks returned'; + is @{$json->{bodies}}, 1, 'Still Bucks returned'; }; my ($report) = $mech->create_problems_for_body(1, $body->id, 'On Road', { category => 'Flytipping', cobrand => 'fixmystreet', latitude => 51.812244, longitude => -0.827363, + dt => DateTime->now()->subtract(minutes => 10), }); subtest 'flytipping on road sent to extra email' => sub { @@ -75,6 +100,7 @@ subtest 'flytipping on road sent to extra email' => sub { contributed_as => 'another_user', contributed_by => $counciluser->id, }, + dt => DateTime->now()->subtract(minutes => 9), }); subtest 'pothole on road not sent to extra email, only confirm sent' => sub { @@ -86,22 +112,38 @@ subtest 'pothole on road not sent to extra email, only confirm sent' => sub { is $report->external_id, 248, 'Report has right external ID'; }; -($report) = $mech->create_problems_for_body(1, $district->id, 'Off Road', { - category => 'Flytipping', cobrand => 'buckinghamshire', - latitude => 51.813173, longitude => -0.826741, -}); -subtest 'flytipping off road sent to extra email' => sub { + +# report made in Flytipping category off road should get moved to other category +subtest 'Flytipping not on a road gets recategorised' => sub { + $mech->log_in_ok($publicuser->email); + $mech->get_ok('/report/new?latitude=51.615559&longitude=-0.556903&category=Flytipping'); + $mech->submit_form_ok({ + with_fields => { + title => "Test Report", + detail => 'Test report details.', + category => 'Flytipping', + 'road-placement' => 'off-road', + } + }, "submit details"); + $mech->content_contains('Your issue is on its way to the council.'); + my $report = FixMyStreet::DB->resultset("Problem")->search(undef, { order_by => { -desc => 'id' } })->first; + ok $report, "Found the report"; + is $report->category, "Flytipping (off-road)", 'Report was recategorised correctly'; + + $mech->log_out_ok; +}; + +subtest 'Ex-district reports are sent to correct emails' => sub { FixMyStreet::Script::Reports::send(); + $mech->email_count_is(2); # one for council, one confirmation for user my @email = $mech->get_email; - is $email[0]->header('To'), 'Chiltern <flytipping@chiltern>'; - unlike $mech->get_text_body_from_email($email[1]), qr/Please note that Buckinghamshire Council is not responsible/; - $report->discard_changes; - is $report->external_id, undef, 'Report has right external ID'; + is $email[0]->header('To'), 'Buckinghamshire <flytipping@chiltern>'; }; my ($report2) = $mech->create_problems_for_body(1, $body->id, 'Drainage problem', { category => 'Blocked drain', cobrand => 'fixmystreet', latitude => 51.812244, longitude => -0.827363, + dt => DateTime->now()->subtract(minutes => 8), }); subtest 'blocked drain sent to extra email' => sub { @@ -114,29 +156,6 @@ subtest 'blocked drain sent to extra email' => sub { $cobrand = FixMyStreet::Cobrand::Buckinghamshire->new(); -subtest 'Flytipping extra question used if necessary' => sub { - my $errors = { 'xroad-placement' => 'This field is required' }; - - $report->update({ bodies_str => $body->id }); - $cobrand->flytipping_body_fix($report, 'road', $errors); - is $errors->{'xroad-placement'}, 'This field is required', 'Error stays if sent to county'; - - $report->update({ bodies_str => $district->id }); - $report->discard_changes; # As e.g. ->bodies has been remembered. - $cobrand->flytipping_body_fix($report, 'road', $errors); - is $errors->{'xroad-placement'}, undef, 'Error removed if sent to district'; - - $report->update({ bodies_str => $body->id . ',' . $district->id }); - $report->discard_changes; # As e.g. ->bodies has been remembered. - $cobrand->flytipping_body_fix($report, 'road', $errors); - is $report->bodies_str, $body->id, 'Sent to both becomes sent to county on-road'; - - $report->update({ bodies_str => $district->id . ',' . $body->id }); - $report->discard_changes; # As e.g. ->bodies has been remembered. - $cobrand->flytipping_body_fix($report, 'off-road', $errors); - is $report->bodies_str, $district->id, 'Sent to both becomes sent to district off-road'; -}; - for my $test ( { desc => 'filters basic emails', diff --git a/web/cobrands/buckinghamshire/assets.js b/web/cobrands/buckinghamshire/assets.js index 82a1d5b0d..efba02d85 100644 --- a/web/cobrands/buckinghamshire/assets.js +++ b/web/cobrands/buckinghamshire/assets.js @@ -288,34 +288,17 @@ fixmystreet.assets.add(defaults, { fixmystreet.body_overrides.remove_only_send(); fixmystreet.message_controller.road_found(layer, feature, function(feature) { if (OpenLayers.Util.indexOf(bucks_types, feature.attributes.feature_ty) != -1) { - var cat = $('select#form_category').val(); - if (cat === 'Flytipping') { - fixmystreet.body_overrides.only_send(layer.fixmystreet.body); - } return true; } else { return false; } }, msg_id); - - // Make sure Flytipping related things reset - $('#category_meta').show(); - $('#form_road-placement').attr('required', ''); }, not_found: function(layer) { fixmystreet.body_overrides.do_not_send(layer.fixmystreet.body); fixmystreet.body_overrides.remove_only_send(); fixmystreet.message_controller.road_not_found(layer); - - // If flytipping is picked, we don't want to ask the extra question - var cat = $('select#form_category').val(); - if (cat === 'Flytipping') { - $('#category_meta').hide(); - $('#form_road-placement').removeAttr('required'); - } else { - $('#category_meta').show(); - } } }, no_asset_msg_id: '#js-not-a-road', @@ -327,18 +310,6 @@ fixmystreet.assets.add(defaults, { filter_value: types_to_show, }); -// As with the road found/not_found above, we want to change the destination -// depending upon the answer to the extra question shown when on a road -$("#problem_form").on("change", "#form_road-placement", function() { - if (this.value == 'road') { - fixmystreet.body_overrides.allow_send(defaults.body); - fixmystreet.body_overrides.only_send(defaults.body); - } else if (this.value == 'off-road') { - fixmystreet.body_overrides.do_not_send(defaults.body); - fixmystreet.body_overrides.remove_only_send(); - } -}); - fixmystreet.assets.add(defaults, { http_options: { params: { |