aboutsummaryrefslogtreecommitdiffstats
path: root/t/open311/populate-service-list.t
diff options
context:
space:
mode:
Diffstat (limited to 't/open311/populate-service-list.t')
-rw-r--r--t/open311/populate-service-list.t194
1 files changed, 79 insertions, 115 deletions
diff --git a/t/open311/populate-service-list.t b/t/open311/populate-service-list.t
index ec6c175f9..606bcbc44 100644
--- a/t/open311/populate-service-list.t
+++ b/t/open311/populate-service-list.t
@@ -4,42 +4,50 @@ use strict;
use warnings;
use Test::More;
-use FixMyStreet::App;
-
-use FindBin;
-use lib "$FindBin::Bin/../perllib";
-use lib "$FindBin::Bin/../commonlib/perllib";
+use FixMyStreet::DB;
use_ok( 'Open311::PopulateServiceList' );
use_ok( 'Open311' );
-my $processor = Open311::PopulateServiceList->new( council_list => [] );
+my $processor = Open311::PopulateServiceList->new();
ok $processor, 'created object';
-
+my $body = FixMyStreet::DB->resultset('Body')->find_or_create( {
+ id => 1,
+ name => 'Body Numero Uno',
+} );
+$body->body_areas->find_or_create({
+ area_id => 1
+} );
+
+my $BROMLEY = 'Bromley Council';
+my $bromley = FixMyStreet::DB->resultset('Body')->find_or_create( {
+ id => 2482,
+ name => $BROMLEY,
+} );
+$bromley->update({ name => $BROMLEY });
+$bromley->body_areas->find_or_create({
+ area_id => 2482
+} );
subtest 'check basic functionality' => sub {
- FixMyStreet::App->model('DB::Contact')->search( { body_id => 1 } )->delete();
+ FixMyStreet::DB->resultset('Contact')->search( { body_id => 1 } )->delete();
my $service_list = get_xml_simple_object( get_standard_xml() );
- my $council = FixMyStreet::App->model('DB::Body')->new( {
- area_id => 1
- } );
-
- my $processor = Open311::PopulateServiceList->new( council_list => [] );
- $processor->_current_council( $council );
+ my $processor = Open311::PopulateServiceList->new();
+ $processor->_current_body( $body );
$processor->process_services( $service_list );
- my $contact_count = FixMyStreet::App->model('DB::Contact')->search( { body_id => 1 } )->count();
+ my $contact_count = FixMyStreet::DB->resultset('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( { body_id => 1 } )->delete();
+ FixMyStreet::DB->resultset('Contact')->search( { body_id => 1 } )->delete();
- my $contact = FixMyStreet::App->model('DB::Contact')->create(
+ my $contact = FixMyStreet::DB->resultset('Contact')->create(
{
body_id => 1,
email => 'contact@example.com',
@@ -47,32 +55,28 @@ subtest 'check non open311 contacts marked as deleted' => sub {
confirmed => 1,
deleted => 0,
editor => $0,
- whenedited => \'ms_current_timestamp()',
+ whenedited => \'current_timestamp',
note => 'test contact',
}
);
my $service_list = get_xml_simple_object( get_standard_xml() );
- my $council = FixMyStreet::App->model('DB::Body')->new( {
- area_id => 1
- } );
-
- my $processor = Open311::PopulateServiceList->new( council_list => [] );
- $processor->_current_council( $council );
+ my $processor = Open311::PopulateServiceList->new();
+ $processor->_current_body( $body );
$processor->process_services( $service_list );
- my $contact_count = FixMyStreet::App->model('DB::Contact')->search( { body_id => 1 } )->count();
+ my $contact_count = FixMyStreet::DB->resultset('Contact')->search( { body_id => 1 } )->count();
is $contact_count, 4, 'correct number of contacts';
- $contact_count = FixMyStreet::App->model('DB::Contact')->search( { body_id => 1, deleted => 1 } )->count();
+ $contact_count = FixMyStreet::DB->resultset('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( { body_id => 1 } )->delete();
+ FixMyStreet::DB->resultset('Contact')->search( { body_id => 1 } )->delete();
- my $contact = FixMyStreet::App->model('DB::Contact')->create(
+ my $contact = FixMyStreet::DB->resultset('Contact')->create(
{
body_id => 1,
email => '009',
@@ -80,7 +84,7 @@ subtest 'check email changed if matching category' => sub {
confirmed => 1,
deleted => 0,
editor => $0,
- whenedited => \'ms_current_timestamp()',
+ whenedited => \'current_timestamp',
note => 'test contact',
}
);
@@ -89,12 +93,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::Body')->new( {
- area_id => 1
- } );
-
- my $processor = Open311::PopulateServiceList->new( council_list => [] );
- $processor->_current_council( $council );
+ my $processor = Open311::PopulateServiceList->new();
+ $processor->_current_body( $body );
$processor->process_services( $service_list );
$contact->discard_changes;
@@ -102,14 +102,14 @@ 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( { body_id => 1 } )->count();
+ my $contact_count = FixMyStreet::DB->resultset('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( { body_id => 1 } )->delete();
+ FixMyStreet::DB->resultset('Contact')->search( { body_id => 1 } )->delete();
- my $contact = FixMyStreet::App->model('DB::Contact')->create(
+ my $contact = FixMyStreet::DB->resultset('Contact')->create(
{
body_id => 1,
email => '001',
@@ -117,7 +117,7 @@ subtest 'check category name changed if updated' => sub {
confirmed => 1,
deleted => 0,
editor => $0,
- whenedited => \'ms_current_timestamp()',
+ whenedited => \'current_timestamp',
note => 'test contact',
}
);
@@ -126,12 +126,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::Body')->new( {
- area_id => 1
- } );
-
- my $processor = Open311::PopulateServiceList->new( council_list => [] );
- $processor->_current_council( $council );
+ my $processor = Open311::PopulateServiceList->new();
+ $processor->_current_body( $body );
$processor->process_services( $service_list );
$contact->discard_changes;
@@ -140,14 +136,14 @@ 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( { body_id => 1 } )->count();
+ my $contact_count = FixMyStreet::DB->resultset('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( { body_id => 1 } )->delete();
+ FixMyStreet::DB->resultset('Contact')->search( { body_id => 1 } )->delete();
- my $contact = FixMyStreet::App->model('DB::Contact')->create(
+ my $contact = FixMyStreet::DB->resultset('Contact')->create(
{
body_id => 1,
email => 'existing@example.com',
@@ -155,14 +151,14 @@ subtest 'check conflicting contacts not changed' => sub {
confirmed => 1,
deleted => 0,
editor => $0,
- whenedited => \'ms_current_timestamp()',
+ whenedited => \'current_timestamp',
note => 'test contact',
}
);
ok $contact, 'contact created';
- my $contact2 = FixMyStreet::App->model('DB::Contact')->create(
+ my $contact2 = FixMyStreet::DB->resultset('Contact')->create(
{
body_id => 1,
email => '001',
@@ -170,7 +166,7 @@ subtest 'check conflicting contacts not changed' => sub {
confirmed => 1,
deleted => 0,
editor => $0,
- whenedited => \'ms_current_timestamp()',
+ whenedited => \'current_timestamp',
note => 'test contact',
}
);
@@ -179,12 +175,8 @@ subtest 'check conflicting contacts not changed' => sub {
my $service_list = get_xml_simple_object( get_standard_xml() );
- my $council = FixMyStreet::App->model('DB::Body')->new( {
- area_id => 1
- } );
-
- my $processor = Open311::PopulateServiceList->new( council_list => [] );
- $processor->_current_council( $council );
+ my $processor = Open311::PopulateServiceList->new();
+ $processor->_current_body( $body );
$processor->process_services( $service_list );
$contact->discard_changes;
@@ -199,12 +191,12 @@ 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( { body_id => 1 } )->count();
+ my $contact_count = FixMyStreet::DB->resultset('Contact')->search( { body_id => 1 } )->count();
is $contact_count, 4, 'correct number of contacts';
};
subtest 'check meta data population' => sub {
- my $processor = Open311::PopulateServiceList->new( council_list => [] );
+ my $processor = Open311::PopulateServiceList->new();
my $meta_xml = '<?xml version="1.0" encoding="utf-8"?>
<service_definition>
@@ -223,7 +215,7 @@ subtest 'check meta data population' => sub {
</service_definition>
';
- my $contact = FixMyStreet::App->model('DB::Contact')->find_or_create(
+ my $contact = FixMyStreet::DB->resultset('Contact')->find_or_create(
{
body_id => 1,
email => '001',
@@ -231,7 +223,7 @@ subtest 'check meta data population' => sub {
confirmed => 1,
deleted => 0,
editor => $0,
- whenedited => \'ms_current_timestamp()',
+ whenedited => \'current_timestamp',
note => 'test contact',
}
);
@@ -243,12 +235,8 @@ subtest 'check meta data population' => sub {
test_get_returns => { 'services/100.xml' => $meta_xml }
);
- my $council = FixMyStreet::App->model('DB::Body')->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 );
@@ -266,14 +254,14 @@ subtest 'check meta data population' => sub {
$contact->discard_changes;
- is_deeply $contact->extra, $extra, 'meta data saved';
+ is_deeply $contact->get_extra_fields, $extra, 'meta data saved';
};
for my $test (
{
desc => 'check meta data added to existing contact',
has_meta => 1,
- orig_meta => undef,
+ orig_meta => [],
end_meta => [ {
variable => 'true',
code => 'type',
@@ -344,7 +332,7 @@ for my $test (
{
desc => 'check meta data removed',
has_meta => 0,
- end_meta => undef,
+ end_meta => [],
orig_meta => [ {
variable => 'true',
code => 'type',
@@ -375,8 +363,8 @@ for my $test (
{
desc => 'check empty meta data handled',
has_meta => 1,
- orig_meta => undef,
- end_meta => undef,
+ orig_meta => [],
+ end_meta => [],
meta_xml => '<?xml version="1.0" encoding="utf-8"?>
<service_definition>
<service_code>100</service_code>
@@ -387,7 +375,7 @@ for my $test (
},
) {
subtest $test->{desc} => sub {
- my $processor = Open311::PopulateServiceList->new( council_list => [] );
+ my $processor = Open311::PopulateServiceList->new();
my $services_xml = '<?xml version="1.0" encoding="utf-8"?>
<services>
@@ -407,7 +395,7 @@ for my $test (
$services_xml =~ s/metadata>false/metadata>true/ms;
}
- my $contact = FixMyStreet::App->model('DB::Contact')->find_or_create(
+ my $contact = FixMyStreet::DB->resultset('Contact')->find_or_create(
{
body_id => 1,
email => '100',
@@ -415,12 +403,13 @@ for my $test (
confirmed => 1,
deleted => 0,
editor => $0,
- whenedited => \'ms_current_timestamp()',
+ whenedited => \'current_timestamp',
note => 'test contact',
}
);
- $contact->update( { extra => $test->{orig_meta} } );
+ $contact->set_extra_fields(@{$test->{orig_meta}});
+ $contact->update;
my $o = Open311->new(
jurisdiction => 'mysociety',
@@ -430,25 +419,20 @@ for my $test (
);
my $service_list = get_xml_simple_object( $services_xml );
- $service_list = { service => [ $service_list->{ service } ] };
-
- my $council = FixMyStreet::App->model('DB::Body')->new( {
- area_id => 1
- } );
$processor->_current_open311( $o );
- $processor->_current_council( $council );
+ $processor->_current_body( $body );
$processor->process_services( $service_list );
$contact->discard_changes;
- is_deeply $contact->extra, $test->{end_meta}, 'meta data saved';
+ is_deeply $contact->get_extra_fields, $test->{end_meta}, 'meta data saved';
};
}
subtest 'check attribute ordering' => sub {
- my $processor = Open311::PopulateServiceList->new( council_list => [] );
+ my $processor = Open311::PopulateServiceList->new();
my $meta_xml = '<?xml version="1.0" encoding="utf-8"?>
<service_definition>
@@ -485,7 +469,7 @@ subtest 'check attribute ordering' => sub {
</service_definition>
';
- my $contact = FixMyStreet::App->model('DB::Contact')->find_or_create(
+ my $contact = FixMyStreet::DB->resultset('Contact')->find_or_create(
{
body_id => 1,
email => '001',
@@ -493,7 +477,7 @@ subtest 'check attribute ordering' => sub {
confirmed => 1,
deleted => 0,
editor => $0,
- whenedited => \'ms_current_timestamp()',
+ whenedited => \'current_timestamp',
note => 'test contact',
}
);
@@ -505,12 +489,8 @@ subtest 'check attribute ordering' => sub {
test_get_returns => { 'services/100.xml' => $meta_xml }
);
- my $council = FixMyStreet::App->model('DB::Body')->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 );
@@ -550,11 +530,11 @@ subtest 'check attribute ordering' => sub {
$contact->discard_changes;
- is_deeply $contact->extra, $extra, 'meta data re-ordered correctly';
+ is_deeply $contact->get_extra_fields, $extra, 'meta data re-ordered correctly';
};
subtest 'check bromely skip code' => sub {
- my $processor = Open311::PopulateServiceList->new( council_list => [] );
+ my $processor = Open311::PopulateServiceList->new();
my $meta_xml = '<?xml version="1.0" encoding="utf-8"?>
<service_definition>
@@ -591,7 +571,7 @@ subtest 'check bromely skip code' => sub {
</service_definition>
';
- my $contact = FixMyStreet::App->model('DB::Contact')->find_or_create(
+ my $contact = FixMyStreet::DB->resultset('Contact')->find_or_create(
{
body_id => 1,
email => '001',
@@ -599,7 +579,7 @@ subtest 'check bromely skip code' => sub {
confirmed => 1,
deleted => 0,
editor => $0,
- whenedited => \'ms_current_timestamp()',
+ whenedited => \'current_timestamp',
note => 'test contact',
}
);
@@ -611,12 +591,8 @@ subtest 'check bromely skip code' => sub {
test_get_returns => { 'services/100.xml' => $meta_xml }
);
- my $council = FixMyStreet::App->model('DB::Body')->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 );
@@ -634,11 +610,9 @@ subtest 'check bromely skip code' => sub {
$contact->discard_changes;
- is_deeply $contact->extra, $extra, 'only non std bromley meta data saved';
+ is_deeply $contact->get_extra_fields, $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 = [
@@ -676,7 +650,7 @@ subtest 'check bromely skip code' => sub {
$contact->discard_changes;
- is_deeply $contact->extra, $extra, 'all meta data saved for non bromley';
+ is_deeply $contact->get_extra_fields, $extra, 'all meta data saved for non bromley';
};
sub get_standard_xml {
@@ -715,17 +689,7 @@ sub get_standard_xml {
sub get_xml_simple_object {
my $xml = shift;
-
- my $simple = XML::Simple->new();
- my $obj;
-
- eval {
- $obj = $simple->XMLin( $xml );
- };
-
- die $@ if $@;
-
- return $obj;
+ return Open311->_get_xml_object($xml);
}
done_testing();