diff --git a/perllib/FixMyStreet/Cobrand/Gloucestershire.pm b/perllib/FixMyStreet/Cobrand/Gloucestershire.pm index 1c0364a6d47..c70b40c9954 100644 --- a/perllib/FixMyStreet/Cobrand/Gloucestershire.pm +++ b/perllib/FixMyStreet/Cobrand/Gloucestershire.pm @@ -199,6 +199,21 @@ around open311_extra_data_include => sub { return $open311_only; }; +=head2 open311_munge_update_params + +We want to include whether the update was made by the probem reporter. + +=cut + +around open311_munge_update_params => sub { + my ($orig, $self, $params, $comment, $body) = @_; + + $self->$orig($params, $comment, $body); + + if ($comment->user_id eq $comment->problem->user_id) { + $params->{'attribute[by_reporter]'} = 1; + } +}; sub disambiguate_location { my $self = shift; diff --git a/t/cobrand/gloucestershire.t b/t/cobrand/gloucestershire.t index cb22d703071..517124988e3 100644 --- a/t/cobrand/gloucestershire.t +++ b/t/cobrand/gloucestershire.t @@ -1,5 +1,7 @@ use FixMyStreet::TestMech; use Test::Deep; +use Open311::PostServiceRequestUpdates; +use CGI::Simple; FixMyStreet::App->log->disable('info'); END { FixMyStreet::App->log->enable('info'); } @@ -10,6 +12,7 @@ my $body = $mech->create_body_ok( 2226, 'Gloucestershire County Council', { send_method => 'Open311', + send_comments => 1, api_key => 'key', endpoint => 'endpoint', jurisdiction => 'jurisdiction', @@ -447,6 +450,29 @@ FixMyStreet::override_config { }; } + + subtest 'Does not send updates on now-email categories' => sub { + # Create a report that had been sent via Open311 + my ($p) = $mech->create_problems_for_body(1, $body->id, 'Title', { + whensent => \'current_timestamp', + send_method_used => 'Open311', + external_id => 'EXT', + }); + my $updates = Open311::PostServiceRequestUpdates->new(); + + $mech->create_comment_for_problem($p, $p->user, 'Name', 'Text', 't', 'confirmed'); + $updates->send; + my $req = Open311->test_req_used; + my $cgi = CGI::Simple->new($req->content); + is $cgi->param('attribute[by_reporter]'), 1; + + $mech->create_comment_for_problem($p, $staff_user, 'Name', 'Staff text', 't', 'confirmed'); + $updates->send; + $req = Open311->test_req_used; + $cgi = CGI::Simple->new($req->content); + is $cgi->param('attribute[by_reporter]'), undef; + }; + }; done_testing();