Skip to content

Commit

Permalink
[Merton] Pass Echo event ID to Crimson when sending reports
Browse files Browse the repository at this point in the history
  • Loading branch information
davea authored and dracos committed May 10, 2024
1 parent 3c6980a commit 0c9bf34
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 0 deletions.
23 changes: 23 additions & 0 deletions perllib/FixMyStreet/Script/Merton/SendWaste.pm
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ use FixMyStreet::DB;
use FixMyStreet::Queue::Item::Report;
use FixMyStreet::SendReport::Open311;
use Open311;
use Integrations::Echo;

has body => (
is => 'ro',
Expand All @@ -17,6 +18,7 @@ sub send_reports {
my $problems = $self->_problems;

while (my $row = $problems->next) {
$self->set_echo_id($row) or next; # skip if no echo_id
my $item = FixMyStreet::Queue::Item::Report->new( report => $row );
FixMyStreet::DB->schema->cobrand($item->cobrand);
$item->cobrand->set_lang_and_domain($row->lang, 1);
Expand Down Expand Up @@ -55,6 +57,27 @@ sub _problems {
});
}

sub set_echo_id {
my ($self, $problem) = @_;

unless ($problem->get_extra_field_value('echo_id')) {
my $cobrand = $problem->get_cobrand_logged;
my $cfg = $cobrand->feature('echo');
my $echo = Integrations::Echo->new(%$cfg);
my $event = $echo->GetEvent($problem->external_id);
return unless $event && $event->{Id};

my $row2 = FixMyStreet::DB->resultset('Problem')->search({ id => $problem->id }, { for => \'UPDATE' })->single;
$row2->update_extra_field({
name => 'echo_id',
value => $event->{Id},
});
$row2->update;
}

return 1;
}

sub send_comments {
my ($self) = @_;
my $comments = $self->_comments;
Expand Down
3 changes: 3 additions & 0 deletions t/app/controller/waste_merton.t
Original file line number Diff line number Diff line change
Expand Up @@ -139,6 +139,7 @@ FixMyStreet::override_config {
};
subtest 'Test sending of reports to other endpoint' => sub {
use_ok 'FixMyStreet::Script::Merton::SendWaste';
$e->mock('GetEvent', sub { { Id => 1928374 } });
Open311->_inject_response('/api/requests.xml', '<?xml version="1.0" encoding="utf-8"?><service_requests><request><service_request_id>359</service_request_id></request></service_requests>');
my $send = FixMyStreet::Script::Merton::SendWaste->new;
$send->send_reports;
Expand All @@ -147,9 +148,11 @@ FixMyStreet::override_config {
is $cgi->param('api_key'), 'api_key';
is $cgi->param('attribute[Action]'), '3';
is $cgi->param('attribute[Reason]'), '2';
is $cgi->param('attribute[echo_id]'), '1928374';
my $report = FixMyStreet::DB->resultset("Problem")->search(undef, { order_by => { -desc => 'id' } })->first;
is $report->get_extra_metadata('sent_to_crimson'), 1;
is $report->get_extra_metadata('crimson_external_id'), "359";
is $report->get_extra_field_value('echo_id'), "1928374";
is $report->external_id, "248";
};
subtest 'Test sending of updates to other endpoint' => sub {
Expand Down

0 comments on commit 0c9bf34

Please sign in to comment.