diff options
Diffstat (limited to 't/open311')
-rw-r--r-- | t/open311/getservicerequests.t | 40 | ||||
-rw-r--r-- | t/open311/getupdates.t | 31 | ||||
-rw-r--r-- | t/open311/populate-service-list.t | 64 | ||||
-rw-r--r-- | t/open311/post-service-request-updates.t | 17 |
4 files changed, 120 insertions, 32 deletions
diff --git a/t/open311/getservicerequests.t b/t/open311/getservicerequests.t index 672459f3f..7a69d0ff6 100644 --- a/t/open311/getservicerequests.t +++ b/t/open311/getservicerequests.t @@ -534,6 +534,46 @@ subtest "non_public contacts result in non_public reports" => sub { }; +subtest "staff and non_public contacts result in non_public reports" => sub { + + $contact->update({ + non_public => 1, + state => 'staff' + }); + my $o = Open311->new( + jurisdiction => 'mysociety', + endpoint => 'http://example.com', + test_mode => 1, + test_get_returns => { 'requests.xml' => prepare_xml( {} ) } + ); + + my $update = Open311::GetServiceRequests->new( + system_user => $user, + start_date => $start_date, + end_date => $end_date + ); + + FixMyStreet::override_config { + MAPIT_URL => 'http://mapit.uk/', + }, sub { + $update->create_problems( $o, $body ); + }; + + my $p = FixMyStreet::DB->resultset('Problem')->search( + { external_id => 123456, category => $contact->category } + )->first; + + ok $p, 'problem created'; + is $p->non_public, 1, "report non_public is set correctly"; + + $p->delete; + $contact->update({ + non_public => 0, + state => 'confirmed' + }); + +}; + for my $test ( { test_desc => 'filters out phone numbers', diff --git a/t/open311/getupdates.t b/t/open311/getupdates.t index 351f17f6f..c1e51d380 100644 --- a/t/open311/getupdates.t +++ b/t/open311/getupdates.t @@ -18,9 +18,6 @@ my $body = FixMyStreet::DB->resultset('Body')->new( { name => 'Test Body', } ); -my $updates = Open311::GetUpdates->new( system_user => $user ); -ok $updates, 'created object'; - my $requests_xml = qq{<?xml version="1.0" encoding="utf-8"?> <service_requests> <request> @@ -101,7 +98,12 @@ for my $test ( my $o = Open311->new( jurisdiction => 'mysociety', endpoint => 'http://example.com', test_mode => 1, test_get_returns => { 'requests.xml' => $local_requests_xml } ); - ok $updates->update_reports( [ 638344 ], $o, $body ), 'Updated reports'; + my $updates = Open311::GetUpdates->new( + system_user => $user, + current_open311 => $o, + current_body => $body, + ); + $updates->update_reports( [ $problem ] ); my @parts = uri_split($o->test_uri_used); is $parts[2], '/requests.xml', 'path matches'; my @qs = sort split '&', $parts[3]; @@ -179,7 +181,13 @@ subtest 'update with two requests' => sub { my $o = Open311->new( jurisdiction => 'mysociety', endpoint => 'http://example.com', test_mode => 1, test_get_returns => { 'requests.xml' => $local_requests_xml } ); - ok $updates->update_reports( [ 638344,638345 ], $o, $body ), 'Updated reports'; + my $updates = Open311::GetUpdates->new( + system_user => $user, + current_open311 => $o, + current_body => $body, + ); + + $updates->update_reports( [ $problem, $problem2 ] ); my @parts = uri_split($o->test_uri_used); is $parts[2], '/requests.xml', 'path matches'; my @qs = sort split '&', $parts[3]; @@ -227,7 +235,7 @@ my $problem3 = $problem_rs->create( { external_id => 638346, } ); -subtest 'test translation of auto-added comment from old-style Open311 update' => sub { +subtest 'test auto-added comment from old-style Open311 update' => sub { my $dt = sprintf( '<updated_datetime>%s</updated_datetime>', DateTime->now ); $requests_xml =~ s/UPDATED_DATETIME/$dt/; @@ -236,7 +244,13 @@ subtest 'test translation of auto-added comment from old-style Open311 update' = FixMyStreet::override_config { ALLOWED_COBRANDS => [ 'fixamingata' ], }, sub { - ok $updates->update_reports( [ 638346 ], $o, $body ), 'Updated reports'; + my $updates = Open311::GetUpdates->new( + system_user => $user, + current_open311 => $o, + current_body => $body, + blank_updates_permitted => 1, + ); + $updates->update_reports( [ $problem3 ] ); }; my @parts = uri_split($o->test_uri_used); is $parts[2], '/requests.xml', 'path matches'; @@ -244,7 +258,8 @@ subtest 'test translation of auto-added comment from old-style Open311 update' = is_deeply(\@qs, [ 'jurisdiction_id=mysociety', 'service_request_id=638346' ], 'query string matches'); is $problem3->comments->count, 1, 'added a comment'; - is $problem3->comments->first->text, "Stängd av kommunen", 'correct comment text'; + is $problem3->comments->first->problem_state, 'fixed - council'; + is $problem3->comments->first->text, '', 'correct comment text'; }; END { diff --git a/t/open311/populate-service-list.t b/t/open311/populate-service-list.t index bd837f203..20f092da4 100644 --- a/t/open311/populate-service-list.t +++ b/t/open311/populate-service-list.t @@ -175,33 +175,53 @@ subtest "set multiple groups with groups element" => sub { is_deeply $contact->get_extra->{group}, ['sanitation & cleaning','street'], "groups set correctly"; }; -subtest 'check non open311 contacts marked as deleted' => sub { - FixMyStreet::DB->resultset('Contact')->search( { body_id => $body->id } )->delete(); +$body->update({ can_be_devolved => 1 }); +for my $test ( + { + test => 'check non open311 contacts marked as deleted', + contact_params => { + email => 'contact@example.com', + }, + deleted => 1, + }, + { + test => 'check devolved non open311 contacts not marked as deleted', + contact_params => { + email => 'contact', + send_method => 'Open311', + }, + deleted => 0, + }, +) { + subtest $test->{test} => sub { + FixMyStreet::DB->resultset('Contact')->search( { body_id => $body->id } )->delete(); - my $contact = FixMyStreet::DB->resultset('Contact')->create( - { - body_id => $body->id, - email => 'contact@example.com', - category => 'An old category', - state => 'confirmed', - editor => $0, - whenedited => \'current_timestamp', - note => 'test contact', - } - ); + my $contact = FixMyStreet::DB->resultset('Contact')->create( + { + body_id => $body->id, + category => 'An old category', + state => 'confirmed', + editor => $0, + whenedited => \'current_timestamp', + note => 'test contact', + %{$test->{contact_params}}, + } + ); - my $service_list = get_xml_simple_object( get_standard_xml() ); + my $service_list = get_xml_simple_object( get_standard_xml() ); - my $processor = Open311::PopulateServiceList->new(); - $processor->_current_body( $body ); - $processor->process_services( $service_list ); + my $processor = Open311::PopulateServiceList->new(); + $processor->_current_body( $body ); + $processor->process_services( $service_list ); - my $contact_count = FixMyStreet::DB->resultset('Contact')->search( { body_id => $body->id } )->count(); - is $contact_count, 4, 'correct number of contacts'; + my $contact_count = FixMyStreet::DB->resultset('Contact')->search( { body_id => $body->id } )->count(); + is $contact_count, 4, 'correct number of contacts'; - $contact_count = FixMyStreet::DB->resultset('Contact')->search( { body_id => $body->id, state => 'deleted' } )->count(); - is $contact_count, 1, 'correct number of deleted contacts'; -}; + $contact_count = FixMyStreet::DB->resultset('Contact')->search( { body_id => $body->id, state => 'deleted' } )->count(); + is $contact_count, $test->{deleted}, 'correct number of deleted contacts'; + }; +} +$body->update({ can_be_devolved => 0 }); subtest 'check email changed if matching category' => sub { FixMyStreet::DB->resultset('Contact')->search( { body_id => $body->id } )->delete(); diff --git a/t/open311/post-service-request-updates.t b/t/open311/post-service-request-updates.t index adfd4e3c5..03fcbeae4 100644 --- a/t/open311/post-service-request-updates.t +++ b/t/open311/post-service-request-updates.t @@ -1,12 +1,13 @@ #!/usr/bin/env perl use FixMyStreet::TestMech; +use Test::Output; my $mech = FixMyStreet::TestMech->new; use_ok( 'Open311::PostServiceRequestUpdates' ); -my $o = Open311::PostServiceRequestUpdates->new( site => 'fixmystreet.com' ); +my $o = Open311::PostServiceRequestUpdates->new; my $params = { send_method => 'Open311', @@ -15,7 +16,10 @@ my $params = { endpoint => 'endpoint', jurisdiction => 'home', }; -my $bromley = $mech->create_body_ok(2482, 'Bromley', { %$params, send_extended_statuses => 1 }); +my $bromley = $mech->create_body_ok(2482, 'Bromley', { %$params, + endpoint => 'www.bromley.gov.uk', + send_extended_statuses => 1, + can_be_devolved => 1 }); my $oxon = $mech->create_body_ok(2237, 'Oxfordshire', { %$params, id => "5" . $bromley->id }); my $bucks = $mech->create_body_ok(2217, 'Buckinghamshire', $params); my $lewisham = $mech->create_body_ok(2492, 'Lewisham', $params); @@ -33,6 +37,7 @@ subtest 'Check Open311 params' => sub { my %conf = $o->open311_params($bromley); is_deeply \%conf, { %$result, + endpoint => 'www.bromley.gov.uk', extended_statuses => 1, endpoints => { service_request_updates => 'update.xml', update => 'update.xml' }, fixmystreet_body => $bromley, @@ -130,8 +135,16 @@ subtest 'Oxfordshire gets an ID' => sub { $o->send; $c2->discard_changes; is $c2->send_fail_count, 1, 'Oxfordshire update tried to send, failed'; + stdout_like { $o->summary_failures } qr/The following updates failed sending/; }; }; +subtest 'Devolved contact' => sub { + $mech->create_contact_ok(body_id => $bromley->id, category => 'Other', email => "OTHER", send_method => 'Open311', endpoint => '/devolved-endpoint/'); + $c1->update({ send_fail_count => 0 }); + $o->send; + $c1->discard_changes; + like $c1->send_fail_reason, qr/devolved-endpoint/, 'Failure message contains correct endpoint'; +}; done_testing(); |