aboutsummaryrefslogtreecommitdiffstats
path: root/t/open311
diff options
context:
space:
mode:
Diffstat (limited to 't/open311')
-rw-r--r--t/open311/endpoint/mysociety.t12
-rw-r--r--t/open311/endpoint/warwick.t140
-rw-r--r--t/open311/populate-service-list.t4
3 files changed, 147 insertions, 9 deletions
diff --git a/t/open311/endpoint/mysociety.t b/t/open311/endpoint/mysociety.t
index ea4f72820..c63e03e43 100644
--- a/t/open311/endpoint/mysociety.t
+++ b/t/open311/endpoint/mysociety.t
@@ -64,36 +64,36 @@ CONTENT
my $update_0_xml = <<CONTENT;
<?xml version="1.0" encoding="utf-8"?>
<service_request_updates>
- <request_updates>
+ <request_update>
<description>Fixed</description>
<media_url></media_url>
<service_request_id>0</service_request_id>
<status>closed</status>
<update_id>1</update_id>
<updated_datetime>2014-01-01T13:00:00Z</updated_datetime>
- </request_updates>
+ </request_update>
</service_request_updates>
CONTENT
my $updates_xml = <<CONTENT;
<?xml version="1.0" encoding="utf-8"?>
<service_request_updates>
- <request_updates>
+ <request_update>
<description>Fixed</description>
<media_url></media_url>
<service_request_id>0</service_request_id>
<status>closed</status>
<update_id>1</update_id>
<updated_datetime>2014-01-01T13:00:00Z</updated_datetime>
- </request_updates>
- <request_updates>
+ </request_update>
+ <request_update>
<description>Have investigated. Looks tricky!</description>
<media_url></media_url>
<service_request_id>1</service_request_id>
<status>open</status>
<update_id>2</update_id>
<updated_datetime>2014-03-01T13:00:00Z</updated_datetime>
- </request_updates>
+ </request_update>
</service_request_updates>
CONTENT
diff --git a/t/open311/endpoint/warwick.t b/t/open311/endpoint/warwick.t
index 7021a37d7..8d0b7284b 100644
--- a/t/open311/endpoint/warwick.t
+++ b/t/open311/endpoint/warwick.t
@@ -7,7 +7,11 @@ use Test::MockTime ':all';
use Data::Dumper;
use JSON;
+use FixMyStreet::App;
use t::open311::endpoint::Endpoint_Warwick;
+use LWP::Protocol::PSGI;
+use Open311::PopulateServiceList;
+use Open311::GetServiceRequestUpdates;
my $endpoint = t::open311::endpoint::Endpoint_Warwick->new;
my $json = JSON->new;
@@ -257,14 +261,14 @@ subtest 'updates' => sub {
my $expected = <<XML;
<?xml version="1.0" encoding="utf-8"?>
<service_request_updates>
- <request_updates>
+ <request_update>
<description>Closed the ticket</description>
<media_url></media_url>
<service_request_id>1001</service_request_id>
<status>closed</status>
<update_id>999</update_id>
<updated_datetime>2014-07-23T11:07:00+01:00</updated_datetime>
- </request_updates>
+ </request_update>
</service_request_updates>
XML
@@ -287,5 +291,137 @@ SQL
is_string $t::open311::endpoint::Endpoint_Warwick::UPDATES_SQL, $expected_sql, 'SQL as expected';
};
+subtest "End to end" => sub {
+
+ # We create and instance of the endpoint as a PSGI app
+ # And then bind it to the dummy URL. This mocks that whole hostname, so that FMS's
+ # calls via Open311.pm are rerouted to our PSGI app.
+ # (This saves us all the faff of having to launch and manage a new server process
+ # for this test)
+
+ my $endpoint_psgi = t::open311::endpoint::Endpoint_Warwick->run_if_script;
+
+ my $ENDPOINT = 'open311.warwickshire.gov.uk';
+ LWP::Protocol::PSGI->register($endpoint_psgi, host => $ENDPOINT);
+
+ my $WARWICKSHIRE_MAPIT_ID = 2243;
+
+ my $db = FixMyStreet::App->model('DB')->schema;
+
+ $db->txn_begin;
+
+ my $body = FixMyStreet::App->model('DB::Body')->find_or_create( {
+ id => $WARWICKSHIRE_MAPIT_ID,
+ name => 'Warwickshire County Council',
+ });
+
+ my $user = FixMyStreet::App->model('DB::User')
+ ->find_or_create( { email => 'test@example.com', name => 'Test User' } );
+
+ $body->update({
+ jurisdiction => 'wcc',
+ endpoint => "http://$ENDPOINT",
+ api_key => 'SEEKRIT',
+ send_method => 'Open311',
+ send_comments => 1,
+ comment_user_id => $user->id,
+ });
+
+ $body->body_areas->find_or_create({
+ area_id => $WARWICKSHIRE_MAPIT_ID
+ } );
+
+ subtest "Populate service list" => sub {
+ # as per bin/open311-populate-service-list
+
+ $body->contacts->delete;
+
+ is $body->contacts->count, 0, 'sanity check';
+
+ my $bodies = self_rs($body);
+
+ my $p = Open311::PopulateServiceList->new( bodies => $bodies, verbose => 0 );
+ $p->process_bodies;
+
+ is $body->contacts->count, 19, 'Categories imported from Open311';
+ };
+
+ set_fixed_time('2014-07-20T15:05:00Z');
+
+ my $problem = FixMyStreet::App->model('DB::Problem')->create({
+ postcode => 'WC1 1AA',
+ bodies_str => $WARWICKSHIRE_MAPIT_ID,
+ areas => ",$WARWICKSHIRE_MAPIT_ID,",
+ category => 'Pothole',
+ title => 'Testing',
+ detail => 'Testing Detail',
+ used_map => 1,
+ name => 'Joe Bloggs',
+ anonymous => 0,
+ state => 'confirmed',
+ confirmed => '2014-07-20 15:00:00',
+ lastupdate => '2014-07-20 15:00:00',
+ lang => 'en-gb',
+ service => '',
+ cobrand => 'fixmystreet', # e.g. UK
+ cobrand_data => '',
+ send_questionnaire => 0,
+ latitude => '52.2804',
+ longitude => '-1.5897',
+ user_id => $user->id,
+ });
+
+ subtest "Send report" => sub {
+ # as per bin/send-reports
+
+ FixMyStreet::override_config {
+ ALLOWED_COBRANDS => [ 'fixmystreet' ],
+ SEND_REPORTS_ON_STAGING => 1,
+ }, sub {
+ self_rs($problem)->send_reports;
+ };
+ $problem->discard_changes;
+
+ # Our test endpoint returns a hardcoded external ID.
+ ok $problem->whensent, 'whensent has been set';
+ is $problem->external_id, 1001, 'External ID set correctly'
+ or die;
+ };
+
+ subtest "Send update" => sub {
+ # as per bin/send-reports
+
+ $problem->update({ lastupdate => '2014-07-20 15:05:00' }); # override
+
+ set_fixed_time('2014-07-23T11:07:00Z');
+
+ is $problem->comments->count, 0, 'sanity check update count';
+ is $problem->state, 'confirmed', 'sanity check status';
+
+
+ my $updates = Open311::GetServiceRequestUpdates->new( verbose => 1 );
+ $updates->fetch;
+
+ $problem->discard_changes;
+ is $problem->comments->count, 1, 'comment has been added';
+
+
+ my $update = $problem->comments->single;
+ is $update->user_id, $user->id, 'update user correct';
+ is $update->state, 'confirmed', 'update itself is confirmed';
+
+ is $update->problem_state, 'fixed - council', 'update marked problem as closed';
+ is $problem->state, 'fixed - council', 'has been closed';
+ };
+
+ $db->txn_rollback;
+};
+
restore_time();
done_testing;
+
+sub self_rs {
+ my ($row) = @_;
+ # create a result-set with just this body (see also DBIx::Class::Helper::Row::SelfResultSet)
+ return $row->result_source->resultset->search( $row->ident_condition );
+}
diff --git a/t/open311/populate-service-list.t b/t/open311/populate-service-list.t
index 9fd18b607..d9d65945b 100644
--- a/t/open311/populate-service-list.t
+++ b/t/open311/populate-service-list.t
@@ -25,10 +25,12 @@ $body->body_areas->find_or_create({
area_id => 1
} );
+my $BROMLEY = 'Bromley Council';
my $bromley = FixMyStreet::App->model('DB::Body')->find_or_create( {
id => 2482,
- name => 'Bromley Council',
+ name => $BROMLEY,
} );
+$bromley->update({ name => $BROMLEY });
$bromley->body_areas->find_or_create({
area_id => 2482
} );