aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorDave Arter <davea@mysociety.org>2019-04-11 17:24:54 +0100
committerDave Arter <davea@mysociety.org>2019-06-04 14:54:30 +0100
commit0d67c672ca10538695eadd48c406e2707ea9c5c6 (patch)
tree70be08c38e759458dce49701035196fdaee9d833
parent1def9598bee006b52ca8a6223cf552bebaefe555 (diff)
[Hounslow] Mark comments not left by original reporter when posting to Open311
-rw-r--r--perllib/FixMyStreet/Cobrand/Hounslow.pm12
-rw-r--r--t/open311.t66
2 files changed, 67 insertions, 11 deletions
diff --git a/perllib/FixMyStreet/Cobrand/Hounslow.pm b/perllib/FixMyStreet/Cobrand/Hounslow.pm
index ac8d904ee..fdcfd4fd5 100644
--- a/perllib/FixMyStreet/Cobrand/Hounslow.pm
+++ b/perllib/FixMyStreet/Cobrand/Hounslow.pm
@@ -85,12 +85,14 @@ sub open311_config {
$row->set_extra_fields(@$extra);
}
-sub should_skip_sending_update {
- my ($self, $update ) = @_;
+sub open311_munge_update_params {
+ my ($self, $params, $comment, $body) = @_;
- # Hounslow don't want to receive updates into Confirm that were made by
- # anyone except the original problem reporter.
- return $update->user_id != $update->problem->user_id;
+ # Hounslow want to make it clear in Confirm when an update is left by
+ # someone who's not the original reporter.
+ unless ($comment->user eq $comment->problem->user) {
+ $params->{description} = "[This comment was not left by the original problem reporter] " . $params->{description};
+ }
}
diff --git a/t/open311.t b/t/open311.t
index 85176ff0d..73bb488d5 100644
--- a/t/open311.t
+++ b/t/open311.t
@@ -302,14 +302,14 @@ subtest 'basic request update post parameters' => sub {
my $c = CGI::Simple->new( $results->{ req }->content );
- is $c->param('description'), 'this is a comment', 'email correct';
+ is $c->param('description'), 'this is a comment', 'description correct';
is $c->param('email'), 'test@example.com', 'email correct';
is $c->param('status'), 'OPEN', 'status correct';
is $c->param('service_request_id'), 81, 'request id correct';
is $c->param('updated_datetime'), DateTime::Format::W3CDTF->format_datetime($dt), 'correct date';
is $c->param('title'), 'Mr', 'correct title';
- is $c->param('last_name'), 'User', 'correct first name';
- is $c->param('first_name'), 'Test', 'correct second name';
+ is $c->param('first_name'), 'Test', 'correct first name';
+ is $c->param('last_name'), 'User', 'correct second name';
is $c->param('media_url'), undef, 'no media url';
};
@@ -326,7 +326,7 @@ subtest 'extended request update post parameters' => sub {
my $c = CGI::Simple->new( $results->{ req }->content );
- is $c->param('description'), 'this is a comment', 'email correct';
+ is $c->param('description'), 'this is a comment', 'description correct';
is $c->param('email'), 'test@example.com', 'email correct';
is $c->param('status'), 'OPEN', 'status correct';
is $c->param('service_request_id_ext'), 80, 'external request id correct';
@@ -334,12 +334,66 @@ subtest 'extended request update post parameters' => sub {
is $c->param('public_anonymity_required'), 'FALSE', 'anon status correct';
is $c->param('updated_datetime'), DateTime::Format::W3CDTF->format_datetime($dt), 'correct date';
is $c->param('title'), 'Mr', 'correct title';
- is $c->param('last_name'), 'User', 'correct first name';
- is $c->param('first_name'), 'Test', 'correct second name';
+ is $c->param('first_name'), 'Test', 'correct first name';
+ is $c->param('last_name'), 'User', 'correct second name';
is $c->param('email_alerts_requested'), 'FALSE', 'email alerts flag correct';
is $c->param('media_url'), undef, 'no media url';
};
+subtest 'Hounslow update description is correct for same user' => sub {
+ my $comment = make_comment('hounslow');
+ my $results;
+ FixMyStreet::override_config {
+ ALLOWED_COBRANDS => 'hounslow',
+ }, sub {
+ $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>' );
+ };
+
+ is $results->{ res }, 248, 'got update id';
+
+ my $c = CGI::Simple->new( $results->{ req }->content );
+
+ is $c->param('description'), 'this is a comment', 'description correct';
+ is $c->param('email'), 'test@example.com', 'email correct';
+ is $c->param('status'), 'OPEN', 'status correct';
+ is $c->param('service_request_id'), 81, 'request id correct';
+ is $c->param('updated_datetime'), DateTime::Format::W3CDTF->format_datetime($dt), 'correct date';
+ is $c->param('title'), 'Mr', 'correct title';
+ is $c->param('first_name'), 'Test', 'correct first name';
+ is $c->param('last_name'), 'User', 'correct second name';
+ is $c->param('media_url'), undef, 'no media url';
+};
+
+subtest 'Hounslow update description is correct for a different user' => sub {
+ my $user2 = FixMyStreet::DB->resultset('User')->new( {
+ name => 'Another User',
+ email => 'another@example.org',
+ } );
+
+ my $comment = make_comment('hounslow');
+ $comment->user($user2);
+ my $results;
+ FixMyStreet::override_config {
+ ALLOWED_COBRANDS => 'hounslow',
+ }, sub {
+ $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>' );
+ };
+
+ is $results->{ res }, 248, 'got update id';
+
+ my $c = CGI::Simple->new( $results->{ req }->content );
+
+ is $c->param('description'), "[This comment was not left by the original problem reporter] this is a comment", 'description correct';
+ is $c->param('email'), 'another@example.org', 'email correct';
+ is $c->param('status'), 'OPEN', 'status correct';
+ is $c->param('service_request_id'), 81, 'request id correct';
+ is $c->param('updated_datetime'), DateTime::Format::W3CDTF->format_datetime($dt), 'correct date';
+ is $c->param('title'), 'Mr', 'correct title';
+ is $c->param('first_name'), 'Another', 'correct first name';
+ is $c->param('last_name'), 'User', 'correct second name';
+ is $c->param('media_url'), undef, 'no media url';
+};
+
subtest 'check media url set' => sub {
my $UPLOAD_DIR = tempdir( CLEANUP => 1 );