diff options
Diffstat (limited to 't/open311')
-rw-r--r-- | t/open311/getservicerequestupdates.t | 18 | ||||
-rw-r--r-- | t/open311/getupdates.t | 198 | ||||
-rw-r--r-- | t/open311/populate-service-list.t | 114 |
3 files changed, 54 insertions, 276 deletions
diff --git a/t/open311/getservicerequestupdates.t b/t/open311/getservicerequestupdates.t index ba2854460..36ed13615 100644 --- a/t/open311/getservicerequestupdates.t +++ b/t/open311/getservicerequestupdates.t @@ -123,7 +123,7 @@ my $problem = $problem_rs->new( lastupdate => DateTime->now()->subtract( days => 1 ), anonymous => 1, external_id => time(), - council => 2482, + bodies_str => 2482, } ); @@ -350,7 +350,7 @@ for my $test ( $problem->state( $test->{start_state} ); $problem->update; - my $council_details = { areaid => 2482 }; + my $council_details = { areas => { 2482 => 1 } }; my $update = Open311::GetServiceRequestUpdates->new( system_user => $user ); $update->update_comments( $o, $council_details ); @@ -389,7 +389,7 @@ foreach my $test ( $problem->comments->delete; - my $council_details = { areaid => 2482 }; + my $council_details = { areas => { 2482 => 1 } }; my $update = Open311::GetServiceRequestUpdates->new( system_user => $user ); $update->update_comments( $o, $council_details ); @@ -419,7 +419,7 @@ my $problem2 = $problem_rs->new( lastupdate => DateTime->now(), anonymous => 1, external_id => $problem->external_id, - council => 2651, + bodies_str => 2651, } ); @@ -458,7 +458,7 @@ for my $test ( my $o = Open311->new( jurisdiction => 'mysociety', endpoint => 'http://example.com', test_mode => 1, test_get_returns => { 'servicerequestupdates.xml' => $local_requests_xml } ); - my $council_details = { areaid => $test->{area_id} }; + my $council_details = { areas => { $test->{area_id} => 1 } }; my $update = Open311::GetServiceRequestUpdates->new( system_user => $user ); $update->update_comments( $o, $council_details ); @@ -498,7 +498,7 @@ subtest 'using start and end date' => sub { end_date => $end_dt, ); - my $council_details = { areaid => 2482 }; + my $council_details = { areas => { 2482 => 1 } }; $update->update_comments( $o, $council_details ); my $start = $start_dt . ''; @@ -558,7 +558,7 @@ subtest 'check that existing comments are not duplicated' => sub { system_user => $user, ); - my $council_details = { areaid => 2482 }; + my $council_details = { areas => { 2482 => 1 } }; $update->update_comments( $o, $council_details ); $problem->discard_changes; @@ -619,7 +619,7 @@ foreach my $test ( { system_user => $user, ); - my $council_details = { areaid => 2482 }; + my $council_details = { areas => { 2482 => 1 } }; $update->update_comments( $o, $council_details ); $problem->discard_changes; @@ -671,7 +671,7 @@ foreach my $test ( { suppress_alerts => $test->{suppress_alerts}, ); - my $council_details = { areaid => 2482 }; + my $council_details = { areas => { 2482 => 1 } }; $update->update_comments( $o, $council_details ); $problem->discard_changes; diff --git a/t/open311/getupdates.t b/t/open311/getupdates.t deleted file mode 100644 index 500ac97d2..000000000 --- a/t/open311/getupdates.t +++ /dev/null @@ -1,198 +0,0 @@ -#!/usr/bin/env perl - -use strict; -use warnings; -use Test::More; - -use FindBin; -use lib "$FindBin::Bin/../perllib"; -use lib "$FindBin::Bin/../commonlib/perllib"; - -use_ok( 'Open311::GetUpdates' ); -use_ok( 'Open311' ); - -my $user = FixMyStreet::App->model('DB::User')->find_or_create( - { - email => 'system_user@example.com' - } -); - - -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> -<service_request_id>638344</service_request_id> -<status>open</status> -<status_notes>This is a note.</status_notes> -<service_name>Sidewalk and Curb Issues</service_name> -<service_code>006</service_code> -<description></description> -<agency_responsible></agency_responsible> -<service_notice></service_notice> -<requested_datetime>2010-04-14T06:37:38-08:00</requested_datetime> -UPDATED_DATETIME -<expected_datetime>2010-04-15T06:37:38-08:00</expected_datetime> -<lat>37.762221815</lat> -<long>-122.4651145</long> -</request> -</service_requests> -}; - -my $problem_rs = FixMyStreet::App->model('DB::Problem'); -my $problem = $problem_rs->new( - { - postcode => 'EH99 1SP', - latitude => 1, - longitude => 1, - areas => 1, - title => '', - detail => '', - used_map => 1, - user_id => 1, - name => '', - state => 'confirmed', - service => '', - cobrand => 'default', - cobrand_data => '', - user => $user, - created => DateTime->now()->subtract( days => 1 ), - lastupdate => DateTime->now()->subtract( days => 1 ), - anonymous => 1, - external_id => 638344, - } -); - -$problem->insert; - -for my $test ( - { - desc => 'element missing', - updated_datetime => '', - comment_count => 0, - }, - { - desc => 'empty element', - updated_datetime => '<updated_datetime />', - comment_count => 0, - }, - { - desc => 'element with no content', - updated_datetime => '<updated_datetime></updated_datetime>', - comment_count => 0, - }, - { - desc => 'element with old content', - updated_datetime => sprintf( '<updated_datetime>%s</updated_datetime>', DateTime->now->subtract( days => 3 ) ), - comment_count => 0, - }, - { - desc => 'element with new content', - updated_datetime => sprintf( '<updated_datetime>%s</updated_datetime>', DateTime->now ), - comment_count => 1, - }, -) { - subtest $test->{desc} => sub { - $problem->comments->delete; - $problem->lastupdate(DateTime->now()->subtract( days => 1 ) ), - $problem->update; - - my $local_requests_xml = $requests_xml; - $local_requests_xml =~ s/UPDATED_DATETIME/$test->{updated_datetime}/; - - 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, { name => 'Test Council' } ); - is $o->test_uri_used, 'http://example.com/requests.xml?jurisdiction_id=mysociety&service_request_id=638344', 'get url'; - - is $problem->comments->count, $test->{comment_count}, 'added a comment'; - }; -} - -$requests_xml = qq{<?xml version="1.0" encoding="utf-8"?> -<service_requests> -<request> -<service_request_id>638344</service_request_id> -<status>open</status> -<status_notes>This is a note.</status_notes> -<service_name>Sidewalk and Curb Issues</service_name> -<service_code>006</service_code> -<description></description> -<agency_responsible></agency_responsible> -<service_notice></service_notice> -<requested_datetime>2010-04-14T06:37:38-08:00</requested_datetime> -<updated_datetime>UPDATED_DATETIME</updated_datetime> -<expected_datetime>2010-04-15T06:37:38-08:00</expected_datetime> -<lat>37.762221815</lat> -<long>-122.4651145</long> -</request> -<request> -<service_request_id>638345</service_request_id> -<status>open</status> -<status_notes>This is a for a different issue.</status_notes> -<service_name>Sidewalk and Curb Issues</service_name> -<service_code>006</service_code> -<description></description> -<agency_responsible></agency_responsible> -<service_notice></service_notice> -<requested_datetime>2010-04-14T06:37:38-08:00</requested_datetime> -<updated_datetime>UPDATED_DATETIME2</updated_datetime> -<expected_datetime>2010-04-15T06:37:38-08:00</expected_datetime> -<lat>37.762221815</lat> -<long>-122.4651145</long> -</request> -</service_requests> -}; - -my $problem2 = $problem_rs->create( - { - postcode => 'EH99 1SP', - latitude => 1, - longitude => 1, - areas => 1, - title => '', - detail => '', - used_map => 1, - user_id => 1, - name => '', - state => 'confirmed', - service => '', - cobrand => 'default', - cobrand_data => '', - user => $user, - created => DateTime->now()->subtract( days => 1 ), - lastupdate => DateTime->now()->subtract( days => 1 ), - anonymous => 1, - external_id => 638345, - } -); - -$problem->comments->delete; -subtest 'update with two requests' => sub { - $problem->comments->delete; - $problem->lastupdate(DateTime->now()->subtract( days => 1 ) ), - - my $date1 = DateTime::Format::W3CDTF->new->format_datetime( DateTime->now() ); - my $date2 = DateTime::Format::W3CDTF->new->format_datetime( DateTime->now->subtract( hours => 1) ); - my $local_requests_xml = $requests_xml; - $local_requests_xml =~ s/UPDATED_DATETIME2/$date2/; - $local_requests_xml =~ s/UPDATED_DATETIME/$date1/; - - 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, { name => 'Test Council' } ); - is $o->test_uri_used, 'http://example.com/requests.xml?jurisdiction_id=mysociety&service_request_id=638344%2C638345', 'get url'; - - is $problem->comments->count, 1, 'added a comment to first problem'; - is $problem2->comments->count, 1, 'added a comment to second problem'; -}; - -$problem->comments->delete; -$problem->delete; -$user->comments->delete; -$user->problems->delete; -$user->delete; - -done_testing(); diff --git a/t/open311/populate-service-list.t b/t/open311/populate-service-list.t index 00026cd9f..f33fc97b4 100644 --- a/t/open311/populate-service-list.t +++ b/t/open311/populate-service-list.t @@ -17,31 +17,41 @@ use_ok( 'Open311' ); my $processor = Open311::PopulateServiceList->new( council_list => [] ); ok $processor, 'created object'; - +my $body = FixMyStreet::App->model('DB::Body')->find_or_create( { + id => 1, + name => 'Body Numero Uno', +} ); +$body->body_areas->find_or_create({ + area_id => 1 +} ); + +my $bromley = FixMyStreet::App->model('DB::Body')->find_or_create( { + id => 2482, + name => 'Bromley Council', +} ); +$bromley->body_areas->find_or_create({ + area_id => 2482 +} ); subtest 'check basic functionality' => sub { - FixMyStreet::App->model('DB::Contact')->search( { area_id => 1 } )->delete(); + FixMyStreet::App->model('DB::Contact')->search( { body_id => 1 } )->delete(); my $service_list = get_xml_simple_object( get_standard_xml() ); - my $council = FixMyStreet::App->model('DB::Open311Conf')->new( { - area_id => 1 - } ); - my $processor = Open311::PopulateServiceList->new( council_list => [] ); - $processor->_current_council( $council ); + $processor->_current_body( $body ); $processor->process_services( $service_list ); - my $contact_count = FixMyStreet::App->model('DB::Contact')->search( { area_id => 1 } )->count(); + my $contact_count = FixMyStreet::App->model('DB::Contact')->search( { body_id => 1 } )->count(); is $contact_count, 3, 'correct number of contacts'; }; subtest 'check non open311 contacts marked as deleted' => sub { - FixMyStreet::App->model('DB::Contact')->search( { area_id => 1 } )->delete(); + FixMyStreet::App->model('DB::Contact')->search( { body_id => 1 } )->delete(); my $contact = FixMyStreet::App->model('DB::Contact')->create( { - area_id => 1, + body_id => 1, email => 'contact@example.com', category => 'An old category', confirmed => 1, @@ -54,27 +64,23 @@ subtest 'check non open311 contacts marked as deleted' => sub { my $service_list = get_xml_simple_object( get_standard_xml() ); - my $council = FixMyStreet::App->model('DB::Open311Conf')->new( { - area_id => 1 - } ); - my $processor = Open311::PopulateServiceList->new( council_list => [] ); - $processor->_current_council( $council ); + $processor->_current_body( $body ); $processor->process_services( $service_list ); - my $contact_count = FixMyStreet::App->model('DB::Contact')->search( { area_id => 1 } )->count(); + my $contact_count = FixMyStreet::App->model('DB::Contact')->search( { body_id => 1 } )->count(); is $contact_count, 4, 'correct number of contacts'; - $contact_count = FixMyStreet::App->model('DB::Contact')->search( { area_id => 1, deleted => 1 } )->count(); + $contact_count = FixMyStreet::App->model('DB::Contact')->search( { body_id => 1, deleted => 1 } )->count(); is $contact_count, 1, 'correct number of deleted contacts'; }; subtest 'check email changed if matching category' => sub { - FixMyStreet::App->model('DB::Contact')->search( { area_id => 1 } )->delete(); + FixMyStreet::App->model('DB::Contact')->search( { body_id => 1 } )->delete(); my $contact = FixMyStreet::App->model('DB::Contact')->create( { - area_id => 1, + body_id => 1, email => '009', category => 'Cans left out 24x7', confirmed => 1, @@ -89,12 +95,8 @@ subtest 'check email changed if matching category' => sub { my $service_list = get_xml_simple_object( get_standard_xml() ); - my $council = FixMyStreet::App->model('DB::Open311Conf')->new( { - area_id => 1 - } ); - my $processor = Open311::PopulateServiceList->new( council_list => [] ); - $processor->_current_council( $council ); + $processor->_current_body( $body ); $processor->process_services( $service_list ); $contact->discard_changes; @@ -102,16 +104,16 @@ subtest 'check email changed if matching category' => sub { is $contact->confirmed, 1, 'contact still confirmed'; is $contact->deleted, 0, 'contact still not deleted'; - my $contact_count = FixMyStreet::App->model('DB::Contact')->search( { area_id => 1 } )->count(); + my $contact_count = FixMyStreet::App->model('DB::Contact')->search( { body_id => 1 } )->count(); is $contact_count, 3, 'correct number of contacts'; }; subtest 'check category name changed if updated' => sub { - FixMyStreet::App->model('DB::Contact')->search( { area_id => 1 } )->delete(); + FixMyStreet::App->model('DB::Contact')->search( { body_id => 1 } )->delete(); my $contact = FixMyStreet::App->model('DB::Contact')->create( { - area_id => 1, + body_id => 1, email => '001', category => 'Bins left out 24x7', confirmed => 1, @@ -126,12 +128,8 @@ subtest 'check category name changed if updated' => sub { my $service_list = get_xml_simple_object( get_standard_xml() ); - my $council = FixMyStreet::App->model('DB::Open311Conf')->new( { - area_id => 1 - } ); - my $processor = Open311::PopulateServiceList->new( council_list => [] ); - $processor->_current_council( $council ); + $processor->_current_body( $body ); $processor->process_services( $service_list ); $contact->discard_changes; @@ -140,16 +138,16 @@ subtest 'check category name changed if updated' => sub { is $contact->confirmed, 1, 'contact still confirmed'; is $contact->deleted, 0, 'contact still not deleted'; - my $contact_count = FixMyStreet::App->model('DB::Contact')->search( { area_id => 1 } )->count(); + my $contact_count = FixMyStreet::App->model('DB::Contact')->search( { body_id => 1 } )->count(); is $contact_count, 3, 'correct number of contacts'; }; subtest 'check conflicting contacts not changed' => sub { - FixMyStreet::App->model('DB::Contact')->search( { area_id => 1 } )->delete(); + FixMyStreet::App->model('DB::Contact')->search( { body_id => 1 } )->delete(); my $contact = FixMyStreet::App->model('DB::Contact')->create( { - area_id => 1, + body_id => 1, email => 'existing@example.com', category => 'Cans left out 24x7', confirmed => 1, @@ -164,7 +162,7 @@ subtest 'check conflicting contacts not changed' => sub { my $contact2 = FixMyStreet::App->model('DB::Contact')->create( { - area_id => 1, + body_id => 1, email => '001', category => 'Bins left out 24x7', confirmed => 1, @@ -179,12 +177,8 @@ subtest 'check conflicting contacts not changed' => sub { my $service_list = get_xml_simple_object( get_standard_xml() ); - my $council = FixMyStreet::App->model('DB::Open311Conf')->new( { - area_id => 1 - } ); - my $processor = Open311::PopulateServiceList->new( council_list => [] ); - $processor->_current_council( $council ); + $processor->_current_body( $body ); $processor->process_services( $service_list ); $contact->discard_changes; @@ -199,7 +193,7 @@ subtest 'check conflicting contacts not changed' => sub { is $contact2->confirmed, 1, 'second contact contact still confirmed'; is $contact2->deleted, 0, 'second contact contact still not deleted'; - my $contact_count = FixMyStreet::App->model('DB::Contact')->search( { area_id => 1 } )->count(); + my $contact_count = FixMyStreet::App->model('DB::Contact')->search( { body_id => 1 } )->count(); is $contact_count, 4, 'correct number of contacts'; }; @@ -225,7 +219,7 @@ subtest 'check meta data population' => sub { my $contact = FixMyStreet::App->model('DB::Contact')->find_or_create( { - area_id => 1, + body_id => 1, email => '001', category => 'Bins left out 24x7', confirmed => 1, @@ -243,12 +237,8 @@ subtest 'check meta data population' => sub { test_get_returns => { 'services/100.xml' => $meta_xml } ); - my $council = FixMyStreet::App->model('DB::Open311conf')->new( { - area_id => 2482 - } ); - $processor->_current_open311( $o ); - $processor->_current_council( $council ); + $processor->_current_body( $bromley ); $processor->_current_service( { service_code => 100 } ); $processor->_add_meta_to_contact( $contact ); @@ -409,7 +399,7 @@ for my $test ( my $contact = FixMyStreet::App->model('DB::Contact')->find_or_create( { - area_id => 1, + body_id => 1, email => '100', category => 'Cans left out 24x7', confirmed => 1, @@ -432,12 +422,8 @@ for my $test ( my $service_list = get_xml_simple_object( $services_xml ); $service_list = { service => [ $service_list->{ service } ] }; - my $council = FixMyStreet::App->model('DB::Open311conf')->new( { - area_id => 1 - } ); - $processor->_current_open311( $o ); - $processor->_current_council( $council ); + $processor->_current_body( $body ); $processor->process_services( $service_list ); @@ -487,7 +473,7 @@ subtest 'check attribute ordering' => sub { my $contact = FixMyStreet::App->model('DB::Contact')->find_or_create( { - area_id => 1, + body_id => 1, email => '001', category => 'Bins left out 24x7', confirmed => 1, @@ -505,12 +491,8 @@ subtest 'check attribute ordering' => sub { test_get_returns => { 'services/100.xml' => $meta_xml } ); - my $council = FixMyStreet::App->model('DB::Open311conf')->new( { - area_id => 1 - } ); - $processor->_current_open311( $o ); - $processor->_current_council( $council ); + $processor->_current_body( $body ); $processor->_current_service( { service_code => 100 } ); $processor->_add_meta_to_contact( $contact ); @@ -593,7 +575,7 @@ subtest 'check bromely skip code' => sub { my $contact = FixMyStreet::App->model('DB::Contact')->find_or_create( { - area_id => 1, + body_id => 1, email => '001', category => 'Bins left out 24x7', confirmed => 1, @@ -611,12 +593,8 @@ subtest 'check bromely skip code' => sub { test_get_returns => { 'services/100.xml' => $meta_xml } ); - my $council = FixMyStreet::App->model('DB::Open311conf')->new( { - area_id => 2482 - } ); - $processor->_current_open311( $o ); - $processor->_current_council( $council ); + $processor->_current_body( $bromley ); $processor->_current_service( { service_code => 100 } ); $processor->_add_meta_to_contact( $contact ); @@ -636,9 +614,7 @@ subtest 'check bromely skip code' => sub { is_deeply $contact->extra, $extra, 'only non std bromley meta data saved'; - $council->area_id(1); - - $processor->_current_council( $council ); + $processor->_current_body( $body ); $processor->_add_meta_to_contact( $contact ); $extra = [ |