Skip to content

Commit

Permalink
Merge branch 'bromley-referral' into staging
Browse files Browse the repository at this point in the history
  • Loading branch information
MorayMySoc committed Apr 16, 2024
2 parents eda7c46 + ae5480b commit a636e63
Show file tree
Hide file tree
Showing 2 changed files with 48 additions and 1 deletion.
17 changes: 17 additions & 0 deletions perllib/Open311/Endpoint/Integration/UK/Bromley/Echo.pm
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,10 @@ around process_service_request_args => sub {
}
$args->{attributes}{Notes} =~ s/(\r?\n)+/ | /g;

if ($args->{attributes}{Notes} && $args->{attributes}{Notes} =~ m/^Closed report has a new comment:/ ) {
$args->{attributes}{Notes} = _truncate_text($args->{attributes}{Notes}, 2000, '...');
}

if (my $title = $args->{attributes}{title}) {
$args->{attributes}{Title} = echo_title_id($title);
}
Expand Down Expand Up @@ -89,5 +93,18 @@ around post_service_request_update => sub {
return $class->$orig($args);
};

sub _truncate_text {
my ($text, $max_length, $postscript) = @_;

return $text if length($text) <= $max_length;

if ($postscript) {
$max_length = $max_length - length($postscript);
};

return substr( $text, 0, $max_length ) . $postscript;
}


1;

32 changes: 31 additions & 1 deletion t/open311/endpoint/bromley_echo.t
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,11 @@ $soap_lite->mock(call => sub {
is $loc[1]->value, 'Behind the wall';
my @notes = ${$data[5]->value}->value;
is $notes[0]->value, 1006;
is $notes[1]->value, 'This is the details';
if ($notes[1]->value =~ /^Closed report has a/) {
is $notes[1]->value, 'Closed report has a new comment: comment that was left | Jay User user@user.com | This was the text!' . 'a' x 1897 . '...',
} else {
is $notes[1]->value, 'This is the details';
}
my @type = ${$data[6]->value}->value;
is $type[0]->value, 1007;
is $type[1]->value, 3;
Expand Down Expand Up @@ -163,6 +167,32 @@ subtest "POST add assisted collection OK" => sub {
} ], 'correct json returned';
};

subtest "POST add assisted collection OK" => sub {
my $res = $endpoint->run_test_request(
POST => '/requests.json',
api_key => 'test',
service_code => EVENT_TYPE_ASSISTED . "-add",
first_name => 'Bob',
last_name => 'Mould',
description => "Closed report has a new comment: comment that was left\r\nJay User user\@user.com\r\nThis was the text!" . 'a' x 2000,
lat => 51,
long => -1,
'attribute[service_id]' => 531, # Domestic refuse
'attribute[uprn]' => 1000001,
'attribute[fixmystreet_id]' => 2000123,
'attribute[Exact_Location]' => 'Behind the wall',
'attribute[Container_Type]' => 3,
'attribute[title]' => 'MRS',
);
ok $res->is_success, 'valid request'
or diag $res->content;

is_deeply decode_json($res->content),
[ {
"service_request_id" => '1234',
} ], 'correct json returned';
};

subtest "POST remove assisted collection OK" => sub {
my $res = $endpoint->run_test_request(
POST => '/requests.json',
Expand Down

0 comments on commit a636e63

Please sign in to comment.