aboutsummaryrefslogtreecommitdiffstats
path: root/t/open311/populate-service-list.t
diff options
context:
space:
mode:
authorMatthew Somerville <matthew@mysociety.org>2013-02-01 15:28:08 +0000
committerMatthew Somerville <matthew@mysociety.org>2013-02-04 06:53:02 +0000
commit488a8f21a0c1bc2b9501c9d94d69db56cccd80ae (patch)
tree68becf501e9492466a80015e8ace9a7fb1557cfa /t/open311/populate-service-list.t
parent3e0d12e8584d132b573f536ab5cd01e24241827b (diff)
parent28aa1dd7fb1c9bc93aa204afae67cf68fe36ee6b (diff)
Merge remote branch 'origin/zurich'
Conflicts: bin/open311-populate-service-list bin/send-comments bin/update-all-reports conf/crontab.ugly db/schema.sql perllib/FixMyStreet/App/Controller/Admin.pm perllib/FixMyStreet/App/Controller/Report/New.pm perllib/FixMyStreet/App/Controller/Reports.pm perllib/FixMyStreet/Cobrand/Default.pm perllib/FixMyStreet/Cobrand/LichfieldDC.pm perllib/FixMyStreet/DB/Result/Open311conf.pm perllib/FixMyStreet/DB/Result/Problem.pm perllib/FixMyStreet/DB/ResultSet/Problem.pm perllib/FixMyStreet/SendReport.pm perllib/FixMyStreet/SendReport/Email.pm perllib/FixMyStreet/SendReport/Open311.pm perllib/Open311/GetServiceRequestUpdates.pm perllib/Open311/PopulateServiceList.pm t/app/controller/report_new.t t/app/controller/rss.t templates/web/bromley/report/display.html templates/web/default/admin/council_contacts.html templates/web/default/common_header_tags.html templates/web/default/dashboard/index.html templates/web/default/front/stats.html templates/web/default/report/_main.html templates/web/default/report/update-form.html templates/web/emptyhomes/index.html templates/web/emptyhomes/report/display.html templates/web/emptyhomes/report/new/councils_text_all.html templates/web/emptyhomes/reports/body.html templates/web/emptyhomes/reports/index.html templates/web/fixmystreet/report/new/fill_in_details_form.html templates/web/fixmystreet/report/update-form.html web/cobrands/fixmystreet/fixmystreet.js web/js/fixmystreet.js
Diffstat (limited to 't/open311/populate-service-list.t')
-rw-r--r--t/open311/populate-service-list.t114
1 files changed, 45 insertions, 69 deletions
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 = [