aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--perllib/Open311.pm8
-rw-r--r--t/open311.t24
2 files changed, 30 insertions, 2 deletions
diff --git a/perllib/Open311.pm b/perllib/Open311.pm
index e609fb086..a01a0528f 100644
--- a/perllib/Open311.pm
+++ b/perllib/Open311.pm
@@ -156,6 +156,9 @@ sub post_service_request_update {
my $self = shift;
my $comment = shift;
+ my $name = $comment->name || $comment->user->name;
+ my ( $firstname, $lastname ) = ( $name =~ /(\w+)\s+(.+)/ );
+
my $params = {
update_id_ext => $comment->id,
updated_datetime => $comment->confirmed,
@@ -165,11 +168,12 @@ sub post_service_request_update {
email => $comment->user->email,
description => $comment->text,
public_anonymity_required => $comment->anonymous ? 'TRUE' : 'FALSE',
- # also need last_name, title
+ last_name => $lastname,
+ first_name => $firstname,
};
if ( $comment->extra ) {
- $params->{'email_alerts_request'}
+ $params->{'email_alerts_requested'}
= $comment->extra->{email_alerts_requested} ? 'TRUE' : 'FALSE';
$params->{'title'} = $comment->extra->{title};
}
diff --git a/t/open311.t b/t/open311.t
index 2a9d513eb..2a5e5d11c 100644
--- a/t/open311.t
+++ b/t/open311.t
@@ -45,6 +45,7 @@ warning_like {$o2->send_service_request( $p, { url => 'http://example.com/' }, 1
my $dt = DateTime->now();
my $user = FixMyStreet::App->model('DB::User')->new( {
+ name => 'Test User',
email => 'test@example.com',
} );
@@ -61,6 +62,7 @@ my $comment = FixMyStreet::App->model('DB::Comment')->new( {
anonymous => 0,
text => 'this is a comment',
confirmed => $dt,
+ extra => { title => 'Mr', email_alerts_requested => 0 },
} );
subtest 'testing posting updates' => sub {
@@ -79,6 +81,10 @@ subtest 'testing posting updates' => sub {
is $c->param('service_request_id'), 81, 'request id correct';
is $c->param('public_anonymity_required'), 'FALSE', 'anon status correct';
is $c->param('updated_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('email_alerts_requested'), 'FALSE', 'email alerts flag correct';
};
foreach my $test (
@@ -143,6 +149,24 @@ foreach my $test (
};
}
+
+subtest 'check correct name used' => sub {
+ $comment->name( 'First Last' );
+ $user->name( 'Personal Family');
+
+ 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('first_name'), 'First', 'Name from comment';
+
+ $comment->name( '' );
+
+ $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>' );
+
+ $c = CGI::Simple->new( $results->{ req }->content );
+ is $c->param('first_name'), 'Personal', 'Name from user';
+};
+
subtest 'No update id in reponse' => sub {
my $results;
warning_like {