aboutsummaryrefslogtreecommitdiffstats
path: root/t/open311
diff options
context:
space:
mode:
Diffstat (limited to 't/open311')
-rw-r--r--t/open311/getservicerequests.t107
-rw-r--r--t/open311/populate-service-list.t101
2 files changed, 208 insertions, 0 deletions
diff --git a/t/open311/getservicerequests.t b/t/open311/getservicerequests.t
index 55bb9ba11..c44be5099 100644
--- a/t/open311/getservicerequests.t
+++ b/t/open311/getservicerequests.t
@@ -17,6 +17,9 @@ my $contact = $mech->create_contact_ok( body_id => $body->id, category => 'Sidew
my $body2 = $mech->create_body_ok(2217, 'Buckinghamshire');
my $contact2 = $mech->create_contact_ok( body_id => $body2->id, category => 'Sidewalk and Curb Issues', email => 'sidewalks' );
+my $hounslow = $mech->create_body_ok(2483, 'Hounslow');
+my $hounslowcontact = $mech->create_contact_ok( body_id => $hounslow->id, category => 'Sidewalk and Curb Issues', email => 'sidewalks' );
+
my $dtf = DateTime::Format::W3CDTF->new;
my $requests_xml = qq{<?xml version="1.0" encoding="utf-8"?>
@@ -469,6 +472,110 @@ for my $test (
};
}
+my $hounslow_non_public_xml = qq[<?xml version="1.0" encoding="utf-8"?>
+<service_requests>
+<request>
+<service_request_id>123456</service_request_id>
+<status>open</status>
+<status_notes></status_notes>
+<service_name>Sidewalk and Curb Issues</service_name>
+<service_code>sidewalks</service_code>
+<description>this is a problem</description>
+<agency_responsible></agency_responsible>
+<service_notice></service_notice>
+<requested_datetime>2010-04-14T06:37:38-08:00</requested_datetime>
+<updated_datetime>2010-04-14T06:37:38-08:00</updated_datetime>
+<expected_datetime>2010-04-15T06:37:38-08:00</expected_datetime>
+<lat>51.482286</lat>
+<long>-0.328163</long>
+<non_public>1</non_public>
+</request>
+</service_requests>
+];
+
+for my $test (
+ {
+ desc => 'Hounslow non_public reports not created',
+ non_public => 1,
+ count => 0,
+ },
+ {
+ desc => 'Hounslow public reports are created',
+ non_public => 0,
+ count => 1,
+ },
+) {
+ subtest $test->{desc} => sub {
+ (my $xml = $hounslow_non_public_xml) =~ s/non_public>1/non_public>$test->{non_public}/;
+
+ my $o = Open311->new(
+ jurisdiction => 'mysociety',
+ endpoint => 'http://example.com',
+ test_mode => 1,
+ test_get_returns => { 'requests.xml' => $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/',
+ ALLOWED_COBRANDS => [ 'hounslow' ],
+ }, sub {
+ $update->create_problems( $o, $hounslow );
+ };
+
+ my $q = FixMyStreet::DB->resultset('Problem')->search(
+ { external_id => 123456 }
+ );
+
+ is $q->count, $test->{count}, 'problem count is correct';
+
+ $q->first->delete if $test->{count};
+ };
+}
+
+subtest "non_public contacts result in non_public reports" => sub {
+
+ $contact->update({
+ non_public => 1
+ });
+ 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 }
+ )->first;
+
+ ok $p, 'problem created';
+ is $p->non_public, 1, "report non_public is set correctly";
+
+ $p->delete;
+ $contact->update({
+ non_public => 0
+ });
+
+};
+
for my $test (
{
test_desc => 'filters out phone numbers',
diff --git a/t/open311/populate-service-list.t b/t/open311/populate-service-list.t
index ff4c4cf9d..c67fae9bd 100644
--- a/t/open311/populate-service-list.t
+++ b/t/open311/populate-service-list.t
@@ -225,6 +225,107 @@ subtest 'check conflicting contacts not changed' => sub {
is $contact_count, 4, 'correct number of contacts';
};
+subtest 'check new category marked non_public' => sub {
+ FixMyStreet::DB->resultset('Contact')->search( { body_id => $body->id } )->delete();
+
+ my $services_xml = '<?xml version="1.0" encoding="utf-8"?>
+ <services>
+ <service>
+ <service_code>100</service_code>
+ <service_name>Cans left out 24x7</service_name>
+ <description>Garbage or recycling cans that have been left out for more than 24 hours after collection. Violators will be cited.</description>
+ <metadata>false</metadata>
+ <type>realtime</type>
+ <keywords>private</keywords>
+ <group>sanitation</group>
+ </service>
+ </services>
+ ';
+
+ my $service_list = get_xml_simple_object( $services_xml );
+
+ 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, 1, 'correct number of contacts';
+
+ my $contact = FixMyStreet::DB->resultset('Contact')->search( { body_id => $body->id } )->first;
+ is $contact->email, '100', 'email correct';
+ is $contact->category, 'Cans left out 24x7', 'category correct';
+ is $contact->non_public, 1, 'contact marked as non_public';
+};
+
+subtest 'check existing category marked non_public' => sub {
+ my $contact = FixMyStreet::DB->resultset('Contact')->search( { body_id => $body->id } )->first;
+ $contact->update({
+ non_public => 0
+ });
+ is $contact->non_public, 0, 'contact not marked as non_public';
+
+ my $services_xml = '<?xml version="1.0" encoding="utf-8"?>
+ <services>
+ <service>
+ <service_code>100</service_code>
+ <service_name>Cans left out 24x7</service_name>
+ <description>Garbage or recycling cans that have been left out for more than 24 hours after collection. Violators will be cited.</description>
+ <metadata>false</metadata>
+ <type>realtime</type>
+ <keywords>private</keywords>
+ <group>sanitation</group>
+ </service>
+ </services>
+ ';
+
+ my $service_list = get_xml_simple_object( $services_xml );
+
+ 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, 1, 'correct number of contacts';
+
+ $contact->discard_changes;
+ is $contact->email, '100', 'email correct';
+ is $contact->category, 'Cans left out 24x7', 'category correct';
+ is $contact->non_public, 1, 'contact changed to non_public';
+};
+
+subtest 'check existing non_public category does not get marked public' => sub {
+ my $contact = FixMyStreet::DB->resultset('Contact')->search( { body_id => $body->id } )->first;
+ is $contact->non_public, 1, 'contact marked as non_public';
+
+ my $services_xml = '<?xml version="1.0" encoding="utf-8"?>
+ <services>
+ <service>
+ <service_code>100</service_code>
+ <service_name>Cans left out 24x7</service_name>
+ <description>Garbage or recycling cans that have been left out for more than 24 hours after collection. Violators will be cited.</description>
+ <metadata>false</metadata>
+ <type>realtime</type>
+ <keywords></keywords>
+ <group>sanitation</group>
+ </service>
+ </services>
+ ';
+
+ my $service_list = get_xml_simple_object( $services_xml );
+
+ 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, 1, 'correct number of contacts';
+
+ $contact->discard_changes;
+ is $contact->email, '100', 'email correct';
+ is $contact->category, 'Cans left out 24x7', 'category correct';
+ is $contact->non_public, 1, 'contact remains non_public';
+};
+
for my $test (
{
desc => 'check meta data added to existing contact',