diff options
author | Marius Halden <marius.h@lden.org> | 2021-10-07 13:32:40 +0200 |
---|---|---|
committer | Marius Halden <marius.h@lden.org> | 2021-10-07 13:32:40 +0200 |
commit | 09dacfc6b8bf62addeee16c20b1d90c2a256da96 (patch) | |
tree | 7caa2bf9e92227ab74448f9b746dd28bbcb81b2a /t/app/controller/report_inspect.t | |
parent | 585e57484f9c6332668bf1ac0a6a3b39dbe32223 (diff) | |
parent | cea89fb87a96943708a1db0f646492fbfaaf000f (diff) |
Merge tag 'v3.1' into fiksgatami-devfiksgatami-dev
Diffstat (limited to 't/app/controller/report_inspect.t')
-rw-r--r-- | t/app/controller/report_inspect.t | 178 |
1 files changed, 146 insertions, 32 deletions
diff --git a/t/app/controller/report_inspect.t b/t/app/controller/report_inspect.t index 8deb2667e..3f267a086 100644 --- a/t/app/controller/report_inspect.t +++ b/t/app/controller/report_inspect.t @@ -1,5 +1,6 @@ use FixMyStreet::TestMech; use Test::MockModule; +use Path::Class; my $mech = FixMyStreet::TestMech->new; @@ -7,7 +8,7 @@ my $brum = $mech->create_body_ok(2514, 'Birmingham City Council'); my $oxon = $mech->create_body_ok(2237, 'Oxfordshire County Council', { can_be_devolved => 1 } ); my $contact = $mech->create_contact_ok( body_id => $oxon->id, category => 'Cows', email => 'cows@example.net' ); my $contact2 = $mech->create_contact_ok( body_id => $oxon->id, category => 'Sheep', email => 'SHEEP', send_method => 'Open311' ); -my $contact3 = $mech->create_contact_ok( body_id => $oxon->id, category => 'Badgers', email => 'badgers@example.net' ); +my $contact3 = $mech->create_contact_ok( body_id => $oxon->id, category => 'Badgers & Voles', email => 'badgers@example.net' ); my $rp = FixMyStreet::DB->resultset("ResponsePriority")->create({ body => $oxon, name => 'High Priority', @@ -16,6 +17,11 @@ my $rp2 = FixMyStreet::DB->resultset("ResponsePriority")->create({ body => $oxon, name => 'Low Priority', }); +my $rp3 = FixMyStreet::DB->resultset("ResponsePriority")->create({ + body => $oxon, + name => 'Deleted Priority', + deleted => 1, +}); FixMyStreet::DB->resultset("ContactResponsePriority")->create({ contact => $contact, response_priority => $rp, @@ -42,6 +48,9 @@ my $user = $mech->log_in_ok('body@example.com'); $user->set_extra_metadata('categories', [ $contact->id ]); $user->update( { from_body => $oxon } ); +my $sample_file = file(__FILE__)->parent->file("sample.jpg")->stringify; +ok -e $sample_file, "sample file $sample_file exists"; + FixMyStreet::override_config { MAPIT_URL => 'http://mapit.uk/', ALLOWED_COBRANDS => 'fixmystreet', @@ -51,15 +60,15 @@ FixMyStreet::override_config { $mech->content_lacks('Save changes'); $mech->content_lacks('Private'); $mech->content_lacks('Priority'); - $mech->content_lacks('Traffic management'); + $mech->content_lacks('Change asset'); $mech->content_lacks('/admin/report_edit/'.$report_id.'">admin</a>)'); $user->user_body_permissions->create({ body => $oxon, permission_type => 'report_mark_private' }); $mech->get_ok("/report/$report_id"); $mech->content_contains('Private'); $mech->content_contains('Save changes'); + $mech->content_lacks('Change asset'); $mech->content_lacks('Priority'); - $mech->content_lacks('Traffic management'); $mech->content_lacks('/admin/report_edit/'.$report_id.'">admin</a>)'); $user->user_body_permissions->create({ body => $oxon, permission_type => 'report_edit_priority' }); @@ -67,7 +76,7 @@ FixMyStreet::override_config { $mech->content_contains('Private'); $mech->content_contains('Save changes'); $mech->content_contains('Priority'); - $mech->content_lacks('Traffic management'); + $mech->content_lacks('Change asset'); $mech->content_lacks('/admin/report_edit/'.$report_id.'">admin</a>)'); $user->user_body_permissions->create({ body => $oxon, permission_type => 'report_inspect' }); @@ -75,7 +84,7 @@ FixMyStreet::override_config { $mech->content_contains('Save changes'); $mech->content_contains('Private'); $mech->content_contains('Priority'); - $mech->content_contains('Traffic management'); + $mech->content_contains('Change asset'); $mech->content_lacks('/admin/report_edit/'.$report_id.'">admin</a>)'); }; @@ -197,14 +206,14 @@ FixMyStreet::override_config { $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 => { traffic_information => 'Yes', state => 'Action scheduled', include_update => undef } }); + $mech->submit_form_ok({ button => 'save', with_fields => { detailed_information => 'Info', state => 'Action scheduled', include_update => undef } }); $report->discard_changes; my $alert = FixMyStreet::DB->resultset('Alert')->find( { user => $user, alert_type => 'new_updates', confirmed => 1, } ); is $report->state, 'action scheduled', 'report state changed'; - is $report->get_extra_metadata('traffic_information'), 'Yes', 'report data changed'; + is $report->get_extra_metadata('detailed_information'), 'Info', 'report data changed'; ok defined( $alert ) , 'sign up for alerts'; }; @@ -233,7 +242,7 @@ FixMyStreet::override_config { $user->update; }; - subtest "test update is required when instructing" => sub { + subtest "test public update is required if include_update is checked" => sub { $report->update; $report->comments->delete_all; $mech->get_ok("/report/$report_id"); @@ -439,6 +448,7 @@ FixMyStreet::override_config { subtest "default response priorities display correctly" => sub { $mech->get_ok("/report/$report_id"); $mech->content_contains('Priority</label', 'report priority list present'); + $mech->content_lacks('Deleted Priority'); like $mech->content, qr/<select name="priority" id="problem_priority" class="form-control">[^<]*<option value="" selecte/s, 'blank priority option is selected'; $mech->content_lacks('value="' . $rp->id . '" selected>High', 'non default priority not selected'); @@ -448,6 +458,12 @@ FixMyStreet::override_config { $mech->content_contains('value="' . $rp->id . '" selected>High', 'default priority selected'); }; + subtest "check when report has deleted priority" => sub { + $report->update({ response_priority => $rp3 }); + $mech->get_ok("/report/$report_id"); + $mech->content_contains('value="' . $rp3->id . '" selected>Deleted Priority'); + }; + foreach my $test ( { type => 'report_edit_priority', priority => 1 }, { type => 'report_edit_category', category => 1 }, @@ -589,7 +605,27 @@ FixMyStreet::override_config { $mech->get_ok("/report/$report_id"); $mech->content_contains('Nearest calculated address', 'Address displayed'); $mech->content_contains('Constitution Hill, London, SW1A', 'Correct address displayed'); - } + }; + + subtest "test upload photo with public updates" => sub { + $user->user_body_permissions->delete; + $user->user_body_permissions->create({ body => $oxon, permission_type => 'report_inspect' }); + + $report->state('confirmed'); + $report->update; + $mech->get_ok("/report/$report_id"); + $mech->submit_form_ok({ button => 'save', with_fields => { + public_update => "This is a public update.", include_update => "1", + state => 'action scheduled', + photo1 => [ [ $sample_file, undef, Content_Type => 'image/jpeg' ], 1 ], + } }); + $report->discard_changes; + my $comment = $report->comments(undef, { rows => 1, order_by => { -desc => "id" }})->first; + is $comment->photo, '74e3362283b6ef0c48686fb0e161da4043bbcc97.jpeg', 'photo added to comment'; + $mech->get_ok("/report/$report_id"); + $mech->content_contains("/photo/c/" . $comment->id . ".0.jpeg"); + }; + }; foreach my $test ( @@ -663,15 +699,6 @@ FixMyStreet::override_config { return $perms; }); - subtest "Oxfordshire-specific traffic management options are shown" => sub { - $report->update({ state => 'confirmed' }); - $mech->get_ok("/report/$report_id"); - $mech->submit_form_ok({ button => 'save', with_fields => { traffic_information => 'Signs and Cones', state => 'Action scheduled', include_update => undef } }); - $report->discard_changes; - is $report->state, 'action scheduled', 'report state changed'; - is $report->get_extra_metadata('traffic_information'), 'Signs and Cones', 'report data changed'; - }; - subtest "admin link present on inspect page on cobrand" => sub { my $report_edit_permission = $user->user_body_permissions->create({ body => $oxon, permission_type => 'report_edit' }); @@ -683,19 +710,20 @@ FixMyStreet::override_config { FixMyStreet::override_config { MAPIT_URL => 'http://mapit.uk/', - ALLOWED_COBRANDS => 'fixmystreet', + ALLOWED_COBRANDS => 'oxfordshire', }, 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' }); + $mech->submit_form(button => 'save', with_fields => { category => 'Badgers & Voles' }); $report->discard_changes; is $report->category, "Cows", "Report in correct category"; - $mech->content_contains('Badgers" selected', 'Changed category still selected'); + $mech->content_contains('Badgers & Voles" selected', 'Changed category still selected'); }; subtest "test invalid form maintains Category and priority" => sub { $mech->get_ok("/report/$report_id"); + $mech->content_like(qr/data-priorities='[^']*?Low Priority/); my $expected_fields = { state => 'action scheduled', category => 'Cows', @@ -704,14 +732,16 @@ FixMyStreet::override_config { priority => $rp->id, include_update => '1', detailed_information => 'XXX164XXXxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx', - traffic_information => '' + photo1 => '', + photo2 => '', + photo3 => '', }; 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 }); + $mech->submit_form(button => 'save', with_fields => { category => 'Badgers & Voles', priority => $rp2->id }); - $expected_fields->{category} = 'Badgers'; + $expected_fields->{category} = 'Badgers & Voles'; $expected_fields->{priority} = $rp2->id; my $new_values = $mech->visible_form_values('report_inspect_form'); @@ -724,15 +754,15 @@ FixMyStreet::override_config { $mech->submit_form( button => 'save', with_fields => { - category => 'Badgers', + category => 'Badgers & Voles', include_update => 1, public_update => 'This is a public update', }); $report->discard_changes; - is $report->category, "Badgers", "Report in correct category"; + is $report->category, "Badgers & Voles", "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'; + like $report->comments->first->text, qr/Category changed.*Badgers & Voles/, 'update text included category change'; }; subtest "test non-public changing" => sub { @@ -779,10 +809,10 @@ FixMyStreet::override_config { }); subtest "test report not resent when category changes if send_method doesn't change" => sub { $mech->get_ok("/report/$report3_id"); - $mech->submit_form(button => 'save', with_fields => { category => 'Badgers', include_update => undef, }); + $mech->submit_form(button => 'save', with_fields => { category => 'Badgers & Voles', include_update => undef, }); $report3->discard_changes; - is $report3->category, "Badgers", "Report in correct category"; + is $report3->category, "Badgers & Voles", "Report in correct category"; isnt $report3->whensent, undef, "Report not marked as unsent"; is $report3->bodies_str, $oxon->id, "Reported to OCC"; }; @@ -822,7 +852,91 @@ FixMyStreet::override_config { }; }; +FixMyStreet::override_config { + MAPIT_URL => 'http://mapit.uk/', + ALLOWED_COBRANDS => 'oxfordshire', +}, sub { + subtest 'test relevant staff user display' => sub { + $user->user_body_permissions->create({ body => $oxon, permission_type => 'planned_reports' }); + $user->user_body_permissions->create({ body => $oxon, permission_type => 'moderate' }); + $mech->log_in_ok('body@example.com'); -END { - done_testing(); -} + # First, check user can see staff things on reports 2 and 3 + $mech->get_ok("/report/$report2_id"); + $mech->content_contains('<select class="form-control" name="state" id="state">'); + $mech->content_contains('<div class="inspect-section">'); + $mech->get_ok("/report/$report3_id"); + $mech->content_contains('<select class="form-control" name="state" id="state">'); + $mech->content_contains('<div class="inspect-section">'); + + # User's categories are ["Cows"], which is currently report 2 + # So should be able to see staff things on 2, but no longer on 3 + $user->set_extra_metadata(assigned_categories_only => 1); + $user->update; + $mech->get_ok("/report/$report2_id"); + $mech->content_contains('<select class="form-control" name="state" id="state">'); + $mech->content_contains('<div class="inspect-section">'); + $mech->get_ok("/report/$report3_id"); + $mech->content_lacks('<select class="form-control" name="state" id="state">'); + $mech->content_lacks('<div class="inspect-section">'); + $mech->content_lacks('Moderate this report'); + $mech->content_lacks('shortlist'); + $user->unset_extra_metadata('assigned_categories_only'); + $user->update; + + # Contact 2 is "Sheep", which is currently report 3 + # So again, should be able to see staff things on 2, but no longer on 3 + $contact2->set_extra_metadata(assigned_users_only => 1); + $contact2->update; + $mech->get_ok("/report/$report2_id"); + $mech->content_contains('<select class="form-control" name="state" id="state">'); + $mech->content_contains('<div class="inspect-section">'); + $mech->get_ok("/report/$report3_id"); + $mech->content_lacks('<select class="form-control" name="state" id="state">'); + $mech->content_lacks('<div class="inspect-section">'); + $mech->content_lacks('Moderate this report'); + $mech->content_lacks('shortlist'); + $contact2->unset_extra_metadata('assigned_users_only'); + $contact2->update; + }; + + subtest 'instruct defect' => sub { + $user->user_body_permissions->create({ body => $oxon, permission_type => 'report_instruct' }); + $mech->get_ok("/report/$report2_id"); + $mech->submit_form_ok({ button => 'save', with_fields => { + public_update => "This is a public update.", include_update => "1", + traffic_information => 'Signs and cones', + state => 'action scheduled', raise_defect => 1, + defect_item_category => 'Kerbing', + } }); + $report2->discard_changes; + is $report2->get_extra_metadata('inspected'), 1, 'report marked as inspected'; + $mech->get_ok("/report/$report2_id"); + $mech->content_like(qr/Defect category<\/dt>\s*<dd>Kerbing/); + my $meta = $mech->extract_update_metas; + like $meta->[0], qr/State changed to: Action scheduled/, 'First update mentions action scheduled'; + like $meta->[1], qr/Posted by .*defect raised/, 'Update mentions defect raised'; + my $log_entry = $report2->inspection_log_entry; + is $log_entry->object_id, $report2_id, 'Log entry has correct ID'; + is $log_entry->object_type, 'problem', 'Log entry has correct type'; + is $log_entry->action, 'inspected', 'Log entry has correct action'; + }; + + subtest "test update is required when instructing defect" => sub { + $report2->unset_extra_metadata('inspected'); + $report2->update; + $report2->inspection_log_entry->delete; + $report2->comments->delete_all; + $mech->get_ok("/report/$report2_id"); + $mech->submit_form_ok({ button => 'save', with_fields => { + public_update => "", include_update => "0", + state => 'action scheduled', raise_defect => 1, + } }); + is_deeply $mech->page_errors, [ "Please provide a public update for this report." ], 'errors match'; + $report2->discard_changes; + is $report2->comments->count, 0, "Update wasn't created"; + is $report2->get_extra_metadata('inspected'), undef, 'report not marked as inspected'; + }; +}; + +done_testing(); |