aboutsummaryrefslogtreecommitdiffstats
path: root/t/app/controller/report_inspect.t
diff options
context:
space:
mode:
Diffstat (limited to 't/app/controller/report_inspect.t')
-rw-r--r--t/app/controller/report_inspect.t289
1 files changed, 283 insertions, 6 deletions
diff --git a/t/app/controller/report_inspect.t b/t/app/controller/report_inspect.t
index 5bbbdff79..239cc408b 100644
--- a/t/app/controller/report_inspect.t
+++ b/t/app/controller/report_inspect.t
@@ -11,10 +11,18 @@ my $rp = FixMyStreet::DB->resultset("ResponsePriority")->create({
body => $oxon,
name => 'High Priority',
});
+my $rp2 = FixMyStreet::DB->resultset("ResponsePriority")->create({
+ body => $oxon,
+ name => 'Low Priority',
+});
FixMyStreet::DB->resultset("ContactResponsePriority")->create({
contact => $contact,
response_priority => $rp,
});
+FixMyStreet::DB->resultset("ContactResponsePriority")->create({
+ contact => $contact3,
+ response_priority => $rp2,
+});
my $wodc = $mech->create_body_ok(2420, 'West Oxfordshire District Council');
$mech->create_contact_ok( body_id => $wodc->id, category => 'Horses', email => 'horses@example.net' );
@@ -116,7 +124,6 @@ FixMyStreet::override_config {
$mech->content_contains('Invalid location');
$mech->submit_form_ok({ button => 'save', with_fields => { latitude => 51.754926, longitude => -1.256179, include_update => undef } });
$mech->content_lacks('Invalid location');
- $user->user_body_permissions->search({ body_id => $oxon->id, permission_type => 'planned_reports' })->delete;
};
subtest "test duplicate reports are shown" => sub {
@@ -140,6 +147,71 @@ FixMyStreet::override_config {
$report2->update;
};
+ subtest "can mark a report as duplicate without supplying a duplicate and a public update" => sub {
+ my $old_state = $report->state;
+ $report->comments->delete_all;
+
+ $mech->get_ok("/report/$report_id");
+ $mech->submit_form_ok({ button => 'save', with_fields => { state => 'Duplicate', include_update => "0" } });
+
+ $mech->content_contains('provide a duplicate ID', "error message about missing duplicate id");
+ $report->discard_changes;
+ $report2->discard_changes;
+
+ is $report->state, $old_state, 'report not marked as duplicate';
+ is $report->comments->search({ problem_state => 'duplicate' })->count, 0, 'no update marking report as duplicate was left';
+
+ is $report->get_extra_metadata('duplicate_of'), undef;
+
+ $mech->submit_form_ok({ button => 'save', with_fields => { state => 'Duplicate', public_update => 'This is a duplicate', include_update => "1" } });
+ $mech->content_lacks('provide a duplicate ID', "no error message about missing duplicate id");
+ $report->discard_changes;
+ $report2->discard_changes;
+
+ is $report->state, 'duplicate', 'report marked as duplicate';
+ is $report->comments->search({ problem_state => 'duplicate' })->count, 1, 'update marking report as duplicate was left';
+ is $report->get_extra_metadata('duplicate_of'), undef;
+ is_deeply $report2->get_extra_metadata('duplicates'), undef;
+
+ $report->update({ state => $old_state });
+ };
+
+ subtest "can mark a report as duplicate without supplying a public update and a duplicate id" => sub {
+ my $old_state = $report->state;
+ $report->comments->delete_all;
+
+ $mech->get_ok("/report/$report_id");
+ $mech->submit_form_ok({ button => 'save', with_fields => { state => 'Duplicate', include_update => "0" } });
+
+ $mech->content_contains('provide a duplicate ID', "error message about missing duplicate id");
+ $report->discard_changes;
+ $report2->discard_changes;
+
+ is $report->state, $old_state, 'report not marked as duplicate';
+ is $report->comments->search({ problem_state => 'duplicate' })->count, 0, 'no update marking report as duplicate was left';
+
+ is $report->get_extra_metadata('duplicate_of'), undef;
+
+ $mech->submit_form_ok({ button => 'save', with_fields => { state => 'Duplicate', duplicate_of => $report2->id, include_update => "0" } });
+ $mech->content_lacks('provide a duplicate ID', "no error message about missing duplicate id");
+ $report->discard_changes;
+ $report2->discard_changes;
+
+ is $report->state, 'duplicate', 'report marked as duplicate';
+ is $report->comments->search({ problem_state => 'duplicate' })->count, 1, 'update marking report as duplicate was left';
+ is $report->get_extra_metadata('duplicate_of'), $report2->id;
+ is_deeply $report2->get_extra_metadata('duplicates'), [ $report->id ];
+
+ # Check that duplicate does not include shortlist add button (no form in form)
+ $mech->get_ok("/report/$report_id");
+ $mech->content_lacks('item-list__item__shortlist-add');
+
+ $report->set_extra_metadata('duplicate_of', undef);
+ $report->update({ state => $old_state });
+ $report2->set_extra_metadata('duplicates', undef);
+ $report2->update;
+ };
+
subtest "marking a report as a duplicate with update correctly sets update status" => sub {
my $old_state = $report->state;
$report->comments->delete_all;
@@ -172,6 +244,9 @@ FixMyStreet::override_config {
my $old_state = $report->state;
$report->comments->delete_all;
+ $mech->get_ok("/report/$report2_id/nearby.json");
+ $mech->content_lacks('Add to shortlist');
+
$mech->get_ok("/report/$report_id");
my $update_text = "This text was entered as an update by the user.";
$mech->submit_form_ok({ button => 'save', with_fields => {
@@ -184,6 +259,7 @@ FixMyStreet::override_config {
is $report->state, 'duplicate', 'report marked as duplicate';
is $report->comments->search({ problem_state => 'duplicate' })->count, 1, 'update marked report as duplicate';
+ $mech->get_ok("/report/$report_id"); # Get again as planned_reports permission means redirect to referer...
$mech->content_contains($update_text);
$mech->content_lacks("Thank you for your report. This problem has already been reported.");
@@ -191,7 +267,6 @@ FixMyStreet::override_config {
};
subtest "post-inspect redirect is to the right place if URL set" => sub {
- $user->user_body_permissions->create({ body => $oxon, permission_type => 'planned_reports' });
$mech->get_ok("/report/$report_id");
my $update_text = "This text was entered as an update by the user.";
$mech->submit_form_ok({ button => 'save', with_fields => {
@@ -202,11 +277,9 @@ FixMyStreet::override_config {
is $mech->res->code, 200, "got 200";
is $mech->res->previous->code, 302, "got 302 for redirect";
is $mech->uri->path, '/', 'redirected to front page';
- $user->user_body_permissions->search({ body_id => $oxon->id, permission_type => 'planned_reports' })->delete;
};
subtest "post-inspect redirect is to the right place if URL not set" => sub {
- $user->user_body_permissions->create({ body => $oxon, permission_type => 'planned_reports' });
$user->set_extra_metadata(categories => [ $contact->id ]);
$user->update;
$mech->get_ok("/report/$report_id");
@@ -223,7 +296,6 @@ FixMyStreet::override_config {
is $params{lat}, $report->latitude, "latitude param is correct";
is $params{lon}, $report->longitude, "longitude param is correct";
is $params{filter_category}, $contact->category, "categories param is correct";
- $user->user_body_permissions->search({ body_id => $oxon->id, permission_type => 'planned_reports' })->delete;
};
subtest "default response priorities display correctly" => sub {
@@ -254,15 +326,165 @@ FixMyStreet::override_config {
$mech->submit_form_ok({
button => 'save',
with_fields => {
- $test->{priority} ? (priority => 1) : (),
+ $test->{priority} ? (priority => $rp->id) : (),
$test->{category} ? (category => 'Cows') : (),
$test->{detailed} ? (detailed_information => 'Highland ones') : (),
}
});
};
}
+
+ subtest "check priority not set for category with no priorities" => sub {
+ $report->discard_changes;
+ $report->update({ category => 'Cows', response_priority_id => undef });
+ $report->discard_changes;
+ is $report->response_priority, undef, 'response priority not set';
+ $user->user_body_permissions->delete;
+ $user->user_body_permissions->create({ body => $oxon, permission_type => 'report_edit_category' });
+ $user->user_body_permissions->create({ body => $oxon, permission_type => 'report_edit_priority' });
+ $mech->get_ok("/report/$report_id");
+ $mech->submit_form_ok({
+ button => 'save',
+ with_fields => {
+ priority => $rp->id,
+ category => 'Sheep',
+ }
+ });
+
+ $report->discard_changes;
+ is $report->response_priority, undef, 'response priority not set';
+ };
+
+ subtest "check can set priority for category when changing from category with no priorities" => sub {
+ $report->discard_changes;
+ $report->update({ category => 'Sheep', response_priority_id => undef });
+ $report->discard_changes;
+ is $report->response_priority, undef, 'response priority not set';
+ $user->user_body_permissions->delete;
+ $user->user_body_permissions->create({ body => $oxon, permission_type => 'report_edit_category' });
+ $user->user_body_permissions->create({ body => $oxon, permission_type => 'report_edit_priority' });
+ $mech->get_ok("/report/$report_id");
+ $mech->submit_form_ok({
+ button => 'save',
+ with_fields => {
+ priority => $rp->id,
+ category => 'Cows',
+ }
+ });
+
+ $report->discard_changes;
+ is $report->response_priority->id, $rp->id, 'response priority set';
+ };
+
+ subtest "check can't set priority that isn't for a category" => sub {
+ $report->discard_changes;
+ $report->update({ category => 'Cows', response_priority_id => $rp->id });
+ $report->discard_changes;
+ is $report->response_priority->id, $rp->id, 'response priority set';
+ $user->user_body_permissions->delete;
+ $user->user_body_permissions->create({ body => $oxon, permission_type => 'report_edit_category' });
+ $user->user_body_permissions->create({ body => $oxon, permission_type => 'report_edit_priority' });
+ $mech->get_ok("/report/$report_id");
+ $mech->submit_form_ok({
+ button => 'save',
+ with_fields => {
+ priority => $rp2->id,
+ }
+ });
+
+ $report->discard_changes;
+ is $report->response_priority, undef, 'response priority set';
+ };
+
+ subtest "check nearest address display" => sub {
+ $mech->get_ok("/report/$report_id");
+ $mech->content_lacks('Nearest calculated address', 'No address displayed');
+
+ my $data = {
+ resourceSets => [ {
+ resources => [ {
+ address => {
+ addressLine => 'Constitution Hill',
+ locality => 'London',
+ }
+ } ],
+ } ],
+ };
+ $report->geocode($data);
+ $report->update;
+ $mech->get_ok("/report/$report_id");
+ $mech->content_lacks('Nearest calculated address', 'No address displayed');
+
+ $data = {
+ resourceSets => [ {
+ resources => [ {
+ name => 'Constitution Hill, London, SW1A',
+ address => {
+ addressLine => 'Constitution Hill',
+ locality => 'London',
+ }
+ } ],
+ } ],
+ };
+ $report->geocode($data);
+ $report->update;
+ $mech->get_ok("/report/$report_id");
+ $mech->content_contains('Nearest calculated address', 'Address displayed');
+ $mech->content_contains('Constitution Hill, London, SW1A', 'Correct address displayed');
+ }
};
+foreach my $test (
+ { cobrand => 'fixmystreet', limited => 0, desc => 'detailed_information has no max length' },
+ { cobrand => 'oxfordshire', limited => 1, desc => 'detailed_information has max length' },
+) {
+
+ FixMyStreet::override_config {
+ ALLOWED_COBRANDS => $test->{cobrand},
+ }, sub {
+ subtest $test->{desc} => sub {
+ $user->user_body_permissions->delete;
+ $user->user_body_permissions->create({ body => $oxon, permission_type => 'report_inspect' });
+ $mech->get_ok("/report/$report_id");
+ $mech->submit_form_ok({
+ button => 'save',
+ with_fields => {
+ include_update => 0,
+ detailed_information => 'XXX164XXX' . 'x' x (164-9)
+ }
+ });
+
+ $report->discard_changes;
+ like $report->get_extra_metadata('detailed_information'), qr/XXX164XXX/, 'detailed information saved';
+ $mech->content_lacks('limited to 164 characters', "164 charcters of detailed information ok");
+ $mech->content_contains('XXX164XXX', "Detailed information field contains submitted text");
+
+ $mech->submit_form_ok({
+ button => 'save',
+ with_fields => {
+ include_update => 0,
+ detailed_information => 'XXX165XXX' . 'x' x (164-8)
+ }
+ });
+ if ($test->{limited}) {
+ $mech->content_contains('164 characters maximum');
+ $mech->content_contains('limited to 164 characters', "165 charcters of detailed information not ok");
+ $mech->content_contains('XXX165XXX', "Detailed information field contains submitted text");
+
+ $report->discard_changes;
+ like $report->get_extra_metadata('detailed_information'), qr/XXX164XXX/, 'detailed information not saved';
+ } else {
+ $mech->content_lacks(' characters maximum');
+ $mech->content_lacks('limited to 164 characters', "165 charcters of detailed information ok");
+ $mech->content_contains('XXX165XXX', "Detailed information field contains submitted text");
+
+ $report->discard_changes;
+ like $report->get_extra_metadata('detailed_information'), qr/XXX165XXX/, 'detailed information saved';
+ }
+ };
+ };
+}
+
FixMyStreet::override_config {
ALLOWED_COBRANDS => 'oxfordshire',
}, sub {
@@ -320,6 +542,61 @@ FixMyStreet::override_config {
};
FixMyStreet::override_config {
+ MAPIT_URL => 'http://mapit.uk/',
+ ALLOWED_COBRANDS => 'fixmystreet',
+}, sub {
+ subtest "test category not updated if fail to include public update" => sub {
+ $mech->get_ok("/report/$report_id");
+ $mech->submit_form(button => 'save', with_fields => { category => 'Badgers' });
+
+ $report->discard_changes;
+ is $report->category, "Cows", "Report in correct category";
+ $mech->content_contains('Badgers" selected', 'Changed category still selected');
+ };
+
+ subtest "test invalid form maintains Category and priority" => sub {
+ $mech->get_ok("/report/$report_id");
+ my $expected_fields = {
+ state => 'action scheduled',
+ category => 'Cows',
+ public_update => '',
+ priority => $rp->id,
+ include_update => '1',
+ detailed_information => 'XXX164XXXxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx',
+ defect_type => '',
+ traffic_information => ''
+ };
+ my $values = $mech->visible_form_values('report_inspect_form');
+ is_deeply $values, $expected_fields, 'correct form fields present';
+
+ $mech->submit_form(button => 'save', with_fields => { category => 'Badgers', priority => $rp2->id });
+
+ $expected_fields->{category} = 'Badgers';
+ $expected_fields->{priority} = $rp2->id;
+
+ my $new_values = $mech->visible_form_values('report_inspect_form');
+ is_deeply $new_values, $expected_fields, 'correct form fields present';
+ };
+
+ subtest "test changing category and leaving an update only creates one comment" => sub {
+ $report->comments->delete;
+ $mech->get_ok("/report/$report_id");
+ $mech->submit_form(
+ button => 'save',
+ with_fields => {
+ category => 'Badgers',
+ include_update => 1,
+ public_update => 'This is a public update',
+ });
+
+ $report->discard_changes;
+ is $report->category, "Badgers", "Report in correct category";
+ is $report->comments->count, 1, "Only leaves one update";
+ like $report->comments->first->text, qr/Category changed.*Badgers/, 'update text included category change';
+ };
+};
+
+FixMyStreet::override_config {
ALLOWED_COBRANDS => [ 'oxfordshire', 'fixmystreet' ],
BASE_URL => 'http://fixmystreet.site',
}, sub {