diff options
-rw-r--r-- | perllib/FixMyStreet/App/Controller/Admin.pm | 17 | ||||
-rw-r--r-- | t/app/controller/report_inspect.t | 29 |
2 files changed, 44 insertions, 2 deletions
diff --git a/perllib/FixMyStreet/App/Controller/Admin.pm b/perllib/FixMyStreet/App/Controller/Admin.pm index fc21aeedb..d1ac5e76b 100644 --- a/perllib/FixMyStreet/App/Controller/Admin.pm +++ b/perllib/FixMyStreet/App/Controller/Admin.pm @@ -10,6 +10,8 @@ use Digest::SHA qw(sha1_hex); use mySociety::EmailUtil qw(is_valid_email is_valid_email_list); use DateTime::Format::Strptime; use List::Util 'first'; +use List::MoreUtils 'uniq'; +use mySociety::ArrayUtils; use FixMyStreet::SendReport; @@ -847,6 +849,21 @@ sub report_edit_category : Private { if (grep !$old_map{$_}, @new_body_ids) { $problem->whensent(undef); } + # If the send methods of the old/new contacts differ we need to resend the report + my @old_contacts = grep { $_->category eq $category_old } @{$c->stash->{contacts}}; + my @new_send_methods = uniq map { + ( $_->body->can_be_devolved && $_->send_method ) ? + $_->send_method : $_->body->send_method; + } @contacts; + my @old_send_methods = map { + ( $_->body->can_be_devolved && $_->send_method ) ? + $_->send_method : $_->body->send_method; + } @old_contacts; + if ( scalar @{ mySociety::ArrayUtils::symmetric_diff(\@old_send_methods, \@new_send_methods) } ) { + $c->log->debug("Report changed, resending"); + $problem->whensent(undef); + } + $problem->bodies_str(join( ',', @new_body_ids )); $problem->add_to_comments({ text => '*' . sprintf(_('Category changed from ā%sā to ā%sā'), $category_old, $category) . '*', diff --git a/t/app/controller/report_inspect.t b/t/app/controller/report_inspect.t index 481d8dc87..1a3cc0fbc 100644 --- a/t/app/controller/report_inspect.t +++ b/t/app/controller/report_inspect.t @@ -3,8 +3,10 @@ use FixMyStreet::TestMech; my $mech = FixMyStreet::TestMech->new; my $brum = $mech->create_body_ok(2514, 'Birmingham City Council'); -my $oxon = $mech->create_body_ok(2237, 'Oxfordshire County Council'); +my $oxon = $mech->create_body_ok(2237, 'Oxfordshire County Council', { can_be_devolved => 1 } ); my $contact = $mech->create_contact_ok( body_id => $oxon->id, category => 'Cows', email => 'cows@example.net' ); +my $contact2 = $mech->create_contact_ok( body_id => $oxon->id, category => 'Sheep', email => 'SHEEP', send_method => 'Open311' ); +my $contact3 = $mech->create_contact_ok( body_id => $oxon->id, category => 'Badgers', email => 'badgers@example.net' ); my $rp = FixMyStreet::DB->resultset("ResponsePriority")->create({ body => $oxon, name => 'High Priority', @@ -17,13 +19,14 @@ my $wodc = $mech->create_body_ok(2420, 'West Oxfordshire District Council'); $mech->create_contact_ok( body_id => $wodc->id, category => 'Horses', email => 'horses@example.net' ); -my ($report, $report2) = $mech->create_problems_for_body(2, $oxon->id, 'Test', { +my ($report, $report2, $report3) = $mech->create_problems_for_body(3, $oxon->id, 'Test', { category => 'Cows', cobrand => 'fixmystreet', areas => ',2237,2420', whensent => \'current_timestamp', latitude => 51.847693, longitude => -1.355908, }); my $report_id = $report->id; my $report2_id = $report2->id; +my $report3_id = $report3->id; my $user = $mech->log_in_ok('test@example.com'); @@ -247,6 +250,28 @@ FixMyStreet::override_config { ALLOWED_COBRANDS => [ 'oxfordshire', 'fixmystreet' ], BASE_URL => 'http://fixmystreet.site', }, sub { + subtest "test report not resent when category changes if send_method doesn't change" => sub { + $mech->get_ok("/report/$report3_id"); + $mech->submit_form(button => 'save', with_fields => { category => 'Badgers', include_update => undef, }); + + $report3->discard_changes; + is $report3->category, "Badgers", "Report in correct category"; + isnt $report3->whensent, undef, "Report not marked as unsent"; + is $report3->bodies_str, $oxon->id, "Reported to OCC"; + }; + + subtest "test resending when send_method changes" => sub { + $mech->get_ok("/report/$report3_id"); + # Then change the category to the other category within the same council, + # which should cause it to be resent because it has a different send method + $mech->submit_form(button => 'save', with_fields => { category => 'Sheep', include_update => undef, }); + + $report3->discard_changes; + is $report3->category, "Sheep", "Report in correct category"; + is $report3->whensent, undef, "Report marked as unsent"; + is $report3->bodies_str, $oxon->id, "Reported to OCC"; + }; + subtest "test category/body changes" => sub { $mech->host('oxfordshire.fixmystreet.site'); $report->update({ state => 'confirmed' }); |