aboutsummaryrefslogtreecommitdiffstats
path: root/t/open311
diff options
context:
space:
mode:
Diffstat (limited to 't/open311')
-rw-r--r--t/open311/endpoint.t27
-rw-r--r--t/open311/endpoint/Endpoint1.pm3
-rw-r--r--t/open311/endpoint/mysociety.t5
-rw-r--r--t/open311/endpoint/spark.t2
-rw-r--r--t/open311/endpoint/warwick.t21
-rw-r--r--t/open311/getservicerequestupdates.t45
-rw-r--r--t/open311/getupdates.t29
-rw-r--r--t/open311/populate-service-list.t46
8 files changed, 105 insertions, 73 deletions
diff --git a/t/open311/endpoint.t b/t/open311/endpoint.t
index 7e684c491..a2a4ea83e 100644
--- a/t/open311/endpoint.t
+++ b/t/open311/endpoint.t
@@ -6,12 +6,11 @@ use Test::MockTime ':all';
use Open311::Endpoint;
use Data::Dumper;
-use JSON;
+use JSON::MaybeXS;
use t::open311::endpoint::Endpoint1;
my $endpoint = t::open311::endpoint::Endpoint1->new;
-my $json = JSON->new;
subtest "GET Service List" => sub {
my $res = $endpoint->run_test_request( GET => '/services.xml' );
@@ -43,7 +42,7 @@ CONTENT
$res = $endpoint->run_test_request( GET => '/services.json' );
ok $res->is_success, 'json success';
- is_deeply $json->decode($res->content),
+ is_deeply decode_json($res->content),
[ {
"keywords" => "deep,hole,wow",
"group" => "highways",
@@ -90,10 +89,6 @@ subtest "GET Service Definition" => sub {
<required>false</required>
<values>
<value>
- <name>Triangle</name>
- <key>triangle</key>
- </value>
- <value>
<name>Circle</name>
<key>circle</key>
</value>
@@ -101,6 +96,10 @@ subtest "GET Service Definition" => sub {
<name>Square</name>
<key>square</key>
</value>
+ <value>
+ <name>Triangle</name>
+ <key>triangle</key>
+ </value>
</values>
<variable>true</variable>
</attribute>
@@ -111,7 +110,7 @@ CONTENT
$res = $endpoint->run_test_request( GET => '/services/POT.json' );
ok $res->is_success, 'json success';
- is_deeply $json->decode($res->content),
+ is_deeply decode_json($res->content),
{
"service_code" => "POT",
"attributes" => [
@@ -134,17 +133,17 @@ CONTENT
"datatype" => "singlevaluelist",
"values" => [
{
- "name" => "Triangle",
- "key" => "triangle"
- },
- {
"name" => "Circle",
"key" => "circle"
},
{
"name" => "Square",
"key" => "square"
- }
+ },
+ {
+ "name" => "Triangle",
+ "key" => "triangle"
+ },
],
}
],
@@ -209,7 +208,7 @@ subtest "POST Service Request valid test" => sub {
ok $res->is_success, 'valid request'
or diag $res->content;
- is_deeply $json->decode($res->content),
+ is_deeply decode_json($res->content),
[ {
"service_notice" => "This is a test service",
"service_request_id" => 0
diff --git a/t/open311/endpoint/Endpoint1.pm b/t/open311/endpoint/Endpoint1.pm
index c4119075c..ae12172b8 100644
--- a/t/open311/endpoint/Endpoint1.pm
+++ b/t/open311/endpoint/Endpoint1.pm
@@ -103,8 +103,7 @@ sub get_service_requests {
my ($self, $args) = @_;
my $service_code = $args->{service_code} or return $self->get_requests;
- # we use ~~ as the service_code arg will be an arrayref like ['POT']
- return $self->filter_requests( sub { shift->service->service_code ~~ $service_code });
+ return $self->filter_requests( sub { my $c = shift->service->service_code; grep { $_ eq $c } @$service_code });
}
sub get_service_request {
diff --git a/t/open311/endpoint/mysociety.t b/t/open311/endpoint/mysociety.t
index c63e03e43..d0ad60602 100644
--- a/t/open311/endpoint/mysociety.t
+++ b/t/open311/endpoint/mysociety.t
@@ -6,12 +6,11 @@ use Test::MockTime ':all';
use Open311::Endpoint;
use Data::Dumper;
-use JSON;
+use JSON::MaybeXS;
use t::open311::endpoint::Endpoint2;
my $endpoint = t::open311::endpoint::Endpoint2->new;
-my $json = JSON->new;
subtest "POST OK" => sub {
diag "Serves as sanity test of subclassing, as well as preparing our data";
@@ -31,7 +30,7 @@ subtest "POST OK" => sub {
ok $res->is_success, 'valid request'
or diag $res->content;
- is_deeply $json->decode($res->content),
+ is_deeply decode_json($res->content),
[ {
"service_notice" => "This is a test service",
"service_request_id" => 0
diff --git a/t/open311/endpoint/spark.t b/t/open311/endpoint/spark.t
index 589f39baf..015876c94 100644
--- a/t/open311/endpoint/spark.t
+++ b/t/open311/endpoint/spark.t
@@ -4,10 +4,8 @@ use Test::More;
use Open311::Endpoint;
use Data::Dumper;
-use JSON;
my $endpoint = Open311::Endpoint->new;
-my $json = JSON->new;
subtest "Spark test" => sub {
my $spark = $endpoint->spark;
diff --git a/t/open311/endpoint/warwick.t b/t/open311/endpoint/warwick.t
index b51c601f3..e5f124c8d 100644
--- a/t/open311/endpoint/warwick.t
+++ b/t/open311/endpoint/warwick.t
@@ -5,9 +5,9 @@ use Test::LongString;
use Test::MockTime ':all';
use Data::Dumper;
-use JSON;
+use JSON::MaybeXS;
-use FixMyStreet::App;
+use FixMyStreet::DB;
use Module::Loaded;
BEGIN { mark_as_loaded('DBD::Oracle') }
@@ -19,7 +19,6 @@ use Open311::PopulateServiceList;
use Open311::GetServiceRequestUpdates;
my $endpoint = t::open311::endpoint::Endpoint_Warwick->new;
-my $json = JSON->new;
subtest "GET Service List" => sub {
my $res = $endpoint->run_test_request( GET => '/services.xml' );
@@ -59,7 +58,7 @@ subtest "POST OK" => sub {
ok $res->is_success, 'valid request'
or diag $res->content;
- is_deeply $json->decode($res->content),
+ is_deeply decode_json($res->content),
[ {
"service_notice" => "Warwickshire Open311 Endpoint",
"service_request_id" => 1001
@@ -141,16 +140,16 @@ subtest "End to end" => sub {
my $WARWICKSHIRE_MAPIT_ID = 2243;
- my $db = FixMyStreet::App->model('DB')->schema;
+ my $db = FixMyStreet::DB->connect;
$db->txn_begin;
- my $body = FixMyStreet::App->model('DB::Body')->find_or_create( {
+ my $body = FixMyStreet::DB->resultset('Body')->find_or_create( {
id => $WARWICKSHIRE_MAPIT_ID,
name => 'Warwickshire County Council',
});
- my $user = FixMyStreet::App->model('DB::User')
+ my $user = FixMyStreet::DB->resultset('User')
->find_or_create( { email => 'test@example.com', name => 'Test User' } );
$body->update({
@@ -175,7 +174,7 @@ subtest "End to end" => sub {
my $bodies = self_rs($body);
- my $p = Open311::PopulateServiceList->new( bodies => $bodies, verbose => 0 );
+ my $p = Open311::PopulateServiceList->new( bodies => $bodies, verbose => 0, schema => $db );
$p->process_bodies;
is $body->contacts->count, 1, 'Categories imported from Open311';
@@ -183,7 +182,7 @@ subtest "End to end" => sub {
set_fixed_time('2014-07-20T15:05:00Z');
- my $problem = FixMyStreet::App->model('DB::Problem')->create({
+ my $problem = FixMyStreet::DB->resultset('Problem')->create({
postcode => 'WC1 1AA',
bodies_str => $WARWICKSHIRE_MAPIT_ID,
areas => ",$WARWICKSHIRE_MAPIT_ID,",
@@ -219,7 +218,7 @@ subtest "End to end" => sub {
# self_rs($problem)->send_reports;
## instead, as we are in a transaction, we'll just delete everything else.
- my $rs = FixMyStreet::App->model('DB::Problem');
+ my $rs = FixMyStreet::DB->resultset('Problem');
$rs->search({ id => { '!=', $problem->id } })->delete;
$rs->send_reports;
};
@@ -242,7 +241,7 @@ subtest "End to end" => sub {
is $problem->state, 'confirmed', 'sanity check status';
- my $updates = Open311::GetServiceRequestUpdates->new( verbose => 1 );
+ my $updates = Open311::GetServiceRequestUpdates->new( verbose => 1, schema => $db );
$updates->fetch;
$problem->discard_changes;
diff --git a/t/open311/getservicerequestupdates.t b/t/open311/getservicerequestupdates.t
index 0ab5b232d..18a5802bb 100644
--- a/t/open311/getservicerequestupdates.t
+++ b/t/open311/getservicerequestupdates.t
@@ -4,23 +4,25 @@ use strict;
use warnings;
use Test::More;
use CGI::Simple;
+use LWP::Protocol::PSGI;
+use t::Mock::Static;
use_ok( 'Open311' );
use_ok( 'Open311::GetServiceRequestUpdates' );
use DateTime;
use DateTime::Format::W3CDTF;
-use FixMyStreet::App;
+use FixMyStreet::DB;
-my $user = FixMyStreet::App->model('DB::User')->find_or_create(
+my $user = FixMyStreet::DB->resultset('User')->find_or_create(
{
email => 'system_user@example.com'
}
);
my %bodies = (
- 2482 => FixMyStreet::App->model("DB::Body")->new({ id => 2482 }),
- 2651 => FixMyStreet::App->model("DB::Body")->new({ id => 2651 }),
+ 2482 => FixMyStreet::DB->resultset("Body")->new({ id => 2482 }),
+ 2651 => FixMyStreet::DB->resultset("Body")->new({ id => 2651 }),
);
my $requests_xml = qq{<?xml version="1.0" encoding="utf-8"?>
@@ -104,7 +106,7 @@ subtest 'check extended request parsed correctly' => sub {
};
-my $problem_rs = FixMyStreet::App->model('DB::Problem');
+my $problem_rs = FixMyStreet::DB->resultset('Problem');
my $problem = $problem_rs->new(
{
postcode => 'EH99 1SP',
@@ -353,7 +355,7 @@ for my $test (
is $problem->comments->count, 1, 'comment count';
$problem->discard_changes;
- my $c = FixMyStreet::App->model('DB::Comment')->search( { external_id => $test->{external_id} } )->first;
+ my $c = FixMyStreet::DB->resultset('Comment')->search( { external_id => $test->{external_id} } )->first;
ok $c, 'comment exists';
is $c->text, $test->{description}, 'text correct';
is $c->mark_fixed, $test->{mark_fixed}, 'mark_closed correct';
@@ -363,6 +365,31 @@ for my $test (
};
}
+subtest 'Update with media_url includes image in update' => sub {
+ my $guard = LWP::Protocol::PSGI->register(t::Mock::Static->to_psgi_app, host => 'example.com');
+
+ my $local_requests_xml = $requests_xml;
+ my $updated_datetime = sprintf( '<updated_datetime>%s</updated_datetime>', $dt );
+ $local_requests_xml =~ s/UPDATED_DATETIME/$updated_datetime/;
+ $local_requests_xml =~ s#<service_request_id>\d+</service_request_id>#
+ <service_request_id>@{[$problem->external_id]}</service_request_id>
+ <media_url>http://example.com/image.jpeg</media_url>#;
+
+ my $o = Open311->new( jurisdiction => 'mysociety', endpoint => 'http://example.com', test_mode => 1, test_get_returns => { 'servicerequestupdates.xml' => $local_requests_xml } );
+
+ $problem->comments->delete;
+ $problem->lastupdate( DateTime->now()->subtract( days => 1 ) );
+ $problem->state('confirmed');
+ $problem->update;
+
+ my $update = Open311::GetServiceRequestUpdates->new( system_user => $user );
+ $update->update_comments( $o, $bodies{2482} );
+
+ is $problem->comments->count, 1, 'comment count';
+ my $c = $problem->comments->first;
+ is $c->external_id, 638344;
+ is $c->photo, '1cdd4329ceee2234bd4e89cb33b42061a0724687', 'photo exists';
+};
foreach my $test (
{
@@ -527,7 +554,7 @@ subtest 'check that existing comments are not duplicated' => sub {
$problem->comments->delete;
- my $comment = FixMyStreet::App->model('DB::Comment')->new(
+ my $comment = FixMyStreet::DB->resultset('Comment')->new(
{
problem => $problem,
external_id => 638344,
@@ -660,7 +687,7 @@ foreach my $test ( {
$problem->update;
my @alerts = map {
- my $alert = FixMyStreet::App->model('DB::Alert')->create( {
+ my $alert = FixMyStreet::DB->resultset('Alert')->create( {
alert_type => 'new_updates',
parameter => $problem->id,
confirmed => 1,
@@ -680,7 +707,7 @@ foreach my $test ( {
$update->update_comments( $o, $bodies{2482} );
$problem->discard_changes;
- my $alerts_sent = FixMyStreet::App->model('DB::AlertSent')->search(
+ my $alerts_sent = FixMyStreet::DB->resultset('AlertSent')->search(
{
alert_id => [ map $_->id, @alerts ],
parameter => $problem->comments->first->id,
diff --git a/t/open311/getupdates.t b/t/open311/getupdates.t
index 7dc7ff164..0e31db482 100644
--- a/t/open311/getupdates.t
+++ b/t/open311/getupdates.t
@@ -3,19 +3,21 @@
use strict;
use warnings;
use Test::More;
+use URI::Split qw(uri_split);
use FixMyStreet;
+use FixMyStreet::DB;
use_ok( 'Open311::GetUpdates' );
use_ok( 'Open311' );
-my $user = FixMyStreet::App->model('DB::User')->find_or_create(
+my $user = FixMyStreet::DB->resultset('User')->find_or_create(
{
email => 'system_user@example.com'
}
);
-my $body = FixMyStreet::App->model('DB::Body')->new( {
+my $body = FixMyStreet::DB->resultset('Body')->new( {
name => 'Test Body',
} );
@@ -42,7 +44,7 @@ UPDATED_DATETIME
</service_requests>
};
-my $problem_rs = FixMyStreet::App->model('DB::Problem');
+my $problem_rs = FixMyStreet::DB->resultset('Problem');
my $problem = $problem_rs->new(
{
postcode => 'EH99 1SP',
@@ -102,8 +104,11 @@ for my $test (
my $o = Open311->new( jurisdiction => 'mysociety', endpoint => 'http://example.com', test_mode => 1, test_get_returns => { 'requests.xml' => $local_requests_xml } );
- ok $updates->update_reports( [ 638344 ], $o, $body );
- is $o->test_uri_used, 'http://example.com/requests.xml?jurisdiction_id=mysociety&service_request_id=638344', 'get url';
+ ok $updates->update_reports( [ 638344 ], $o, $body ), 'Updated reports';
+ my @parts = uri_split($o->test_uri_used);
+ is $parts[2], '/requests.xml', 'path matches';
+ my @qs = sort split '&', $parts[3];
+ is_deeply(\@qs, [ 'jurisdiction_id=mysociety', 'service_request_id=638344' ], 'query string matches');
is $problem->comments->count, $test->{comment_count}, 'added a comment';
};
@@ -177,8 +182,11 @@ subtest 'update with two requests' => sub {
my $o = Open311->new( jurisdiction => 'mysociety', endpoint => 'http://example.com', test_mode => 1, test_get_returns => { 'requests.xml' => $local_requests_xml } );
- ok $updates->update_reports( [ 638344,638345 ], $o, $body );
- is $o->test_uri_used, 'http://example.com/requests.xml?jurisdiction_id=mysociety&service_request_id=638344%2C638345', 'get url';
+ ok $updates->update_reports( [ 638344,638345 ], $o, $body ), 'Updated reports';
+ my @parts = uri_split($o->test_uri_used);
+ is $parts[2], '/requests.xml', 'path matches';
+ my @qs = sort split '&', $parts[3];
+ is_deeply(\@qs, [ 'jurisdiction_id=mysociety', 'service_request_id=638344%2C638345' ], 'query string matches');
is $problem->comments->count, 1, 'added a comment to first problem';
is $problem2->comments->count, 1, 'added a comment to second problem';
@@ -231,9 +239,12 @@ subtest 'test translation of auto-added comment from old-style Open311 update' =
FixMyStreet::override_config {
ALLOWED_COBRANDS => [ 'fixamingata' ],
}, sub {
- ok $updates->update_reports( [ 638346 ], $o, $body );
+ ok $updates->update_reports( [ 638346 ], $o, $body ), 'Updated reports';
};
- is $o->test_uri_used, 'http://example.com/requests.xml?jurisdiction_id=mysociety&service_request_id=638346', 'get url';
+ my @parts = uri_split($o->test_uri_used);
+ is $parts[2], '/requests.xml', 'path matches';
+ my @qs = sort split '&', $parts[3];
+ is_deeply(\@qs, [ 'jurisdiction_id=mysociety', 'service_request_id=638346' ], 'query string matches');
is $problem3->comments->count, 1, 'added a comment';
is $problem3->comments->first->text, "St\xe4ngd av kommunen", 'correct comment text';
diff --git a/t/open311/populate-service-list.t b/t/open311/populate-service-list.t
index 1574732fb..f001926d2 100644
--- a/t/open311/populate-service-list.t
+++ b/t/open311/populate-service-list.t
@@ -4,7 +4,7 @@ use strict;
use warnings;
use Test::More;
-use FixMyStreet::App;
+use FixMyStreet::DB;
use_ok( 'Open311::PopulateServiceList' );
use_ok( 'Open311' );
@@ -13,7 +13,7 @@ use_ok( 'Open311' );
my $processor = Open311::PopulateServiceList->new();
ok $processor, 'created object';
-my $body = FixMyStreet::App->model('DB::Body')->find_or_create( {
+my $body = FixMyStreet::DB->resultset('Body')->find_or_create( {
id => 1,
name => 'Body Numero Uno',
} );
@@ -22,7 +22,7 @@ $body->body_areas->find_or_create({
} );
my $BROMLEY = 'Bromley Council';
-my $bromley = FixMyStreet::App->model('DB::Body')->find_or_create( {
+my $bromley = FixMyStreet::DB->resultset('Body')->find_or_create( {
id => 2482,
name => $BROMLEY,
} );
@@ -32,7 +32,7 @@ $bromley->body_areas->find_or_create({
} );
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() );
@@ -40,14 +40,14 @@ subtest 'check basic functionality' => sub {
$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',
@@ -66,17 +66,17 @@ subtest 'check non open311 contacts marked as deleted' => sub {
$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',
@@ -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',
@@ -136,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',
@@ -158,7 +158,7 @@ subtest 'check conflicting contacts not changed' => sub {
ok $contact, 'contact created';
- my $contact2 = FixMyStreet::App->model('DB::Contact')->create(
+ my $contact2 = FixMyStreet::DB->resultset('Contact')->create(
{
body_id => 1,
email => '001',
@@ -191,7 +191,7 @@ 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';
};
@@ -215,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',
@@ -395,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',
@@ -470,7 +470,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',
@@ -572,7 +572,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',