aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorStruan Donald <struan@exo.org.uk>2012-04-27 18:29:58 +0100
committerStruan Donald <struan@exo.org.uk>2012-04-27 18:29:58 +0100
commit7ed720d5c1b40466a21eb9a383bb8ae1b0bf1888 (patch)
tree61e0c15ff16e21296d29375ca866a203d34e76d0
parent57440ef98d69e156832653c536422f129cb71b9d (diff)
tests for ignoring old comment state and related fixes
-rw-r--r--perllib/Open311/GetServiceRequestUpdates.pm6
-rw-r--r--t/open311/getservicerequestupdates.t57
2 files changed, 60 insertions, 3 deletions
diff --git a/perllib/Open311/GetServiceRequestUpdates.pm b/perllib/Open311/GetServiceRequestUpdates.pm
index 28c7140ed..b423bbeb3 100644
--- a/perllib/Open311/GetServiceRequestUpdates.pm
+++ b/perllib/Open311/GetServiceRequestUpdates.pm
@@ -93,16 +93,16 @@ sub update_comments {
# if the comment is older than the last update
# do not change the status of the problem as it's
# tricky to determine the right thing to do.
- if ( $comment->created > $p->lastupdate ) {
+ if ( $comment->created_local > $p->lastupdate_local ) {
if ( $p->is_open and lc($request->{status}) eq 'closed' ) {
$p->state( 'fixed - council' );
- $p->last_update( $comment->created );
+ $p->lastupdate( $comment->created );
$p->update;
$comment->mark_fixed( 1 );
} elsif ( ( $p->is_closed || $p->is_fixed ) and lc($request->{status}) eq 'open' ) {
$p->state( 'confirmed' );
- $p->last_update( $comment->created );
+ $p->lastupdate( $comment->created );
$p->update;
$comment->mark_open( 1 );
diff --git a/t/open311/getservicerequestupdates.t b/t/open311/getservicerequestupdates.t
index 063d7e378..062a9e2f1 100644
--- a/t/open311/getservicerequestupdates.t
+++ b/t/open311/getservicerequestupdates.t
@@ -170,6 +170,7 @@ for my $test (
my $o = Open311->new( jurisdiction => 'mysociety', endpoint => 'http://example.com', test_mode => 1, test_get_returns => { 'update.xml' => $local_requests_xml } );
$problem->comments->delete;
+ $problem->lastupdate( DateTime->now()->subtract( days => 1 ) );
$problem->state( $test->{start_state} );
$problem->update;
@@ -398,6 +399,62 @@ subtest 'check that existing comments are not duplicated' => sub {
is $problem->comments->count, 2, 'if comments are deleted then they are added';
};
+foreach my $test ( {
+ desc => 'check that closed and then open comment results in correct state',
+ dt1 => $dt->subtract( hours => 1 ),
+ dt2 => $dt,
+ },
+ {
+ desc => 'check that old comments do not change problem status',
+ dt1 => $dt->subtract( hours => 2 ),
+ dt2 => $dt,
+ }
+) {
+ subtest $test->{desc} => sub {
+ my $requests_xml = qq{<?xml version="1.0" encoding="utf-8"?>
+ <service_requests_updates>
+ <request_update>
+ <update_id>638344</update_id>
+ <service_request_id>@{[ $problem->external_id ]}</service_request_id>
+ <service_request_id_ext>@{[ $problem->id ]}</service_request_id_ext>
+ <status>closed</status>
+ <description>This is a note</description>
+ <updated_datetime>UPDATED_DATETIME</updated_datetime>
+ </request_update>
+ <request_update>
+ <update_id>638354</update_id>
+ <service_request_id>@{[ $problem->external_id ]}</service_request_id>
+ <service_request_id_ext>@{[ $problem->id ]}</service_request_id_ext>
+ <status>open</status>
+ <description>This is a different note</description>
+ <updated_datetime>UPDATED_DATETIME2</updated_datetime>
+ </request_update>
+ </service_requests_updates>
+ };
+
+ $problem->comments->delete;
+ $problem->state( 'confirmed' );
+ $problem->lastupdate( $dt->subtract( hours => 3 ) );
+ $problem->update;
+
+ $requests_xml =~ s/UPDATED_DATETIME/$test->{dt1}/;
+ $requests_xml =~ s/UPDATED_DATETIME2/$test->{dt2}/;
+
+ my $o = Open311->new( jurisdiction => 'mysociety', endpoint => 'http://example.com', test_mode => 1, test_get_returns => { 'update.xml' => $requests_xml } );
+
+ my $update = Open311::GetServiceRequestUpdates->new(
+ system_user => $user,
+ );
+
+ my $council_details = { areaid => 2482 };
+ $update->update_comments( $o, $council_details );
+
+ $problem->discard_changes;
+ is $problem->comments->count, 2, 'two comments after fetching updates';
+ is $problem->state, 'confirmed', 'correct problem status';
+ };
+}
+
$problem2->comments->delete();
$problem->comments->delete();
$problem2->delete;