Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Bromley] Referral changes #334

Open
wants to merge 4 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
41 changes: 41 additions & 0 deletions perllib/Open311/Endpoint/Integration/UK/Bromley/Echo.pm
Original file line number Diff line number Diff line change
Expand Up @@ -30,9 +30,37 @@ start/end/review dates; when removing, we set the action and end date.

=cut

sub echo_title_id {
my $title = shift;
return 1 if $title eq 'MR';
return 2 if $title eq 'MRS';
return 3 if $title eq 'MISS';
return 4 if $title eq 'MS';
return 5 if $title eq 'DR';
return 7;
}

around process_service_request_args => sub {
my ($orig, $class, $args) = @_;
my $request = $class->$orig($args);

if (!$args->{attributes}{Notes}) {
$args->{attributes}{Notes} = join(" | ", $args->{attributes}{report_title} || (), $args->{description} || ());
}
$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);
}

if ($request->{event_type} == 3045 && !$args->{attributes}{Event_ID}) {
$args->{attributes}{Event_ID} = 'LBB_REFERRAL';
}

# Assisted collection
if ($request->{event_type} == 2149) {
my $date = DateTime->today(time_zone => "Europe/London");
Expand Down Expand Up @@ -65,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;

4 changes: 4 additions & 0 deletions perllib/Open311/Endpoint/Role/mySociety.pm
Original file line number Diff line number Diff line change
Expand Up @@ -342,6 +342,8 @@ sub learn_additional_types {
'cancelled',
'reopen',
'for_triage',
'referred_to_veolia_streets', # Bromley passthrough
'referred_to_lbb_streets', # Bromley passthrough
)
);
$schema->learn_type( 'tag:wiki.open311.org,GeoReport_v2:rx/status_extended_upper',
Expand All @@ -360,6 +362,8 @@ sub learn_additional_types {
'CANCELLED',
'REOPEN',
'FOR_TRIAGE',
'REFERRED_TO_VEOLIA_STREETS', # Bromley passthrough
'REFERRED_TO_LBB_STREETS', # Bromley passthrough
)
);
$schema->learn_type( 'tag:wiki.open311.org,GeoReport_v2:rx/service_request_update',
Expand Down
2 changes: 2 additions & 0 deletions perllib/Open311/Endpoint/Service/Request/Update/mySociety.pm
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,8 @@ has status => (
'cancelled',
'reopen',
'for_triage',
'referred_to_veolia_streets', # Bromley passthrough
'referred_to_lbb_streets', # Bromley passthrough
],
);

Expand Down
49 changes: 45 additions & 4 deletions t/open311/endpoint/bromley_echo.t
Original file line number Diff line number Diff line change
Expand Up @@ -62,8 +62,8 @@ $soap_lite->mock(call => sub {

my @data = ${$params[0]->value}->value->value;
is $uprn, 1000001;
if (@data == 6) {
is @data, 6, 'Various supplied data';
if (@data == 8) {
is @data, 8, 'Various supplied data';
my @action = ${$data[0]->value}->value;
is $action[0]->value, 1001;
is $action[1]->value, 1;
Expand All @@ -79,17 +79,30 @@ $soap_lite->mock(call => sub {
my @loc = ${$data[4]->value}->value;
is $loc[0]->value, 1005;
is $loc[1]->value, 'Behind the wall';
my @type = ${$data[5]->value}->value;
my @notes = ${$data[5]->value}->value;
is $notes[0]->value, 1006;
if ($notes[1]->value =~ /^Closed report has a/) {
is $notes[1]->value, 'Closed report has a new comment: comment that was left | Jay User [email protected] | 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;
my @title = ${$data[7]->value}->value;
is $title[0]->value, 1008;
is $title[1]->value, 2;
} else {
is @data, 2, 'Various supplied data';
is @data, 3, 'Various supplied data';
my @action = ${$data[0]->value}->value;
is $action[0]->value, 1001;
is $action[1]->value, 2;
my @start = ${$data[1]->value}->value;
is $start[0]->value, 1003;
is $start[1]->value, $date->strftime("%d/%m/%Y");
my @notes = ${$data[2]->value}->value;
is $notes[0]->value, 1006;
is $notes[1]->value, 'This is the details';
}

return SOAP::Result->new(result => {
Expand All @@ -107,6 +120,7 @@ $soap_lite->mock(call => sub {
{ Id => 1005, Name => "Exact Location" },
{ Id => 1006, Name => "Notes" },
{ Id => 1007, Name => "Container Type" },
{ Id => 1008, Name => "Title" },
] },
});
} elsif ($method eq 'PerformEventAction') {
Expand Down Expand Up @@ -142,6 +156,33 @@ subtest "POST add assisted collection OK" => sub {
'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 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;
Expand Down
Loading