aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--perllib/Open311/GetServiceRequestUpdates.pm7
-rw-r--r--t/open311/getservicerequestupdates.t23
2 files changed, 30 insertions, 0 deletions
diff --git a/perllib/Open311/GetServiceRequestUpdates.pm b/perllib/Open311/GetServiceRequestUpdates.pm
index 480a78cf1..fa852a80d 100644
--- a/perllib/Open311/GetServiceRequestUpdates.pm
+++ b/perllib/Open311/GetServiceRequestUpdates.pm
@@ -115,6 +115,7 @@ sub update_comments {
my $state = $open311->map_state( $request->{status} );
my $old_state = $p->state;
my $external_status_code = $request->{external_status_code} || '';
+ my $customer_reference = $request->{customer_reference} || '';
my $old_external_status_code = $p->get_extra_metadata('external_status_code') || '';
my $comment = $self->schema->resultset('Comment')->new(
{
@@ -143,6 +144,12 @@ sub update_comments {
$p->set_extra_metadata(external_status_code => $external_status_code);
}
+ # if the customer reference to display in the report metadata is
+ # not the same as the external_id
+ if ( $customer_reference ) {
+ $p->set_extra_metadata( customer_reference => $customer_reference );
+ }
+
$open311->add_media($request->{media_url}, $comment)
if $request->{media_url};
diff --git a/t/open311/getservicerequestupdates.t b/t/open311/getservicerequestupdates.t
index 9383b8476..995338063 100644
--- a/t/open311/getservicerequestupdates.t
+++ b/t/open311/getservicerequestupdates.t
@@ -521,6 +521,29 @@ subtest 'Update with media_url includes image in update' => sub {
$problem->comments->delete;
};
+subtest 'Update with customer_reference adds reference to problem' => sub {
+ my $guard = LWP::Protocol::PSGI->register(t::Mock::Static->to_psgi_app, host => 'example.com');
+
+ my $local_requests_xml = setup_xml($problem->external_id, 1, "");
+ $local_requests_xml =~ s#</service_request_id>#</service_request_id>
+ <customer_reference>REFERENCE</customer_reference>#;
+ my $o = Open311->new( jurisdiction => 'mysociety', endpoint => 'http://example.com', test_mode => 1, test_get_returns => { 'servicerequestupdates.xml' => $local_requests_xml } );
+
+ $problem->lastupdate( DateTime->now()->subtract( days => 1 ) );
+ $problem->state('confirmed');
+ $problem->update;
+
+ my $update = Open311::GetServiceRequestUpdates->new( system_user => $user );
+ $update->update_comments( $o, $bodies{2482} );
+
+ $problem->discard_changes;
+ is $problem->comments->count, 1, 'comment count';
+ my $c = $problem->comments->first;
+ is $c->external_id, 638344;
+ is $problem->get_extra_metadata('customer_reference'), 'REFERENCE';
+ $problem->comments->delete;
+};
+
subtest 'date for comment correct' => sub {
my $local_requests_xml = setup_xml($problem->external_id, $problem->id, "");
my $o = Open311->new( jurisdiction => 'mysociety', endpoint => 'http://example.com', test_mode => 1, test_get_returns => { 'servicerequestupdates.xml' => $local_requests_xml } );