diff --git a/perllib/Integrations/Surrey/Boomi.pm b/perllib/Integrations/Surrey/Boomi.pm index 66f168ba6..a9c772cde 100644 --- a/perllib/Integrations/Surrey/Boomi.pm +++ b/perllib/Integrations/Surrey/Boomi.pm @@ -80,12 +80,12 @@ Returns the ID of the created or updated ticket. =cut sub getHighwaysTicketUpdates { - my ($self, $start, $end) = @_; + my ($self, $integration_id, $start, $end) = @_; my $resp = $self->get('getHighwaysTicketUpdates', { from => format_datetime($start), to => format_datetime($end), - integration_id => $self->config->{integration_ids}->{getHighwaysTicketUpdates}, + integration_id => $integration_id, }); if (my $errors = $resp->{errors}) { diff --git a/perllib/Open311/Endpoint/Integration/Boomi.pm b/perllib/Open311/Endpoint/Integration/Boomi.pm index b547216a7..dbfdf4119 100644 --- a/perllib/Open311/Endpoint/Integration/Boomi.pm +++ b/perllib/Open311/Endpoint/Integration/Boomi.pm @@ -217,31 +217,50 @@ sub _get_service_requests_for_integration_id { return @requests; } - - sub get_service_request_updates { my ($self, $args) = @_; + my $integration_ids = $self->endpoint_config->{integration_ids}->{getHighwaysTicketUpdates}; + return () unless $integration_ids; + $integration_ids = [ $integration_ids ] unless ref $integration_ids eq 'ARRAY'; + + my @updates; + foreach (@$integration_ids) { + push @updates, $self->_get_service_request_updates_for_integration_id($_, $args); + } + + return @updates; +} + +sub _get_service_request_updates_for_integration_id { + my ($self, $integration_id, $args) = @_; + my $start = DateTime::Format::W3CDTF->parse_datetime($args->{start_date}); my $end = DateTime::Format::W3CDTF->parse_datetime($args->{end_date}); - my $results = $self->boomi->getHighwaysTicketUpdates($start, $end); + my $results = $self->boomi->getHighwaysTicketUpdates($integration_id, $start, $end); my $w3c = DateTime::Format::W3CDTF->new; my @updates; for my $update (@$results) { - my $log = $update->{confirmEnquiryStatusLog}; + my $enquiry_update = $update->{confirmEnquiryStatusLog} ? 1 : 0; + my $log = $enquiry_update ? $update->{confirmEnquiryStatusLog} : $update->{confirmJobStatusLog}; my $fms = $update->{fmsReport}; - my $id = $log->{enquiry}->{externalSystemReference} . "_" . $log->{logNumber}; + my $id = $enquiry_update + ? $log->{enquiry}->{externalSystemReference} . "_" . $log->{logNumber} + : $log->{job}->{jobNumber} . "_" . $log->{logNumber}; + my $service_request_id = $enquiry_update + ? "Zendesk_" . $log->{enquiry}->{externalSystemReference} + : "Zendesk_JOB_" . $log->{job}->{jobNumber}; my $status = lc $fms->{status}->{state}; $status =~ s/ /_/g; push @updates, Open311::Endpoint::Service::Request::Update::mySociety->new( status => $status, update_id => $id, - service_request_id => "Zendesk_" . $log->{enquiry}->{externalSystemReference}, + service_request_id => $service_request_id, description => $fms->{status}->{label}, updated_datetime => $w3c->parse_datetime( $log->{loggedDate} )->truncate( to => 'second' ), ); diff --git a/t/open311/endpoint/surrey_boomi.t b/t/open311/endpoint/surrey_boomi.t index ff949feb2..073838fd0 100644 --- a/t/open311/endpoint/surrey_boomi.t +++ b/t/open311/endpoint/surrey_boomi.t @@ -141,46 +141,72 @@ $lwp->mock(request => sub { return HTTP::Response->new(200, 'OK', [], encode_json({"ticket" => { system => "Zendesk", id => 1234 }})); } } elsif ($req->uri =~ /getHighwaysTicketUpdates/) { + my %query = $req->uri->query_form; is $req->method, 'GET', "Correct method used"; - return HTTP::Response->new(200, 'OK', [], encode_json({ - "executionId" => "execution-7701f16b-036c-4e6e-8e14-998f81f5b6b8-2024.06.27", - "results" => [ - { - "confirmEnquiryStatusLog" => { - "loggedDate" => "2024-05-01T09:07:47.000Z", - "logNumber" => 11, - "statusCode" => "5800", - "enquiry" => { - "enquiryNumber" => 129293, - "externalSystemReference" => "2929177" + if ($query{integration_id} eq 'Integration.2') { + return HTTP::Response->new(200, 'OK', [], encode_json({ + "executionId" => "execution-7701f16b-036c-4e6e-8e14-998f81f5b6b8-2024.06.27", + "results" => [ + { + "confirmEnquiryStatusLog" => { + "loggedDate" => "2024-05-01T09:07:47.000Z", + "logNumber" => 11, + "statusCode" => "5800", + "enquiry" => { + "enquiryNumber" => 129293, + "externalSystemReference" => "2929177" + } + }, + "fmsReport" => { + "status" => { + "state" => "Closed", + "label" => "Enquiry closed" + } } }, - "fmsReport" => { - "status" => { - "state" => "Closed", - "label" => "Enquiry closed" - } - } - }, - { - "confirmEnquiryStatusLog" => { - "loggedDate" => "2024-05-01T09:10:41.000Z", - "logNumber" => 7, - "statusCode" => "3200", - "enquiry" => { - "enquiryNumber" => 132361, - "externalSystemReference" => "2939061" + { + "confirmEnquiryStatusLog" => { + "loggedDate" => "2024-05-01T09:10:41.000Z", + "logNumber" => 7, + "statusCode" => "3200", + "enquiry" => { + "enquiryNumber" => 132361, + "externalSystemReference" => "2939061" + } + }, + "fmsReport" => { + "status" => { + "state" => "Action scheduled", + "label" => "Assessed - scheduling a repair within 5 Working Days" + } } }, - "fmsReport" => { - "status" => { - "state" => "Action scheduled", - "label" => "Assessed - scheduling a repair within 5 Working Days" + ] + })); + } elsif ($query{integration_id} eq 'Integration.5') { + return HTTP::Response->new(200, 'OK', [], encode_json({ + "executionId" => "execution-7701f16b-036c-4e6e-8e14-998f81f5b6b8-2024.06.27", + "results" => [ + { + "confirmJobStatusLog" => { + "loggedDate" => "2024-08-09T11:23:10.000Z", + "logNumber" => 2, + "statusCode" => "2000", + "job" => { + "jobNumber" => 569276 + } + }, + "fmsReport" => { + "externalId" => "569276", + "status" => { + "state" => "Action scheduled", + "label" => "Assessed - scheduling a repair within 5 Working Days" + } } } - }, - ] - })); + ] + })); + } } elsif ($req->uri =~ /getNewHighwaysTickets/) { is $req->method, 'GET', "Correct method used"; my %query = $req->uri->query_form; @@ -367,6 +393,14 @@ subtest "GET Service Request Updates" => sub { "status" => "action_scheduled", "update_id" => "2939061_7", "updated_datetime" => "2024-05-01T09:10:41Z", + }, + { + "update_id" => "569276_2", + "service_request_id" => "Zendesk_JOB_569276", + "description" => "Assessed - scheduling a repair within 5 Working Days", + "media_url" => "", + "updated_datetime" => "2024-08-09T11:23:10Z", + "status" => "action_scheduled" } ]; }; diff --git a/t/open311/endpoint/surrey_boomi.yml b/t/open311/endpoint/surrey_boomi.yml index 33d6e7100..60f00899b 100644 --- a/t/open311/endpoint/surrey_boomi.yml +++ b/t/open311/endpoint/surrey_boomi.yml @@ -4,7 +4,9 @@ api_url: http://localhost/ws/simple/ integration_ids: upsertHighwaysTicket: "Integration.1" - getHighwaysTicketUpdates: "Integration.2" + getHighwaysTicketUpdates: + - "Integration.2" + - "Integration.5" getNewHighwaysTickets: - "Integration.3" - "Integration.4"