aboutsummaryrefslogtreecommitdiffstats
path: root/t/open311/getservicerequestupdates.t
diff options
context:
space:
mode:
Diffstat (limited to 't/open311/getservicerequestupdates.t')
-rw-r--r--t/open311/getservicerequestupdates.t45
1 files changed, 36 insertions, 9 deletions
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,