aboutsummaryrefslogtreecommitdiffstats
path: root/t/app/controller/admin
diff options
context:
space:
mode:
Diffstat (limited to 't/app/controller/admin')
-rw-r--r--t/app/controller/admin/bodies.t39
-rw-r--r--t/app/controller/admin/report_edit.t125
-rw-r--r--t/app/controller/admin/stats.t26
-rw-r--r--t/app/controller/admin/templates.t51
4 files changed, 239 insertions, 2 deletions
diff --git a/t/app/controller/admin/bodies.t b/t/app/controller/admin/bodies.t
index 9bdf8fb9a..a485d286d 100644
--- a/t/app/controller/admin/bodies.t
+++ b/t/app/controller/admin/bodies.t
@@ -150,6 +150,45 @@ subtest 'check open311 configuring' => sub {
is $conf->endpoint, 'http://example.org/open311', 'endpoint updated';
is $conf->api_key, 'new api key', 'api key updated';
is $conf->jurisdiction, 'open311', 'jurisdiction configures';
+ ok !$conf->get_extra_metadata('fetch_all_problems'), 'fetch all problems unset';
+
+ $mech->form_number(3);
+ $mech->submit_form_ok(
+ {
+ with_fields => {
+ api_key => 'new api key',
+ endpoint => 'http://example.org/open311',
+ jurisdiction => 'open311',
+ send_comments => 0,
+ send_method => 'Open311',
+ fetch_all_problems => 1,
+ }
+ }
+ );
+
+ $mech->content_contains('Values updated');
+
+ $conf = FixMyStreet::App->model('DB::Body')->find( $body->id );
+ ok $conf->get_extra_metadata('fetch_all_problems'), 'fetch all problems set';
+
+ $mech->form_number(3);
+ $mech->submit_form_ok(
+ {
+ with_fields => {
+ api_key => 'new api key',
+ endpoint => 'http://example.org/open311',
+ jurisdiction => 'open311',
+ send_comments => 0,
+ send_method => 'Open311',
+ fetch_all_problems => 0,
+ }
+ }
+ );
+
+ $mech->content_contains('Values updated');
+
+ $conf = FixMyStreet::App->model('DB::Body')->find( $body->id );
+ ok !$conf->get_extra_metadata('fetch_all_problems'), 'fetch all problems unset';
};
subtest 'check text output' => sub {
diff --git a/t/app/controller/admin/report_edit.t b/t/app/controller/admin/report_edit.t
index a8a0bd143..5e3e6c315 100644
--- a/t/app/controller/admin/report_edit.t
+++ b/t/app/controller/admin/report_edit.t
@@ -79,6 +79,7 @@ foreach my $test (
anonymous => 0,
flagged => undef,
non_public => undef,
+ closed_updates => undef,
},
changes => { title => 'Edited Report', },
log_entries => [qw/edit/],
@@ -95,6 +96,7 @@ foreach my $test (
anonymous => 0,
flagged => undef,
non_public => undef,
+ closed_updates => undef,
},
changes => { detail => 'Edited Detail', },
log_entries => [qw/edit edit/],
@@ -111,6 +113,7 @@ foreach my $test (
anonymous => 0,
flagged => undef,
non_public => undef,
+ closed_updates => undef,
},
changes => { name => 'Edited User', },
log_entries => [qw/edit edit edit/],
@@ -128,6 +131,7 @@ foreach my $test (
anonymous => 0,
flagged => undef,
non_public => undef,
+ closed_updates => undef,
},
changes => {
flagged => 'on',
@@ -147,6 +151,7 @@ foreach my $test (
anonymous => 0,
flagged => 'on',
non_public => undef,
+ closed_updates => undef,
},
changes => { username => $user2->email, },
log_entries => [qw/edit edit edit edit edit/],
@@ -164,6 +169,7 @@ foreach my $test (
anonymous => 0,
flagged => 'on',
non_public => undef,
+ closed_updates => undef,
},
expect_comment => 1,
changes => { state => 'unconfirmed' },
@@ -181,6 +187,7 @@ foreach my $test (
anonymous => 0,
flagged => 'on',
non_public => undef,
+ closed_updates => undef,
},
expect_comment => 1,
changes => { state => 'confirmed' },
@@ -198,6 +205,7 @@ foreach my $test (
anonymous => 0,
flagged => 'on',
non_public => undef,
+ closed_updates => undef,
},
expect_comment => 1,
changes => { state => 'fixed' },
@@ -216,6 +224,7 @@ foreach my $test (
anonymous => 0,
flagged => 'on',
non_public => undef,
+ closed_updates => undef,
},
expect_comment => 1,
changes => { state => 'hidden' },
@@ -235,6 +244,7 @@ foreach my $test (
anonymous => 0,
flagged => 'on',
non_public => undef,
+ closed_updates => undef,
},
expect_comment => 1,
changes => {
@@ -257,6 +267,7 @@ foreach my $test (
anonymous => 1,
flagged => 'on',
non_public => undef,
+ closed_updates => undef,
},
changes => {},
log_entries => [
@@ -275,6 +286,7 @@ foreach my $test (
anonymous => 1,
flagged => 'on',
non_public => undef,
+ closed_updates => undef,
},
changes => {
non_public => 'on',
@@ -285,6 +297,24 @@ foreach my $test (
resend => 0,
},
{
+ description => 'close to updates',
+ fields => {
+ title => 'Edited Report',
+ detail => 'Edited Detail',
+ state => 'confirmed',
+ name => 'Edited User',
+ username => $user2->email,
+ anonymous => 1,
+ flagged => 'on',
+ non_public => 'on',
+ closed_updates => undef,
+ },
+ changes => { closed_updates => 'on' },
+ log_entries => [
+ qw/edit edit resend edit state_change edit state_change edit state_change edit state_change edit state_change edit edit edit edit edit/
+ ],
+ },
+ {
description => 'change state to investigating as body superuser',
fields => {
title => 'Edited Report',
@@ -295,12 +325,13 @@ foreach my $test (
anonymous => 1,
flagged => 'on',
non_public => 'on',
+ closed_updates => undef,
},
expect_comment => 1,
user_body => $oxfordshire,
changes => { state => 'investigating' },
log_entries => [
- qw/edit state_change edit resend edit state_change edit state_change edit state_change edit state_change edit state_change edit edit edit edit edit/
+ qw/edit state_change edit edit resend edit state_change edit state_change edit state_change edit state_change edit state_change edit edit edit edit edit/
],
resend => 0,
},
@@ -315,13 +346,14 @@ foreach my $test (
anonymous => 1,
flagged => 'on',
non_public => 'on',
+ closed_updates => undef,
},
expect_comment => 1,
expected_text => '*Category changed from ‘Other’ to ‘Potholes’*',
user_body => $oxfordshire,
changes => { state => 'in progress', category => 'Potholes' },
log_entries => [
- qw/edit state_change edit state_change edit resend edit state_change edit state_change edit state_change edit state_change edit state_change edit edit edit edit edit/
+ qw/edit state_change edit state_change edit edit resend edit state_change edit state_change edit state_change edit state_change edit state_change edit edit edit edit edit/
],
resend => 0,
},
@@ -364,9 +396,22 @@ foreach my $test (
$mech->content_lacks( 'type="submit" name="resend"', 'no resend button' );
}
+ if ($report->state eq 'fixed') {
+ $mech->content_contains('pin-green');
+ }
+
$test->{changes}->{flagged} = 1 if $test->{changes}->{flagged};
$test->{changes}->{non_public} = 1 if $test->{changes}->{non_public};
+ if ($test->{changes}->{closed_updates}) {
+ is $report->get_extra_metadata('closed_updates'), 1, "closed_updates updated";
+ $mech->get_ok("/report/$report_id");
+ $mech->content_lacks('Provide an update');
+ $report->unset_extra_metadata('closed_updates');
+ $report->update;
+ delete $test->{changes}->{closed_updates};
+ }
+
is $report->$_, $test->{changes}->{$_}, "$_ updated" for grep { $_ ne 'username' } keys %{ $test->{changes} };
if ( $test->{user} ) {
@@ -447,6 +492,7 @@ subtest 'change email to new user' => sub {
anonymous => 1,
flagged => 'on',
non_public => 'on',
+ closed_updates => undef,
external_id => '13',
external_body => '',
external_team => '',
@@ -553,4 +599,79 @@ subtest "Test setting a report from unconfirmed to something else doesn't cause
$mech->get_ok("/report/$report_id");
};
+subtest "Test display of report extra data" => sub {
+ $mech->get_ok("/admin/report_edit/$report_id");
+ $mech->content_contains('Extra data: No');
+ $report->set_extra_metadata('extra_field', 'this is extra data');
+ $report->update;
+ $mech->get_ok("/admin/report_edit/$report_id");
+ $mech->content_contains('extra_field</strong>: this is extra data');
+};
+
+my $report2 = FixMyStreet::App->model('DB::Problem')->find_or_create(
+ {
+ postcode => 'SW1A 1AA',
+ bodies_str => '2504',
+ areas => ',105255,11806,11828,2247,2504,',
+ category => 'Other',
+ title => 'Report to Duplicate Edit',
+ detail => 'Detail for Duplicate Report to Edit',
+ used_map => 't',
+ name => 'Test User',
+ anonymous => 'f',
+ external_id => '13',
+ state => 'confirmed',
+ confirmed => $dt->ymd . ' ' . $dt->hms,
+ lang => 'en-gb',
+ service => '',
+ cobrand => '',
+ cobrand_data => '',
+ send_questionnaire => 't',
+ latitude => '51.5016605453401',
+ longitude => '-0.142497580865087',
+ user_id => $user->id,
+ whensent => $dt->ymd . ' ' . $dt->hms,
+ }
+);
+
+subtest "Test display of report duplicates extra data" => sub {
+ $report->update( { extra => undef } );
+ $mech->get_ok("/admin/report_edit/$report_id");
+ $mech->content_contains('Extra data: No');
+
+ $report2->set_duplicate_of($report_id);
+ $report2->update;
+
+ $mech->get_ok("/admin/report_edit/$report_id");
+ $mech->content_contains('Duplicates</strong>: ' . $report2->id);
+};
+
+subtest "Test display of fields extra data" => sub {
+ $report->unset_extra_metadata( 'duplicates' );
+ $report->update;
+ $mech->get_ok("/admin/report_edit/$report_id");
+ $mech->content_contains('Extra data: No');
+
+ $report->push_extra_fields( {
+ name => 'report_url',
+ value => 'http://example.com',
+ });
+ $report->update;
+
+ $report->discard_changes;
+
+ $mech->get_ok("/admin/report_edit/$report_id");
+ $mech->content_contains('report_url</strong>: http://example.com');
+
+ $report->set_extra_fields( {
+ description => 'Report URL',
+ name => 'report_url',
+ value => 'http://example.com',
+ });
+ $report->update;
+
+ $mech->get_ok("/admin/report_edit/$report_id");
+ $mech->content_contains('Report URL (report_url)</strong>: http://example.com');
+};
+
done_testing();
diff --git a/t/app/controller/admin/stats.t b/t/app/controller/admin/stats.t
index dae51d31f..ce6f8466c 100644
--- a/t/app/controller/admin/stats.t
+++ b/t/app/controller/admin/stats.t
@@ -9,4 +9,30 @@ subtest "smoke view some stats pages" => sub {
$mech->get_ok('/admin/stats/questionnaire');
};
+subtest "test refused stats page works" => sub {
+ my $body1 = $mech->create_body_ok(2651, 'Edinburgh Council');
+ my $body2 = $mech->create_body_ok(2237, 'Oxfordshire Council', { send_method => 'Refused' });
+ my $body3 = $mech->create_body_ok(2243, 'Warwickshire Council', { can_be_devolved => 1 });
+ $mech->create_contact_ok(body_id => $body1->id, category => 'Street lighting', email => 'REFUSED');
+ $mech->create_contact_ok(body_id => $body1->id, category => 'Potholes', email => 'potholes@example.org');
+ $mech->create_contact_ok(body_id => $body2->id, category => 'Potholes', email => 'potholes@example.org');
+ $mech->create_contact_ok(body_id => $body3->id, category => 'Street lighting', email => 'lights@example.org');
+ $mech->create_contact_ok(body_id => $body3->id, category => 'Potholes', email => 'potholes@example.org', send_method => 'Refused');
+
+ FixMyStreet::override_config {
+ ALLOWED_COBRANDS => [ { fixmystreet => '.' } ],
+ }, sub {
+ $mech->get_ok('/admin/stats/refused');
+ };
+ $mech->content =~ /class="content"(.*)class="nav-wrapper/s;
+ my @lines = split /<li>/, $1;
+ is @lines, 7;
+ like $lines[1], qr/Edinburgh/;
+ like $lines[2], qr/Street lighting/;
+ like $lines[3], qr/Oxfordshire/;
+ like $lines[4], qr/ALL/;
+ like $lines[5], qr/Warwickshire/;
+ like $lines[6], qr/Potholes/;
+};
+
done_testing();
diff --git a/t/app/controller/admin/templates.t b/t/app/controller/admin/templates.t
index 179a1afcb..0d4430cad 100644
--- a/t/app/controller/admin/templates.t
+++ b/t/app/controller/admin/templates.t
@@ -180,4 +180,55 @@ subtest "all-category auto-response templates that duplicate a single category c
is $oxfordshire->response_templates->count, 1, "Duplicate response template wasn't added";
};
+subtest "auto-response templates that duplicate external_status_code can't be added" => sub {
+ $mech->delete_response_template($_) for $oxfordshire->response_templates;
+ my $template = $oxfordshire->response_templates->create({
+ title => "Report fixed - potholes",
+ text => "Thank you for your report. This problem has been fixed.",
+ auto_response => 1,
+ external_status_code => '100',
+ });
+ $template->contact_response_templates->find_or_create({
+ contact_id => $oxfordshirecontact->id,
+ });
+ is $oxfordshire->response_templates->count, 1, "Initial response template was created";
+
+
+ $mech->log_in_ok( $superuser->email );
+ $mech->get_ok( "/admin/templates/" . $oxfordshire->id . "/new" );
+
+ my $fields = {
+ title => "Report marked fixed - all cats",
+ text => "Thank you for your report. This problem has been fixed.",
+ auto_response => 'on',
+ external_status_code => '100',
+ };
+ $mech->submit_form_ok( { with_fields => $fields } );
+ is $mech->uri->path, '/admin/templates/' . $oxfordshire->id . '/new', 'not redirected';
+ $mech->content_contains( 'Please correct the errors below' );
+ $mech->content_contains( 'There is already an auto-response template for this category/state.' );
+
+ is $oxfordshire->response_templates->count, 1, "Duplicate response template wasn't added";
+};
+
+subtest "templates that set state and external_status_code can't be added" => sub {
+ $mech->delete_response_template($_) for $oxfordshire->response_templates;
+ $mech->log_in_ok( $superuser->email );
+ $mech->get_ok( "/admin/templates/" . $oxfordshire->id . "/new" );
+
+ my $fields = {
+ title => "Report marked fixed - all cats",
+ text => "Thank you for your report. This problem has been fixed.",
+ auto_response => 'on',
+ state => 'fixed - council',
+ external_status_code => '100',
+ };
+ $mech->submit_form_ok( { with_fields => $fields } );
+ is $mech->uri->path, '/admin/templates/' . $oxfordshire->id . '/new', 'not redirected';
+ $mech->content_contains( 'Please correct the errors below' );
+ $mech->content_contains( 'State and external status code cannot be used simultaneously.' );
+
+ is $oxfordshire->response_templates->count, 0, "Invalid response template wasn't added";
+};
+
done_testing();