aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorMatthew Somerville <matthew@mysociety.org>2016-04-26 12:16:26 +0100
committerMatthew Somerville <matthew@mysociety.org>2016-04-26 13:41:18 +0100
commit810759ae13d7dca1b16f36841ca7d364c1738cb5 (patch)
tree64c4691165ed502eb9e2e81584fb2571974edbd1
parent0246627c929f700a46c5065ac1f70fe14aa1ac03 (diff)
Skip fetched updates if they're out of date range.
Even when we ask for a specific range of dates, we sometimes get given more in the response.
-rw-r--r--perllib/Open311/GetServiceRequestUpdates.pm9
-rw-r--r--t/open311/getservicerequestupdates.t13
2 files changed, 14 insertions, 8 deletions
diff --git a/perllib/Open311/GetServiceRequestUpdates.pm b/perllib/Open311/GetServiceRequestUpdates.pm
index 11bc1e64f..daa5fb64d 100644
--- a/perllib/Open311/GetServiceRequestUpdates.pm
+++ b/perllib/Open311/GetServiceRequestUpdates.pm
@@ -89,6 +89,13 @@ sub update_comments {
# what problem it belongs to so just skip
next unless $request_id;
+ my $comment_time = eval {
+ DateTime::Format::W3CDTF->parse_datetime( $request->{updated_datetime} || "" );
+ };
+ next if $@;
+ my $updated = DateTime::Format::W3CDTF->format_datetime($comment_time->clone->set_time_zone('UTC'));
+ next if @args && ($updated lt $args[0] || $updated gt $args[1]);
+
my $problem;
my $criteria = {
external_id => $request_id,
@@ -99,8 +106,6 @@ sub update_comments {
my $c = $p->comments->search( { external_id => $request->{update_id} } );
if ( !$c->first ) {
- my $comment_time = DateTime::Format::W3CDTF->parse_datetime( $request->{updated_datetime} );
-
my $comment = $self->schema->resultset('Comment')->new(
{
problem => $p,
diff --git a/t/open311/getservicerequestupdates.t b/t/open311/getservicerequestupdates.t
index a57d2d0e6..134d5422e 100644
--- a/t/open311/getservicerequestupdates.t
+++ b/t/open311/getservicerequestupdates.t
@@ -38,7 +38,7 @@ UPDATED_DATETIME
};
-my $dt = DateTime->now;
+my $dt = DateTime->now(formatter => DateTime::Format::W3CDTF->new);
# basic xml -> perl object tests
for my $test (
@@ -571,7 +571,8 @@ subtest 'check that existing comments are not duplicated' => sub {
is $problem->comments->count, 1, 'one comment before fetching updates';
$requests_xml =~ s/UPDATED_DATETIME2/$dt/;
- $requests_xml =~ s/UPDATED_DATETIME/@{[ $comment->confirmed ]}/;
+ my $confirmed = DateTime::Format::W3CDTF->format_datetime($comment->confirmed);
+ $requests_xml =~ s/UPDATED_DATETIME/$confirmed/;
my $o = Open311->new( jurisdiction => 'mysociety', endpoint => 'http://example.com', test_mode => 1, test_get_returns => { 'servicerequestupdates.xml' => $requests_xml } );
@@ -596,12 +597,12 @@ subtest 'check that existing comments are not duplicated' => sub {
foreach my $test ( {
desc => 'check that closed and then open comment results in correct state',
- dt1 => $dt->subtract( hours => 1 ),
+ dt1 => $dt->clone->subtract( hours => 1 ),
dt2 => $dt,
},
{
desc => 'check that old comments do not change problem status',
- dt1 => $dt->subtract( hours => 2 ),
+ dt1 => $dt->clone->subtract( minutes => 90 ),
dt2 => $dt,
}
) {
@@ -627,7 +628,7 @@ foreach my $test ( {
$problem->comments->delete;
$problem->state( 'confirmed' );
- $problem->lastupdate( $dt->subtract( hours => 3 ) );
+ $problem->lastupdate( $dt->clone->subtract( hours => 3 ) );
$problem->update;
$requests_xml =~ s/UPDATED_DATETIME/$test->{dt1}/;
@@ -683,7 +684,7 @@ foreach my $test ( {
$problem->comments->delete;
$problem->state( 'confirmed' );
- $problem->lastupdate( $dt->subtract( hours => 3 ) );
+ $problem->lastupdate( $dt->clone->subtract( hours => 3 ) );
$problem->update;
my @alerts = map {