aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--perllib/Open311/PopulateServiceList.pm16
-rw-r--r--t/open311/populate-service-list.t67
2 files changed, 78 insertions, 5 deletions
diff --git a/perllib/Open311/PopulateServiceList.pm b/perllib/Open311/PopulateServiceList.pm
index 2dfe7e5c4..f490607e4 100644
--- a/perllib/Open311/PopulateServiceList.pm
+++ b/perllib/Open311/PopulateServiceList.pm
@@ -83,8 +83,22 @@ sub process_service {
}
);
- my $contact = $contacts->first;
+ if ( $contacts->count() > 1 ) {
+ sprintf(
+ "Multiple contacts for service code %s, category %s - Skipping\n",
+ $self->_current_service->{service_code},
+ $self->_current_service->{service_name},
+ );
+
+ # best to not mark them as deleted as we don't know what we're doing
+ while ( my $contact = $contacts->next ) {
+ push @{ $self->found_contacts }, $contact->email;
+ }
+ return;
+ }
+
+ my $contact = $contacts->first;
if ( $contact ) {
$self->_handle_existing_contact( $contact );
diff --git a/t/open311/populate-service-list.t b/t/open311/populate-service-list.t
index 83df47358..bdb7404f9 100644
--- a/t/open311/populate-service-list.t
+++ b/t/open311/populate-service-list.t
@@ -22,7 +22,7 @@ ok $processor, 'created object';
subtest 'check basic functionality' => sub {
FixMyStreet::App->model('DB::Contact')->search( { area_id => 1 } )->delete();
- my $service_list = get_xml_simple_object( get_standard_xml );
+ my $service_list = get_xml_simple_object( get_standard_xml() );
my $council = FixMyStreet::App->model('DB::Open311Conf')->new( {
area_id => 1
@@ -52,7 +52,7 @@ subtest 'check non open311 contacts marked as deleted' => sub {
}
);
- my $service_list = get_xml_simple_object( get_standard_xml );
+ my $service_list = get_xml_simple_object( get_standard_xml() );
my $council = FixMyStreet::App->model('DB::Open311Conf')->new( {
area_id => 1
@@ -87,7 +87,7 @@ subtest 'check email changed if matching category' => sub {
ok $contact, 'contact created';
- my $service_list = get_xml_simple_object( get_standard_xml );
+ my $service_list = get_xml_simple_object( get_standard_xml() );
my $council = FixMyStreet::App->model('DB::Open311Conf')->new( {
area_id => 1
@@ -124,7 +124,7 @@ subtest 'check category name changed if updated' => sub {
ok $contact, 'contact created';
- my $service_list = get_xml_simple_object( get_standard_xml );
+ my $service_list = get_xml_simple_object( get_standard_xml() );
my $council = FixMyStreet::App->model('DB::Open311Conf')->new( {
area_id => 1
@@ -144,6 +144,65 @@ subtest 'check category name changed if updated' => sub {
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();
+
+ my $contact = FixMyStreet::App->model('DB::Contact')->create(
+ {
+ area_id => 1,
+ email => 'existing@example.com',
+ category => 'Cans left out 24x7',
+ confirmed => 1,
+ deleted => 0,
+ editor => $0,
+ whenedited => \'ms_current_timestamp()',
+ note => 'test contact',
+ }
+ );
+
+ ok $contact, 'contact created';
+
+ my $contact2 = FixMyStreet::App->model('DB::Contact')->create(
+ {
+ area_id => 1,
+ email => '001',
+ category => 'Bins left out 24x7',
+ confirmed => 1,
+ deleted => 0,
+ editor => $0,
+ whenedited => \'ms_current_timestamp()',
+ note => 'test contact',
+ }
+ );
+
+ ok $contact2, 'contact created';
+
+ 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->process_services( $service_list );
+
+ $contact->discard_changes;
+ is $contact->email, 'existing@example.com', 'first contact email unchanged';
+ is $contact->category, 'Cans left out 24x7', 'first contact category unchanged';
+ is $contact->confirmed, 1, 'first contact contact still confirmed';
+ is $contact->deleted, 0, 'first contact contact still not deleted';
+
+ $contact2->discard_changes;
+ is $contact2->email, '001', 'second contact email unchanged';
+ is $contact2->category, 'Bins left out 24x7', 'second contact category unchanged';
+ 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();
+ is $contact_count, 4, 'correct number of contacts';
+};
+
sub get_standard_xml {
return qq{<?xml version="1.0" encoding="utf-8"?>
<services>
n330'>330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372