aboutsummaryrefslogtreecommitdiffstats
path: root/t/cobrand
diff options
context:
space:
mode:
authorDave Whiteland <dave@mysociety.org>2013-02-06 15:08:23 +0000
committerDave Whiteland <dave@mysociety.org>2013-02-06 15:08:23 +0000
commit0f24a44cd6e8b056db482cb91c85768b6d1e7d1d (patch)
tree09a90f38574ee62754f3c8ac077152ed99a38296 /t/cobrand
parentc061769ba72f420e2f2c6064fa526648e57339f1 (diff)
parent5b2e18389734751165d2eeb21a3b3f2e8d2e8755 (diff)
Merge remote branch 'origin/master' into oxfordshire-header
Diffstat (limited to 't/cobrand')
-rw-r--r--t/cobrand/closest.t6
-rw-r--r--t/cobrand/fixmybarangay.t98
-rw-r--r--t/cobrand/get_body_sender.t38
-rw-r--r--t/cobrand/get_council_sender.t30
-rw-r--r--t/cobrand/zurich.t172
5 files changed, 313 insertions, 31 deletions
diff --git a/t/cobrand/closest.t b/t/cobrand/closest.t
index 464c95e67..d06f7e9a0 100644
--- a/t/cobrand/closest.t
+++ b/t/cobrand/closest.t
@@ -5,6 +5,9 @@ use Test::More;
use mySociety::Locale;
use FixMyStreet::App;
+use FixMyStreet::TestMech;
+
+my $mech = FixMyStreet::TestMech->new;
use_ok 'FixMyStreet::Cobrand';
@@ -29,7 +32,7 @@ my $dt = DateTime->new(
my $report = FixMyStreet::App->model('DB::Problem')->find_or_create(
{
postcode => 'SW1A 1AA',
- council => '2504',
+ bodies_str => '2504',
areas => ',105255,11806,11828,2247,2504,',
category => 'Other',
title => 'Test 2',
@@ -81,4 +84,5 @@ SKIP: {
}
# all done
+$mech->delete_user( $user );
done_testing();
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();
diff --git a/t/cobrand/get_body_sender.t b/t/cobrand/get_body_sender.t
new file mode 100644
index 000000000..245cb1a13
--- /dev/null
+++ b/t/cobrand/get_body_sender.t
@@ -0,0 +1,38 @@
+use strict;
+use warnings;
+
+use Test::More;
+
+use mySociety::Locale;
+use FixMyStreet::App;
+
+use_ok 'FixMyStreet::Cobrand';
+
+mySociety::Locale::gettext_domain( 'FixMyStreet' );
+
+my $c = FixMyStreet::Cobrand::FixMyStreet->new();
+
+FixMyStreet::App->model('DB::BodyArea')->search( { body_id => 1000 } )->delete;
+FixMyStreet::App->model('DB::Body')->search( { name => 'Body of a Thousand' } )->delete;
+
+my $body = FixMyStreet::App->model('DB::Body')->find_or_create({
+ id => 1000,
+ name => 'Body of a Thousand',
+});
+my $body_area = $body->body_areas->find_or_create({ area_id => 1000 });
+
+is_deeply $c->get_body_sender( $body ), { method => 'Email' }, 'defaults to email';
+
+$body_area->update({ area_id => 2481 }); # Croydon LBO
+is_deeply $c->get_body_sender( $body ), { method => 'London' }, 'returns london report it if London borough';
+
+$body->send_method( 'TestMethod' );
+is $c->get_body_sender( $body )->{ method }, 'TestMethod', 'uses send_method in preference to London';
+
+$body_area->update({ area_id => 1000 }); # Nothing
+is $c->get_body_sender( $body )->{ method }, 'TestMethod', 'uses send_method in preference to Email';
+
+$body_area->delete;
+$body->delete;
+
+done_testing();
diff --git a/t/cobrand/get_council_sender.t b/t/cobrand/get_council_sender.t
deleted file mode 100644
index e61f36370..000000000
--- a/t/cobrand/get_council_sender.t
+++ /dev/null
@@ -1,30 +0,0 @@
-use strict;
-use warnings;
-
-use Test::More;
-
-use mySociety::Locale;
-use FixMyStreet::App;
-
-use_ok 'FixMyStreet::Cobrand';
-
-mySociety::Locale::gettext_domain( 'FixMyStreet' );
-
-my $c = FixMyStreet::Cobrand::FixMyStreet->new();
-
-
-is_deeply $c->get_council_sender( '1000', { type => 'DIS' } ), { method => 'Email' }, 'defaults to email';
-is_deeply $c->get_council_sender( '1000', { type => 'LBO' } ), { method=> 'London' }, 'returns london report it if London borough';
-
-my $conf = FixMyStreet::App->model('DB::Open311Conf')->find_or_create(
- area_id => 1000,
- endpoint => '',
- send_method => 'TestMethod'
-);
-
-is $c->get_council_sender( '1000', { type => 'LBO' } )->{ method }, 'TestMethod', 'uses send_method in preference to London';
-is $c->get_council_sender( '1000', { type => 'DIS' } )->{ method }, 'TestMethod', 'uses send_method in preference to Email';
-
-$conf->delete;
-
-done_testing();
diff --git a/t/cobrand/zurich.t b/t/cobrand/zurich.t
new file mode 100644
index 000000000..f354f0da4
--- /dev/null
+++ b/t/cobrand/zurich.t
@@ -0,0 +1,172 @@
+# TODO
+# Report to third party (with third_personal)
+# Overdue alerts
+
+use strict;
+use warnings;
+use DateTime;
+use Test::More;
+
+plan skip_all => 'Skipping Zurich test without Zurich cobrand'
+ unless FixMyStreet::Cobrand->exists('zurich');
+
+use FixMyStreet::TestMech;
+my $mech = FixMyStreet::TestMech->new;
+
+# Front page test
+ok $mech->host("zurich.fixmystreet.com"), "change host to Zurich";
+$mech->get_ok('/');
+$mech->content_like( qr/zurich/i );
+
+# Set up bodies
+my $zurich = $mech->create_body_ok( 1, 'Zurich' );
+my $division = $mech->create_body_ok( 2, 'Division 1' );
+$division->parent( $zurich->id );
+$division->send_method( 'Zurich' );
+$division->endpoint( 'division@example.org' );
+$division->update;
+my $subdivision = $mech->create_body_ok( 3, 'Subdivision A' );
+$subdivision->parent( $division->id );
+$subdivision->send_method( 'Zurich' );
+$subdivision->endpoint( 'subdivision@example.org' );
+$subdivision->update;
+
+my @reports = $mech->create_problems_for_body( 1, 2, 'Test', {
+ state => 'unconfirmed',
+ confirmed => undef,
+ cobrand => 'zurich',
+});
+my $report = $reports[0];
+
+$mech->get_ok( '/report/' . $report->id );
+$mech->content_contains('&Uuml;berpr&uuml;fung ausstehend');
+
+# Check logging in to deal with this report
+$mech->get_ok( '/admin' );
+is $mech->uri->path, '/auth', "got sent to the sign in page";
+
+my $user = $mech->log_in_ok( 'dm1@example.org') ;
+$user->from_body( undef );
+$user->update;
+$mech->get_ok( '/admin' );
+is $mech->uri->path, '/auth', "got sent to the sign in page";
+$user->from_body( 2 );
+$user->update;
+
+$mech->get_ok( '/admin' );
+is $mech->uri->path, '/admin', "am logged in";
+
+$mech->content_contains( 'report_edit/' . $report->id );
+$mech->content_contains( DateTime->now->strftime("%d.%m.%Y") );
+$mech->content_contains( 'Erfasst' );
+
+$mech->get_ok( '/admin/report_edit/' . $report->id );
+$mech->submit_form_ok( { with_fields => { state => 'confirmed' } } );
+$mech->get_ok( '/report/' . $report->id );
+$mech->content_contains('Aufgenommen');
+$mech->content_contains('Test Test');
+$mech->content_lacks('photo/' . $report->id . '.jpeg');
+$mech->email_count_is(0);
+
+# Photo publishing
+$mech->get_ok( '/admin/report_edit/' . $report->id );
+$mech->submit_form_ok( { with_fields => { publish_photo => 1 } } );
+$mech->get_ok( '/report/' . $report->id );
+$mech->content_contains('photo/' . $report->id . '.jpeg');
+
+# Internal notes
+$mech->get_ok( '/admin/report_edit/' . $report->id );
+$mech->submit_form_ok( { with_fields => { internal_notes => 'Some internal notes.' } } );
+$mech->content_contains( 'Some internal notes' );
+
+# Original description
+$mech->submit_form_ok( { with_fields => { detail => 'Edited details text.' } } );
+$mech->content_contains( 'Edited details text.' );
+$mech->content_contains( 'originally entered: &ldquo;Test Test 1 for 2 Detail&rdquo;' );
+
+$mech->get_ok( '/admin/report_edit/' . $report->id );
+$mech->submit_form_ok( { with_fields => { body_subdivision => 3 } } );
+
+$mech->get_ok( '/report/' . $report->id );
+$mech->content_contains('In Bearbeitung');
+$mech->content_contains('Test Test');
+
+FixMyStreet::App->model('DB::Problem')->send_reports('zurich');
+my $email = $mech->get_email;
+like $email->header('Subject'), qr/Neue Meldung/, 'subject looks okay';
+like $email->header('To'), qr/subdivision\@example.org/, 'to line looks correct';
+$mech->clear_emails_ok;
+
+$mech->log_out_ok;
+
+$user = $mech->log_in_ok( 'sdm1@example.org') ;
+$mech->get_ok( '/admin' );
+is $mech->uri->path, '/auth', "got sent to the sign in page";
+$user->from_body( 3 );
+$user->update;
+
+$mech->get_ok( '/admin' );
+is $mech->uri->path, '/admin', "am logged in";
+
+$mech->content_contains( 'report_edit/' . $report->id );
+$mech->content_contains( DateTime->now->strftime("%d.%m.%Y") );
+$mech->content_contains( 'In Bearbeitung' );
+
+$mech->get_ok( '/admin/report_edit/' . $report->id );
+$mech->content_contains( 'Some internal notes' );
+
+$mech->submit_form_ok( { with_fields => { status_update => 'This is an update.' } } );
+is $mech->uri->path, '/admin/report_edit/' . $report->id, "still on edit page";
+$mech->content_contains('This is an update');
+ok $mech->form_with_fields( 'status_update' );
+$mech->submit_form_ok( { button => 'no_more_updates' } );
+is $mech->uri->path, '/admin/summary', "redirected now finished with report.";
+
+$mech->get_ok( '/report/' . $report->id );
+$mech->content_contains('In Bearbeitung');
+$mech->content_contains('Test Test');
+
+FixMyStreet::App->model('DB::Problem')->send_reports('zurich');
+$email = $mech->get_email;
+like $email->header('Subject'), qr/Feedback/, 'subject looks okay';
+like $email->header('To'), qr/division\@example.org/, 'to line looks correct';
+$mech->clear_emails_ok;
+
+$report->discard_changes;
+is $report->state, 'planned', 'Report now in planned state';
+
+$mech->log_out_ok;
+$user = $mech->log_in_ok( 'dm1@example.org') ;
+$mech->get_ok( '/admin' );
+
+$mech->content_contains( 'report_edit/' . $report->id );
+$mech->content_contains( DateTime->now->strftime("%d.%m.%Y") );
+
+# User confirms their email address
+my $extra = $report->extra;
+$extra->{email_confirmed} = 1;
+$report->extra ( { %$extra } );
+$report->update;
+
+$mech->get_ok( '/admin/report_edit/' . $report->id );
+$mech->submit_form_ok( { with_fields => { status_update => 'FINAL UPDATE' } } );
+$mech->form_with_fields( 'status_update' );
+$mech->submit_form_ok( { button => 'publish_response' } );
+
+$mech->get_ok( '/report/' . $report->id );
+$mech->content_contains('Erledigt');
+$mech->content_contains('Test Test');
+$mech->content_contains('FINAL UPDATE');
+
+$email = $mech->get_email;
+like $email->header('To'), qr/test\@example.com/, 'to line looks correct';
+like $email->body, qr/FINAL UPDATE/, 'body looks correct';
+$mech->clear_emails_ok;
+
+$mech->delete_problems_for_body( 2 );
+$mech->delete_user( 'dm1@example.org' );
+$mech->delete_user( 'sdm1@example.org' );
+
+ok $mech->host("www.fixmystreet.com"), "change host back";
+
+done_testing();