aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--perllib/FixMyStreet.pm2
-rw-r--r--perllib/FixMyStreet/SendReport/Open311.pm12
-rw-r--r--t/cobrand/fixmybarangay.t98
3 files changed, 110 insertions, 2 deletions
diff --git a/perllib/FixMyStreet.pm b/perllib/FixMyStreet.pm
index 2d8f462d5..be488a796 100644
--- a/perllib/FixMyStreet.pm
+++ b/perllib/FixMyStreet.pm
@@ -33,7 +33,7 @@ Thus module has utility functions for the FMS project.
FixMyStreet->test_mode( $bool );
my $in_test_mode_bool = FixMyStreet->test_mode;
-Put the FixMyStreet into test mode - inteded for the unit tests:
+Put the FixMyStreet into test mode - intended for the unit tests:
BEGIN {
use FixMyStreet;
diff --git a/perllib/FixMyStreet/SendReport/Open311.pm b/perllib/FixMyStreet/SendReport/Open311.pm
index 5f25dfc70..61f59f725 100644
--- a/perllib/FixMyStreet/SendReport/Open311.pm
+++ b/perllib/FixMyStreet/SendReport/Open311.pm
@@ -97,7 +97,7 @@ sub send {
category => $row->category
} );
- my $open311 = Open311->new(
+ my %open311_params = (
jurisdiction => $conf->jurisdiction,
endpoint => $conf->endpoint,
api_key => $conf->api_key,
@@ -106,6 +106,16 @@ sub send {
use_service_as_deviceid => $use_service_as_deviceid,
extended_description => $extended_desc,
);
+ if (FixMyStreet->test_mode) {
+ my $test_res = HTTP::Response->new();
+ $test_res->code(200);
+ $test_res->message('OK');
+ $test_res->content('<?xml version="1.0" encoding="utf-8"?><service_requests><request><service_request_id>248</service_request_id></request></service_requests>');
+ $open311_params{test_mode} = 1;
+ $open311_params{test_get_returns} = { 'requests.xml' => $test_res };
+ }
+
+ my $open311 = Open311->new( %open311_params );
# non standard west berks end points
if ( $row->bodies_str =~ /2619/ ) {
diff --git a/t/cobrand/fixmybarangay.t b/t/cobrand/fixmybarangay.t
new file mode 100644
index 000000000..bc099bb20
--- /dev/null
+++ b/t/cobrand/fixmybarangay.t
@@ -0,0 +1,98 @@
+use strict;
+use warnings;
+use Test::More;
+
+plan skip_all => 'Skipping Zurich test without FixMyBarangay cobrand'
+ unless FixMyStreet::Cobrand->exists('fixmybarangay');
+
+use FixMyStreet::TestMech;
+my $mech = FixMyStreet::TestMech->new;
+
+# Front page test
+
+ok $mech->host("www.fixmybarangay.com"), "change host to FixMyBarangay";
+$mech->get_ok('/');
+$mech->content_like( qr/FixMyBarangay/ );
+
+# Set up bodies
+
+my $luz = $mech->create_body_ok( 1, 'Bgy Luz' );
+$luz->update( { send_method => 'Email' } );
+
+my $bsn = $mech->create_body_ok( 2, 'Bgy BSN' );
+$bsn->update( { send_method => 'Email' } );
+
+my $dps = $mech->create_body_ok( 3, 'DPS' );
+$dps->update( { send_method => 'Open311', endpoint => 'http://dps.endpoint.example.com', jurisdiction => 'FMB', api_key => 'test' } );
+FixMyStreet::App->model('DB::BodyArea')->find_or_create({ area_id => 1, body_id => 3 });
+FixMyStreet::App->model('DB::BodyArea')->find_or_create({ area_id => 2, body_id => 3 });
+
+# Create contacts for these bodies
+# TODO: log in as a Bgy user, and create a report using the front end,
+# testing that the drop-down has the right things in it, and so on.
+
+my %contact_params = (
+ confirmed => 1,
+ deleted => 0,
+ editor => 'Test',
+ whenedited => \'current_timestamp',
+ note => 'Created for test',
+);
+FixMyStreet::App->model('DB::Contact')->search( {
+ email => { 'like', '%example.com' },
+} )->delete;
+my $contact1 = FixMyStreet::App->model('DB::Contact')->find_or_create( {
+ %contact_params,
+ body_id => 1,
+ category => 'Streetlight (BGY)',
+ email => 'bgy@example.com',
+} );
+my $contact2 = FixMyStreet::App->model('DB::Contact')->find_or_create( {
+ %contact_params,
+ body_id => 3,
+ category => 'Streetlight (DPS)',
+ email => 'LIGHT',
+} );
+
+# Create a couple of reports
+
+my @reports = $mech->create_problems_for_body( 1, 1, 'Test', {
+ cobrand => 'fixmybarangay',
+ category => 'Streetlight (BGY)',
+});
+my $luz_report = $reports[0];
+
+@reports = $mech->create_problems_for_body( 1, 3, 'Test', {
+ cobrand => 'fixmybarangay',
+ category => 'Streetlight (DPS)',
+});
+my $dps_report = $reports[0];
+
+$mech->get_ok( '/report/' . $luz_report->id );
+$mech->get_ok( '/report/' . $dps_report->id );
+
+# Send the reports
+
+$mech->email_count_is(0);
+
+FixMyStreet::App->model('DB::Problem')->send_reports('fixmybarangay');
+
+# Check BGY one sent by email
+my $email = $mech->get_email;
+like $email->header('Subject'), qr/Problem Report: Test Test/, 'subject looks okay';
+like $email->header('To'), qr/bgy\@example.com/, 'to line looks correct';
+$mech->clear_emails_ok;
+
+$luz_report->discard_changes;
+$dps_report->discard_changes;
+ok $luz_report->whensent, 'Luz report marked as sent';
+ok $dps_report->whensent, 'DPS report marked as sent';
+is $dps_report->send_method_used, 'Open311', 'DPS report sent via Open311';
+is $dps_report->external_id, 248, 'DPS report has right external ID';
+
+$mech->delete_problems_for_body( 1 );
+$mech->delete_problems_for_body( 3 );
+
+ok $mech->host("www.fixmystreet.com"), "change host back";
+
+done_testing();