diff options
author | Dave Arter <davea@mysociety.org> | 2016-08-30 18:48:07 +0100 |
---|---|---|
committer | Dave Arter <davea@mysociety.org> | 2016-09-09 12:01:45 +0100 |
commit | 638c5d3be601c3949f1d1ce7ecae5d8b77ad8f7c (patch) | |
tree | 064a223fdcc62298dfb3f88858ddbd53084d2e65 /t | |
parent | 3f55b249eb6dfe46fa3f6855d90510ff2d4900e9 (diff) |
Add ‘Inspection required’ field to categories
Categories can now require reports to be marked as 'inspected' via the frontend
before they're sent by send-reports.
A side-effect here is that send-reports will perform an extra n queries for each
report, where n is the number of bodies that report is being sent to, but
hopefully in practice this won't matter as it's an offline cronjob.
See mysociety/fixmystreetforcouncils#50
Diffstat (limited to 't')
-rw-r--r-- | t/app/sendreport/inspection_required.t | 59 | ||||
-rw-r--r-- | t/cobrand/get_body_sender.t | 4 |
2 files changed, 61 insertions, 2 deletions
diff --git a/t/app/sendreport/inspection_required.t b/t/app/sendreport/inspection_required.t new file mode 100644 index 000000000..178fa2a1f --- /dev/null +++ b/t/app/sendreport/inspection_required.t @@ -0,0 +1,59 @@ +use strict; +use warnings; + +use Test::More; + +use FixMyStreet; +use FixMyStreet::DB; +use FixMyStreet::TestMech; +use FixMyStreet::SendReport::Email; +use mySociety::Locale; + +ok( my $mech = FixMyStreet::TestMech->new, 'Created mech object' ); + +my $user = $mech->create_user_ok( 'user@example.com' ); + +my $body = $mech->create_body_ok( 2237, 'Oxfordshire County Council', id => 2237 ); +# $body->update({ send_method => 'Email' }); + +my $contact = $mech->create_contact_ok( + body_id => $body->id, + category => 'Pothole', + email => 'test@example.org', +); +$contact->set_extra_metadata(inspection_required => 1); +$contact->update; + +my @reports = $mech->create_problems_for_body( 1, $body->id, 'Test', { + cobrand => 'oxfordshire', + category => $contact->category, + user => $user, +}); +my $report = $reports[0]; + +subtest 'Report isn’t sent if uninspected' => sub { + $mech->clear_emails_ok; + + FixMyStreet::DB->resultset('Problem')->send_reports(); + + $mech->email_count_is( 0 ); + is $report->whensent, undef, 'Report hasn’t been sent'; +}; + +subtest 'Report is sent when inspected' => sub { + $mech->clear_emails_ok; + $report->set_extra_metadata(inspected => 1); + $report->update; + + FixMyStreet::DB->resultset('Problem')->send_reports(); + + $report->discard_changes; + $mech->email_count_is( 1 ); + ok $report->whensent, 'Report marked as sent'; +}; + +done_testing(); + +END { + $mech->delete_body($body); +} diff --git a/t/cobrand/get_body_sender.t b/t/cobrand/get_body_sender.t index 66cfc02b7..fbdfbffa7 100644 --- a/t/cobrand/get_body_sender.t +++ b/t/cobrand/get_body_sender.t @@ -25,9 +25,9 @@ FixMyStreet::override_config { MAPIT_TYPES => [ 'LBO' ], MAPIT_URL => 'http://mapit.mysociety.org/', }, sub { - is_deeply $c->get_body_sender( $body ), { method => 'Email' }, 'defaults to email'; + is_deeply $c->get_body_sender( $body ), { method => 'Email', contact => undef }, 'defaults to email'; $body_area->update({ area_id => 2481 }); # Croydon LBO - is_deeply $c->get_body_sender( $body ), { method => 'Email' }, 'still email if London borough'; + is_deeply $c->get_body_sender( $body ), { method => 'Email', contact => undef }, 'still email if London borough'; }; $body->send_method( 'TestMethod' ); |