Skip to content

Commit

Permalink
[Kingston] Container request changes.
Browse files Browse the repository at this point in the history
There is no Replace action any longer, nor a Change capacity reason;
the reason IDs have changed.
  • Loading branch information
dracos committed Jan 18, 2025
1 parent 799aa5c commit 40affa6
Show file tree
Hide file tree
Showing 5 changed files with 70 additions and 59 deletions.
18 changes: 15 additions & 3 deletions perllib/FixMyStreet/App/Form/Waste/Request/Kingston.pm
Original file line number Diff line number Diff line change
Expand Up @@ -74,15 +74,27 @@ has_page how_many_exchange => (
fields => ['how_many_exchange', 'continue'],
title => 'Black bin size change request',
intro => 'request/intro.html',
post_process => sub {
my $form = shift;
my $data = $form->saved_data;
if ($data) {
my $how_many = $data->{"how_many_exchange"} || '';
return if $how_many eq 'less5' || $how_many eq '7more';
my $c = $form->c;
my $bin = $c->stash->{current_refuse_bin};
$data->{'container-' . CONTAINER_REFUSE_240} = 1;
$data->{'quantity-' . CONTAINER_REFUSE_240} = 1;
$data->{"container-$bin"} = 1;
$data->{"quantity-$bin"} = 0;
$data->{"removal-$bin"} = 1;
}
},
next => sub {
my $data = shift;
my $how_many = $data->{"how_many_exchange"};
if ($how_many eq 'less5' || $how_many eq '7more') {
return 'biggest_bin_allowed';
}
$data->{'container-' . CONTAINER_REFUSE_240} = 1;
$data->{'quantity-' . CONTAINER_REFUSE_240} = 1;
$data->{'removal-' . CONTAINER_REFUSE_240} = 1;
return 'about_you';
},
);
Expand Down
40 changes: 14 additions & 26 deletions perllib/FixMyStreet/Cobrand/Kingston.pm
Original file line number Diff line number Diff line change
Expand Up @@ -200,9 +200,9 @@ sub waste_munge_request_form_fields {
}

