diff options
author | Struan Donald <struan@exo.org.uk> | 2012-11-22 19:26:18 +0000 |
---|---|---|
committer | Struan Donald <struan@exo.org.uk> | 2012-11-22 19:29:01 +0000 |
commit | bacba6c39090cbd6dfbca7f89303480e1dcc742a (patch) | |
tree | e74e20d7b86fa91b86aee116fe522fcb527c5393 | |
parent | 0492b90bdb2a4666f85cdab3d8f636910bbe40c1 (diff) |
use the problem_state of the comment to set the update state rather
than the state of the problem in case a second update has changed the
problem state since. On the of chance that there is no problem_state
for the comment then fall back to the state of the problem
-rw-r--r-- | perllib/Open311.pm | 23 | ||||
-rw-r--r-- | t/open311.t | 55 |
2 files changed, 69 insertions, 9 deletions
diff --git a/perllib/Open311.pm b/perllib/Open311.pm index 34a9b1bfb..a34677a38 100644 --- a/perllib/Open311.pm +++ b/perllib/Open311.pm @@ -275,26 +275,31 @@ sub _populate_service_request_update_params { my $name = $comment->name || $comment->user->name; my ( $firstname, $lastname ) = ( $name =~ /(\w+)\.?\s+(.+)/ ); + # fall back to problem state as it's probably correct + my $state = $comment->problem_state || $comment->problem->state; + my $status = 'OPEN'; if ( $self->extended_statuses ) { - if ( $comment->problem->is_fixed ) { + if ( FixMyStreet::DB::Result::Problem->fixed_states()->{$state} ) { $status = 'FIXED'; - } elsif ( $comment->problem->state eq 'in progress' ) { + } elsif ( $state eq 'in progress' ) { $status = 'IN_PROGRESS'; - } elsif ($comment->problem->state eq 'action scheduled' - || $comment->problem->state eq 'planned' ) { + } elsif ($state eq 'action scheduled' + || $state eq 'planned' ) { $status = 'ACTION_SCHEDULED'; - } elsif ( $comment->problem->state eq 'investigating' ) { + } elsif ( $state eq 'investigating' ) { $status = 'INVESTIGATING'; - } elsif ( $comment->problem->state eq 'duplicate' ) { + } elsif ( $state eq 'duplicate' ) { $status = 'DUPLICATE'; - } elsif ( $comment->problem->state eq 'not responsible' ) { + } elsif ( $state eq 'not responsible' ) { $status = 'NOT_COUNCILS_RESPONSIBILITY'; - } elsif ( $comment->problem->state eq 'unable to fix' ) { + } elsif ( $state eq 'unable to fix' ) { $status = 'NO_FURTHER_ACTION'; } } else { - $status = $comment->problem->is_open ? 'OPEN' : 'CLOSED',; + if ( !FixMyStreet::DB::Result::Problem->open_states()->{$state} ) { + $status = 'CLOSED'; + } } my $params = { diff --git a/t/open311.t b/t/open311.t index e897d3524..f9315982d 100644 --- a/t/open311.t +++ b/t/open311.t @@ -191,6 +191,7 @@ my $comment = FixMyStreet::App->model('DB::Comment')->new( { anonymous => 0, text => 'this is a comment', confirmed => $dt, + problem_state => 'confirmed', extra => { title => 'Mr', email_alerts_requested => 0 }, } ); @@ -317,6 +318,7 @@ foreach my $test ( }, ) { subtest $test->{desc} => sub { + $comment->problem_state( $test->{state} ); $comment->problem->state( $test->{state} ); $comment->anonymous( $test->{anon} ); @@ -334,6 +336,59 @@ foreach my $test ( }; } +my $dt2 = $dt->clone; +$dt2->add( 'minutes' => 1 ); + +my $comment2 = FixMyStreet::App->model('DB::Comment')->new( { + id => 38363, + user => $user, + problem => $problem, + anonymous => 0, + text => 'this is a comment', + confirmed => $dt, + problem_state => 'confirmed', + extra => { title => 'Mr', email_alerts_requested => 0 }, +} ); + +for my $test ( + { + desc => 'comment with fixed - council state sends status of CLOSED even if problem is open', + state => 'fixed - council', + problem_state => 'confirmed', + status => 'CLOSED', + extended => 'FIXED', + }, + { + desc => 'comment marked open sends status of OPEN even if problem is closed', + state => 'confirmed', + problem_state => 'fixed - council', + status => 'OPEN', + extended => 'OPEN', + }, + { + desc => 'comment with no problem state falls back to report state', + state => '', + problem_state => 'fixed - council', + status => 'CLOSED', + extended => 'FIXED', + }, +) { + subtest $test->{desc} => sub { + $comment->problem_state( $test->{state} ); + $comment->problem->state( $test->{problem_state} ); + my $results = make_update_req( $comment, '<?xml version="1.0" encoding="utf-8"?><service_request_updates><request_update><update_id>248</update_id></request_update></service_request_updates>' ); + + my $c = CGI::Simple->new( $results->{ req }->content ); + is $c->param('status'), $test->{status}, 'correct status'; + + if ( $test->{extended} ) { + my $results = make_update_req( $comment, '<?xml version="1.0" encoding="utf-8"?><service_request_updates><request_update><update_id>248</update_id></request_update></service_request_updates>', { extended_statuses => 1 } ); + my $c = CGI::Simple->new( $results->{ req }->content ); + is $c->param('status'), $test->{extended}, 'correct extended status'; + } + }; +} + for my $test ( { |