aboutsummaryrefslogtreecommitdiffstats
path: root/t
diff options
context:
space:
mode:
Diffstat (limited to 't')
-rw-r--r--t/Mock/MapIt.pm1
-rw-r--r--t/app/controller/admin/bodies.t4
-rw-r--r--t/app/controller/admin/triage.t126
-rw-r--r--t/app/controller/report_new_open311.t2
-rw-r--r--t/cobrand/isleofwight.t567
-rw-r--r--t/cobrand/zurich.t1078
-rw-r--r--t/map/tests.t1
-rw-r--r--t/open311/getservicerequestupdates.t46
8 files changed, 1204 insertions, 621 deletions
diff --git a/t/Mock/MapIt.pm b/t/Mock/MapIt.pm
index b5cc694df..8b8bb5978 100644
--- a/t/Mock/MapIt.pm
+++ b/t/Mock/MapIt.pm
@@ -49,6 +49,7 @@ my @PLACES = (
[ 'TA1 1QP', 51.023569, -3.099055, 2239, 'Somerset County Council', 'CTY', 2429, 'Taunton Deane Borough Council', 'DIS' ],
[ 'GU51 4AE', 51.279456, -0.846216, 2333, 'Hart District Council', 'DIS', 2227, 'Hampshire County Council', 'CTY' ],
[ 'WS1 4NH', 52.563074, -1.991032, 2535, 'Sandwell Borough Council', 'MTD' ],
+ [ 'PO30 5XJ', 50.71086, -1.29573, 2636, 'Isle of Wight Council', 'UTA' ],
[ 'OX28 4DS', 51.784721, -1.494453 ],
[ 'E14 2DN', 51.508536, '0.000001' ],
# Norway
diff --git a/t/app/controller/admin/bodies.t b/t/app/controller/admin/bodies.t
index c1072eb15..75f0f606f 100644
--- a/t/app/controller/admin/bodies.t
+++ b/t/app/controller/admin/bodies.t
@@ -162,7 +162,7 @@ subtest 'check open311 configuring' => sub {
jurisdiction => 'open311',
send_comments => 0,
send_method => 'Open311',
- fetch_all_problems => 1,
+ 'extra[fetch_all_problems]' => 1,
}
}
);
@@ -181,7 +181,7 @@ subtest 'check open311 configuring' => sub {
jurisdiction => 'open311',
send_comments => 0,
send_method => 'Open311',
- fetch_all_problems => 0,
+ 'extra[fetch_all_problems]' => 0,
can_be_devolved => 1, # for next test
}
}
diff --git a/t/app/controller/admin/triage.t b/t/app/controller/admin/triage.t
new file mode 100644
index 000000000..6c84d1ff4
--- /dev/null
+++ b/t/app/controller/admin/triage.t
@@ -0,0 +1,126 @@
+use FixMyStreet::TestMech;
+use FixMyStreet::Script::Alerts;
+
+my $mech = FixMyStreet::TestMech->new;
+
+my $user = $mech->create_user_ok('test@example.com', name => 'Test User');
+my $user2 = $mech->create_user_ok('test2@example.com', name => 'Test User 2');
+my $superuser = $mech->create_user_ok(
+ 'superuser@example.com',
+ name => 'Super User',
+ is_superuser => 1
+);
+
+my $iow = $mech->create_body_ok(2636, 'Isle of Wight Council', { can_be_devolved => 1 } );
+my $iow_contact = $mech->create_contact_ok(
+ body_id => $iow->id,
+ category => 'Potholes',
+ email => 'potholes@example.com',
+ send_method => 'Triage'
+);
+$mech->create_contact_ok(
+ body_id => $iow->id,
+ category => 'Traffic lights',
+ email => 'lights@example.com'
+);
+
+my $dt = DateTime->now();
+
+my ($report) = $mech->create_problems_for_body(
+ 1,
+ $iow->id,
+ 'TITLE',
+ {
+ areas => 2636,
+ category => 'Potholes',
+ whensent => $dt,
+ latitude => 50.71086,
+ longitude => -1.29573,
+ send_method_used => 'Triage',
+ }
+);
+
+FixMyStreet::override_config {
+ STAGING_FLAGS => { send_reports => 1, skip_checks => 0 },
+ ALLOWED_COBRANDS => [ 'isleofwight' ],
+ MAPIT_URL => 'http://mapit.uk/',
+}, sub {
+ subtest "user can access triage page with triage permission" => sub {
+ $user->update({ from_body => $iow });
+ $mech->log_out_ok;
+ $mech->get_ok('/admin/triage');
+
+ $mech->log_in_ok($user->email);
+ $mech->get('/admin/triage');
+ is $mech->res->code, 403, 'permission denied';
+
+ $user->user_body_permissions->create( { body => $iow, permission_type => 'triage' } );
+ $mech->get_ok('/admin/triage');
+ };
+
+ subtest "reports marked for triage show triage interface" => sub {
+ $mech->log_out_ok;
+ $mech->log_in_ok( $user->email );
+
+ $mech->get_ok('/report/' . $report->id);
+ $mech->content_lacks('CONFIRM Subject');
+
+ $report->update( { state => 'for triage' } );
+
+ $mech->get_ok('/report/' . $report->id);
+ $mech->content_contains('CONFIRM Subject');
+ };
+
+ subtest "changing report category marks report as confirmed" => sub {
+ my $report_url = '/report/' . $report->id;
+ $mech->get_ok($report_url);
+
+ my $alert = FixMyStreet::App->model('DB::Alert')->create(
+ {
+ user => $user2,
+ alert_type => 'new_updates',
+ parameter => $report->id,
+ parameter2 => '',
+ confirmed => 1,
+ }
+ );
+
+ $mech->content_contains('Traffic lights');
+
+ $mech->submit_form_ok( {
+ with_fields => {
+ category => 'Traffic lights',
+ include_update => 0,
+ }
+ },
+ 'triage form submitted'
+ );
+
+ $mech->content_contains('Potholes');
+
+ $report->discard_changes;
+ is $report->state, 'confirmed', 'report marked as confirmed';
+ ok !$report->whensent, 'report marked to resend';
+
+ my @comments = $report->comments;
+ my $comment = $comments[0];
+ my $extra = $comment->get_extra_metadata();
+ is $extra->{triage_report}, 1, 'comment indicates it is for triage in extra';
+ is $extra->{holding_category}, 'Potholes', 'comment extra has previous category';
+ is $extra->{new_category}, 'Traffic lights', 'comment extra has new category';
+ ok $comment->whensent, 'comment is marked as sent';
+
+ $mech->get_ok($report_url);
+ $mech->content_contains('Report triaged from Potholes to Traffic lights');
+
+ $mech->log_out_ok;
+ $mech->get_ok($report_url);
+ $mech->content_lacks('Report triaged from Potholes to Traffic lights');
+
+ $mech->clear_emails_ok;
+ FixMyStreet::Script::Alerts::send();
+ $mech->email_count_is(0);
+ };
+};
+
+done_testing();
diff --git a/t/app/controller/report_new_open311.t b/t/app/controller/report_new_open311.t
index 52f1ddc6e..a0d122a7b 100644
--- a/t/app/controller/report_new_open311.t
+++ b/t/app/controller/report_new_open311.t
@@ -203,6 +203,8 @@ foreach my $test (
# check that we got the errors expected
is_deeply $mech->page_errors, $test->{errors}, "check errors";
+ $mech->content_contains('Help <strong>Borsetshire Council</strong> resolve your problem quicker');
+
# check that fields have changed as expected
my $new_values = {
%{ $test->{fields} }, # values added to form
diff --git a/t/cobrand/isleofwight.t b/t/cobrand/isleofwight.t
new file mode 100644
index 000000000..67088bc54
--- /dev/null
+++ b/t/cobrand/isleofwight.t
@@ -0,0 +1,567 @@
+use CGI::Simple;
+use DateTime;
+use FixMyStreet::TestMech;
+use Open311;
+use Open311::GetServiceRequests;
+use Open311::GetServiceRequestUpdates;
+use Open311::PostServiceRequestUpdates;
+use FixMyStreet::Script::Alerts;
+use FixMyStreet::Script::Reports;
+
+ok( my $mech = FixMyStreet::TestMech->new, 'Created mech object' );
+
+my $params = {
+ send_method => 'Open311',
+ send_comments => 1,
+ api_key => 'KEY',
+ endpoint => 'endpoint',
+ jurisdiction => 'home',
+ can_be_devolved => 1,
+};
+my $isleofwight = $mech->create_body_ok(2636, 'Isle of Wight Council', $params);
+my $contact = $mech->create_contact_ok(
+ body_id => $isleofwight->id,
+ category => 'Potholes',
+ email => 'pothole@example.org',
+);
+$contact->set_extra_fields( ( {
+ code => 'urgent',
+ datatype => 'string',
+ description => 'question',
+ variable => 'true',
+ required => 'false',
+ order => 1,
+ datatype_description => 'datatype',
+} ) );
+$contact->update;
+
+my $user = $mech->create_user_ok('user@example.org', name => 'Test User');
+my $iow_user = $mech->create_user_ok('iow_user@example.org', name => 'IoW User', from_body => $isleofwight);
+$iow_user->user_body_permissions->create({
+ body => $isleofwight,
+ permission_type => 'moderate',
+});
+
+my $contact2 = $mech->create_contact_ok(
+ body_id => $isleofwight->id,
+ category => 'Roads',
+ email => 'roads@example.org',
+ send_method => 'Triage',
+);
+
+my $admin_user = $mech->create_user_ok('admin-user@example.org', name => 'Admin User', from_body => $isleofwight);
+
+$admin_user->user_body_permissions->create({
+ body => $isleofwight,
+ permission_type => 'triage'
+});
+
+my @reports = $mech->create_problems_for_body(1, $isleofwight->id, 'An Isle of wight report', {
+ confirmed => '2019-05-25 09:00',
+ lastupdate => '2019-05-25 09:00',
+ latitude => 50.7108,
+ longitude => -1.29573,
+ user => $user,
+ external_id => 101202303
+});
+
+subtest "check clicking all reports link" => sub {
+ FixMyStreet::override_config {
+ MAPIT_URL => 'http://mapit.uk/',
+ ALLOWED_COBRANDS => 'isleofwight',
+ }, sub {
+ $mech->get_ok('/');
+ $mech->follow_link_ok({ text => 'All reports' });
+ };
+
+ $mech->content_contains("An Isle of wight report", "Isle of Wight report there");
+ $mech->content_contains("Island Roads", "is still on cobrand");
+};
+
+subtest "use external id for reference number" => sub {
+ FixMyStreet::override_config {
+ MAPIT_URL => 'http://mapit.uk/',
+ ALLOWED_COBRANDS => 'isleofwight',
+ }, sub {
+ $mech->get_ok('/report/' . $reports[0]->id);
+ };
+
+ $mech->content_contains("101202303", "Display external id as reference number");
+};
+
+subtest "only original reporter can comment" => sub {
+ FixMyStreet::override_config {
+ MAPIT_URL => 'http://mapit.uk/',
+ ALLOWED_COBRANDS => 'isleofwight',
+ }, sub {
+ $mech->get_ok('/report/' . $reports[0]->id);
+ $mech->content_contains('Only the original reporter may leave updates');
+
+ $mech->log_in_ok('user@example.org');
+ $mech->get_ok('/report/' . $reports[0]->id);
+ $mech->content_lacks('Only the original reporter may leave updates');
+ };
+};
+
+subtest "check moderation label uses correct name" => sub {
+ my $REPORT_URL = '/report/' . $reports[0]->id;
+ FixMyStreet::override_config {
+ MAPIT_URL => 'http://mapit.uk/',
+ ALLOWED_COBRANDS => ['isleofwight'],
+ }, sub {
+ $mech->log_out_ok;
+ $mech->log_in_ok( $iow_user->email );
+ $mech->get_ok($REPORT_URL);
+ $mech->content_lacks('show-moderation');
+ $mech->follow_link_ok({ text_regex => qr/^Moderate$/ });
+ $mech->content_contains('show-moderation');
+ $mech->submit_form_ok({ with_fields => {
+ problem_title => 'Good good',
+ problem_detail => 'Good good improved',
+ }});
+ $mech->base_like( qr{\Q$REPORT_URL\E} );
+ $mech->content_like(qr/Moderated by Island Roads/);
+ };
+};
+
+$_->delete for @reports;
+
+my $system_user = $mech->create_user_ok('system_user@example.org');
+
+for my $status ( qw/ CLOSED FIXED DUPLICATE NOT_COUNCILS_RESPONSIBILITY NO_FURTHER_ACTION / ) {
+ subtest "updates which mark report as $status close it to comments" => sub {
+ my $dt = DateTime->now(formatter => DateTime::Format::W3CDTF->new)->add( minutes => -5 );
+ my ($p) = $mech->create_problems_for_body(1, $isleofwight->id, '', { lastupdate => $dt });
+ $p->update({ external_id => $p->id });
+
+ my $requests_xml = qq{<?xml version="1.0" encoding="utf-8"?>
+ <service_requests_updates>
+ <request_update>
+ <update_id>UPDATE_ID</update_id>
+ <service_request_id>SERVICE_ID</service_request_id>
+ <service_request_id_ext>ID_EXTERNAL</service_request_id_ext>
+ <status>STATUS</status>
+ <description>This is a note</description>
+ <updated_datetime>UPDATED_DATETIME</updated_datetime>
+ </request_update>
+ </service_requests_updates>
+ };
+
+ my $update_dt = DateTime->now(formatter => DateTime::Format::W3CDTF->new);
+
+ $requests_xml =~ s/STATUS/$status/;
+ $requests_xml =~ s/UPDATE_ID/@{[$p->id]}/;
+ $requests_xml =~ s/SERVICE_ID/@{[$p->id]}/;
+ $requests_xml =~ s/ID_EXTERNAL/@{[$p->id]}/;
+ $requests_xml =~ s/UPDATED_DATETIME/$update_dt/;
+
+ my $o = Open311->new( jurisdiction => 'mysociety', endpoint => 'http://example.com', test_mode => 1, test_get_returns => { 'servicerequestupdates.xml' => $requests_xml } );
+
+ my $update = Open311::GetServiceRequestUpdates->new(
+ system_user => $system_user,
+ current_open311 => $o,
+ current_body => $isleofwight,
+ );
+ FixMyStreet::override_config {
+ ALLOWED_COBRANDS => 'isleofwight',
+ }, sub {
+ $update->process_body;
+ };
+
+ $mech->log_in_ok('user@example.org');
+ $mech->get_ok('/report/' . $p->id);
+ $mech->content_lacks('Provide an update', "No update form on report");
+
+ $p->discard_changes;
+ is $p->get_extra_metadata('closed_updates'), 1, "report closed to updates";
+ $p->comments->delete;
+ $p->delete;
+ };
+}
+
+subtest "fetched requests do not use the description text" => sub {
+ my $requests_xml = qq{<?xml version="1.0" encoding="utf-8"?>
+ <service_requests>
+ <request>
+ <service_request_id>638344</service_request_id>
+ <status>open</status>
+ <status_notes>This is a note.</status_notes>
+ <service_name>Potholes</service_name>
+ <service_code>potholes\@example.org</service_code>
+ <description>This the description of a pothole problem</description>
+ <agency_responsible></agency_responsible>
+ <service_notice></service_notice>
+ <requested_datetime>DATETIME</requested_datetime>
+ <updated_datetime>DATETIME</updated_datetime>
+ <expected_datetime>DATETIME</expected_datetime>
+ <lat>50.71086</lat>
+ <long>-1.29573</long>
+ </request>
+ </service_requests>
+ };
+
+ my $dt = DateTime->now(formatter => DateTime::Format::W3CDTF->new)->add( minutes => -5 );
+ $requests_xml =~ s/DATETIME/$dt/gm;
+
+ my $o = Open311->new( jurisdiction => 'mysociety', endpoint => 'http://example.com', test_mode => 1, test_get_returns => { 'requests.xml' => $requests_xml } );
+
+ my $update = Open311::GetServiceRequests->new(
+ system_user => $iow_user,
+ );
+ FixMyStreet::override_config {
+ MAPIT_URL => 'http://mapit.uk/',
+ ALLOWED_COBRANDS => 'isleofwight',
+ }, sub {
+ $update->create_problems( $o, $isleofwight );
+ };
+
+ my $p = FixMyStreet::DB->resultset('Problem')->search(
+ { external_id => 638344 }
+ )->first;
+
+ ok $p, 'Found problem';
+ is $p->title, 'Potholes problem', 'correct problem title';
+ is $p->detail, 'Potholes problem', 'correct problem description';
+ $p->delete;
+};
+
+subtest "fixing passes along the correct message" => sub {
+ FixMyStreet::override_config {
+ MAPIT_URL => 'http://mapit.uk/',
+ ALLOWED_COBRANDS => 'isleofwight',
+ }, sub {
+ 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_request_updates><request_update><update_id>248</update_id></request_update></service_request_updates>');
+
+ my $o = Open311->new(
+ fixmystreet_body => $isleofwight,
+ test_mode => 1,
+ test_get_returns => { 'servicerequestupdates.xml' => $test_res },
+ );
+
+ my ($p) = $mech->create_problems_for_body(1, $isleofwight->id, 'Title', { external_id => 1 });
+
+ my $c = FixMyStreet::App->model('DB::Comment')->create({
+ problem => $p, user => $p->user, anonymous => 't', text => 'Update text',
+ problem_state => 'fixed - council', state => 'confirmed', mark_fixed => 0,
+ confirmed => DateTime->now(),
+ });
+
+ my $id = $o->post_service_request_update($c);
+ is $id, 248, 'correct update ID returned';
+ my $cgi = CGI::Simple->new($o->test_req_used->content);
+ like $cgi->param('description'), qr/^FMS-Update:/, 'FMS update prefix included';
+ unlike $cgi->param('description'), qr/The customer indicated that this issue had been fixed/, 'No fixed message included';
+
+ $c = $mech->create_comment_for_problem($p, $p->user, 'Name', 'Update text', 'f', 'confirmed', 'fixed - user', { confirmed => \'current_timestamp' });
+ $c->discard_changes; # Otherwise cannot set_nanosecond
+
+ $id = $o->post_service_request_update($c);
+ is $id, 248, 'correct update ID returned';
+ $cgi = CGI::Simple->new($o->test_req_used->content);
+ like $cgi->param('description'), qr/^FMS-Update: \[The customer indicated that this issue had been fixed/, 'Fixed message included';
+ $p->comments->delete;
+ $p->delete;
+ };
+};
+
+subtest 'Check special Open311 request handling', sub {
+ $mech->clear_emails_ok;
+ my ($p) = $mech->create_problems_for_body(1, $isleofwight->id, 'Title', { category => 'Potholes', latitude => 50.7108, longitude => -1.29573, cobrand => 'isleofwight' });
+ $p->set_extra_fields({ name => 'urgent', value => 'no'});
+ $p->update;
+
+ my $test_data;
+ FixMyStreet::override_config {
+ STAGING_FLAGS => { send_reports => 1 },
+ ALLOWED_COBRANDS => ['isleofwight' ],
+ MAPIT_URL => 'http://mapit.uk/',
+ }, sub {
+ $test_data = FixMyStreet::Script::Reports::send();
+ };
+
+ $p->discard_changes;
+ ok $p->whensent, 'Report marked as sent';
+ is $p->send_method_used, 'Open311', 'Report sent via Open311';
+ is $p->external_id, 248, 'Report has right external ID';
+
+ my $req = $test_data->{test_req_used};
+ my $c = CGI::Simple->new($req->content);
+ is $c->param('attribute[urgent]'), undef, 'no urgent param sent';
+
+ $mech->email_count_is(1);
+ my $email = $mech->get_email;
+ ok $email, "got an email";
+ like $mech->get_text_body_from_email($email),
+ qr/your enquiry has been received by Island Roads/, "correct report send email text";
+};
+
+subtest "comment recording triage details is not sent" => sub {
+ FixMyStreet::override_config {
+ MAPIT_URL => 'http://mapit.uk/',
+ ALLOWED_COBRANDS => [ 'isleofwight' ],
+ }, sub {
+ 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_request_updates></service_request_updates>');
+
+ my $o = Open311->new(
+ fixmystreet_body => $isleofwight,
+ test_mode => 1,
+ test_get_returns => { 'servicerequestupdates.xml' => $test_res },
+ );
+
+ my ($p) = $mech->create_problems_for_body(
+ 1, $isleofwight->id, 'Title',
+ {
+ category => 'Roads',
+ areas => 2636,
+ latitude => 50.71086,
+ longitude => -1.29573,
+ whensent => DateTime->now->add( minutes => -5 ),
+ send_method_used => 'Triage',
+ state => 'for triage',
+ external_id => 1,
+ });
+
+ $mech->log_out_ok;
+ $mech->log_in_ok($admin_user->email);
+ my $report_url = '/report/' . $p->id;
+ $mech->get_ok($report_url);
+ $mech->submit_form_ok( {
+ with_fields => {
+ category => 'Potholes',
+ include_update => 0,
+ }
+ },
+ 'triage form submitted'
+ );
+
+ ok $p->comments->first, 'comment created for problem';
+
+ $p->update({
+ send_method_used => 'Open311',
+ whensent => DateTime->now->add( minutes => -5 ),
+ });
+
+ my $updates = Open311::PostServiceRequestUpdates->new(
+ current_open311 => $o,
+ );
+ my $id = $updates->process_body($isleofwight);
+ ok !$o->test_req_used, 'no open311 update sent';
+
+ $p->comments->delete;
+ $p->delete;
+ };
+};
+
+my ($p) = $mech->create_problems_for_body(1, $isleofwight->id, '', { cobrand => 'isleofwight' });
+my $alert = FixMyStreet::App->model('DB::Alert')->create( {
+ parameter => $p->id,
+ alert_type => 'new_updates',
+ user => $user,
+ cobrand => 'isleofwight',
+} )->confirm;
+
+subtest "sends branded alert emails" => sub {
+ $mech->create_comment_for_problem($p, $system_user, 'Other User', 'This is some update text', 'f', 'confirmed', undef, { confirmed => DateTime->now->add( minutes => 5 ) });
+ $mech->clear_emails_ok;
+
+ FixMyStreet::override_config {
+ MAPIT_URL => 'http://mapit.uk/',
+ ALLOWED_COBRANDS => ['isleofwight','fixmystreet'],
+ }, sub {
+ FixMyStreet::Script::Alerts::send();
+ };
+
+ $mech->email_count_is(1);
+ my $email = $mech->get_email;
+ ok $email, "got an email";
+ like $mech->get_text_body_from_email($email), qr/Island Roads/, "emails are branded";
+};
+
+$p->comments->delete;
+$p->delete;
+
+subtest "sends branded confirmation emails" => sub {
+ $mech->log_out_ok;
+ $mech->clear_emails_ok;
+ $mech->get_ok('/around');
+ FixMyStreet::override_config {
+ ALLOWED_COBRANDS => [ 'isleofwight' ],
+ MAPIT_URL => 'http://mapit.uk/',
+ }, sub {
+ $mech->submit_form_ok( { with_fields => { pc => 'PO30 5XJ', } },
+ "submit location" );
+
+ # click through to the report page
+ $mech->follow_link_ok( { text_regex => qr/skip this step/i, },
+ "follow 'skip this step' link" );
+
+ $mech->submit_form_ok(
+ {
+ button => 'submit_register',
+ with_fields => {
+ title => 'Test Report',
+ detail => 'Test report details.',
+ photo1 => '',
+ name => 'Joe Bloggs',
+ username => 'test-1@example.com',
+ category => 'Roads',
+ }
+ },
+ "submit good details"
+ );
+
+ $mech->email_count_is(1);
+ my $email = $mech->get_email;
+ ok $email, "got an email";
+ like $mech->get_text_body_from_email($email), qr/Island Roads/, "emails are branded";
+
+ my $url = $mech->get_link_from_email($email);
+ $mech->get_ok($url);
+ $mech->clear_emails_ok;
+ };
+};
+
+subtest "sends branded report sent emails" => sub {
+ $mech->clear_emails_ok;
+ FixMyStreet::override_config {
+ STAGING_FLAGS => { send_reports => 1 },
+ MAPIT_URL => 'http://mapit.uk/',
+ ALLOWED_COBRANDS => ['isleofwight','fixmystreet'],
+ }, sub {
+ FixMyStreet::Script::Reports::send();
+ };
+ $mech->email_count_is(1);
+ my $email = $mech->get_email;
+ ok $email, "got an email";
+ like $mech->get_text_body_from_email($email), qr/Island Roads/, "emails are branded";
+};
+
+subtest "check category extra uses correct name" => sub {
+ my @extras = ( {
+ code => 'test',
+ datatype => 'string',
+ description => 'question',
+ variable => 'true',
+ required => 'false',
+ order => 1,
+ datatype_description => 'datatype',
+ } );
+ $contact2->set_extra_fields( @extras );
+ $contact2->update;
+
+ my $extra_details;
+
+ FixMyStreet::override_config {
+ MAPIT_URL => 'http://mapit.uk/',
+ ALLOWED_COBRANDS => ['isleofwight','fixmystreet'],
+ }, sub {
+ $extra_details = $mech->get_ok_json('/report/new/category_extras?category=Roads&latitude=50.71086&longitude=-1.29573');
+ };
+
+ like $extra_details->{category_extra}, qr/Island Roads/, 'correct name in category extras';
+};
+
+subtest "reports are marked for triage upon submission" => sub {
+ $mech->log_out_ok;
+ $mech->clear_emails_ok;
+ $mech->log_in_ok($user->email);
+ $mech->get_ok('/around');
+ FixMyStreet::override_config {
+ STAGING_FLAGS => { send_reports => 1, skip_checks => 0 },
+ ALLOWED_COBRANDS => [ 'isleofwight' ],
+ MAPIT_URL => 'http://mapit.uk/',
+ }, sub {
+ $mech->submit_form_ok( { with_fields => { pc => 'PO30 5XJ', } },
+ "submit location" );
+
+ # click through to the report page
+ $mech->follow_link_ok( { text_regex => qr/skip this step/i, },
+ "follow 'skip this step' link" );
+
+ $mech->submit_form_ok(
+ {
+ button => 'submit_register',
+ with_fields => {
+ title => 'Test Report',
+ detail => 'Test report details.',
+ photo1 => '',
+ category => 'Roads',
+ }
+ },
+ "submit good details"
+ );
+
+ my $report = $user->problems->first;
+ ok $report, "Found the report";
+ is $report->state, 'confirmed', 'report confirmed';
+
+ $mech->clear_emails_ok;
+
+ FixMyStreet::Script::Reports::send();
+ $report->discard_changes;
+ is $report->state, 'for triage', 'report marked as for triage';
+ ok $report->whensent, 'report marked as sent';
+
+ $mech->email_count_is(1);
+ my $email = $mech->get_email;
+ like $mech->get_text_body_from_email($email),
+ qr/submitted to Island Roads for review/, 'correct text for email sent for Triage';
+ };
+};
+
+for my $cobrand ( 'fixmystreet', 'isleofwight' ) {
+ subtest "only categories for Triage are displayed on " . $cobrand => sub {
+ $mech->log_out_ok;
+ $mech->get_ok('/around');
+ FixMyStreet::override_config {
+ ALLOWED_COBRANDS => [ $cobrand ],
+ MAPIT_URL => 'http://mapit.uk/',
+ }, sub {
+ $mech->submit_form_ok( { with_fields => { pc => 'PO30 5XJ', } },
+ "submit location" );
+
+ # click through to the report page
+ $mech->follow_link_ok( { text_regex => qr/skip this step/i, },
+ "follow 'skip this step' link" );
+
+ my $f = $mech->form_name('mapSkippedForm');
+ ok $f, 'found form';
+ my $cats = $f->find_input('category');
+ ok $cats, 'found category element';
+ my @values = $cats->possible_values;
+ is_deeply \@values, [ '-- Pick a category --', 'Roads' ], 'correct category list';
+ };
+ };
+
+ subtest "staff user can see non Triage categories on " . $cobrand => sub {
+ $mech->log_out_ok;
+ $mech->log_in_ok($admin_user->email);
+ $mech->get_ok('/around');
+ FixMyStreet::override_config {
+ ALLOWED_COBRANDS => [ $cobrand ],
+ MAPIT_URL => 'http://mapit.uk/',
+ }, sub {
+ $mech->submit_form_ok( { with_fields => { pc => 'PO30 5XJ', } },
+ "submit location" );
+
+ # click through to the report page
+ $mech->follow_link_ok( { text_regex => qr/skip this step/i, },
+ "follow 'skip this step' link" );
+
+ my $f = $mech->form_name('mapSkippedForm');
+ ok $f, 'found form';
+ my $cats = $f->find_input('category');
+ ok $cats, 'found category element';
+ my @values = $cats->possible_values;
+ is_deeply \@values, [ '-- Pick a category --', 'Potholes' ], 'correct category list';
+ };
+ };
+}
+
+done_testing();
diff --git a/t/cobrand/zurich.t b/t/cobrand/zurich.t
index 0bfdd8351..a08eb431e 100644
--- a/t/cobrand/zurich.t
+++ b/t/cobrand/zurich.t
@@ -6,6 +6,7 @@ use Email::MIME;
use File::Temp;
use LWP::Protocol::PSGI;
use Test::LongString;
+use Test::MockModule;
use Path::Tiny;
use t::Mock::MapItZurich;
use FixMyStreet::Script::Reports;
@@ -28,18 +29,8 @@ $cobrand->db_state_migration;
my $sample_file = path(__FILE__)->parent->parent->child("app/controller/sample.jpg");
ok $sample_file->exists, "sample file $sample_file exists";
-# This is a helper method that will send the reports but with the config
-# correctly set - notably STAGING_FLAGS send_reports needs to be true, and
-# zurich must be allowed cobrand if we want to be able to call cobrand
-# methods on it.
sub send_reports_for_zurich {
- FixMyStreet::override_config {
- STAGING_FLAGS => { send_reports => 1 },
- ALLOWED_COBRANDS => ['zurich']
- }, sub {
- # Actually send the report
- FixMyStreet::Script::Reports::send('zurich');
- };
+ FixMyStreet::Script::Reports::send('zurich');
}
sub reset_report_state {
my ($report, $created) = @_;
@@ -51,45 +42,45 @@ sub reset_report_state {
$report->whensent(undef);
$report->state('submitted');
$report->created($created) if $created;
+ $report->category('Other');
$report->update;
}
-# Front page test
-ok $mech->host("zurich.example.com"), "change host to Zurich";
+my $UPLOAD_DIR = File::Temp->newdir();
FixMyStreet::override_config {
- ALLOWED_COBRANDS => [ 'zurich' ],
+ STAGING_FLAGS => { send_reports => 1 },
+ ALLOWED_COBRANDS => 'zurich',
+ MAPIT_URL => 'http://mapit.zurich/',
+ MAPIT_TYPES => [ 'O08' ],
+ MAPIT_ID_WHITELIST => [ 423017 ],
+ MAP_TYPE => 'Zurich,OSM',
+ PHOTO_STORAGE_BACKEND => 'FileSystem',
+ PHOTO_STORAGE_OPTIONS => {
+ UPLOAD_DIR => $UPLOAD_DIR,
+ },
}, sub {
- $mech->get_ok('/');
-};
+
+# Front page test
+ok $mech->host("zurich.example.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' );
-$zurich->parent( undef );
-$zurich->update;
-my $division = $mech->create_body_ok( 2, 'Division 1' );
-$division->parent( $zurich->id );
-$division->send_method( 'Zurich' );
-$division->endpoint( 'division@example.org' );
-$division->update;
-$division->body_areas->find_or_create({ area_id => 423017 });
-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 $external_body = $mech->create_body_ok( 4, 'External Body' );
-$external_body->send_method( 'Zurich' );
-$external_body->endpoint( 'external_body@example.net' );
-$external_body->update;
+my $division = $mech->create_body_ok( 423017, 'Division 1', {
+ parent => $zurich->id, send_method => 'Zurich', endpoint => 'division@example.org' } );
+my $division2 = $mech->create_body_ok( 423017, 'Division 2', {
+ parent => $zurich->id, send_method => 'Zurich', endpoint => 'division2@example.org' } );
+my $subdivision = $mech->create_body_ok( 3, 'Subdivision A',
+ { parent => $division->id, send_method => 'Zurich', endpoint => 'subdivision@example.org' } );
+my $external_body = $mech->create_body_ok( 4, 'External Body',
+ { send_method => 'Zurich', endpoint => 'external_body@example.net' } );
+my $external_body2 = $mech->create_body_ok( 4, 'Another Body External',
+ { send_method => 'Zurich', endpoint => 'external_body2@example.net' } );
sub get_export_rows_count {
my $mech = shift;
- FixMyStreet::override_config {
- ALLOWED_COBRANDS => [ 'zurich' ],
- }, sub {
- $mech->get_ok( '/admin/stats?export=1' );
- };
+ $mech->get_ok( '/admin/stats?export=1' );
is $mech->res->code, 200, 'csv retrieved ok';
is $mech->content_type, 'text/csv', 'content_type correct' and do {
my @lines = split /\n/, $mech->content;
@@ -117,29 +108,15 @@ my @reports = $mech->create_problems_for_body( 1, $division->id, 'Test', {
});
my $report = $reports[0];
-FixMyStreet::override_config {
- ALLOWED_COBRANDS => [ 'zurich' ],
- MAP_TYPE => 'Zurich,OSM',
-}, sub {
- $mech->get_ok( '/report/' . $report->id );
-};
+$mech->get_ok( '/report/' . $report->id );
$mech->content_contains('&Uuml;berpr&uuml;fung ausstehend')
or die $mech->content;
-FixMyStreet::override_config {
- ALLOWED_COBRANDS => [ 'zurich' ],
- MAP_TYPE => 'Zurich,OSM',
-}, sub {
- my $json = $mech->get_ok_json( '/report/ajax/' . $report->id );
- is $json->{report}->{title}, "&Uuml;berpr&uuml;fung ausstehend", "correct title";
- is $json->{report}->{state}, "submitted", "correct state";
-};
+my $json = $mech->get_ok_json( '/report/ajax/' . $report->id );
+is $json->{report}->{title}, "&Uuml;berpr&uuml;fung ausstehend", "correct title";
+is $json->{report}->{state}, "submitted", "correct state";
subtest "Banners are displayed correctly" => sub {
- FixMyStreet::override_config {
- ALLOWED_COBRANDS => [ 'zurich' ],
- MAP_TYPE => 'Zurich,OSM',
- }, sub {
for my $test (
{
description => 'new report',
@@ -162,8 +139,8 @@ subtest "Banners are displayed correctly" => sub {
{
description => 'closed report',
state => 'external',
- banner_id => 'closed',
- banner_text => 'Extern',
+ banner_id => 'fixed',
+ banner_text => 'Beantwortet',
},
{
description => 'in progress report',
@@ -211,17 +188,14 @@ subtest "Banners are displayed correctly" => sub {
};
}
$report->update({ state => 'submitted' });
- };
};
-# Check logging in to deal with this report
-FixMyStreet::override_config {
- ALLOWED_COBRANDS => [ 'zurich' ],
-}, sub {
+my $user;
+subtest 'check logging in to deal with this report' => sub {
$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 = $mech->log_in_ok( 'dm1@example.org') ;
$user->from_body( undef );
$user->update;
ok $mech->get( '/admin' );
@@ -230,12 +204,12 @@ FixMyStreet::override_config {
$user->update;
$mech->get_ok( '/admin' );
-};
-is $mech->uri->path, '/admin', "am logged in";
+ 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->content_contains( 'report_edit/' . $report->id );
+ $mech->content_contains( DateTime->now->strftime("%d.%m.%Y") );
+ $mech->content_contains( 'Erfasst' );
+};
subtest "changing of categories" => sub {
# create a few categories (which are actually contacts)
@@ -260,13 +234,8 @@ subtest "changing of categories" => sub {
ok ( !$comments_rs->first, "There are no comments yet" );
# change the category via the web interface
- FixMyStreet::override_config {
- ALLOWED_COBRANDS => [ 'zurich' ],
- MAP_TYPE => 'Zurich,OSM',
- }, sub {
- $mech->get_ok( '/admin/report_edit/' . $report->id );
- $mech->submit_form_ok( { with_fields => { category => 'Cat2' } } );
- };
+ $mech->get_ok( '/admin/report_edit/' . $report->id );
+ $mech->submit_form_ok( { with_fields => { category => 'Cat2' } } );
# check changes correctly saved
$report->discard_changes();
@@ -280,6 +249,38 @@ subtest "changing of categories" => sub {
$report->update({category => $original_category });
};
+subtest "private categories" => sub {
+ $mech->log_in_ok( 'super@example.org' );
+ $mech->get_ok('/admin/bodies');
+ $mech->follow_link_ok({ text => 'Division 1' });
+ $mech->submit_form_ok({ with_fields => {
+ category => 'Allgemein',
+ state => 'inactive',
+ email => 'allgemein@example.org',
+ 'extra[admin_label]' => 'StadtPeople',
+ 'extra[abbreviation]' => 'STA',
+ note => 'New',
+ }});
+ $mech->follow_link_ok({ text => 'Allgemein' });
+ $mech->content_contains('<option value="inactive" selected>');
+ $mech->content_like(qr/admin_label.*?StadtPeople/);
+
+ $mech->get_ok( '/around?lat=47.381817&lon=8.529156' );
+ $mech->content_lacks('StadtPeople');
+ $mech->content_contains('Allgemein');
+ $mech->get_ok( '/report/new?lat=47.381817&lon=8.529156' );
+ $mech->content_lacks('StadtPeople');
+ $mech->content_lacks('Allgemein');
+
+ $report->update({ category => 'Allgemein' });
+ $mech->get_ok('/report/' . $report->id);
+ $mech->content_lacks('StadtPeople');
+ $mech->content_contains('Allgemein');
+
+ $mech->get_ok('/admin/report_edit/' . $report->id);
+ $mech->content_contains('<option value="Allgemein">StadtPeople (STA)</option>');
+};
+
sub get_moderated_count {
# my %date_params = ( );
# my $moderated = FixMyStreet::DB->resultset('Problem')->search({
@@ -288,17 +289,12 @@ sub get_moderated_count {
# use a separate mech to avoid stomping on test state
my $mech = FixMyStreet::TestMech->new;
- my $user = $mech->log_in_ok( 'super@example.org' );
+ $mech->log_in_ok( 'super@example.org' );
- FixMyStreet::override_config {
- ALLOWED_COBRANDS => [ 'zurich' ],
- }, sub {
- $mech->get( '/admin/stats' );
- };
+ $mech->get( '/admin/stats' );
if ($mech->content =~/Innerhalb eines Arbeitstages moderiert: (\d+)/) {
return $1;
- }
- else {
+ } else {
fail sprintf "Could not get moderation results (%d)", $mech->status;
return undef;
}
@@ -306,127 +302,112 @@ sub get_moderated_count {
subtest "report_edit" => sub {
- FixMyStreet::override_config {
- ALLOWED_COBRANDS => [ 'zurich' ],
- MAP_TYPE => 'Zurich,OSM',
- }, sub {
+ reset_report_state($report);
+ ok ( ! $report->get_extra_metadata('moderated_overdue'), 'Report currently unmoderated' );
+ is get_moderated_count(), 0;
- reset_report_state($report);
- ok ( ! $report->get_extra_metadata('moderated_overdue'), 'Report currently unmoderated' );
- is get_moderated_count(), 0;
-
- $mech->get_ok( '/admin/report_edit/' . $report->id );
- $mech->content_contains( 'Unbest&auml;tigt' ); # Unconfirmed email
- $mech->submit_form_ok( { with_fields => { state => 'confirmed' } } );
- $mech->get_ok( '/report/' . $report->id );
+ $mech->log_in_ok( 'dm1@example.org') ;
+ $mech->get_ok( '/admin/report_edit/' . $report->id );
+ $mech->content_contains( 'Unbest&auml;tigt' ); # Unconfirmed email
+ $mech->submit_form_ok( { with_fields => { state => 'confirmed' } } );
+ $mech->get_ok( '/report/' . $report->id );
- $report->discard_changes();
+ $report->discard_changes();
- $mech->content_contains('Aufgenommen');
- $mech->content_contains('Test Test');
- $mech->content_lacks('photo/' . $report->id . '.0.jpeg');
- $mech->email_count_is(0);
+ $mech->content_contains('Aufgenommen');
+ $mech->content_contains('Test Test');
+ $mech->content_lacks('photo/' . $report->id . '.0.jpeg');
+ $mech->email_count_is(0);
- $report->discard_changes;
+ $report->discard_changes;
- is ( $report->get_extra_metadata('moderated_overdue'), 0, 'Report now marked moderated' );
- is get_moderated_count(), 1;
+ is ( $report->get_extra_metadata('moderated_overdue'), 0, 'Report now marked moderated' );
+ is get_moderated_count(), 1;
- # Set state back to 10 days ago so that report is overdue
- my $created = $report->created;
- reset_report_state($report, $created->clone->subtract(days => 10));
+ # Set state back to 10 days ago so that report is overdue
+ my $created = $report->created;
+ reset_report_state($report, $created->clone->subtract(days => 10));
- is get_moderated_count(), 0;
+ is get_moderated_count(), 0;
- $mech->get_ok( '/admin/report_edit/' . $report->id );
- $mech->submit_form_ok( { with_fields => { state => 'confirmed' } } );
- $mech->get_ok( '/report/' . $report->id );
+ $mech->get_ok( '/admin/report_edit/' . $report->id );
+ $mech->submit_form_ok( { with_fields => { state => 'confirmed' } } );
+ $mech->get_ok( '/report/' . $report->id );
- $report->discard_changes;
- is ( $report->get_extra_metadata('moderated_overdue'), 1, 'moderated_overdue set correctly when overdue' );
- is get_moderated_count(), 0, 'Moderated count not increased when overdue';
+ $report->discard_changes;
+ is ( $report->get_extra_metadata('moderated_overdue'), 1, 'moderated_overdue set correctly when overdue' );
+ is get_moderated_count(), 0, 'Moderated count not increased when overdue';
- reset_report_state($report, $created);
+ reset_report_state($report, $created);
- $mech->get_ok( '/admin/report_edit/' . $report->id );
- $mech->submit_form_ok( { with_fields => { state => 'confirmed' } } );
- $mech->get_ok( '/report/' . $report->id );
- $report->discard_changes;
- is ( $report->get_extra_metadata('moderated_overdue'), 0, 'Marking confirmed sets moderated_overdue' );
- is ( $report->get_extra_metadata('closed_overdue'), undef, 'Marking confirmed does NOT set closed_overdue' );
- is get_moderated_count(), 1;
+ $mech->get_ok( '/admin/report_edit/' . $report->id );
+ $mech->submit_form_ok( { with_fields => { state => 'confirmed' } } );
+ $mech->get_ok( '/report/' . $report->id );
+ $report->discard_changes;
+ is ( $report->get_extra_metadata('moderated_overdue'), 0, 'Marking confirmed sets moderated_overdue' );
+ is ( $report->get_extra_metadata('closed_overdue'), undef, 'Marking confirmed does NOT set closed_overdue' );
+ is get_moderated_count(), 1;
- $mech->get_ok( '/admin/report_edit/' . $report->id );
- $mech->submit_form_ok( { with_fields => { state => 'hidden' } } );
- $mech->get_ok( '/report/' . $report->id, 'still visible as response not published yet' );
+ $mech->get_ok( '/admin/report_edit/' . $report->id );
+ $mech->submit_form_ok( { with_fields => { state => 'hidden' } } );
+ $mech->get_ok( '/report/' . $report->id, 'still visible as response not published yet' );
- $report->discard_changes;
- is ( $report->get_extra_metadata('moderated_overdue'), 0, 'Still marked moderated_overdue' );
- is ( $report->get_extra_metadata('closed_overdue'), undef, "Marking hidden doesn't set closed_overdue..." );
- is ( $report->state, 'feedback pending', 'Marking hidden actually sets state to feedback pending');
- is ( $report->get_extra_metadata('closure_status'), 'hidden', 'Marking hidden sets closure_status to hidden');
- is get_moderated_count(), 1, 'Check still counted moderated'
- or diag $report->get_column('extra');
-
- # publishing actually sets hidden
- $mech->get_ok( '/admin/report_edit/' . $report->id );
- $mech->form_with_fields( 'status_update' );
- $mech->submit_form_ok( { button => 'publish_response' } );
- $mech->get_ok( '/admin/report_edit/' . $report->id );
- $report->discard_changes;
+ $report->discard_changes;
+ is ( $report->get_extra_metadata('moderated_overdue'), 0, 'Still marked moderated_overdue' );
+ is ( $report->get_extra_metadata('closed_overdue'), undef, "Marking hidden doesn't set closed_overdue..." );
+ is ( $report->state, 'feedback pending', 'Marking hidden actually sets state to feedback pending');
+ is ( $report->get_extra_metadata('closure_status'), 'hidden', 'Marking hidden sets closure_status to hidden');
+ is get_moderated_count(), 1, 'Check still counted moderated'
+ or diag $report->get_column('extra');
+
+ # publishing actually sets hidden
+ $mech->get_ok( '/admin/report_edit/' . $report->id );
+ $mech->form_with_fields( 'status_update' );
+ $mech->submit_form_ok( { button => 'publish_response' } );
+ $mech->get_ok( '/admin/report_edit/' . $report->id );
+ $report->discard_changes;
- is ( $report->get_extra_metadata('closed_overdue'), 0, "Closing as hidden sets closed_overdue..." );
- is ( $report->state, 'hidden', 'Closing as hidden sets state to hidden');
- is ( $report->get_extra_metadata('closure_status'), undef, 'Closing as hidden unsets closure_status');
+ is ( $report->get_extra_metadata('closed_overdue'), 0, "Closing as hidden sets closed_overdue..." );
+ is ( $report->state, 'hidden', 'Closing as hidden sets state to hidden');
+ is ( $report->get_extra_metadata('closure_status'), undef, 'Closing as hidden unsets closure_status');
- $mech->submit_form_ok( { with_fields => { new_internal_note => 'Initial internal note.' } } );
- $report->discard_changes;
- is ( $report->state, 'hidden', 'Another internal note does not reopen');
+ $mech->submit_form_ok( { with_fields => { new_internal_note => 'Initial internal note.' } } );
+ $report->discard_changes;
+ is ( $report->state, 'hidden', 'Another internal note does not reopen');
- $mech->get( '/report/' . $report->id);
- is $mech->res->code, 410;
+ $mech->get( '/report/' . $report->id);
+ is $mech->res->code, 410;
- reset_report_state($report);
- is ( $report->get_extra_metadata('moderated_overdue'), undef, 'Sanity check' );
- is get_moderated_count(), 0;
+ reset_report_state($report);
+ is ( $report->get_extra_metadata('moderated_overdue'), undef, 'Sanity check' );
+ is get_moderated_count(), 0;
- # Check that setting to 'hidden' also triggers moderation
- $mech->get_ok( '/admin/report_edit/' . $report->id );
- $mech->submit_form_ok( { with_fields => { state => 'hidden' } } );
- $mech->get_ok( '/admin/report_edit/' . $report->id );
- $mech->form_with_fields( 'status_update' );
- $mech->submit_form_ok( { button => 'publish_response' } );
+ # Check that setting to 'hidden' also triggers moderation
+ $mech->get_ok( '/admin/report_edit/' . $report->id );
+ $mech->submit_form_ok( { with_fields => { state => 'hidden' } } );
+ $mech->get_ok( '/admin/report_edit/' . $report->id );
+ $mech->form_with_fields( 'status_update' );
+ $mech->submit_form_ok( { button => 'publish_response' } );
- $report->discard_changes;
- is ( $report->get_extra_metadata('moderated_overdue'), 0, 'Marking hidden from scratch sets moderated_overdue' );
- is ( $report->get_extra_metadata('closed_overdue'), 0, 'Marking hidden from scratch also set closed_overdue' );
- is get_moderated_count(), 1;
+ $report->discard_changes;
+ is ( $report->get_extra_metadata('moderated_overdue'), 0, 'Marking hidden from scratch sets moderated_overdue' );
+ is ( $report->get_extra_metadata('closed_overdue'), 0, 'Marking hidden from scratch also set closed_overdue' );
+ is get_moderated_count(), 1;
- is ($cobrand->get_or_check_overdue($report), 0, 'sanity check');
- $report->update({ created => $created->clone->subtract(days => 10) });
- is ($cobrand->get_or_check_overdue($report), 0, 'overdue call not increased');
+ is ($cobrand->get_or_check_overdue($report), 0, 'sanity check');
+ $report->update({ created => $created->clone->subtract(days => 10) });
+ is ($cobrand->get_or_check_overdue($report), 0, 'overdue call not increased');
- reset_report_state($report, $created);
- }
+ reset_report_state($report, $created);
};
# Give the report three photos
-my $UPLOAD_DIR = File::Temp->newdir();
my @files = map { $_ x 40 . ".jpeg" } (1..3);
$sample_file->copy(path($UPLOAD_DIR, $_)) for @files;
$report->photo(join(',', @files));
$report->update;
-FixMyStreet::override_config {
- ALLOWED_COBRANDS => [ 'zurich' ],
- MAPIT_URL => 'http://mapit.zurich/',
- MAP_TYPE => 'Zurich,OSM',
- PHOTO_STORAGE_BACKEND => 'FileSystem',
- PHOTO_STORAGE_OPTIONS => {
- UPLOAD_DIR => $UPLOAD_DIR,
- },
-}, sub {
- # Photo publishing
+subtest 'Photo publishing' => sub {
$mech->get_ok( '/admin/report_edit/' . $report->id );
$mech->submit_form_ok( { with_fields => { state => 'confirmed', publish_photo_1 => 1 } } );
$mech->get_ok( '/around?lat=' . $report->latitude . ';lon=' . $report->longitude);
@@ -469,50 +450,37 @@ $mech->log_out_ok;
subtest 'SDM' => sub {
my $user = $mech->log_in_ok( 'sdm1@example.org') ;
$user->update({ from_body => undef });
- FixMyStreet::override_config {
- ALLOWED_COBRANDS => [ 'zurich' ],
- }, sub {
- ok $mech->get( '/admin' );
- };
+ ok $mech->get( '/admin' );
is $mech->res->code, 403, 'Got 403';
$user->from_body( $subdivision->id );
$user->update;
- FixMyStreet::override_config {
- ALLOWED_COBRANDS => [ 'zurich' ],
- }, sub {
- $mech->get_ok( '/admin' );
- };
+ $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' );
- FixMyStreet::override_config {
- ALLOWED_COBRANDS => [ 'zurich' ],
- MAP_TYPE => 'Zurich,OSM',
- }, sub {
- $mech->get_ok( '/admin/report_edit/' . $report->id );
- $mech->content_contains( 'Initial internal note' );
+ $mech->get_ok( '/admin/report_edit/' . $report->id );
+ $mech->content_contains( 'Initial internal note' );
- $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->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.";
- # Can still view the edit page but can't change anything
- $mech->get_ok( '/admin/report_edit/' . $report->id );
- $mech->content_contains('<input disabled');
- $mech->submit_form_ok( { with_fields => { status_update => 'This is a disallowed update.' } } );
- $mech->content_lacks('This is a disallowed update');
+ # Can still view the edit page but can't change anything
+ $mech->get_ok( '/admin/report_edit/' . $report->id );
+ $mech->content_contains('<input disabled');
+ $mech->submit_form_ok( { with_fields => { status_update => 'This is a disallowed update.' } } );
+ $mech->content_lacks('This is a disallowed update');
- $mech->get_ok( '/report/' . $report->id );
- $mech->content_contains('In Bearbeitung');
- $mech->content_contains('Test Test');
- };
+ $mech->get_ok( '/report/' . $report->id );
+ $mech->content_contains('In Bearbeitung');
+ $mech->content_contains('Test Test');
send_reports_for_zurich();
$email = $mech->get_email;
@@ -524,106 +492,86 @@ subtest 'SDM' => sub {
is $report->state, 'feedback pending', 'Report now in feedback pending state';
subtest 'send_back' => sub {
- FixMyStreet::override_config {
- ALLOWED_COBRANDS => [ 'zurich' ],
- MAP_TYPE => 'Zurich,OSM',
- }, sub {
- $report->update({ bodies_str => $subdivision->id, state => 'in progress' });
- $mech->get_ok( '/admin/report_edit/' . $report->id );
- $mech->submit_form_ok( { form_number => 2, button => 'send_back' } );
- $report->discard_changes;
- is $report->state, 'confirmed', 'Report sent back to confirmed state';
- is $report->bodies_str, $division->id, 'Report sent back to division';
- };
+ $report->update({ bodies_str => $subdivision->id, state => 'in progress' });
+ $mech->get_ok( '/admin/report_edit/' . $report->id );
+ $mech->submit_form_ok( { form_number => 2, button => 'send_back' } );
+ $report->discard_changes;
+ is $report->state, 'confirmed', 'Report sent back to confirmed state';
+ is $report->bodies_str, $division->id, 'Report sent back to division';
};
subtest 'not contactable' => sub {
- FixMyStreet::override_config {
- ALLOWED_COBRANDS => [ 'zurich' ],
- MAP_TYPE => 'Zurich,OSM',
- }, sub {
- $report->update({ bodies_str => $subdivision->id, state => 'in progress' });
- $mech->get_ok( '/admin/report_edit/' . $report->id );
- $mech->submit_form_ok( { button => 'not_contactable', form_number => 2 } );
- $report->discard_changes;
- is $report->state, 'feedback pending', 'Report sent back to Rueckmeldung ausstehend state';
- is $report->get_extra_metadata('closure_status'), 'not contactable', 'Report sent back to not_contactable state';
- is $report->bodies_str, $division->id, 'Report sent back to division';
- };
+ $report->update({ bodies_str => $subdivision->id, state => 'in progress' });
+ $mech->get_ok( '/admin/report_edit/' . $report->id );
+ $mech->submit_form_ok( { button => 'not_contactable', form_number => 2 } );
+ $report->discard_changes;
+ is $report->state, 'feedback pending', 'Report sent back to Rueckmeldung ausstehend state';
+ is $report->get_extra_metadata('closure_status'), 'not contactable', 'Report sent back to not_contactable state';
+ is $report->bodies_str, $division->id, 'Report sent back to division';
};
$mech->log_out_ok;
};
-my $user = $mech->log_in_ok( 'dm1@example.org') ;
-FixMyStreet::override_config {
- ALLOWED_COBRANDS => [ 'zurich' ],
-}, sub {
+subtest 'Test publishing of final update by DM' => sub {
+ $user = $mech->log_in_ok( 'dm1@example.org');
$mech->get_ok( '/admin' );
-};
-reset_report_state($report);
-$report->update({ state => 'feedback pending' });
+ reset_report_state($report);
+ $report->update({ state => 'feedback pending' });
-$mech->content_contains( 'report_edit/' . $report->id );
-$mech->content_contains( DateTime->now->strftime("%d.%m.%Y") );
+ $mech->content_contains( 'report_edit/' . $report->id );
+ $mech->content_contains( DateTime->now->strftime("%d.%m.%Y") );
-# User confirms their email address
-$report->set_extra_metadata(email_confirmed => 1);
-$report->confirmed(DateTime->now);
-$report->update;
+ # User confirms their email address
+ $report->set_extra_metadata(email_confirmed => 1);
+ $report->confirmed(DateTime->now);
+ $report->update;
-FixMyStreet::override_config {
- ALLOWED_COBRANDS => [ 'zurich' ],
- MAP_TYPE => 'Zurich,OSM',
-}, sub {
# Quick RSS check here, while we have a report
$mech->get_ok('/rss/problems');
+ my $module = Test::MockModule->new('FixMyStreet::Geocode::Zurich');
+ $module->mock(admin_district => sub { 'Admin district' });
+
$mech->get_ok( '/admin/report_edit/' . $report->id );
+
+ $mech->content_contains('Admin district');
+
$mech->content_lacks( 'Unbest&auml;tigt' ); # Confirmed email
$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('Beantwortet');
+ $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->header('From'), qr/do-not-reply\@example.org/, 'from line looks correct';
+ like $email->body, qr/FINAL UPDATE/, 'body looks correct';
+ $mech->clear_emails_ok;
};
-$mech->content_contains('Beantwortet');
-$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->header('From'), qr/do-not-reply\@example.org/, 'from line looks correct';
-like $email->body, qr/FINAL UPDATE/, 'body looks correct';
-$mech->clear_emails_ok;
-# Assign feedback pending (via confirmed), don't confirm email
-@reports = $mech->create_problems_for_body( 1, $division->id, 'Second', {
- state => 'submitted',
- confirmed => undef,
- cobrand => 'zurich',
- areas => ',423017,',
-});
-$report = $reports[0];
+subtest "Assign feedback pending (via confirmed), don't confirm email, no email sent" => sub {
+ @reports = $mech->create_problems_for_body( 1, $division->id, 'Second', {
+ state => 'submitted',
+ confirmed => undef,
+ cobrand => 'zurich',
+ areas => ',423017,',
+ });
+ $report = $reports[0];
-FixMyStreet::override_config {
- ALLOWED_COBRANDS => [ 'zurich' ],
- MAP_TYPE => 'Zurich,OSM',
-}, sub {
$mech->get_ok( '/admin/report_edit/' . $report->id );
$mech->submit_form_ok( { with_fields => { state => 'confirmed' } } );
$mech->get_ok( '/admin/report_edit/' . $report->id );
$mech->submit_form_ok( { with_fields => { state => 'feedback pending' } } );
$mech->get_ok( '/report/' . $report->id );
-};
-$mech->content_contains('In Bearbeitung');
-$mech->content_contains('Second Test');
+ $mech->content_contains('In Bearbeitung');
+ $mech->content_contains('Second Test');
-FixMyStreet::override_config {
- ALLOWED_COBRANDS => [ 'zurich' ],
- MAP_TYPE => 'Zurich,OSM',
-}, sub {
$mech->get_ok( '/admin/report_edit/' . $report->id );
$mech->content_contains( 'Unbest&auml;tigt' );
$report->discard_changes;
@@ -631,12 +579,12 @@ FixMyStreet::override_config {
$mech->submit_form_ok( { button => 'publish_response', with_fields => { status_update => 'FINAL UPDATE' } } );
$mech->get_ok( '/report/' . $report->id );
-};
-$mech->content_contains('Beantwortet');
-$mech->content_contains('Second Test');
-$mech->content_contains('FINAL UPDATE');
+ $mech->content_contains('Beantwortet');
+ $mech->content_contains('Second Test');
+ $mech->content_contains('FINAL UPDATE');
-$mech->email_count_is(0);
+ $mech->email_count_is(0);
+};
# Report assigned to third party
@@ -650,31 +598,27 @@ $report = $reports[0];
subtest "external report triggers email" => sub {
my $EXTERNAL_MESSAGE = 'Look Ma, no hands!';
- FixMyStreet::override_config {
- ALLOWED_COBRANDS => [ 'zurich' ],
- MAP_TYPE => 'Zurich,OSM',
- }, sub {
- # required to see body_external field
- $report->state('feedback pending');
- $report->set_extra_metadata('closure_status' => 'external');
- # Set the public_response manually here because the default one will have line breaks that get escaped as HTML, causing the comparison to fail.
- $report->set_extra_metadata('public_response' => 'Freundliche Gruesse Ihre Stadt Zuerich');
- $report->update;
+ # required to see body_external field
+ $report->state('feedback pending');
+ $report->set_extra_metadata('closure_status' => 'external');
+ # Set the public_response manually here because the default one will have line breaks that get escaped as HTML, causing the comparison to fail.
+ $report->set_extra_metadata('public_response' => 'Freundliche Gruesse Ihre Stadt Zuerich');
+ $report->update;
+
+ $mech->get_ok( '/admin/report_edit/' . $report->id );
+ $mech->form_with_fields( 'publish_response' );
+ $mech->submit_form_ok( {
+ button => 'publish_response',
+ with_fields => {
+ body_external => $external_body->id,
+ external_message => $EXTERNAL_MESSAGE,
+ } });
+ $report->discard_changes;
+ $mech->get_ok( '/report/' . $report->id );
- $mech->get_ok( '/admin/report_edit/' . $report->id );
- $mech->form_with_fields( 'publish_response' );
- $mech->submit_form_ok( {
- button => 'publish_response',
- with_fields => {
- body_external => $external_body->id,
- external_message => $EXTERNAL_MESSAGE,
- } });
- $report->discard_changes;
- $mech->get_ok( '/report/' . $report->id );
- };
is ($report->state, 'external', 'Report was closed correctly');
- $mech->content_contains('Extern')
+ $mech->content_contains('Beantwortet')
or die $mech->content;
$mech->content_contains('Third Test');
$mech->content_contains($report->get_extra_metadata('public_response')) or die $mech->content;
@@ -688,30 +632,25 @@ subtest "external report triggers email" => sub {
$mech->clear_emails_ok;
subtest "Test third_personal boolean setting" => sub {
- FixMyStreet::override_config {
- ALLOWED_COBRANDS => [ 'zurich' ],
- MAP_TYPE => 'Zurich,OSM',
- }, sub {
- $mech->get_ok( '/admin' );
- # required to see body_external field
- $report->state('feedback pending');
- $report->set_extra_metadata('closure_status' => 'external');
- $report->set_extra_metadata('public_response' => 'Freundliche Gruesse Ihre Stadt Zuerich');
- $report->update;
+ $mech->get_ok( '/admin' );
+ # required to see body_external field
+ $report->state('feedback pending');
+ $report->set_extra_metadata('closure_status' => 'external');
+ $report->set_extra_metadata('public_response' => 'Freundliche Gruesse Ihre Stadt Zuerich');
+ $report->update;
- is $mech->uri->path, '/admin', "am logged in";
- $mech->content_contains( 'report_edit/' . $report->id );
- $mech->get_ok( '/admin/report_edit/' . $report->id );
- $mech->form_with_fields( 'publish_response' );
- $mech->submit_form_ok( {
- button => 'publish_response',
- with_fields => {
- body_external => $external_body->id,
- third_personal => 1,
- } });
- $mech->get_ok( '/report/' . $report->id );
- };
- $mech->content_contains('Extern');
+ is $mech->uri->path, '/admin', "am logged in";
+ $mech->content_contains( 'report_edit/' . $report->id );
+ $mech->get_ok( '/admin/report_edit/' . $report->id );
+ $mech->form_with_fields( 'publish_response' );
+ $mech->submit_form_ok( {
+ button => 'publish_response',
+ with_fields => {
+ body_external => $external_body->id,
+ third_personal => 1,
+ } });
+ $mech->get_ok( '/report/' . $report->id );
+ $mech->content_contains('Beantwortet');
$mech->content_contains('Third Test');
$mech->content_contains($report->get_extra_metadata('public_response'));
send_reports_for_zurich();
@@ -724,30 +663,25 @@ subtest "external report triggers email" => sub {
};
subtest "Test external wish sending" => sub {
- FixMyStreet::override_config {
- ALLOWED_COBRANDS => [ 'zurich' ],
- MAP_TYPE => 'Zurich,OSM',
- }, sub {
- # set as wish
- $report->discard_changes;
- $report->state('feedback pending');
- $report->set_extra_metadata('closure_status' => 'wish');
- $report->update;
- is ($report->state, 'feedback pending', 'Sanity check') or die;
-
- $mech->get_ok( '/admin/report_edit/' . $report->id );
-
- $mech->form_with_fields( 'publish_response' );
- $mech->submit_form_ok( {
- button => 'publish_response',
- with_fields => {
- body_external => $external_body->id,
- external_message => $EXTERNAL_MESSAGE,
- } });
- # Wishes publicly viewable
- $mech->get_ok( '/report/' . $report->id );
- $mech->content_contains('Freundliche Gruesse Ihre Stadt Zuerich');
- };
+ # set as wish
+ $report->discard_changes;
+ $report->state('feedback pending');
+ $report->set_extra_metadata('closure_status' => 'wish');
+ $report->update;
+ is ($report->state, 'feedback pending', 'Sanity check') or die;
+
+ $mech->get_ok( '/admin/report_edit/' . $report->id );
+
+ $mech->form_with_fields( 'publish_response' );
+ $mech->submit_form_ok( {
+ button => 'publish_response',
+ with_fields => {
+ body_external => $external_body->id,
+ external_message => $EXTERNAL_MESSAGE,
+ } });
+ # Wishes publicly viewable
+ $mech->get_ok( '/report/' . $report->id );
+ $mech->content_contains('Freundliche Gruesse Ihre Stadt Zuerich');
send_reports_for_zurich();
$email = $mech->get_email;
like $email->header('Subject'), qr/Weitergeleitete Meldung/, 'subject looks okay';
@@ -760,30 +694,26 @@ subtest "external report triggers email" => sub {
subtest "Closure email includes public response" => sub {
my $PUBLIC_RESPONSE = "This is the public response to your report. Freundliche Gruesse.";
- FixMyStreet::override_config {
- ALLOWED_COBRANDS => [ 'zurich' ],
- MAP_TYPE => 'Zurich,OSM',
- }, sub {
- # set as extern
- reset_report_state($report);
- $report->state('feedback pending');
- $report->set_extra_metadata('closure_status' => 'external');
- $report->set_extra_metadata('email_confirmed' => 1);
- $report->unset_extra_metadata('public_response');
- $report->update;
- is ($report->state, 'feedback pending', 'Sanity check') or die;
-
- $mech->get_ok( '/admin/report_edit/' . $report->id );
-
- $mech->form_with_fields( 'publish_response' );
- $mech->submit_form_ok( {
- button => 'publish_response',
- with_fields => {
- body_external => $external_body->id,
- external_message => $EXTERNAL_MESSAGE,
- status_update => $PUBLIC_RESPONSE,
- } });
- };
+ # set as extern
+ reset_report_state($report);
+ $report->state('feedback pending');
+ $report->set_extra_metadata('closure_status' => 'external');
+ $report->set_extra_metadata('email_confirmed' => 1);
+ $report->unset_extra_metadata('public_response');
+ $report->update;
+ is ($report->state, 'feedback pending', 'Sanity check') or die;
+
+ $mech->get_ok( '/admin/report_edit/' . $report->id );
+
+ $mech->form_with_fields( 'publish_response' );
+ $mech->submit_form_ok( {
+ button => 'publish_response',
+ with_fields => {
+ body_external => $external_body->id,
+ external_message => $EXTERNAL_MESSAGE,
+ status_update => $PUBLIC_RESPONSE,
+ } });
+
$email = $mech->get_email;
my $report_id = $report->id;
like Encode::decode('MIME-Header', $email->header('Subject')), qr/Meldung #$report_id/, 'subject looks okay';
@@ -798,91 +728,89 @@ subtest "superuser and dm can see stats" => sub {
$mech->log_out_ok;
$user = $mech->log_in_ok( 'super@example.org' );
- FixMyStreet::override_config {
- ALLOWED_COBRANDS => [ 'zurich' ],
- }, sub {
- $mech->get( '/admin/stats' );
- };
+ $mech->get( '/admin/stats' );
is $mech->res->code, 200, "superuser should be able to see stats page";
$mech->log_out_ok;
$user = $mech->log_in_ok( 'dm1@example.org' );
- FixMyStreet::override_config {
- ALLOWED_COBRANDS => [ 'zurich' ],
- }, sub {
- $mech->get( '/admin/stats' );
- };
+ $mech->get( '/admin/stats' );
is $mech->res->code, 200, "dm can now also see stats page";
$mech->log_out_ok;
};
subtest "only superuser can edit bodies" => sub {
$user = $mech->log_in_ok( 'dm1@example.org' );
- FixMyStreet::override_config {
- ALLOWED_COBRANDS => [ 'zurich' ],
- MAPIT_URL => 'http://mapit.zurich/',
- }, sub {
- $mech->get( '/admin/body/' . $zurich->id );
- };
+ $mech->get( '/admin/body/' . $zurich->id );
is $mech->res->code, 403, "only superuser should be able to edit bodies";
$mech->log_out_ok;
};
subtest "only superuser can see 'Add body' form" => sub {
$user = $mech->log_in_ok( 'dm1@example.org' );
- FixMyStreet::override_config {
- ALLOWED_COBRANDS => [ 'zurich' ],
- MAPIT_URL => 'http://mapit.zurich/',
- MAPIT_TYPES => [ 'O08' ],
- MAPIT_ID_WHITELIST => [ 423017 ],
- }, sub {
- $mech->get_ok( '/admin/bodies' );
- };
+ $mech->get_ok( '/admin/bodies' );
$mech->content_contains('External Body');
$mech->content_lacks( '<form method="post" action="bodies"' );
$mech->log_out_ok;
};
subtest "phone number is mandatory" => sub {
- FixMyStreet::override_config {
- MAPIT_TYPES => [ 'O08' ],
- MAPIT_URL => 'http://mapit.zurich/',
- ALLOWED_COBRANDS => [ 'zurich' ],
- MAPIT_ID_WHITELIST => [ 423017 ],
- MAP_TYPE => 'Zurich,OSM',
- }, sub {
- $user = $mech->log_in_ok( 'dm1@example.org' );
- $mech->get_ok( '/report/new?lat=47.381817&lon=8.529156' );
- $mech->submit_form( with_fields => { phone => "" } );
- $mech->content_contains( 'Diese Information wird ben&ouml;tigt' );
- $mech->log_out_ok;
- };
+ $user = $mech->log_in_ok( 'dm1@example.org' );
+ $mech->get_ok( '/report/new?lat=47.381817&lon=8.529156' );
+ $mech->submit_form( with_fields => { phone => "" } );
+ $mech->content_contains( 'Diese Information wird ben&ouml;tigt' );
+ $mech->log_out_ok;
};
subtest "phone number is not mandatory for reports from mobile apps" => sub {
- FixMyStreet::override_config {
- MAPIT_TYPES => [ 'O08' ],
- MAPIT_URL => 'http://mapit.zurich/',
- ALLOWED_COBRANDS => [ 'zurich' ],
- MAPIT_ID_WHITELIST => [ 423017 ],
- MAP_TYPE => 'Zurich,OSM',
- }, sub {
- $mech->post_ok( '/report/new/mobile?lat=47.381817&lon=8.529156' , {
- service => 'iPhone',
- detail => 'Problem-Bericht',
- lat => 47.381817,
- lon => 8.529156,
- email => 'user@example.org',
- pc => '',
- name => '',
- category => 'bad category',
- });
- my $res = $mech->response;
- ok $res->header('Content-Type') =~ m{^application/json\b}, 'response should be json';
- unlike $res->content, qr/Diese Information wird ben&ouml;tigt/, 'response should not contain phone error';
- # Clear out the mailq
- $mech->clear_emails_ok;
- };
+ $mech->post_ok( '/report/new/mobile?lat=47.381817&lon=8.529156' , {
+ service => 'iPhone',
+ detail => 'Problem-Bericht',
+ lat => 47.381817,
+ lon => 8.529156,
+ email => 'user@example.org',
+ pc => '',
+ name => '',
+ category => 'bad category',
+ });
+ my $res = $mech->response;
+ ok $res->header('Content-Type') =~ m{^application/json\b}, 'response should be json';
+ unlike $res->content, qr/Diese Information wird ben&ouml;tigt/, 'response should not contain phone error';
+ # Clear out the mailq
+ $mech->clear_emails_ok;
+};
+
+subtest "link external body to category" => sub {
+ $mech->log_in_ok( 'super@example.org' );
+ $mech->get_ok( '/admin/body/' . $zurich->id );
+ $mech->content_lacks('extra[category]');
+ $mech->get_ok( '/admin/body/' . $division->id );
+ $mech->content_lacks('extra[category]');
+ $mech->get_ok( '/admin/body/' . $subdivision->id );
+ $mech->content_lacks('extra[category]');
+ $mech->get_ok( '/admin/body/' . $external_body->id );
+ $mech->content_contains('extra[category]');
+ $mech->submit_form_ok({ with_fields => { 'extra[category]' => 'Cat1' } });
+ $mech->content_contains('<option value="Cat1" selected>');
+ $external_body->discard_changes;
+ is $external_body->get_extra_metadata('category'), 'Cat1';
+};
+
+subtest "shows correct external bodies" => sub {
+ $report->discard_changes;
+ $report->state('feedback pending');
+ $report->set_extra_metadata('closure_status' => 'external');
+ $report->update;
+ $user = $mech->log_in_ok( 'dm1@example.org' );
+ $mech->get_ok( '/admin/report_edit/' . $report->id );
+ $mech->content_like(qr/<option[^>]*>External Body<\/option>\s*<option[^>]*>Another Body External<\/option>/); # Test order
+
+ $user = $mech->log_in_ok( 'dm2@example.org' );
+ $user->update({ from_body => $division2->id });
+ $report->update({ bodies_str => $division2->id });
+ $mech->get_ok( '/admin/report_edit/' . $report->id );
+ $mech->content_contains('Another Body External');
+ $mech->content_lacks('External Body');
+ $report->update({ bodies_str => $division->id });
};
subtest "problems can't be assigned to deleted bodies" => sub {
@@ -891,23 +819,15 @@ subtest "problems can't be assigned to deleted bodies" => sub {
$user->update;
$report->state( 'confirmed' );
$report->update;
- FixMyStreet::override_config {
- ALLOWED_COBRANDS => [ 'zurich' ],
- MAPIT_URL => 'http://mapit.zurich/',
- MAPIT_TYPES => [ 'O08' ],
- MAPIT_ID_WHITELIST => [ 423017 ],
- MAP_TYPE => 'Zurich,OSM',
- }, sub {
- $mech->get_ok( '/admin/body/' . $external_body->id );
- $mech->submit_form_ok( { with_fields => { deleted => 1 } } );
- $mech->get_ok( '/admin/report_edit/' . $report->id );
- $mech->content_lacks( $external_body->name )
- or do {
- diag $mech->content;
- diag $external_body->name;
- die;
- };
- };
+ $mech->get_ok( '/admin/body/' . $external_body->id );
+ $mech->submit_form_ok( { with_fields => { deleted => 1 } } );
+ $mech->get_ok( '/admin/report_edit/' . $report->id );
+ $mech->content_lacks( $external_body->name )
+ or do {
+ diag $mech->content;
+ diag $external_body->name;
+ die;
+ };
$user->from_body( $division->id );
$user->update;
$mech->log_out_ok;
@@ -924,44 +844,32 @@ subtest "photo must be supplied for categories that require it" => sub {
note => "note for graffiti",
extra => { photo_required => 1 }
});
- FixMyStreet::override_config {
- MAPIT_TYPES => [ 'O08' ],
- MAPIT_URL => 'http://mapit.zurich/',
- ALLOWED_COBRANDS => [ 'zurich' ],
- MAPIT_ID_WHITELIST => [ 423017 ],
- MAP_TYPE => 'Zurich,OSM',
- }, sub {
- $mech->get_ok('/report/new?lat=47.381817&lon=8.529156');
- $mech->submit_form_ok({ with_fields => {
- detail => 'Problem-Bericht',
- username => 'user@example.org',
- category => 'Graffiti - photo required',
- }});
- is $mech->res->code, 200, "missing photo shouldn't return anything but 200";
- $mech->content_contains(_("Photo is required."), 'response should contain photo error message');
- };
+ $mech->get_ok('/report/new?lat=47.381817&lon=8.529156');
+ $mech->submit_form_ok({ with_fields => {
+ detail => 'Problem-Bericht',
+ username => 'user@example.org',
+ category => 'Graffiti - photo required',
+ }});
+ is $mech->res->code, 200, "missing photo shouldn't return anything but 200";
+ $mech->content_contains(_("Photo is required."), 'response should contain photo error message');
};
subtest "test stats" => sub {
- FixMyStreet::override_config {
- ALLOWED_COBRANDS => [ 'zurich' ],
- }, sub {
- $user = $mech->log_in_ok( 'super@example.org' );
-
- $mech->get_ok( '/admin/stats' );
- is $mech->res->code, 200, "superuser should be able to see stats page";
-
- $mech->content_contains('Innerhalb eines Arbeitstages moderiert: 3');
- $mech->content_contains('Innerhalb von f&uuml;nf Arbeitstagen abgeschlossen: 3');
- # my @data = $mech->content =~ /(?:moderiert|abgeschlossen): \d+/g;
- # diag Dumper(\@data); use Data::Dumper;
-
- my $export_count = get_export_rows_count($mech);
- if (defined $export_count) {
- is $export_count - $EXISTING_REPORT_COUNT, 3, 'Correct number of reports';
- $mech->content_contains('fixed - council');
- }
- };
+ $user = $mech->log_in_ok( 'super@example.org' );
+
+ $mech->get_ok( '/admin/stats' );
+ is $mech->res->code, 200, "superuser should be able to see stats page";
+
+ $mech->content_contains('Innerhalb eines Arbeitstages moderiert: 3');
+ $mech->content_contains('Innerhalb von f&uuml;nf Arbeitstagen abgeschlossen: 3');
+ # my @data = $mech->content =~ /(?:moderiert|abgeschlossen): \d+/g;
+ # diag Dumper(\@data); use Data::Dumper;
+
+ my $export_count = get_export_rows_count($mech);
+ if (defined $export_count) {
+ is $export_count - $EXISTING_REPORT_COUNT, 3, 'Correct number of reports';
+ $mech->content_contains('fixed - council');
+ }
};
subtest "test admin_log" => sub {
@@ -977,136 +885,108 @@ subtest "test admin_log" => sub {
};
subtest 'email images to external partners' => sub {
- FixMyStreet::override_config {
- ALLOWED_COBRANDS => [ 'zurich' ],
- MAP_TYPE => 'Zurich,OSM',
- }, sub {
- reset_report_state($report);
+ reset_report_state($report);
- my $photo = path(__FILE__)->parent->child('zurich-logo_portal.x.jpg')->slurp_raw;
- my $photoset = FixMyStreet::App::Model::PhotoSet->new({
- data_items => [ $photo ],
- });
- my $fileid = $photoset->data;
-
- $report->set_extra_metadata('publish_photo' => { 0 => 1 });
- # The below email comparison must not have an external message.
- $report->unset_extra_metadata('external_message');
- $report->update({
- state => 'external',
- photo => $fileid,
- external_body => $external_body->id,
- });
+ my $photo = path(__FILE__)->parent->child('zurich-logo_portal.x.jpg')->slurp_raw;
+ my $photoset = FixMyStreet::App::Model::PhotoSet->new({
+ data_items => [ $photo ],
+ });
+ my $fileid = $photoset->data;
+
+ $report->set_extra_metadata('publish_photo' => { 0 => 1 });
+ # The below email comparison must not have an external message.
+ $report->unset_extra_metadata('external_message');
+ $report->update({
+ state => 'external',
+ photo => $fileid,
+ external_body => $external_body->id,
+ });
- $mech->clear_emails_ok;
- send_reports_for_zurich();
+ $mech->clear_emails_ok;
+ send_reports_for_zurich();
- my @emails = $mech->get_email;
- my $email_as_string = $mech->get_first_email(@emails);
- my ($boundary) = $email_as_string =~ /boundary="([A-Za-z0-9.]*)"/ms;
- my $email = Email::MIME->new($email_as_string);
-
- my $expected_email_content = path(__FILE__)->parent->child('zurich_attachments.txt')->slurp;
-
- my $REPORT_ID = $report->id;
- $expected_email_content =~ s{Subject: (.*?)\r?\n}{
- my $subj = Encode::decode('MIME-Header', $1);
- $subj =~ s{REPORT_ID}{$REPORT_ID}g;
- 'Subject: ' . Email::MIME::Encode::mime_encode($subj, "utf-8", 9) . "\n";
- }eg;
- $expected_email_content =~ s{REPORT_ID}{$REPORT_ID}g;
- $expected_email_content =~ s{BOUNDARY}{$boundary}g;
- my $expected_email = Email::MIME->new($expected_email_content);
-
- my @email_parts;
- $email->walk_parts(sub {
- my ($part) = @_;
- push @email_parts, [ { $part->header_pairs }, $part->body ];
- });
- my @expected_email_parts;
- $expected_email->walk_parts(sub {
- my ($part) = @_;
- push @expected_email_parts, [ { $part->header_pairs }, $part->body ];
- });
- is_deeply \@email_parts, \@expected_email_parts, 'MIME email text ok'
- or do {
- (my $test_name = $0) =~ s{/}{_}g;
- my $path = path("test-output-$test_name.tmp");
- $path->spew($email_as_string);
- diag "Saved output in $path";
- };
+ my @emails = $mech->get_email;
+ my $email_as_string = $mech->get_first_email(@emails);
+ my ($boundary) = $email_as_string =~ /boundary="([A-Za-z0-9.]*)"/ms;
+ my $email = Email::MIME->new($email_as_string);
+
+ my $expected_email_content = path(__FILE__)->parent->child('zurich_attachments.txt')->slurp;
+
+ my $REPORT_ID = $report->id;
+ $expected_email_content =~ s{Subject: (.*?)\r?\n}{
+ my $subj = Encode::decode('MIME-Header', $1);
+ $subj =~ s{REPORT_ID}{$REPORT_ID}g;
+ 'Subject: ' . Email::MIME::Encode::mime_encode($subj, "utf-8", 9) . "\n";
+ }eg;
+ $expected_email_content =~ s{REPORT_ID}{$REPORT_ID}g;
+ $expected_email_content =~ s{BOUNDARY}{$boundary}g;
+ my $expected_email = Email::MIME->new($expected_email_content);
+
+ my @email_parts;
+ $email->walk_parts(sub {
+ my ($part) = @_;
+ push @email_parts, [ { $part->header_pairs }, $part->body ];
+ });
+ my @expected_email_parts;
+ $expected_email->walk_parts(sub {
+ my ($part) = @_;
+ push @expected_email_parts, [ { $part->header_pairs }, $part->body ];
+ });
+ is_deeply \@email_parts, \@expected_email_parts, 'MIME email text ok'
+ or do {
+ (my $test_name = $0) =~ s{/}{_}g;
+ my $path = path("test-output-$test_name.tmp");
+ $path->spew($email_as_string);
+ diag "Saved output in $path";
};
};
subtest 'Status update shown as appropriate' => sub {
- FixMyStreet::override_config {
- ALLOWED_COBRANDS => [ 'zurich' ],
- MAP_TYPE => 'Zurich,OSM',
- }, sub {
- # ALL closed states must hide the public_response edit, and public ones
- # must show the answer in blue.
- for (['feedback pending', 1, 0, 0],
- ['fixed - council', 0, 1, 0],
- ['external', 0, 1, 0],
- ['hidden', 0, 0, 1])
- {
- my ($state, $update, $public, $user_response) = @$_;
- $report->update({ state => $state });
- $mech->get_ok( '/admin/report_edit/' . $report->id );
- $mech->contains_or_lacks($update, "name='status_update'");
- $mech->contains_or_lacks($public || $user_response, '<div class="admin-official-answer">');
-
- if ($public) {
- $mech->get_ok( '/report/' . $report->id );
- $mech->content_contains('Antwort</h4>');
- }
- }
- };
+ # ALL closed states must hide the public_response edit, and public ones
+ # must show the answer in blue.
+ for (['feedback pending', 1, 0, 0],
+ ['fixed - council', 0, 1, 0],
+ ['external', 0, 1, 0],
+ ['hidden', 0, 0, 1])
+ {
+ my ($state, $update, $public, $user_response) = @$_;
+ $report->update({ state => $state });
+ $mech->get_ok( '/admin/report_edit/' . $report->id );
+ $mech->contains_or_lacks($update, "name='status_update'");
+ $mech->contains_or_lacks($public || $user_response, '<div class="admin-official-answer">');
+
+ if ($public) {
+ $mech->get_ok( '/report/' . $report->id );
+ $mech->content_contains('Antwort</h4>');
+ }
+ }
};
subtest 'time_spent' => sub {
- FixMyStreet::override_config {
- ALLOWED_COBRANDS => [ 'zurich' ],
- MAP_TYPE => 'Zurich,OSM',
- }, sub {
- my $report = $reports[0];
-
- is $report->get_time_spent, 0, '0 minutes spent';
- $report->update({ state => 'in progress' });
- $mech->get_ok( '/admin/report_edit/' . $report->id );
- $mech->form_with_fields( 'time_spent' );
- $mech->submit_form_ok( {
- with_fields => {
- time_spent => 10,
- } });
- is $report->get_time_spent, 10, '10 minutes spent';
- };
+ my $report = $reports[0];
+
+ is $report->get_time_spent, 0, '0 minutes spent';
+ $report->update({ state => 'in progress' });
+ $mech->get_ok( '/admin/report_edit/' . $report->id );
+ $mech->form_with_fields( 'time_spent' );
+ $mech->submit_form_ok( {
+ with_fields => {
+ time_spent => 10,
+ } });
+ is $report->get_time_spent, 10, '10 minutes spent';
};
$mech->log_out_ok;
-FixMyStreet::override_config {
- ALLOWED_COBRANDS => [ 'zurich' ],
- MAPIT_URL => 'http://mapit.zurich/',
- MAPIT_TYPES => [ 'ZZZ' ],
-}, sub {
- subtest 'users at the top level can be edited' => sub {
- $mech->log_in_ok( $superuser->email );
- $mech->get_ok('/admin/users/' . $superuser->id );
- };
+subtest 'users at the top level can be edited' => sub {
+ $mech->log_in_ok( $superuser->email );
+ $mech->get_ok('/admin/users/' . $superuser->id );
};
-FixMyStreet::override_config {
- ALLOWED_COBRANDS => [ 'zurich' ],
-}, sub {
- subtest 'A visit to /reports is okay' => sub {
- $mech->get_ok('/reports');
- };
+subtest 'A visit to /reports is okay' => sub {
+ $mech->get_ok('/reports');
};
-END {
- ok $mech->host("www.fixmystreet.com"), "change host back";
- done_testing();
-}
+};
-1;
+done_testing();
diff --git a/t/map/tests.t b/t/map/tests.t
index 1b152620e..f1f29dc06 100644
--- a/t/map/tests.t
+++ b/t/map/tests.t
@@ -12,6 +12,7 @@ my $requires = {
'Google' => 'map-google.js',
'GoogleOL' => 'map-google-ol.js',
'Hounslow' => 'map-wmts-hounslow.js',
+ 'IsleOfWight' => 'map-wmts-isleofwight.js',
'OSM' => 'OpenStreetMap.js',
'CycleMap' => 'OpenStreetMap.js',
'MapQuest' => 'OpenStreetMap.js',
diff --git a/t/open311/getservicerequestupdates.t b/t/open311/getservicerequestupdates.t
index 809fd3a19..6ed1d44fd 100644
--- a/t/open311/getservicerequestupdates.t
+++ b/t/open311/getservicerequestupdates.t
@@ -24,6 +24,7 @@ my $user = FixMyStreet::DB->resultset('User')->find_or_create(
my %bodies = (
2237 => FixMyStreet::DB->resultset("Body")->create({ name => 'Oxfordshire' }),
2494 => FixMyStreet::DB->resultset("Body")->create({ name => 'Bexley' }),
+ 2636 => FixMyStreet::DB->resultset("Body")->create({ name => 'Isle of Wight' }),
2482 => FixMyStreet::DB->resultset("Body")->create({
name => 'Bromley',
send_method => 'Open311',
@@ -36,6 +37,7 @@ my %bodies = (
);
$bodies{2237}->body_areas->create({ area_id => 2237 });
$bodies{2494}->body_areas->create({ area_id => 2494 });
+$bodies{2636}->body_areas->create({ area_id => 2636 });
my $response_template = $bodies{2482}->response_templates->create({
title => "investigating template",
@@ -529,29 +531,33 @@ for my $test (
};
}
-subtest 'Marking report as fixed closes it for updates (Bexley)' => sub {
- my $local_requests_xml = setup_xml($problemB->external_id, $problemB->id, 'CLOSED');
- my $o = Open311->new( jurisdiction => 'mysociety', endpoint => 'http://example.com', test_mode => 1, test_get_returns => { 'servicerequestupdates.xml' => $local_requests_xml } );
+for (
+ { id => 2494, cobrand => 'bexley' },
+ { id => 2636, cobrand => 'isleofwight' }
+) {
+ subtest "Marking report as fixed closes it for updates ($_->{cobrand})" => sub {
+ my $local_requests_xml = setup_xml($problemB->external_id, $problemB->id, 'CLOSED');
+ my $o = Open311->new( jurisdiction => 'mysociety', endpoint => 'http://example.com', test_mode => 1, test_get_returns => { 'servicerequestupdates.xml' => $local_requests_xml } );
- $problemB->update( { bodies_str => $bodies{2494}->id } );
+ $problemB->update( { bodies_str => $bodies{$_->{id}}->id } );
- my $update = Open311::GetServiceRequestUpdates->new(
- system_user => $user,
- current_open311 => $o,
- current_body => $bodies{2494},
- current_cobrand => $bodies{2494}->get_cobrand_handler,
- );
- FixMyStreet::override_config {
- ALLOWED_COBRANDS => 'bexley',
- }, sub {
- $update->process_body;
- };
+ my $update = Open311::GetServiceRequestUpdates->new(
+ system_user => $user,
+ current_open311 => $o,
+ current_body => $bodies{$_->{id}},
+ );
+ FixMyStreet::override_config {
+ ALLOWED_COBRANDS => $_->{cobrand},
+ }, sub {
+ $update->process_body;
+ };
- $problemB->discard_changes;
- is $problemB->comments->count, 1, 'comment count';
- is $problemB->get_extra_metadata('closed_updates'), 1;
- $problemB->comments->delete;
-};
+ $problemB->discard_changes;
+ is $problemB->comments->count, 1, 'comment count';
+ is $problemB->get_extra_metadata('closed_updates'), 1;
+ $problemB->comments->delete;
+ };
+}
subtest 'Update with media_url includes image in update' => sub {
my $UPLOAD_DIR = tempdir( CLEANUP => 1 );