aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--perllib/FixMyStreet/Cobrand/Hounslow.pm13
-rw-r--r--perllib/FixMyStreet/SendReport/Open311.pm2
-rw-r--r--t/sendreport/open311.t41
3 files changed, 45 insertions, 11 deletions
diff --git a/perllib/FixMyStreet/Cobrand/Hounslow.pm b/perllib/FixMyStreet/Cobrand/Hounslow.pm
index 58da5160c..2146f2b67 100644
--- a/perllib/FixMyStreet/Cobrand/Hounslow.pm
+++ b/perllib/FixMyStreet/Cobrand/Hounslow.pm
@@ -73,14 +73,8 @@ sub link_to_council_cobrand { "Hounslow Highways" }
# Instead, force the borough council name to be used.
sub all_reports_single_body { { name => "Hounslow Borough Council" } }
-sub open311_pre_send {
- my ($self, $row, $open311, $h) = @_;
-
- return unless $row->isa("FixMyStreet::DB::Result::Problem");
-
- # Reload the problem from the DB, as we want to save our changes to it
- # without affecting the existing instance.
- $row = $row->result_source->resultset->find( { id => $row->id } );
+sub open311_post_send {
+ my ($self, $row, $h) = @_;
# Stop the email being sent for each Open311 failure; only the once.
return if $row->get_extra_metadata('hounslow_email_sent');
@@ -88,8 +82,7 @@ sub open311_pre_send {
my $e = join( '@', 'enquiries', $self->council_url . 'highways.org' );
my $sender = FixMyStreet::SendReport::Email->new( to => [ [ $e, 'Hounslow Highways' ] ] );
if (!$sender->send($row, $h)) {
- $row->set_extra_metadata('hounslow_email_sent', 1);
- $row->update;
+ $row->set_extra_metadata('hounslow_email_sent', 1);
}
}
diff --git a/perllib/FixMyStreet/SendReport/Open311.pm b/perllib/FixMyStreet/SendReport/Open311.pm
index 7445699a2..fcb6f7298 100644
--- a/perllib/FixMyStreet/SendReport/Open311.pm
+++ b/perllib/FixMyStreet/SendReport/Open311.pm
@@ -74,7 +74,7 @@ sub send {
my $open311 = Open311->new( %open311_params );
- $cobrand->call_hook(open311_pre_send => $row, $open311, $h);
+ $cobrand->call_hook(open311_pre_send => $row, $open311);
my $resp = $open311->send_service_request( $row, $h, $contact->email );
if (FixMyStreet->test_mode) {
diff --git a/t/sendreport/open311.t b/t/sendreport/open311.t
index 382df39f0..1cec5dd68 100644
--- a/t/sendreport/open311.t
+++ b/t/sendreport/open311.t
@@ -155,4 +155,45 @@ subtest 'test handles bad category', sub {
like $bad_category_report->send_fail_reason, qr/Category Flytipping does not exist for body/, 'failure message set';
};
+my $hounslow = $mech->create_body_ok( 2483, 'Hounslow Borough Council');
+my $contact2 = $mech->create_contact_ok( body_id => $hounslow->id, category => 'Graffiti', email => 'GRAF' );
+$contact2->set_extra_fields(
+ { code => 'easting', datatype => 'number' },
+ { code => 'northing', datatype => 'number' },
+ { code => 'fixmystreet_id', datatype => 'number' },
+);
+$contact2->update;
+
+my ($hounslow_report) = $mech->create_problems_for_body( 1, $hounslow->id, 'Test', {
+ cobrand => 'hounslow',
+ category => 'Graffiti',
+ user => $user,
+ latitude => 51.482286,
+ longitude => -0.328163,
+ cobrand => 'hounslow',
+});
+
+subtest 'Hounslow sends email upon Open311 submission', sub {
+ $hounslow->update( { send_method => 'Open311', endpoint => 'http://endpoint.example.com', jurisdiction => 'hounslow', api_key => 'test' } );
+ $mech->clear_emails_ok;
+ FixMyStreet::override_config {
+ STAGING_FLAGS => { send_reports => 1 },
+ ALLOWED_COBRANDS => [ 'hounslow' ],
+ MAPIT_URL => 'http://mapit.uk/',
+ }, sub {
+ FixMyStreet::Script::Reports::send();
+ };
+ $hounslow_report->discard_changes;
+ ok $hounslow_report->whensent, 'Report marked as sent';
+ ok $hounslow_report->get_extra_metadata('hounslow_email_sent'), "Enquiries inbox email marked as sent";
+ my ($hounslow_email, $user_email) = $mech->get_email;
+ my $body = $mech->get_text_body_from_email($hounslow_email);
+ like $body, qr/A user of FixMyStreet has submitted the following report/;
+ like $body, qr/Category: Graffiti/;
+ like $body, qr/Enquiry ref: 248/;
+ $body = $mech->get_text_body_from_email($user_email);
+ like $body, qr/reference number is 248/;
+};
+
+
done_testing();