diff options
Diffstat (limited to 't')
-rw-r--r-- | t/app/controller/report_inspect.t | 58 | ||||
-rw-r--r-- | t/cobrand/oxfordshire.t | 51 |
2 files changed, 92 insertions, 17 deletions
diff --git a/t/app/controller/report_inspect.t b/t/app/controller/report_inspect.t index c10fe7f94..3f267a086 100644 --- a/t/app/controller/report_inspect.t +++ b/t/app/controller/report_inspect.t @@ -60,7 +60,6 @@ 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>)'); @@ -70,7 +69,6 @@ FixMyStreet::override_config { $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' }); @@ -79,7 +77,6 @@ FixMyStreet::override_config { $mech->content_contains('Save changes'); $mech->content_contains('Priority'); $mech->content_lacks('Change asset'); - $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_inspect' }); @@ -87,7 +84,6 @@ 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>)'); }; @@ -210,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'; }; @@ -246,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"); @@ -703,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' }); @@ -745,7 +732,6 @@ FixMyStreet::override_config { priority => $rp->id, include_update => '1', detailed_information => 'XXX164XXXxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx', - traffic_information => '', photo1 => '', photo2 => '', photo3 => '', @@ -913,6 +899,44 @@ FixMyStreet::override_config { $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(); diff --git a/t/cobrand/oxfordshire.t b/t/cobrand/oxfordshire.t index cfa98254f..a1c842e2d 100644 --- a/t/cobrand/oxfordshire.t +++ b/t/cobrand/oxfordshire.t @@ -4,6 +4,7 @@ use CGI::Simple; use FixMyStreet::TestMech; use FixMyStreet::Script::Alerts; use FixMyStreet::Script::Reports; +use Open311; my $mech = FixMyStreet::TestMech->new; my $oxon = $mech->create_body_ok(2237, 'Oxfordshire County Council'); @@ -178,6 +179,56 @@ FixMyStreet::override_config { }; } + subtest 'extra data sent with defect update' => sub { + my $comment = FixMyStreet::DB->resultset('Comment')->first; + $comment->set_extra_metadata(defect_raised => 1); + $comment->update; + $comment->problem->external_id('hey'); + $comment->problem->set_extra_metadata(defect_location_description => 'Location'); + $comment->problem->set_extra_metadata(defect_item_category => 'Kerbing'); + $comment->problem->set_extra_metadata(defect_item_type => 'Damaged'); + $comment->problem->set_extra_metadata(defect_item_detail => '1 kerb unit or 1 linear m'); + $comment->problem->set_extra_metadata(traffic_information => 'Signs and Cones'); + $comment->problem->set_extra_metadata(detailed_information => '100x100'); + $comment->problem->update; + + my $cbr = Test::MockModule->new('FixMyStreet::Cobrand::Oxfordshire'); + $cbr->mock('_fetch_features', sub { + my ($self, $cfg, $x, $y) = @_; + [ { + type => 'Feature', + geometry => { type => 'LineString', coordinates => [ [ 1, 2 ], [ 3, 4 ] ] }, + properties => { TYPE1_2_USRN => 13579 }, + } ]; + }); + 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 => $oxon, + test_mode => 1, + test_get_returns => { 'servicerequestupdates.xml' => $test_res }, + ); + + $o->post_service_request_update($comment); + my $cgi = CGI::Simple->new($o->test_req_used->content); + is $cgi->param('attribute[usrn]'), 13579, 'USRN sent with update'; + is $cgi->param('attribute[raise_defect]'), 1, 'Defect flag sent with update'; + is $cgi->param('attribute[defect_item_category]'), 'Kerbing'; + is $cgi->param('attribute[extra_details]'), $user2->email . ' TM1 Damaged 100x100'; + + # Now set a USRN on the problem (found at submission) + $comment->problem->push_extra_fields({ name => 'usrn', value => '12345' }); + $comment->problem->update; + + $o->post_service_request_update($comment); + $cgi = CGI::Simple->new($o->test_req_used->content); + is $cgi->param('attribute[usrn]'), 12345, 'USRN sent with update'; + is $cgi->param('attribute[raise_defect]'), 1, 'Defect flag sent with update'; + }; + }; done_testing(); |