if ($id == $CONTAINERS{refuse_180}) {
$c->stash->{current_refuse_bin} = 180;
$c->stash->{current_refuse_bin} = $id;
} elsif ($id == $CONTAINERS{refuse_240}) {
$c->stash->{current_refuse_bin} = 240;
$c->stash->{current_refuse_bin} = $id;
@radio_options = ( {
value => $CONTAINERS{refuse_180},
label => 'Smaller black rubbish bin',
Expand All @@ -216,7 +216,7 @@ sub waste_munge_request_form_fields {
},
);
} elsif ($id == $CONTAINERS{refuse_360}) {
$c->stash->{current_refuse_bin} = 360;
$c->stash->{current_refuse_bin} = $id;
@radio_options = ( {
value => $CONTAINERS{refuse_180},
label => '180L black rubbish bin ‘standard’',
Expand Down Expand Up @@ -267,7 +267,10 @@ sub waste_request_form_first_next {
} else {
$data->{"container-$choice"} = 1;
$data->{"quantity-$choice"} = 1;
$data->{"removal-$choice"} = 1;
my $bin = $c->stash->{current_refuse_bin};
$data->{"container-$bin"} = 1;
$data->{"quantity-$bin"} = 0;
$data->{"removal-$bin"} = 1;
}
return 'about_you';
};
Expand All @@ -285,7 +288,7 @@ sub waste_munge_request_form_pages {
my ($self, $page_list, $field_list) = @_;
my $c = $self->{c};

if (($c->stash->{current_refuse_bin} || 0) == 180) {
if (($c->stash->{current_refuse_bin} || 0) == $CONTAINERS{refuse_180}) {
$c->stash->{first_page} = 'how_many_exchange';
}

Expand Down Expand Up @@ -374,20 +377,10 @@ sub waste_munge_request_form_data {
my $to_remove = $data->{"removal-$id"} || 0;
next unless $data->{$_} || ($id == $CONTAINERS{recycling_240} || $id == $CONTAINERS{recycling_box});

if ($quantity - $to_remove > 0) {
$new_data->{"container-$id-deliver-$_"} = 1
for 1..($quantity-$to_remove);
$new_data->{"container-$id-replace-$_"} = 1
for 1..$to_remove;
} elsif ($to_remove - $quantity > 0) {
$new_data->{"container-$id-collect-$_"} = 1
for 1..($to_remove-$quantity);
$new_data->{"container-$id-replace-$_"} = 1
for 1..$quantity;
} else { # Equal
$new_data->{"container-$id-replace-$_"} = 1
for 1..$quantity;
}
$new_data->{"container-$id-deliver-$_"} = 1
for 1..$quantity;
$new_data->{"container-$id-collect-$_"} = 1
for 1..$to_remove;
}
%$data = map { $_ => $data->{$_} } grep { !/^(container|quantity|removal)-/ } keys %$data;
%$data = (%$data, %$new_data);
Expand All @@ -407,17 +400,12 @@ sub waste_munge_request_data {
$action_id = 1; # Deliver
$reason_id = 1; # Missing (or 4 New)
} elsif ($action eq 'collect') {
$action_id = 2; # Collect
$reason_id = 3; # Change capacity
} elsif ($action eq 'replace') {
$action_id = 3; # Replace
$reason_id = $c->get_param('exchange') ? 3 : 2; # Change capacity : Damaged
$action_id = 2; # Remove
$reason_id = 8; # Remove containers
}

if ($action eq 'deliver') {
$data->{title} = "Request $container delivery";
} elsif ($action eq 'replace') {
$data->{title} = "Request $container replacement";
} else {
$data->{title} = "Request $container collection";
}
Expand Down
16 changes: 8 additions & 8 deletions perllib/FixMyStreet/Cobrand/Sutton.pm
Original file line number Diff line number Diff line change
Expand Up @@ -357,24 +357,24 @@ sub waste_munge_request_data {

my ($action_id, $reason_id);
if ($reason eq 'damaged') {
$action_id = 3; # Replace
$reason_id = 2; # Damaged
$action_id = '2::1'; # Remove/Deliver
$reason_id = '4::4'; # Damaged
} elsif ($reason eq 'missing') {
$action_id = 1; # Deliver
$reason_id = 1; # Missing
} elsif ($reason eq 'new_build') {
$action_id = 1; # Deliver
$reason_id = 4; # New
$reason_id = 6; # New Property
} elsif ($reason eq 'more') {
$action_id = 1; # Deliver
$reason_id = 3; # Change capacity
$reason_id = 9; # Increase capacity
} elsif ($reason eq 'change_capacity') {
$action_id = '2::1';
$reason_id = '3::3';
$action_id = '2::1'; # Remove/Deliver
$reason_id = '10::9'; # Reduce/Increase Capacity
if ($id == $CONTAINERS{refuse_140}) {
$id = $CONTAINERS{refuse_240} . '::' . $CONTAINERS{refuse_140};
} elsif ($id == $CONTAINERS{refuse_240}) {
if ($c->stash->{quantities}{+$CONTAINERS{refuse_360}}) {
if ($c->stash->{quantities}{$CONTAINERS{refuse_360}}) {
$id = $CONTAINERS{refuse_360} . '::' . $CONTAINERS{refuse_240};
} else {
$id = $CONTAINERS{refuse_140} . '::' . $CONTAINERS{refuse_240};
Expand All @@ -385,7 +385,7 @@ sub waste_munge_request_data {
} else {
# No reason, must be a bag
$action_id = 1; # Deliver
$reason_id = 3; # Change capacity
$reason_id = 9; # Increase capacity
$nice_reason = "Additional bag required";
}

Expand Down
49 changes: 30 additions & 19 deletions t/app/controller/waste_kingston_r.t
Original file line number Diff line number Diff line change
Expand Up @@ -210,15 +210,16 @@ FixMyStreet::override_config {
is $report->get_extra_field_value('uprn'), 1000000002;
is $report->detail, "2 Example Street, Kingston, KT1 1AA";
is $report->category, 'Request new container';
is $report->title, 'Request Green recycling box (55L) delivery';
is $report->get_extra_field_value('payment'), '1800', 'correct payment';
is $report->title, 'Request Green recycling box (55L) collection';
is $report->get_extra_field_value('payment'), '', 'correct payment';
is $report->get_extra_field_value('payment_method'), 'credit_card', 'correct payment method on report';
is $report->get_extra_field_value('Container_Type'), 12, 'correct bin type';
is $report->get_extra_field_value('Action'), 1, 'correct container request action';
is $report->get_extra_field_value('Action'), 2, 'correct container request action';
is $report->state, 'unconfirmed', 'report not confirmed';
is $report->get_extra_metadata('scpReference'), '12345', 'correct scp reference on report';

my $sent_count = 1;
my $sent_count = 0;
my $first_pay = 0;
foreach (@{ $report->get_extra_metadata('grouped_ids') }) {
my $report = FixMyStreet::DB->resultset("Problem")->find($_);
is $report->get_extra_field_value('uprn'), 1000000002;
Expand All @@ -227,14 +228,17 @@ FixMyStreet::override_config {
is $report->get_extra_field_value('payment'), '', 'correct payment';
} elsif ($report->title =~ /^Request Green recycling box/) {
is $report->get_extra_field_value('Container_Type'), 12, 'correct bin type';
is $report->get_extra_field_value('payment'), 900, 'correct payment';
is $report->get_extra_field_value('payment'), $first_pay++ ? 900 : 1800, 'correct payment';
} elsif ($report->title eq 'Request Black rubbish bin delivery') {
is $report->get_extra_field_value('Container_Type'), 3, 'correct bin type';
is $report->get_extra_field_value('payment'), 900, 'correct payment';
} elsif ($report->title eq 'Request Food waste bin (outdoor) delivery') {
is $report->get_extra_field_value('Container_Type'), 46, 'correct bin type';
is $report->get_extra_field_value('payment'), "", 'correct payment';
} elsif ($report->title eq 'Request Blue lid paper and cardboard bin (240L) replacement') {
} elsif ($report->title eq 'Request Blue lid paper and cardboard bin (240L) collection') {
is $report->get_extra_field_value('Container_Type'), 27, 'correct bin type';
is $report->get_extra_field_value('payment'), '', 'correct payment';
} elsif ($report->title eq 'Request Blue lid paper and cardboard bin (240L) delivery') {
is $report->get_extra_field_value('Container_Type'), 27, 'correct bin type';
is $report->get_extra_field_value('payment'), 900, 'correct payment';
} else {
Expand All @@ -243,9 +247,7 @@ FixMyStreet::override_config {
is $report->detail, "2 Example Street, Kingston, KT1 1AA";
is $report->category, 'Request new container';
is $report->get_extra_field_value('payment_method'), 'credit_card', 'correct payment method on report';
if ($report->title =~ /replacement$/) {
is $report->get_extra_field_value('Action'), 3, 'correct container request action';
} elsif ($report->title =~ /collection$/) {
if ($report->title =~ /collection$/) {
is $report->get_extra_field_value('Action'), 2, 'correct container request action';
} else {
is $report->get_extra_field_value('Action'), 1, 'correct container request action';
Expand All @@ -263,8 +265,8 @@ FixMyStreet::override_config {
my $req = Open311->test_req_used;
my $cgi = CGI::Simple->new($req->content);
# Not sure which one will have been sent last
like $cgi->param('attribute[Action]'), qr/^[1-3]$/;
like $cgi->param('attribute[Reason]'), qr/^[1-3]$/;
like $cgi->param('attribute[Action]'), qr/^[12]$/;
like $cgi->param('attribute[Reason]'), qr/^[18]$/;
};

subtest 'Request refuse exchange' => sub {
Expand Down Expand Up @@ -321,21 +323,30 @@ FixMyStreet::override_config {
my ( $token, $report, $report_id ) = get_report_from_redirect( $sent_params->{returnUrl} );
$mech->get_ok("/waste/pay_complete/$report_id/$token");
$mech->content_contains('request has been sent');
my $other = FixMyStreet::DB->resultset("Problem")->find($report->get_extra_metadata('grouped_ids'));
is $report->get_extra_metadata('scpReference'), '12345', 'correct scp reference on report';
($report, $other) = ($other, $report) if $_->{has} > $_->{id};
is $report->get_extra_field_value('uprn'), 1000000002;
is $report->detail, "2 Example Street, Kingston, KT1 1AA";
is $report->category, 'Request new container';
is $report->title, "Request $names{$_->{id}} replacement";
is $report->get_extra_field_value('payment'), 1800, 'correct payment';
is $report->get_extra_field_value('payment_method'), 'credit_card', 'correct payment method on report';
is $report->get_extra_field_value('Container_Type'), $_->{id}, 'correct bin type';
is $report->get_extra_field_value('Action'), 3, 'correct container request action';
is $report->get_extra_metadata('scpReference'), '12345', 'correct scp reference on report';
is $report->title, "Request $names{$_->{has}} collection";
is $report->get_extra_field_value('Container_Type'), $_->{has}, 'correct bin type';
is $report->get_extra_field_value('Action'), 2, 'correct container request action';
is $report->get_extra_field_value('payment'), "", 'no payment';
is $other->get_extra_field_value('uprn'), 1000000002;
is $other->detail, "2 Example Street, Kingston, KT1 1AA";
is $other->category, 'Request new container';
is $other->title, "Request $names{$_->{id}} delivery";
is $other->get_extra_field_value('payment'), 1800, 'correct payment';
is $other->get_extra_field_value('payment_method'), 'credit_card', 'correct payment method on report';
is $other->get_extra_field_value('Container_Type'), $_->{id}, 'correct bin type';
is $other->get_extra_field_value('Action'), 1, 'correct container request action';

FixMyStreet::Script::Reports::send();
my $req = Open311->test_req_used;
my $cgi = CGI::Simple->new($req->content);
is $cgi->param('attribute[Action]'), '3';
is $cgi->param('attribute[Reason]'), '3';
like $cgi->param('attribute[Action]'), qr/[12]/;
like $cgi->param('attribute[Reason]'), qr/[18]/;
};
}
};
Expand Down
6 changes: 3 additions & 3 deletions t/app/controller/waste_sutton_r.t
Original file line number Diff line number Diff line change
Expand Up @@ -145,7 +145,7 @@ FixMyStreet::override_config {
is $report->get_extra_field_value('payment'), 500, 'correct payment';
is $report->get_extra_field_value('payment_method'), 'credit_card', 'correct payment method on report';
is $report->get_extra_field_value('Container_Type'), 27, 'correct bin type';
is $report->get_extra_field_value('Action'), '3', 'correct container request action';
is $report->get_extra_field_value('Action'), '2::1', 'correct container request action';
is $report->state, 'unconfirmed', 'report not confirmed';
is $report->get_extra_metadata('scpReference'), '12345', 'correct scp reference on report';

Expand Down Expand Up @@ -175,7 +175,7 @@ FixMyStreet::override_config {
is $report->get_extra_field_value('payment'), 1500, 'correct payment';
is $report->get_extra_field_value('Container_Type'), '1::3', 'correct bin type';
is $report->get_extra_field_value('Action'), '2::1', 'correct container request action';
is $report->get_extra_field_value('Reason'), '3::3', 'correct container request reason';
is $report->get_extra_field_value('Reason'), '10::9', 'correct container request reason';
};
subtest 'Request a paper bin when having a 140L' => sub {
$e->mock('GetServiceUnitsForObject', sub { $bin_140_data });
Expand All @@ -200,7 +200,7 @@ FixMyStreet::override_config {
is $report->get_extra_field_value('payment'), 1500, 'correct payment';
is $report->get_extra_field_value('Container_Type'), '26::27', 'correct bin type';
is $report->get_extra_field_value('Action'), '2::1', 'correct container request action';
is $report->get_extra_field_value('Reason'), '3::3', 'correct container request reason';
is $report->get_extra_field_value('Reason'), '10::9', 'correct container request reason';
$e->mock('GetServiceUnitsForObject', sub { $bin_data });
};
subtest 'Report a new recycling raises a bin delivery request' => sub {
Expand Down

0 comments on commit 40affa6

Please sign in to comment.