From 21c6898a00295179566288b99dab2c14b98ab012 Mon Sep 17 00:00:00 2001 From: Victoria Mihell-Hale Date: Thu, 24 Oct 2024 15:50:28 +0100 Subject: [PATCH 1/2] [Bexley][WW] Implement worksheet sending for delivery requests --- perllib/Integrations/Whitespace.pm | 8 +++-- .../Endpoint/Integration/Whitespace.pm | 5 +++ .../Endpoint/Service/UKCouncil/Whitespace.pm | 8 ++++- t/open311/endpoint/bexley.t | 34 +++++++++++++++++++ t/open311/endpoint/whitespace.t | 1 + 5 files changed, 53 insertions(+), 3 deletions(-) diff --git a/perllib/Integrations/Whitespace.pm b/perllib/Integrations/Whitespace.pm index d432336d5..ab68edeba 100644 --- a/perllib/Integrations/Whitespace.pm +++ b/perllib/Integrations/Whitespace.pm @@ -100,9 +100,13 @@ sub CreateWorksheet { die "No service mapping found for $params->{service_item_name}"; } + my $service_id = $params->{service_code} eq 'request_new_container' + ? $service_params->{delivery_service_id} + : $service_params->{service_id}; + my $worksheet = ixhash( Uprn => $params->{uprn}, - ServiceId => $service_params->{service_id}, + ServiceId => $service_id, WorksheetReference => $params->{worksheet_reference}, WorksheetMessage => $params->{worksheet_message}, ServiceItemInputs => ixhash( @@ -110,7 +114,7 @@ sub CreateWorksheet { ixhash( 'wsap:ServiceItemId' => $service_params->{service_item_id}, 'wsap:ServiceItemName' => '', - 'wsap:ServiceItemQuantity' => 1, + 'wsap:ServiceItemQuantity' => $params->{quantity}, ) ] ), diff --git a/perllib/Open311/Endpoint/Integration/Whitespace.pm b/perllib/Open311/Endpoint/Integration/Whitespace.pm index f923b0787..13b77ac26 100644 --- a/perllib/Open311/Endpoint/Integration/Whitespace.pm +++ b/perllib/Open311/Endpoint/Integration/Whitespace.pm @@ -78,13 +78,18 @@ sub post_service_request { my $integration = $self->get_integration; + $args->{attributes}{location_of_containers} //= ''; + $args->{attributes}{quantity} //= 1; + my $worksheet_id = $integration->CreateWorksheet({ + service_code => $args->{service_code}, uprn => $args->{attributes}->{uprn}, service_item_name => $args->{attributes}->{service_item_name}, worksheet_reference => $args->{attributes}->{fixmystreet_id}, worksheet_message => $self->_worksheet_message($args), assisted_yn => $args->{attributes}->{assisted_yn}, location_of_containers => $args->{attributes}->{location_of_containers}, + quantity => $args->{attributes}->{quantity}, }); my $request = $self->new_request( diff --git a/perllib/Open311/Endpoint/Service/UKCouncil/Whitespace.pm b/perllib/Open311/Endpoint/Service/UKCouncil/Whitespace.pm index ca9dc06d4..b2b9263ae 100644 --- a/perllib/Open311/Endpoint/Service/UKCouncil/Whitespace.pm +++ b/perllib/Open311/Endpoint/Service/UKCouncil/Whitespace.pm @@ -46,10 +46,16 @@ sub _build_attributes { required => 0, automated => 'hidden_field', ), + Open311::Endpoint::Service::Attribute->new( + code => 'quantity', + description => 'Number of containers', + datatype => 'number', + required => 0, + automated => 'hidden_field', + ), ); return \@attributes; } 1; - diff --git a/t/open311/endpoint/bexley.t b/t/open311/endpoint/bexley.t index 1f96537d1..02d8718e4 100644 --- a/t/open311/endpoint/bexley.t +++ b/t/open311/endpoint/bexley.t @@ -228,6 +228,7 @@ subtest "Whitespace worksheets use Bexley's custom message" => sub { my $ws = Test::MockModule->new('Integrations::Whitespace'); $ws->mock(CreateWorksheet => sub { my ($self, $args) = @_; + is $args->{quantity}, 1; is $args->{worksheet_message}, "Assisted collection? Yes\n\nLocation of containers: location of containers\n"; return 1001; }); @@ -255,4 +256,37 @@ subtest "Whitespace worksheets use Bexley's custom message" => sub { } ], 'correct json returned'; }; +subtest "Whitespace worksheet, no location, with quantity" => sub { + my $ws = Test::MockModule->new('Integrations::Whitespace'); + $ws->mock(CreateWorksheet => sub { + my ($self, $args) = @_; + is $args->{quantity}, 3; + is $args->{location_of_containers}, ''; + is $args->{worksheet_message}, "Assisted collection? No\n\nLocation of containers: \n"; + return 1002; + }); + my $res = $endpoint->run_test_request( + POST => '/requests.json', + api_key => 'test', + service_code => 'Whitespace-WS2', + first_name => 'Bob', + last_name => 'Mould', + description => "This is the details", + lat => 51, + long => -1, + 'attribute[uprn]' => 1000001, + 'attribute[service_item_name]' => 'service item name', + 'attribute[fixmystreet_id]' => 'fixmystreet id', + 'attribute[assisted_yn]' => 'No', + 'attribute[quantity]' => 3, + ); + ok $res->is_success, 'valid request' + or diag $res->content; + + is_deeply decode_json($res->content), + [ { + "service_request_id" => "Whitespace-1002" + } ], 'correct json returned'; +}; + done_testing; diff --git a/t/open311/endpoint/whitespace.t b/t/open311/endpoint/whitespace.t index 164d46d16..e9d5a6eba 100644 --- a/t/open311/endpoint/whitespace.t +++ b/t/open311/endpoint/whitespace.t @@ -109,6 +109,7 @@ subtest "GET service" => sub { { code => 'fixmystreet_id', order => 3, required => 'true', variable => 'false', datatype => 'string', datatype_description => '', automated => 'server_set', description => 'external system ID' }, { code => 'assisted_yn', order => 4, required => 'false', variable => 'true', datatype => 'string', datatype_description => '', automated => 'hidden_field', description => 'Assisted collection (Yes/No)' }, { code => 'location_of_containers', order => 5, required => 'false', variable => 'true', datatype => 'string', datatype_description => '', automated => 'hidden_field', description => 'Location of containers' }, + { code => 'quantity', order => 6, required => 'false', variable => 'true', datatype => 'number', datatype_description => '', automated => 'hidden_field', description => 'Number of containers' }, ], }, 'correct json returned'; }; From 68aacc76aa90ef12b23b41dfe988beb8655881bc Mon Sep 17 00:00:00 2001 From: Victoria Mihell-Hale Date: Tue, 29 Oct 2024 11:01:25 +0000 Subject: [PATCH 2/2] [Bexley][WW] Use collection_service_id for removal requests --- perllib/Integrations/Whitespace.pm | 2 ++ 1 file changed, 2 insertions(+) diff --git a/perllib/Integrations/Whitespace.pm b/perllib/Integrations/Whitespace.pm index ab68edeba..817521313 100644 --- a/perllib/Integrations/Whitespace.pm +++ b/perllib/Integrations/Whitespace.pm @@ -102,6 +102,8 @@ sub CreateWorksheet { my $service_id = $params->{service_code} eq 'request_new_container' ? $service_params->{delivery_service_id} + : $params->{service_code} eq 'request_container_removal' + ? $service_params->{collection_service_id} : $service_params->{service_id}; my $worksheet = ixhash(