diff options
Diffstat (limited to 't/cobrand/oxfordshire.t')
-rw-r--r-- | t/cobrand/oxfordshire.t | 107 |
1 files changed, 104 insertions, 3 deletions
diff --git a/t/cobrand/oxfordshire.t b/t/cobrand/oxfordshire.t index 65c6a3864..a1c842e2d 100644 --- a/t/cobrand/oxfordshire.t +++ b/t/cobrand/oxfordshire.t @@ -1,7 +1,10 @@ use Test::MockModule; +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'); @@ -50,6 +53,7 @@ subtest 'check /around?ajax defaults to open reports only' => sub { my @problems = FixMyStreet::DB->resultset('Problem')->search({}, { rows => 3, order_by => 'id' })->all; FixMyStreet::override_config { + STAGING_FLAGS => { send_reports => 1, skip_checks => 1 }, ALLOWED_COBRANDS => 'oxfordshire', MAPIT_URL => 'http://mapit.uk/', }, sub { @@ -63,10 +67,10 @@ FixMyStreet::override_config { is $mech->uri->path, '/report/' . $problem->id, 'redirects to report'; }; - subtest 'check unable to fix label' => sub { - my $user = $mech->create_user_ok( 'user@example.com', name => 'Test User' ); - my $user2 = $mech->create_user_ok( 'user2@example.com', name => 'Test User2' ); + my $user = $mech->create_user_ok( 'user@example.com', name => 'Test User' ); + my $user2 = $mech->create_user_ok( 'user2@example.com', name => 'Test User2' ); + subtest 'check unable to fix label' => sub { my $problem = $problems[0]; $problem->state( 'unable to fix' ); $problem->update; @@ -128,6 +132,103 @@ FixMyStreet::override_config { is $rows[2]->[20], '', 'Report without HIAMS ref has empty ref field'; is $rows[3]->[20], '123098123', 'Older Exor report has correct ref'; }; + + $oxon->update({ + send_method => 'Open311', + endpoint => 'endpoint', + api_key => 'key', + jurisdiction => 'home', + }); + my $contact = $mech->create_contact_ok( body_id => $oxon->id, category => 'Gullies and Catchpits', email => 'GC' ); + $contact->set_extra_fields( ( + { code => 'feature_id', datatype => 'hidden', variable => 'true' }, + { code => 'usrn', datatype => 'hidden', variable => 'true' }, + ) ); + $contact->update; + FixMyStreet::Script::Reports::send(); # Make sure no waiting reports + + for my $test ( + { + field => 'feature_id', + value => '12345', + text => 'Asset Id', + }, + ) { + subtest 'Check special Open311 request handling of ' . $test->{text}, sub { + my ($p) = $mech->create_problems_for_body( 1, $oxon->id, 'Test', { + cobrand => 'oxfordshire', + category => 'Gullies and Catchpits', + user => $user, + latitude => 51.754926, + longitude => -1.256179, + }); + $p->set_extra_fields({ name => $test->{field}, value => $test->{value}}); + $p->update; + + my $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'; + unlike $p->detail, qr/$test->{text}:/, $test->{text} . ' not saved to report detail'; + + my $req = $test_data->{test_req_used}; + my $c = CGI::Simple->new($req->content); + like $c->param('description'), qr/$test->{text}: $test->{value}/, $test->{text} . ' included in body'; + }; + } + + 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(); |