Skip to content

Commit

Permalink
Merge branch 'bexley-ww-container-requests' into staging
Browse files Browse the repository at this point in the history
  • Loading branch information
nephila-nacrea committed Nov 4, 2024
2 parents faa7ead + 68aacc7 commit 3dd2b4b
Show file tree
Hide file tree
Showing 5 changed files with 55 additions and 3 deletions.
10 changes: 8 additions & 2 deletions perllib/Integrations/Whitespace.pm
Original file line number Diff line number Diff line change
Expand Up @@ -100,17 +100,23 @@ 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}
: $params->{service_code} eq 'request_container_removal'
? $service_params->{collection_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(
'wsap:Input.CreateWorksheetInput.ServiceItemInput' => [
ixhash(
'wsap:ServiceItemId' => $service_params->{service_item_id},
'wsap:ServiceItemName' => '',
'wsap:ServiceItemQuantity' => 1,
'wsap:ServiceItemQuantity' => $params->{quantity},
)
]
),
Expand Down
5 changes: 5 additions & 0 deletions perllib/Open311/Endpoint/Integration/Whitespace.pm
Original file line number Diff line number Diff line change
Expand Up @@ -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(
Expand Down
8 changes: 7 additions & 1 deletion perllib/Open311/Endpoint/Service/UKCouncil/Whitespace.pm
Original file line number Diff line number Diff line change
Expand Up @@ -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;

34 changes: 34 additions & 0 deletions t/open311/endpoint/bexley.t
Original file line number Diff line number Diff line change
Expand Up @@ -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;
});
Expand Down Expand Up @@ -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;
1 change: 1 addition & 0 deletions t/open311/endpoint/whitespace.t
Original file line number Diff line number Diff line change
Expand Up @@ -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';
};
Expand Down

0 comments on commit 3dd2b4b

Please sign in to comment.