aboutsummaryrefslogtreecommitdiffstats
path: root/t
diff options
context:
space:
mode:
Diffstat (limited to 't')
-rw-r--r--t/Mock/MapIt.pm1
-rw-r--r--t/app/controller/around.t10
-rw-r--r--t/app/controller/report_new.t14
-rw-r--r--t/map/tests.t1
-rw-r--r--t/open311.t66
-rw-r--r--t/open311/getservicerequests.t107
-rw-r--r--t/open311/populate-service-list.t101
7 files changed, 294 insertions, 6 deletions
diff --git a/t/Mock/MapIt.pm b/t/Mock/MapIt.pm
index 7429d9731..c255c916a 100644
--- a/t/Mock/MapIt.pm
+++ b/t/Mock/MapIt.pm
@@ -39,6 +39,7 @@ my @PLACES = (
[ 'BR1 3UH', 51.402096, 0.015784, 2482, 'Bromley Council', 'LBO' ],
[ 'NN1 1NS', 52.236251, 0.892052, 2234, 'Northamptonshire County Council', 'CTY', 2397, 'Northampton Borough Council', 'DIS' ],
[ 'NN1 2NS', 52.238301, 0.889992, 2234, 'Northamptonshire County Council', 'CTY', 2397, 'Northampton Borough Council', 'DIS' ],
+ [ 'TW7 5JN', 51.482286, -0.328163, 2483, 'Hounslow Borough Council', 'LBO' ],
[ '?', 50.78301, -0.646929 ],
[ 'TA1 1QP', 51.023569, -3.099055, 2239, 'Somerset County Council', 'CTY', 2429, 'Taunton Deane Borough Council', 'DIS' ],
[ 'GU51 4AE', 51.279456, -0.846216, 2333, 'Hart District Council', 'DIS', 2227, 'Hampshire County Council', 'CTY' ],
diff --git a/t/app/controller/around.t b/t/app/controller/around.t
index 5ef37f197..829d78ca3 100644
--- a/t/app/controller/around.t
+++ b/t/app/controller/around.t
@@ -100,6 +100,16 @@ subtest 'check lookup by reference' => sub {
is $mech->uri->path, "/report/$id", "redirected to report page";
};
+subtest 'check lookup by reference does not show non_public reports' => sub {
+ $edinburgh_problems[0]->update({
+ non_public => 1
+ });
+ my $id = $edinburgh_problems[0]->id;
+ $mech->get_ok('/');
+ $mech->submit_form_ok( { with_fields => { pc => "ref:$id" } }, 'non_public ref');
+ $mech->content_contains('Searching found no reports');
+};
+
subtest 'check non public reports are not displayed on around page' => sub {
$mech->get_ok('/');
FixMyStreet::override_config {
diff --git a/t/app/controller/report_new.t b/t/app/controller/report_new.t
index ae6f760d8..d13f9d9ea 100644
--- a/t/app/controller/report_new.t
+++ b/t/app/controller/report_new.t
@@ -52,6 +52,7 @@ for my $body (
{ area_id => 2237, name => 'Oxfordshire County Council' },
{ area_id => 2600, name => 'Rutland County Council' },
{ area_id => 2234, name => 'Northamptonshire County Council' },
+ { area_id => 2483, name => 'Hounslow Borough Council' },
) {
my $body_obj = $mech->create_body_ok($body->{area_id}, $body->{name});
push @bodies, $body_obj;
@@ -139,6 +140,11 @@ my $contact16 = $mech->create_contact_ok(
category => 'Trees',
email => 'trees-2234@example.com',
);
+my $contact17 = $mech->create_contact_ok(
+ body_id => $body_ids{2483}, # Hounslow
+ category => 'Trees',
+ email => 'trees-2483@example.com',
+);
# test that the various bit of form get filled in and errors correctly
# generated.
@@ -1387,6 +1393,14 @@ subtest "check map click ajax response" => sub {
is $extra_details->{category}, '', 'category is empty for council with no contacts';
is_deeply $extra_details->{bodies}, [ "Sandwell Borough Council" ], 'correct bodies for council with no contacts';
ok !$extra_details->{extra_name_info}, 'no extra name info';
+
+ FixMyStreet::override_config {
+ ALLOWED_COBRANDS => 'hounslow',
+ MAPIT_URL => 'http://mapit.uk/',
+ }, sub {
+ $extra_details = $mech->get_ok_json( '/report/new/ajax?latitude=51.482286&longitude=-0.328163' );
+ };
+ is_deeply $extra_details->{display_names}, { 'Hounslow Borough Council' => 'Hounslow Highways' }, 'council display name mapping correct';
};
#### test uploading an image
diff --git a/t/map/tests.t b/t/map/tests.t
index 7cc8f6860..692cf6790 100644
--- a/t/map/tests.t
+++ b/t/map/tests.t
@@ -11,6 +11,7 @@ my $requires = {
'FMS' => 'map-fms.js',
'Google' => 'map-google.js',
'GoogleOL' => 'map-google-ol.js',
+ 'Hounslow' => 'hounslow/assets.js',
'OSM' => 'OpenStreetMap.js',
'CycleMap' => 'OpenStreetMap.js',
'MapQuest' => 'OpenStreetMap.js',
diff --git a/t/open311.t b/t/open311.t
index 85176ff0d..73bb488d5 100644
--- a/t/open311.t
+++ b/t/open311.t
@@ -302,14 +302,14 @@ subtest 'basic request update post parameters' => sub {
my $c = CGI::Simple->new( $results->{ req }->content );
- is $c->param('description'), 'this is a comment', 'email correct';
+ is $c->param('description'), 'this is a comment', 'description correct';
is $c->param('email'), 'test@example.com', 'email correct';
is $c->param('status'), 'OPEN', 'status correct';
is $c->param('service_request_id'), 81, 'request id correct';
is $c->param('updated_datetime'), DateTime::Format::W3CDTF->format_datetime($dt), 'correct date';
is $c->param('title'), 'Mr', 'correct title';
- is $c->param('last_name'), 'User', 'correct first name';
- is $c->param('first_name'), 'Test', 'correct second name';
+ is $c->param('first_name'), 'Test', 'correct first name';
+ is $c->param('last_name'), 'User', 'correct second name';
is $c->param('media_url'), undef, 'no media url';
};
@@ -326,7 +326,7 @@ subtest 'extended request update post parameters' => sub {
my $c = CGI::Simple->new( $results->{ req }->content );
- is $c->param('description'), 'this is a comment', 'email correct';
+ is $c->param('description'), 'this is a comment', 'description correct';
is $c->param('email'), 'test@example.com', 'email correct';
is $c->param('status'), 'OPEN', 'status correct';
is $c->param('service_request_id_ext'), 80, 'external request id correct';
@@ -334,12 +334,66 @@ subtest 'extended request update post parameters' => sub {
is $c->param('public_anonymity_required'), 'FALSE', 'anon status correct';
is $c->param('updated_datetime'), DateTime::Format::W3CDTF->format_datetime($dt), 'correct date';
is $c->param('title'), 'Mr', 'correct title';
- is $c->param('last_name'), 'User', 'correct first name';
- is $c->param('first_name'), 'Test', 'correct second name';
+ is $c->param('first_name'), 'Test', 'correct first name';
+ is $c->param('last_name'), 'User', 'correct second name';
is $c->param('email_alerts_requested'), 'FALSE', 'email alerts flag correct';
is $c->param('media_url'), undef, 'no media url';
};
+subtest 'Hounslow update description is correct for same user' => sub {
+ my $comment = make_comment('hounslow');
+ my $results;
+ FixMyStreet::override_config {
+ ALLOWED_COBRANDS => 'hounslow',
+ }, sub {
+ $results = make_update_req( $comment, '<?xml version="1.0" encoding="utf-8"?><service_request_updates><request_update><update_id>248</update_id></request_update></service_request_updates>' );
+ };
+
+ is $results->{ res }, 248, 'got update id';
+
+ my $c = CGI::Simple->new( $results->{ req }->content );
+
+ is $c->param('description'), 'this is a comment', 'description correct';
+ is $c->param('email'), 'test@example.com', 'email correct';
+ is $c->param('status'), 'OPEN', 'status correct';
+ is $c->param('service_request_id'), 81, 'request id correct';
+ is $c->param('updated_datetime'), DateTime::Format::W3CDTF->format_datetime($dt), 'correct date';
+ is $c->param('title'), 'Mr', 'correct title';
+ is $c->param('first_name'), 'Test', 'correct first name';
+ is $c->param('last_name'), 'User', 'correct second name';
+ is $c->param('media_url'), undef, 'no media url';
+};
+
+subtest 'Hounslow update description is correct for a different user' => sub {
+ my $user2 = FixMyStreet::DB->resultset('User')->new( {
+ name => 'Another User',
+ email => 'another@example.org',
+ } );
+
+ my $comment = make_comment('hounslow');
+ $comment->user($user2);
+ my $results;
+ FixMyStreet::override_config {
+ ALLOWED_COBRANDS => 'hounslow',
+ }, sub {
+ $results = make_update_req( $comment, '<?xml version="1.0" encoding="utf-8"?><service_request_updates><request_update><update_id>248</update_id></request_update></service_request_updates>' );
+ };
+
+ is $results->{ res }, 248, 'got update id';
+
+ my $c = CGI::Simple->new( $results->{ req }->content );
+
+ is $c->param('description'), "[This comment was not left by the original problem reporter] this is a comment", 'description correct';
+ is $c->param('email'), 'another@example.org', 'email correct';
+ is $c->param('status'), 'OPEN', 'status correct';
+ is $c->param('service_request_id'), 81, 'request id correct';
+ is $c->param('updated_datetime'), DateTime::Format::W3CDTF->format_datetime($dt), 'correct date';
+ is $c->param('title'), 'Mr', 'correct title';
+ is $c->param('first_name'), 'Another', 'correct first name';
+ is $c->param('last_name'), 'User', 'correct second name';
+ is $c->param('media_url'), undef, 'no media url';
+};
+
subtest 'check media url set' => sub {
my $UPLOAD_DIR = tempdir( CLEANUP => 1 );
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',