diff options
author | Struan Donald <struan@exo.org.uk> | 2019-02-27 10:31:50 +0000 |
---|---|---|
committer | Matthew Somerville <matthew-github@dracos.co.uk> | 2019-03-12 16:13:00 +0000 |
commit | 2af88a4986b5fc951bdef0586f487735789d36d8 (patch) | |
tree | ab23777d497b9fb76674eec7f1c9e43db389bb6b /t | |
parent | 7aab45bffaab6c5bd7c50acef7dc5bce6f233bc1 (diff) |
[open311] optionally use fixmystreet_id to match update to problem
If an update has a fixmystreet_id field then use the contents of that in
preference to the external_id field to match an update to a problem.
This handles the case where a report in a third party system passes
through different types (eg inspection and defect), resulting in the
external id changing. In this case it is sometimes possible to include
the fixmystreet id in each type and hence use that to match things up at
the fixmystreet side.
Diffstat (limited to 't')
-rw-r--r-- | t/open311/getservicerequestupdates.t | 54 |
1 files changed, 54 insertions, 0 deletions
diff --git a/t/open311/getservicerequestupdates.t b/t/open311/getservicerequestupdates.t index 54a7f192d..055c5ea5f 100644 --- a/t/open311/getservicerequestupdates.t +++ b/t/open311/getservicerequestupdates.t @@ -1037,6 +1037,60 @@ foreach my $test ( { } } +subtest 'check matching on fixmystreet_id overrides service_request_id' => sub { + my $requests_xml = qq{<?xml version="1.0" encoding="utf-8"?> + <service_requests_updates> + <request_update> + <update_id>638344</update_id> + <service_request_id>8888888888888</service_request_id> + <fixmystreet_id>@{[ $problem->id ]}</fixmystreet_id> + <status>open</status> + <description>This is a note</description> + <updated_datetime>UPDATED_DATETIME</updated_datetime> + </request_update> + <request_update> + <update_id>638354</update_id> + <service_request_id>@{[ $problem->external_id ]}</service_request_id> + <fixmystreet_id>999999999</fixmystreet_id> + <status>open</status> + <description>This is a different note</description> + <updated_datetime>UPDATED_DATETIME2</updated_datetime> + </request_update> + <request_update> + <update_id>638356</update_id> + <service_request_id></service_request_id> + <fixmystreet_id>@{[ $problem->id ]}</fixmystreet_id> + <status>investigating</status> + <description>This is a last note</description> + <updated_datetime>UPDATED_DATETIME3</updated_datetime> + </request_update> + </service_requests_updates> + }; + + $problem->comments->delete; + + my $dt2 = $dt->clone->subtract( minutes => 30 ); + my $dt3 = $dt2->clone->subtract( minutes => 30 ); + $requests_xml =~ s/UPDATED_DATETIME3/$dt/; + $requests_xml =~ s/UPDATED_DATETIME2/$dt2/; + $requests_xml =~ s/UPDATED_DATETIME/$dt3/; + + my $o = Open311->new( jurisdiction => 'mysociety', endpoint => 'http://example.com', test_mode => 1, test_get_returns => { 'servicerequestupdates.xml' => $requests_xml } ); + + my $update = Open311::GetServiceRequestUpdates->new( + system_user => $user, + ); + + $update->update_comments( $o, $bodies{2482} ); + + $problem->discard_changes; + is $problem->comments->count, 2, 'two comments after fetching updates'; + + my @comments = $problem->comments->search(undef, { order_by => [ 'created' ] } )->all; + + is $comments[0]->external_id, 638344, "correct first comment added"; + is $comments[1]->external_id, 638356, "correct second comment added"; +}; done_testing(); sub setup_xml { |